-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathVideo2.vue
More file actions
225 lines (197 loc) · 5.43 KB
/
Video2.vue
File metadata and controls
225 lines (197 loc) · 5.43 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<template>
<!-- 内容上方面包屑-->
<a-breadcrumb :style="{ margin: '16px 0' }">
<a-breadcrumb-item>Video</a-breadcrumb-item>
<div class="header-left">
<a-button type="outline" status="success" shape="round" @click="handleOpenForm">
<template #icon>
<icon-apps/>
</template>
<template #default>{{ form.now_site_title }}</template>
</a-button>
<a-button type="outline" status="success" shape="round" @click="refreshPage">
<template #icon>
<icon-refresh/>
</template>
<template #default>重载源</template>
</a-button>
</div>
<!-- 中间搜索框 -->
<div class="header-center">
<a-input-search
placeholder="搜索视频"
enter-button
@search="onSearch"
style="width: 300px;"
/>
</div>
<!-- 右侧控制按钮 -->
<div class="header-right">
<a-button type="outline" status="success" shape="round" @click="minimize">
<template #icon>
<icon-bug/>
</template>
<template #default>调试</template>
</a-button>
<a-button type="outline" status="success" shape="round" @click="maximize">
<template #icon>
<icon-settings/>
</template>
<template #default>设置</template>
</a-button>
<a-button type="outline" status="success" shape="round" @click="closeWindow">
<template #icon>
<icon-user/>
</template>
<template #default>用户设置</template>
</a-button>
<!-- 当前时间显示 -->
<div class="current-time">
<span>{{ currentDateTime }}</span>
</div>
</div>
</a-breadcrumb>
<!-- 内容区域 -->
<a-layout-content class="content">
<div>
<h1>点播</h1>
<p>这是点播页面的内容。</p>
<ul v-if="form.sites.length > 0">
<li v-for="site in form.sites" :key="site.key">{{ site.name }}</li>
</ul>
<p v-else>没有站点信息。</p>
</div>
</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 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: '',
});
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 onSearch = (value) => console.log('搜索内容:', value);
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) => {
console.log('确认换源');
form.now_site = site;
setCurrentSite(site);
form.now_site_title = site.name;
form.visible = false;
};
const handleOpenForm = () => {
form.visible = true;
form.form_title = `请选择数据源(${form.sites.length})`;
checkNowSite();
};
// 页面加载时获取数据
onMounted(() => {
getData(); // 页面加载时获取数据
getNowSite(); // 获取储存的当前源
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>