content.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <!-- Header部分 -->
  4. <div v-if="headerConfig.show" class="w-100% flex content__header">
  5. <!-- 选择下拉框,自动填充剩余空间,这种实现是因为 Select 不支持 suffix -->
  6. <Dropdown
  7. v-if="headerConfig.showSelector"
  8. class="flex-grow-1 content__header_left"
  9. :trigger="['click']"
  10. :bordered="false"
  11. @open-change="headerVisible = $event"
  12. >
  13. <div class="w-100% flex flex-items-center" @click.prevent>
  14. <SwapOutlined class="w-30px" />
  15. <div class="flex-grow-1">
  16. {{ selectedDeviceLabel }}
  17. </div>
  18. <CaretUpOutlined class="w-30px" v-if="headerVisible" />
  19. <CaretDownOutlined class="w-30px" v-else />
  20. </div>
  21. <template #overlay>
  22. <Menu :selected-keys="[selectedDeviceID]" @click="headerSelectHandler">
  23. <MenuItem v-for="item in options" :key="item.value" :title="item.label">
  24. {{ item.label }}
  25. </MenuItem>
  26. </Menu>
  27. </template>
  28. </Dropdown>
  29. <template v-if="headerConfig.showSlot">
  30. <div class="flex flex-items-center flex-grow-1 content__header_right">
  31. <SwapOutlined class="w-30px" />
  32. <div class="flex-grow-1">
  33. {{ selectedDeviceSlot }}
  34. </div>
  35. </div>
  36. </template>
  37. </div>
  38. <!-- 主体内容部分 -->
  39. <div class="content" :class="{ content_without_header: !headerConfig.show }">
  40. <!-- 背景 -->
  41. <img v-if="background.show && background.type === 'image'" class="content__background" :src="background.link" />
  42. <video
  43. v-if="background.show && background.type === 'video'"
  44. class="content__background content__background_video"
  45. width="100%"
  46. autoplay
  47. loop
  48. muted
  49. >
  50. <source :src="background.link" />
  51. Not Supportted Link Or Browser
  52. </video>
  53. <template v-for="config in layoutConfig" :key="config.key">
  54. <!-- 告示板部分 -->
  55. <div v-if="config.key === 'board'" class="flex flex-justify-around pt-10px pb-10px">
  56. <MiniBoard
  57. v-for="item in config.items"
  58. :key="item.prop"
  59. :label="item.label"
  60. :value="item.value"
  61. :type="config.type"
  62. :layout="config.layout"
  63. />
  64. </div>
  65. <!-- 图表部分,这部分通常需要填充,有告示板、Header等内容需要填充父级 -->
  66. <template v-if="config.key === 'chart'">
  67. <CustomChart :chart-config="config.config" :chart-data="config.data" class="flex-grow" />
  68. </template>
  69. <!-- 通常列表部分 -->
  70. <template v-if="config.key === 'list'">
  71. <template v-if="config.type === 'timeline'">
  72. <TimelineList :list-config="config.items" />
  73. </template>
  74. <template v-else>
  75. <CustomList :type="config.type" :list-config="config.items" />
  76. </template>
  77. </template>
  78. <!-- 表格部分,这部分通常是占一整个模块的 -->
  79. <template v-if="config.key === 'table'">
  80. <CommonTable
  81. v-if="config.type === 'A'"
  82. :columns="config.columns"
  83. :data="tableData"
  84. class="mt-20px mb-10px text-center flex-grow overflow-auto"
  85. />
  86. <CustomTable
  87. v-else
  88. :type="config.type"
  89. :columns="config.columns"
  90. :data="tableData"
  91. class="mt-20px mb-10px text-center flex-grow overflow-auto"
  92. />
  93. </template>
  94. <template v-if="config.key === 'blast_delta'">
  95. <BlastDelta class="mt-10px mb-10px" :pos-monitor="blastDeltaData" :canvas-size="{ width: 250, height: 147 }" />
  96. </template>
  97. <template v-if="config.key === 'fire_control'">
  98. <FIreControl class="mt-10px mb-10px" />
  99. </template>
  100. <template v-if="config.key === 'fire_warn'">
  101. <FIreWarn class="mt-10px mb-10px" />
  102. </template>
  103. </template>
  104. </div>
  105. </template>
  106. <script lang="ts" setup>
  107. import { computed, onMounted, ref } from 'vue';
  108. import {
  109. Config,
  110. // ModuleDataBoard,
  111. // ModuleDataChart,
  112. // ModuleDataList,
  113. // ModuleDataPreset,
  114. // ModuleDataTable,
  115. } from '../../../deviceManager/configurationTable/types';
  116. import { useInitDevices } from '../hooks/useInit';
  117. import { MenuItem, Menu, Dropdown } from 'ant-design-vue';
  118. import { SwapOutlined, CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons-vue';
  119. import MiniBoard from './MiniBoard.vue';
  120. import TimelineList from './TimelineList.vue';
  121. import CustomList from './CustomList.vue';
  122. import CustomTable from './CustomTable.vue';
  123. import { getFormattedText } from '../../../deviceManager/configurationTable/adapters';
  124. import CustomChart from './CustomChart.vue';
  125. import { get, clone } from 'lodash-es';
  126. import CommonTable from '../../billboard/components/CommonTable.vue';
  127. import BlastDelta from '../../../monitorManager/deviceMonitor/components/device/modal/blastDelta.vue';
  128. import FIreWarn from './FIreWarn.vue';
  129. import FIreControl from './FIreControl.vue';
  130. import { posMonitorData } from '../configurable.data';
  131. const props = defineProps<{
  132. deviceType: Config['deviceType'];
  133. moduleData: Config['moduleData'];
  134. showStyle: Config['showStyle'];
  135. }>();
  136. const { header: headerConfig, background, layout } = props.moduleData;
  137. /** 根据配置里的layout将配置格式化为带 key 的具体配置,例如:[{ key: 'list', value: any, ...ModuleDataList }] */
  138. const layoutConfig = computed(() => {
  139. const data = selectedDevice.value;
  140. const board = clone(props.moduleData.board);
  141. const list = clone(props.moduleData.list);
  142. const chart = clone(props.moduleData.chart);
  143. const table = clone(props.moduleData.table);
  144. const preset = clone(props.moduleData.preset);
  145. return layout.reduce((arr: any[], key) => {
  146. switch (key) {
  147. case 'board': {
  148. const cfg = board[0];
  149. if (!cfg) break;
  150. arr.push({
  151. ...cfg,
  152. key,
  153. items: cfg.items.map((i) => {
  154. return {
  155. ...i,
  156. value: getFormattedText(data, i.prop, i.formatter),
  157. };
  158. }),
  159. });
  160. break;
  161. }
  162. case 'list': {
  163. const cfg = list.shift();
  164. if (!cfg) break;
  165. arr.push({
  166. ...cfg,
  167. key,
  168. items: cfg.items.map((i) => {
  169. return {
  170. ...i,
  171. value: getFormattedText(data, i.prop, i.formatter),
  172. };
  173. }),
  174. });
  175. break;
  176. }
  177. case 'chart': {
  178. const cfg = chart.shift();
  179. if (!cfg) break;
  180. arr.push({
  181. key,
  182. config: cfg,
  183. data: get(data, cfg.readFrom, []),
  184. });
  185. break;
  186. }
  187. case 'table': {
  188. const cfg = table.shift();
  189. if (!cfg) break;
  190. arr.push({
  191. ...cfg,
  192. key,
  193. columns: (cfg.columns || []).map((e) => {
  194. return {
  195. name: e.label,
  196. prop: e.prop,
  197. };
  198. }),
  199. data: get(data, cfg.readFrom, []),
  200. });
  201. break;
  202. }
  203. default: {
  204. const cfg = preset.shift();
  205. if (!cfg) break;
  206. arr.push({
  207. key,
  208. config: cfg,
  209. });
  210. break;
  211. }
  212. }
  213. return arr;
  214. }, []);
  215. });
  216. // 额外的 header 相关的变量
  217. const headerVisible = ref(false);
  218. function headerSelectHandler({ key }) {
  219. selectedDeviceID.value = key;
  220. }
  221. // 额外的告示牌相关的变量
  222. // const boardConfig = computed(() => {
  223. // const data = selectedDevice.value;
  224. // return (board || []).map((b) => {
  225. // return {
  226. // ...b.items,
  227. // value: getFormattedText(data, b.prop, b.formatter),
  228. // };
  229. // });
  230. // });
  231. // 额外的时间线列表相关的变量
  232. // const listConfig = computed(() => {
  233. // const data = selectedDevice.value;
  234. // return (list || []).map((b) => {
  235. // return {
  236. // ...b,
  237. // value: getFormattedText(data, b.prop, b.formatter),
  238. // };
  239. // });
  240. // });
  241. // const listType = computed(() => {
  242. // return list[0]?.type || 'A';
  243. // });
  244. // const chartConfig = computed(() => {
  245. // return chart[0];
  246. // });
  247. // const chartData = computed(() => {
  248. // const data = selectedDevice.value;
  249. // return get(data, chart[0]?.readFrom, []);
  250. // });
  251. // const tableConfig = computed(() => {
  252. // return {
  253. // columns: (table[0]?.columns || []).map((e) => {
  254. // return {
  255. // name: e.label,
  256. // prop: e.prop,
  257. // };
  258. // }),
  259. // };
  260. // });
  261. const tableData = computed(() => {
  262. // const data = selectedDevice.value;
  263. return [
  264. {
  265. index: '1',
  266. time: '2024/07/22 07:00',
  267. warn: '未知',
  268. cate: 'xxx综采工作面',
  269. temp: '26',
  270. wspd: '2',
  271. spst: 'ON',
  272. },
  273. {
  274. index: '2',
  275. time: '2024/07/22 08:00',
  276. warn: '未知',
  277. cate: 'xxx综采工作面',
  278. temp: '26',
  279. wspd: '2',
  280. spst: 'ON',
  281. },
  282. {
  283. index: '3',
  284. time: '2024/07/22 09:00',
  285. warn: '未知',
  286. cate: 'xxx综采工作面',
  287. temp: '26',
  288. wspd: '2',
  289. spst: 'ON',
  290. },
  291. {
  292. index: '4',
  293. time: '2024/07/22 10:00',
  294. warn: '未知',
  295. cate: 'xxx综采工作面',
  296. temp: '26',
  297. wspd: '2',
  298. spst: 'ON',
  299. },
  300. ];
  301. // return get(data, table[0]?.readFrom, []);
  302. });
  303. const blastDeltaData = ref();
  304. const { selectedDeviceID, selectedDevice, selectedDeviceSlot, selectedDeviceLabel, options, fetchDevices } = useInitDevices(
  305. props.deviceType,
  306. headerConfig
  307. );
  308. onMounted(() => {
  309. blastDeltaData.value = posMonitorData;
  310. fetchDevices();
  311. });
  312. </script>
  313. <style lang="less" scoped>
  314. @import '@/design/vent/color.less';
  315. /* Header 相关的样式 */
  316. .content__header {
  317. height: 30px;
  318. background-image: linear-gradient(90deg, #3df6ff44, transparent 20%, transparent 80%, #3df6ff44);
  319. }
  320. .content__header_left {
  321. border-left: 3px solid;
  322. border-right: 3px solid;
  323. border-image-source: linear-gradient(to top, #185f7188, #3df6ff, #185f7188);
  324. border-image-slice: 1;
  325. }
  326. .content__header_right {
  327. border-left: 3px solid;
  328. border-right: 3px solid;
  329. border-image-source: linear-gradient(to top, #185f7188, #3df6ff, #185f7188);
  330. border-image-slice: 1;
  331. min-width: 160px;
  332. }
  333. .content {
  334. height: calc(100% - 30px);
  335. position: relative;
  336. // z-index: -2;
  337. display: flex;
  338. flex-direction: column;
  339. }
  340. .content_without_header {
  341. height: 100%;
  342. }
  343. .content__background {
  344. width: 100%;
  345. height: 100%;
  346. position: absolute;
  347. top: 0;
  348. left: 0;
  349. z-index: -1;
  350. object-fit: fill;
  351. }
  352. ::v-deep .zxm-select:not(.zxm-select-customize-input) .zxm-select-selector {
  353. /* background-color: transparent; */
  354. color: #fff;
  355. }
  356. ::v-deep .zxm-select-arrow {
  357. color: #fff;
  358. }
  359. ::v-deep .zxm-select-selection-item {
  360. color: #fff !important;
  361. }
  362. ::v-deep .zxm-select-selection-placeholder {
  363. color: #fff !important;
  364. }
  365. </style>