index.vue
19.2 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<template>
<div class="navbar">
<div class="left-side">
<a-space>
<template v-if="!topMenu && appStore.device === 'mobile'">
<component :is="drawerVisible ? 'icon-menu-fold' : 'icon-menu-unfold'" class="menu-icon" size="20"
@click="toggleDrawerMenu"/>
</template>
<!-- <a-select v-model="companyValue" :trigger-props="{ autoFitPopupMinWidth: true }" size="large" placeholder="请选择站点"
@change="companyChange">
<a-option v-for="item in companyList" :key="item.id" :value="item.id" :label="item.deptName" />
</a-select> -->
<a-tree-select v-model="companyValue" :allow-clear="false" :data="companyList" :dropdown-style="{}"
:fieldNames="{
key: 'id', title: 'deptName', children: 'children'
}"
:filter-tree-node="filterTreeNode" allow-search placeholder="请选择站点"
@change="companyChange"></a-tree-select>
</a-space>
</div>
<div class="center-side">
<Menu v-if="topMenu"/>
</div>
<ul class="right-side">
<!-- <li>
<a-tooltip :content="$t('settings.search')">
<a-button class="nav-btn" type="outline" :shape="'circle'">
<template #icon>
<icon-search />
</template>
</a-button>
</a-tooltip>
</li> -->
<li>
<a-tooltip :content="$t('settings.language')">
<a-button
:shape="'circle'"
class="nav-btn"
type="outline"
@click="setDropDownVisible"
>
<template #icon>
<icon-language/>
</template>
</a-button>
</a-tooltip>
<a-dropdown trigger="click" @select="changeLocale as any">
<div ref="triggerBtn" class="trigger-btn"></div>
<template #content>
<a-doption
v-for="item in locales"
:key="item.value"
:value="item.value"
>
<template #icon>
<icon-check v-show="item.value === currentLocale"/>
</template>
{{ item.label }}
</a-doption>
</template>
</a-dropdown>
</li>
<li>
<a-tooltip :content="theme === 'light'
? $t('settings.navbar.theme.toDark')
: $t('settings.navbar.theme.toLight')
">
<a-button :shape="'circle'" class="nav-btn" type="outline" @click="handleToggleTheme">
<template #icon>
<icon-moon-fill v-if="theme === 'dark'"/>
<icon-sun-fill v-else/>
</template>
</a-button>
</a-tooltip>
</li>
<li>
<a-tooltip :content="$t('settings.navbar.alerts')">
<div class="message-box-trigger">
<a-badge :count="warnCount" dot>
<a-button
class="nav-btn"
type="outline"
:shape="'circle'"
@click="setPopoverVisible"
>
<icon-notification/>
</a-button>
</a-badge>
</div>
</a-tooltip>
<!-- <a-popover-->
<!-- trigger="click"-->
<!-- :arrow-style="{ display: 'none' }"-->
<!-- :content-style="{ padding: 0, minWidth: '400px' }"-->
<!-- content-class="message-popover"-->
<!-- >-->
<!-- <div ref="refBtn" class="ref-btn"></div>-->
<!-- <template #content>-->
<!-- <message-box/>-->
<!-- </template>-->
<!-- </a-popover>-->
</li>
<!-- <li>-->
<!-- <a-tooltip :content="$t('settings.navbar.toMotif')" position="bottom">-->
<!-- <a-button :shape="'circle'" class="nav-btn" type="outline" @click="toggleMotif">-->
<!-- <template #icon>-->
<!-- <icon-skin/>-->
<!-- </template>-->
<!-- </a-button>-->
<!-- </a-tooltip>-->
<!-- </li>-->
<li>
<a-tooltip :content="isFullscreen
? $t('settings.navbar.screen.toExit')
: $t('settings.navbar.screen.toFull')
">
<a-button :shape="'circle'" class="nav-btn" type="outline" @click="toggleFullScreen">
<template #icon>
<icon-fullscreen-exit v-if="isFullscreen"/>
<icon-fullscreen v-else/>
</template>
</a-button>
</a-tooltip>
</li>
<li>
<a-dropdown trigger="click">
<div class="avatar-container">
<a-avatar :size="32" :style="{ marginRight: '8px', cursor: 'pointer' }">
<img :alt="userName" :src="avatar"/>
</a-avatar>
<p style="color:var(--color-neutral-9);">{{ userName }}</p>
</div>
<template #content>
<a-doption>
<div @click="handleMessage">
<icon-user/>
<span style="margin-left: 2px">个人信息</span>
</div>
</a-doption>
<a-doption>
<div @click="handleLogout">
<icon-export/>
<span style="margin-left: 2px"> {{ $t('messageBox.logout') }}</span>
</div>
</a-doption>
</template>
</a-dropdown>
</li>
</ul>
</div>
<reset-password/>
<!-- 换肤抽屉-->
<a-modal v-model:visible="motifVisible" :footer="false" width="900px">
<template #title>
<div class="theme-box-header">
{{ $t('settings.navbar.theme.title') }}
<a-input :style="{width:'220px'}" @input="searchMotif" allow-clear/>
</div>
</template>
<a-spin :loading="modalLoading" class="lab-grid-view">
<a-grid :colGap="12" :cols="{ xs: 1, sm: 2, md: 3 }" :rowGap="16" class="lab-grid-view">
<a-grid-item v-for="(item,index) in motifData.list" :key="index">
<a-card>
<template #cover>
<img :src="item.cover"
:style="{ width: '100%', height: '160px' }"
alt="dessert"
/>
</template>
<a-typography-paragraph ellipsis>
{{ item.themeName }}
</a-typography-paragraph>
<a-tag color="arcoblue" bordered v-if="item.packageName === localMotif.packageName">
{{ $t('settings.navbar.theme.currentThemes') }}
</a-tag>
<a-button size="mini" type="primary" @click="changeTheme(item)" v-else>
{{ $t('settings.navbar.theme.install') }}
</a-button>
</a-card>
</a-grid-item>
</a-grid>
<a-row>
<a-col :span="12">
<a-button size="small" type="primary" @click="resetTheme">{{
$t('settings.navbar.theme.resetTheme')
}}
</a-button>
</a-col>
<a-col :span="12">
<a-pagination :current="motifPage.currentPage"
:page-size="motifPage.pageSize"
:total="motifData.total"
style="justify-content: flex-end;"
@change="handlePageChange"/>
</a-col>
</a-row>
</a-spin>
</a-modal>
</template>
<script lang="ts" setup>
import Menu from '@/components/menu/index.vue'
import useLocale from '@/hooks/locale'
import useUser from '@/hooks/user'
import {LOCALE_OPTIONS} from '@/locale'
import {useAppStore, useCompanyStore, useThemeStore, useUserStore} from '@/store'
import {Message, Notification} from '@arco-design/web-vue'
import { useFullscreen } from '@vueuse/core'
import {computed, h, inject, nextTick, onMounted, onUnmounted, ref, watch} from 'vue'
import {storeToRefs} from 'pinia'
import {changeTheme, resetTheme, updateLinkTag} from '@/utils/changeTheme'
import {findById} from '@/utils/ruoyi'
import {getThemesList} from "@/api/user";
import useLoading from "@/hooks/loading";
import ResetPassword from "@/components/reset-password/index.vue";
import {DeviceVarAlarmMessage, SocketData} from "@/api/websocketService";
import {useRoute, useRouter} from "vue-router";
import {useDebounceFn} from '@vueuse/core'
defineProps({
drawerVisible: {
type: Boolean,
default: false
}
});
const router = useRouter();
const route = useRoute();
const appStore = useAppStore();
const userStore = useUserStore();
const companyStore = useCompanyStore();
const {companyValue, companyList, selectCompany} = storeToRefs(companyStore); // 选择的机构, 机构列表
const {setCompanyList, updateCompanyValue} = companyStore; // 设置机构
const {logout} = useUser();
const {changeLocale, currentLocale} = useLocale();
const {isFullscreen, toggle: toggleFullScreen} = useFullscreen();
const locales = [...LOCALE_OPTIONS];
const avatar = computed(() => {
return userStore.user.headPic ? userStore.user.headPic : loadImage()
});
const userName = computed(() => {
return userStore.user.nickName;
})
const refBtn = ref()
const triggerBtn = ref()
const theme = computed(() => {
return appStore.theme
})
const topMenu = computed(() => appStore.topMenu && appStore.menu)
const renderFatherMenu = computed(() => appStore.appAsyncFatherMenu);
// 切换主题 弹框
const motifVisible = ref<boolean>(false);
// 主题列表
const motifData = ref<any>({
total: 0,
list: []
})
const motifPage = ref({
currentPage: 1,
pageSize: 6,
});
const {loading: modalLoading, setLoading} = useLoading(false);
const localMotif = computed<any>(() => {
return useThemeStore().themePackage
})
const warnCount = ref(0);
if (localMotif.value._id) {
updateLinkTag(localMotif.value)
}
/**
* 加载图片
*/
const loadImage = () => {
const result = (userStore.user.id % 80) + 1;
const resultFormat = result.toString().padStart(2, '0');
const path = `/src/assets/heads/head_${resultFormat}.jpg`;
const modules: Record<string, any> = import.meta.glob("@/assets/heads/*.{png,svg,jpg,jpeg}", {eager: true});
if (modules[path]) {
return modules[path].default;
} else {
// 地址错误
console.error("头像地址错误");
}
}
/**
* 左补零
* @param val 值
* @param targetLength 长度
*/
const padLeft = (val: number, targetLength: number) => {
return val.toString().padStart(targetLength, '0');
}
const handleToggleTheme = () => {
appStore.toggleTheme(appStore.theme !== 'dark');
}
const setVisible = () => {
appStore.updateSettings({globalSettings: true})
}
/**
* 站点搜索
* @param searchValue
* @param nodeData
*/
const filterTreeNode = (searchValue: any, nodeData: any) => {
return nodeData.deptName.toLowerCase().indexOf(searchValue.toLowerCase()) > -1;
}
const reload = inject('reload') as () => void
// 机构下拉框change
const companyChange = async (val: any) => {
const findData = findById(companyList.value, val);
let res = await updateCompanyValue(findData)
if (res.code == 200) {
reload();
}
}
const handleLogout = () => {
logout();
}
const handleMessage = () => {
router.push({
path: '/user/profile/setting'
})
}
// 打开主题弹窗
const toggleMotif = () => {
motifVisible.value = true;
setThemesList()
}
const searchMotif = useDebounceFn((keyword?: string) => {
setThemesList(keyword)
}, 500)
// 获得主题包
const setThemesList = async (keyword?: string) => {
try {
setLoading(true)
const params = {
...motifPage.value,
depLibrary: '@arco-design/web-vue',
keyword
}
motifData.value = await getThemesList(params);
} catch (e) {
} finally {
setLoading(false)
}
}
const handlePageChange = (val: number) => {
motifPage.value.currentPage = val;
setThemesList()
}
const setDropDownVisible = () => {
const event = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
})
triggerBtn.value.dispatchEvent(event)
}
const switchRoles = async () => {
const res = await userStore.switchRoles()
Message.success(res as string)
}
const toggleDrawerMenu = inject('toggleDrawerMenu') as () => void
// 使用 h 函数构建 VNode
const renderContent = (data: DeviceVarAlarmMessage) => {
return h(
'div',
null,
[
h('p', null, [h('strong', null, '站点:'), ' ', data.stationName]),
h('p', null, [h('strong', null, '设备:'), ' ', `${data.deviceName} ${data.deviceVarName}`]),
h(
'p',
null,
[
h('strong', null, '类型:'),
' ',
h('span', {style: {color: 'rgb(var(--orange-6))'}}, data.categoryName)
]
),
h('p', null, [h('strong', null, '信息:'), ' ', data.content]),
h('p', null, [h('strong', null, '时间:'), ' ', data.happenTime]),
]
);
}
const isChildOf = (child: any, parent: any) => {
var el = child;
while ((el = el.parentElement) && el !== parent) {
}
return el === parent;
}
const startNotificationTimer = (newVal: DeviceVarAlarmMessage) => {
Notification.info({
title: newVal.triggerLevelName,
content: () => renderContent(newVal),
closable: true,
duration: 1000 * 60
})
warnCount.value = 1;
// 通知在最上面
nextTick(() => {
const elementContainer: any = document.querySelector('.arco-notification-list');
if (!elementContainer) return;
elementContainer.style.top = "50px";
const lastElement = elementContainer.lastElementChild;
if (!lastElement) return;
var closeElement = lastElement.querySelector('.arco-icon-close');
var notificationLeftElement = lastElement.querySelector('.arco-notification-left');
var titleElement = lastElement.querySelector('.arco-notification-title');
var contentElement = lastElement.querySelector('.arco-notification-content');
notificationLeftElement.style.display = "none";
// 当前选中报警
const lastStylePorps = {
position: 'relative',
paddingTop: '40px',
marginBottom: '10px',
background: '#fff',
}
// 当前content
const contentStyleProps = {
color: '#666',
paddingBottom: '0',
}
// 关闭按钮
const closeProps = {
width: '20px',
height: '20px',
}
// 设置title背景
const styleProps = {
position: 'absolute',
left: '0',
top: '0',
width: '100%',
height: '40px',
lineHeight: '40px',
paddingLeft: '20px',
backgroundColor: newVal.triggerStatus == 0 && newVal.triggerLevel == 100 ? 'rgb(var(--red-6))' : newVal.triggerStatus == 0 && newVal.triggerLevel > 100 ? 'rgb(var(--orange-6))' : 'rgb(var(--arcoblue-6))',
color: '#fff',
};
// 添加点击事件监听器
lastElement.addEventListener('click', function (event: any) {
const classes = event.target.classList;
if (!event.target.matches('.arco-icon-close') && !classes.contains(closeElement) && !isChildOf(event.target, closeElement)) {
const aaa: any = renderFatherMenu.value.find(item => item.props?.stationType == newVal.stationType);
console.log(aaa.path)
// 创建一个新的 MouseEvent 对象
const clickEvent = new MouseEvent('click', {
bubbles: true, // 这里可以保留,但我们将手动阻止冒泡
cancelable: true,
view: window
});
// 路由替换
router.replace({
path: `${aaa.path}/alarm/list`
});
// 触发 click 事件
setTimeout(() => {
closeElement.dispatchEvent(clickEvent);
warnCount.value = 0;
}, 1000 * 2)
} else {
return false;
}
});
Object.assign(titleElement.style, styleProps);
Object.assign(lastElement.style, lastStylePorps);
Object.assign(contentElement.style, contentStyleProps);
Object.assign(closeElement.style, closeProps);
elementContainer.insertBefore(lastElement, elementContainer.firstChild);
})
};
// WebSocket 数据
const {data, sendData}: SocketData = inject('webSocketData', {
data: {value: 0},
sendData: () => {
}
});
// 订阅
const subscribe = () => {
sendData({
action: 'subscribe',
bizSn: selectCompany.value.deptSn
});
}
// 取消订阅
const onSubscribe = () => {
sendData({
action: 'unsubscribe',
bizSn: selectCompany.value.deptSn
});
}
const setPopoverVisible = () => {
const aaa: any = renderFatherMenu.value.find(item => selectCompany.value.stationType && item.props?.stationType == selectCompany.value.stationType);
router.replace({
path: `${aaa.path}/alarm/list`
});
const elementContainer: any = document.querySelector('.arco-notification-list');
if (elementContainer) elementContainer.style.display = "none";
warnCount.value = 0;
}
watch(data, async (newVal: any) => {
if (selectCompany.value.deptSn && newVal.stationSn == selectCompany.value.deptSn) {
startNotificationTimer(newVal);
}
});
onMounted(async () => {
// 设置公司列表
// startNotificationTimer({
// stationName: '红太阳广电',
// deviceName: 'D1',
// deviceVarName: '三相电压',
// categoryName: '电流过低',
// content: '【D1 D1.1b】205.849三相电压过低',
// happenTime: '2024-8-24 12:00',
// triggerStatusName: '已完成',
// triggerLevelName: '二级报警',
// triggerStatus: 0,
// triggerLevel: 101
// });
await setCompanyList();
subscribe();
})
onUnmounted(() => {
onSubscribe();
})
</script>
<style lang="less" scoped>
.navbar {
display: flex;
justify-content: space-between;
height: 100%;
background-color: var(--color-bg-2);
border-bottom: 1px solid var(--color-border);
}
.left-side {
display: flex;
align-items: center;
padding-left: 10px;
}
.center-side {
flex: 1;
}
.right-side {
display: flex;
padding-right: 20px;
list-style: none;
:deep(.locale-select) {
border-radius: 20px;
}
li {
display: flex;
align-items: center;
padding: 0 10px;
}
a {
color: var(--color-text-1);
text-decoration: none;
}
.nav-btn {
color: rgb(var(--gray-8));
font-size: 16px;
border-color: rgb(var(--gray-3));
}
.trigger-btn,
.ref-btn {
position: absolute;
bottom: 14px;
}
.trigger-btn {
margin-left: 14px;
}
}
.message-popover {
.arco-popover-content {
margin-top: 0;
}
}
:deep(.arco-select-view-single) {
border: none;
background-color: transparent;
border-radius: 0;
.arco-select-view-suffix .arco-select-view-icon svg {
font-size: 18px
}
}
.lab-box {
margin-top: 10px;
display: flex;
align-items: center;
div {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
margin-right: 10px;
width: 20px;
height: 20px;
border-radius: 3px;
}
}
.menu-icon {
cursor: pointer;
color: var(--color-text-1)
}
.lab-grid-view {
height: 550px;
width: 100%;
}
.custom-close-button {
width: 26px !important;
height: 26px !important;
border-radius: 50% !important;
background: red !important;
text-align: center;
line-height: 26px;
}
.theme-box-header {
width: 100%;
padding-right: 24px;
display: flex;
justify-content: space-between;
align-items: center
}
.avatar-container {
width: 100%;
display: flex;
align-items: center;
p {
max-width: 80px;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>