index.vue
10.8 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
<script lang="ts" setup>
import { onMounted, unref } from 'vue';
import { ref } from 'vue';
import { Empty, Spin, Button } from 'ant-design-vue';
import { getBoundingClientRect } from '/@/utils/domUtils';
import { GridItem, GridLayout } from 'vue3-grid-layout';
import {
DEFAULT_MAX_COL,
DEFAULT_MIN_HEIGHT,
DEFAULT_MIN_WIDTH,
DEFAULT_ITEM_MARIGN,
VisualComponentPermission,
PHONE_SIZE,
} from './index';
import { useDragGridLayout } from './hooks/useDragGridLayout';
import { WidgetHeader, WidgetWrapper } from './components/WidgetWrapper';
import { computed } from 'vue';
import { WidgetDataType, useDataSource } from './hooks/useDataSource';
import { WidgetDistribute } from './components/WidgetDistribute';
import { DataSourceBindPanel } from '../dataSourceBindPanel';
import { PageHeader } from './components/PagerHeader';
import { useShare } from './hooks/useShare';
import { useApp } from './hooks/useApp';
import { useRole } from '/@/hooks/business/useRole';
import { Authority } from '/@/components/Authority';
import { useModal } from '/@/components/Modal';
import { ModalParamsType } from '/#/utils';
import { DataActionModeEnum } from '/@/enums/toolEnum';
import { HistoryTrendModal } from './components/HistoryTrendModal';
import { AlarmTimeModal } from './components/AlarmTimeModal';
import { watch } from 'vue';
import { useRootSetting } from '/@/hooks/setting/useRootSetting';
import { ThemeEnum } from '/@/enums/appEnum';
import { createDataBoardContext } from './hooks/useDataBoardContext';
import { useSocket } from '/@/views/visual/packages/hook/socket/useSocket';
import { createAlarmContext } from './hooks/useAlarmTime';
import { createHistoryContext } from './hooks/useHistoryForm';
import { MoreOutlined, LeftOutlined } from '@ant-design/icons-vue';
import WIFISVG from '/@/assets/svg/wifi.svg';
import SIGNALSVG from '/@/assets/svg/signal.svg';
import BATTERYSVG from '/@/assets/svg/battery.svg';
import { useRoute } from 'vue-router';
import { createDeviceProfileQueryContext } from './hooks/useDeviceProfileQueryContext';
const props = defineProps<{
value?: Recordable;
}>();
const getProps = computed(() => props);
const containerRefEl = ref<Nullable<HTMLDivElement>>(null);
const containerRectRef = ref<DOMRect>({} as unknown as DOMRect);
const ROUTE = useRoute();
const {
loading,
draggable,
resizable,
dataSource,
rawDataSource,
setLayoutInfo,
getDataSource,
getDeviceProfileDetailById,
getDeviceProfileTslByIdWithIdentifier,
} = useDataSource(getProps);
const { resize, resized, moved, containerResized } = useDragGridLayout(dataSource, setLayoutInfo);
const [register, { openModal }] = useModal();
const [registerTrendModal, { openModal: openTrendModal }] = useModal();
/**
* @description 获取画板宽高
*/
onMounted(() => {
const rect = getBoundingClientRect(unref(containerRefEl)!);
if (rect) {
containerRectRef.value = rect as DOMRect;
}
});
const { getIsSharePage } = useShare();
// getIsAppPage 是否是小程序进入的页面 isPhone 是否是创建的手机端
const { getIsAppPage, isPhone } = useApp();
const { isCustomerUser } = useRole();
const handleOpenCreatePanel = () => {
openModal(true, { mode: DataActionModeEnum.CREATE } as ModalParamsType);
};
const handleUpdateWidget = (data: WidgetDataType) => {
openModal(true, { mode: DataActionModeEnum.UPDATE, record: data } as ModalParamsType);
};
const handleOpenTrend = (data: WidgetDataType) => {
openTrendModal(true, { mode: DataActionModeEnum.READ, record: data } as ModalParamsType);
};
// 设备告警时间选择
const [registerAlarmModal, { openModal: openAlarmModal }] = useModal();
const handleOpenAlarm = (data: WidgetDataType) => {
openAlarmModal(true, { mode: DataActionModeEnum.READ, record: data } as ModalParamsType);
};
const alarmForm = ref<{
time?: number | string;
pageSize: number;
startTs?: number | string;
endTs?: string | number;
}>({
time: 2592000000,
pageSize: 20,
startTs: undefined,
endTs: undefined,
});
//告警发送数据
const getAlarmForm = (values) => {
const { way, pageSize, startTs, endTs } = values;
if (way == 'timePeriod') {
alarmForm.value = {
time: undefined,
startTs,
endTs,
pageSize,
};
} else
alarmForm.value = {
time: startTs,
pageSize,
startTs: undefined,
endTs: undefined,
};
};
createAlarmContext({ alarmForm: alarmForm });
// 历史数据发送
const historyForm = ref({
startTs: Date.now() - 30 * 24 * 60 * 60 * 1000,
endTs: Date.now(),
agg: 'NONE',
limit: 30,
interval: undefined,
way: 'latest',
});
const getHistoryForm = (values) => {
const { startTs, endTs, agg, limit, interval, way } = values;
historyForm.value = {
startTs,
endTs,
agg,
limit,
interval,
way,
};
if (way === 'latest') {
historyForm.value.startTs = Date.now() - startTs;
historyForm.value.endTs = Date.now();
}
};
createHistoryContext({ historyForm: historyForm, getHistoryForm });
const { send, close } = useSocket(dataSource);
createDataBoardContext({ send, close });
createDeviceProfileQueryContext({
getDeviceProfileDetailById,
getDeviceProfileTslByIdWithIdentifier,
});
const { getDarkMode } = useRootSetting();
watch(
getIsSharePage,
(value) => {
if (value) {
const root = document.querySelector('#app');
(root as HTMLDivElement).style.backgroundColor =
unref(getDarkMode) === ThemeEnum.LIGHT ? '#F5F5F5' : '#1b1b1b';
}
},
{ immediate: true }
);
watch(
getIsAppPage,
(value) => {
if (value) {
const root = document.querySelector('#app');
(root as HTMLDivElement).style.backgroundColor =
unref(getDarkMode) === ThemeEnum.LIGHT ? '#F5F5F5' : '#1b1b1b';
}
},
{ immediate: true }
);
const getDataBoardName = computed(() => {
return decodeURIComponent((ROUTE.params as { boardName: string }).boardName || '');
});
const phoneSize = ref({
width: 375,
height: 667,
});
</script>
<template>
<section
ref="containerRefEl"
class="palette w-full h-full flex-col bg-neutral-100 flex dark:bg-dark-700 dark:text-light-50"
>
<PageHeader v-if="!getIsAppPage" :widget-number="dataSource.length">
<Authority :value="VisualComponentPermission.CREATE">
<Button
v-if="!getIsSharePage && !isCustomerUser"
type="primary"
@click="handleOpenCreatePanel"
>
创建组件
</Button>
</Authority>
</PageHeader>
<Spin :spinning="loading">
<div class="w-full h-full flex justify-center items-center mb-3">
<div
:style="
!getIsAppPage && isPhone()
? {
width: phoneSize.width + 'px',
height: phoneSize.height + 'px',
border: '2px solid #e5e7eb',
}
: { width: '100%', height: '100%' }
"
style="border-radius: 1%"
>
<!-- 手机端的模拟样式 -->
<div
v-if="!getIsAppPage && isPhone()"
style="height: 60px; background: white"
class="px-1 py-1 relative"
>
<div class="flex justify-between">
<div>thingskit</div>
<div class="flex items-center">
<img :src="WIFISVG" alt="" class="w-3 h-3" />
<img :src="SIGNALSVG" alt="" class="w-3 h-3 mx-1" />
<img :src="BATTERYSVG" alt="" class="w-4 h-4 rotate-45" />
<h1 class="mb-0">18:13</h1>
</div>
</div>
<div class="flex items-center justify-between">
<LeftOutlined class="transform cursor-pointer text-lg" />
<h1 class="font-bold">{{ getDataBoardName }}</h1>
<MoreOutlined class="transform rotate-90 cursor-pointer text-lg" />
</div>
</div>
<div
id="appLayoutId"
:style="
!getIsAppPage && isPhone() ? { height: `calc(${phoneSize.height}px - 67px)` } : {}
"
class="overflow-y-scroll"
>
<GridLayout
v-model:layout="dataSource"
:col-num="DEFAULT_MAX_COL"
:row-height="30"
:margin="[DEFAULT_ITEM_MARIGN, DEFAULT_ITEM_MARIGN]"
:is-draggable="draggable"
:is-resizable="resizable"
:vertical-compact="true"
:use-css-transforms="true"
style="width: 100%"
:style="{
'--is-app': getIsAppPage ? 'auto' : 'none',
}"
>
<GridItem
v-for="item in dataSource"
:key="item.i"
:static="item.static"
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:i="item.i"
:min-h="isPhone() ? PHONE_SIZE.DEFAULT_MIN_HEIGHT : DEFAULT_MIN_HEIGHT"
:min-w="isPhone() ? PHONE_SIZE.DEFAULT_MIN_WIDTH : DEFAULT_MIN_WIDTH"
:style="{ display: 'flex', flexWrap: 'wrap' }"
class="grid-item-layout"
@resized="resized"
@resize="resize"
@moved="moved"
@container-resized="containerResized"
drag-ignore-from=".no-drag"
>
<WidgetWrapper>
<template #header>
<WidgetHeader
:raw-data-source="rawDataSource"
:source-info="item"
@update="handleUpdateWidget"
@open-trend="handleOpenTrend"
@open-alarm="handleOpenAlarm"
@ok="getDataSource"
/>
</template>
<WidgetDistribute :source-info="item" />
</WidgetWrapper>
</GridItem>
</GridLayout>
</div>
<Empty
v-if="!dataSource.length"
:class="isPhone() ? 'absolute' : 'fixed'"
class="top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
/>
</div>
</div>
</Spin>
<DataSourceBindPanel @register="register" :layout="dataSource" @ok="getDataSource" />
<!-- 趋势 -->
<HistoryTrendModal @register="registerTrendModal" />
<!-- 选择时间 -->
<AlarmTimeModal @register="registerAlarmModal" @getAlarmForm="getAlarmForm" />
</section>
</template>
<style lang="less">
.vue-grid-item {
pointer-events: painted;
touch-action: var(--is-app) !important;
}
</style>