-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathVideo2.vue
More file actions
198 lines (175 loc) · 4.46 KB
/
Video2.vue
File metadata and controls
198 lines (175 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<template>
<Breadcrumb
@handleOpenForm="handleOpenForm"
@refreshPage="refreshPage"
@minimize="minimize"
@maximize="maximize"
@closeWindow="closeWindow"
@onSearch="onSearch"
:now_site_title="form.now_site_title"
>
<!-- 默认插槽的内容放这里 -->
<div class="current-time">
<span>{{ currentDateTime }}</span>
</div>
</Breadcrumb>
<!-- 内容区域 -->
<a-layout-content class="content">
<VideoList :classList="form.classList" />
</a-layout-content>
<SourceDialog
:visible="form.visible"
:title="form.form_title"
:sites="form.sites"
:currentSiteKey="form.now_site.key"
@update:visible="(val) => (form.visible = val)"
@confirm-clear="handleConfirmClear"
@confirm-change="handleConfirmChange"
@change-rule="handleChangeRule"
/>
</template>
<script setup>
import { ref, reactive, onMounted, onBeforeUnmount } from "vue";
import SourceDialog from "../components/SourceDialog.vue";
import Breadcrumb from "../components/Breadcrumb.vue";
import VideoList from "../components/VideoList.vue";
import req from "@/utils/req";
import { useSiteStore } from "@/stores/siteStore";
const { nowSite, setCurrentSite } = useSiteStore();
const currentDateTime = ref("");
const form = reactive({
sites: [],
now_site_title: "hipy影视",
now_site: {},
visible: false,
form_title: "",
classList: {},
videoList: {},
});
const timer = ref(null);
const getData = async () => {
try {
let response;
if (req.defaults.baseURL === "") {
response = await req.get("/mock/data.json");
response = response.config;
} else {
response = await req.get("/config"); // 假设这个请求返回 sites 数组
}
form.sites = response.sites; // 给 form.sites 赋值
} catch (error) {
console.error("请求数据失败:", error);
}
};
const getNowSite = () => {
if (nowSite && nowSite.name) {
form.now_site = nowSite;
form.now_site_title = nowSite.name;
}
};
const checkNowSite = () => {
form.new_site = form.now_site;
if (!form.new_site.key && form.sites.length > 0) {
form.new_site = form.sites[0];
} else if (
form.new_site.key &&
!form.sites.map((i) => i.key).includes(form.new_site.key)
) {
form.new_site = form.sites[0];
}
};
const formatDate = (date) => {
const options = {
weekday: "long", // 星期几
year: "numeric",
month: "numeric",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: true, // 12小时制
};
return date.toLocaleString("zh-CN", options);
};
// 启动定时器
const startClock = () => {
timer.value = setInterval(() => {
currentDateTime.value = formatDate(new Date());
}, 1000); // 每秒更新时间
};
const refreshPage = () => {
window.location.reload();
};
const minimize = () => {};
const maximize = () => {};
const closeWindow = () => {};
const handleChangeRule = (site) => (form.new_site = site);
const handleConfirmClear = () => {
form.now_site = form.new_site;
setCurrentSite(form.now_site);
form.visible = false;
getData();
checkNowSite();
};
const handleConfirmChange = (site) => {
form.now_site = site;
setCurrentSite(site);
form.now_site_title = site.name;
form.visible = false;
getClassList(site); //获取分类列表
};
//获取分类列表
const getClassList = async (site) => {
console.log(site, "确认换源");
let response;
if (req.defaults.baseURL === "") {
response = await req.get("/mock/data.json");
form.classList = response.home;
} else {
response = await req.get("/home");
form.classList = response;
}
console.log(form.classList);
};
const onSearch = (value) => {
console.log("搜索内容:", value);
};
const handleOpenForm = () => {
form.visible = true;
form.form_title = `请选择数据源(${form.sites.length})`;
checkNowSite();
};
// 页面加载时获取数据
onMounted(() => {
getData(); // 页面加载时获取数据
getNowSite(); // 获取储存的当前源
getClassList(form.now_site);
startClock(); // 启动时钟
});
// 清理定时器
onBeforeUnmount(() => {
if (timer.value) {
clearInterval(timer.value); // 销毁时清除定时器
}
});
</script>
<style scoped>
/* 样式代码 */
.header-left,
.header-right {
display: flex;
align-items: center;
}
.header-left button,
.header-right button {
margin-right: 10px;
}
.header-center {
flex-grow: 1;
display: flex;
justify-content: center;
}
.header-center a-input-search {
width: 300px;
}
</style>