content.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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="content__module 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 class="content__module flex-grow" :chart-config="config.config" :chart-data="config.data" />
  68. </template>
  69. <!-- 通常列表部分 -->
  70. <template v-if="config.key === 'list'">
  71. <template v-if="config.type === 'timeline'">
  72. <TimelineList class="content__module" :list-config="config.items" />
  73. </template>
  74. <template v-else>
  75. <CustomList class="content__module" :type="config.type" :list-config="config.items" />
  76. </template>
  77. </template>
  78. <!-- 画廊部分 -->
  79. <template v-if="config.key === 'gallery'">
  80. <CustomGallery class="content__module" :type="config.type" :gallery-config="config.items" />
  81. </template>
  82. <!-- 复杂列表部分 -->
  83. <template v-if="config.key === 'complex_list'">
  84. <ComplexList class="content__module" :type="config.type" :list-config="config.items" :gallery-config="config.galleryItems" />
  85. </template>
  86. <!-- 表格部分,这部分通常是占一整个模块的 -->
  87. <template v-if="config.key === 'table'">
  88. <CommonTable
  89. v-if="config.type === 'A'"
  90. :columns="config.columns"
  91. :data="config.data"
  92. class="content__module text-center flex-grow overflow-auto"
  93. />
  94. <CustomTable
  95. v-else
  96. :type="config.type"
  97. :columns="config.columns"
  98. :data="config.data"
  99. class="content__module text-center flex-grow overflow-auto"
  100. />
  101. </template>
  102. <template v-if="config.key === 'blast_delta'">
  103. <BlastDelta class="content__module" :pos-monitor="config.config.mock" :canvas-size="{ width: 250, height: 137 }" />
  104. </template>
  105. <template v-if="config.key === 'fire_control'">
  106. <FIreControl class="content__module" />
  107. </template>
  108. <template v-if="config.key === 'fire_warn'">
  109. <FIreWarn class="content__module" />
  110. </template>
  111. </template>
  112. </div>
  113. </template>
  114. <script lang="ts" setup>
  115. import { computed, onMounted, ref } from 'vue';
  116. import {
  117. Config,
  118. // ModuleDataBoard,
  119. // ModuleDataChart,
  120. // ModuleDataList,
  121. // ModuleDataPreset,
  122. // ModuleDataTable,
  123. } from '../../../deviceManager/configurationTable/types';
  124. import { useInitDevices } from '../hooks/useInit';
  125. import { MenuItem, Menu, Dropdown } from 'ant-design-vue';
  126. import { SwapOutlined, CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons-vue';
  127. import MiniBoard from './MiniBoard.vue';
  128. import TimelineList from './TimelineList.vue';
  129. import CustomList from './CustomList.vue';
  130. import CustomGallery from './CustomGallery.vue';
  131. import ComplexList from './ComplexList.vue';
  132. import CustomTable from './CustomTable.vue';
  133. import { getFormattedText } from '../../../deviceManager/configurationTable/adapters';
  134. import CustomChart from './CustomChart.vue';
  135. import { get, clone } from 'lodash-es';
  136. import CommonTable from '../../billboard/components/CommonTable.vue';
  137. import BlastDelta from '../../../monitorManager/deviceMonitor/components/device/modal/blastDelta.vue';
  138. import FIreWarn from './FIreWarn.vue';
  139. import FIreControl from './FIreControl.vue';
  140. const props = defineProps<{
  141. deviceType: Config['deviceType'];
  142. moduleData: Config['moduleData'];
  143. showStyle: Config['showStyle'];
  144. }>();
  145. const { header: headerConfig, background, layout, mock } = props.moduleData;
  146. // 额外的 header 相关的变量
  147. const headerVisible = ref(false);
  148. function headerSelectHandler({ key }) {
  149. selectedDeviceID.value = key;
  150. }
  151. const { selectedDeviceID, selectedDevice, selectedDeviceSlot, selectedDeviceLabel, options, fetchDevices } = useInitDevices(
  152. props.deviceType,
  153. headerConfig
  154. );
  155. function getData(raw, readFrom) {
  156. if (mock) return mock;
  157. if (readFrom) {
  158. return get(raw, readFrom);
  159. }
  160. return raw;
  161. }
  162. /** 根据配置里的layout将配置格式化为带 key 的具体配置,例如:[{ key: 'list', value: any, ...ModuleDataList }] */
  163. const layoutConfig = computed(() => {
  164. const refData = selectedDevice.value;
  165. const board = clone(props.moduleData.board);
  166. const list = clone(props.moduleData.list);
  167. const gallery = clone(props.moduleData.gallery);
  168. const complex_list = clone(props.moduleData.complex_list);
  169. const chart = clone(props.moduleData.chart);
  170. const table = clone(props.moduleData.table);
  171. const preset = clone(props.moduleData.preset);
  172. return layout.reduce((arr: any[], key) => {
  173. switch (key) {
  174. case 'board': {
  175. const cfg = board.shift();
  176. if (!cfg) break;
  177. const data = getData(refData, cfg.readFrom);
  178. arr.push({
  179. ...cfg,
  180. key,
  181. items: cfg.items.map((i) => {
  182. return {
  183. ...i,
  184. label: getFormattedText(data, i.label),
  185. value: getFormattedText(data, i.value),
  186. };
  187. }),
  188. });
  189. break;
  190. }
  191. case 'list': {
  192. const cfg = list.shift();
  193. if (!cfg) break;
  194. const data = getData(refData, cfg.readFrom);
  195. arr.push({
  196. ...cfg,
  197. key,
  198. items: cfg.items.map((i) => {
  199. return {
  200. ...i,
  201. label: getFormattedText(data, i.label),
  202. value: getFormattedText(data, i.value),
  203. };
  204. }),
  205. });
  206. break;
  207. }
  208. case 'gallery': {
  209. const cfg = gallery.shift();
  210. if (!cfg) break;
  211. const data = getData(refData, cfg.readFrom);
  212. arr.push({
  213. ...cfg,
  214. key,
  215. items: cfg.items.map((i) => {
  216. return {
  217. ...i,
  218. label: getFormattedText(data, i.label),
  219. value: getFormattedText(data, i.value),
  220. };
  221. }),
  222. });
  223. break;
  224. }
  225. case 'complex_list': {
  226. const cfg = complex_list.shift();
  227. if (!cfg) break;
  228. const data = getData(refData, cfg.readFrom);
  229. arr.push({
  230. ...cfg,
  231. key,
  232. items: cfg.items.map((i) => {
  233. return {
  234. ...i,
  235. label: getFormattedText(data, i.label),
  236. value: getFormattedText(data, i.value),
  237. };
  238. }),
  239. galleryItems: cfg.galleryItems.map((i) => {
  240. return {
  241. ...i,
  242. label: getFormattedText(data, i.label),
  243. value: getFormattedText(data, i.value),
  244. };
  245. }),
  246. });
  247. break;
  248. }
  249. case 'chart': {
  250. const cfg = chart.shift();
  251. if (!cfg) break;
  252. const data = getData(refData, cfg.readFrom);
  253. arr.push({
  254. key,
  255. config: cfg,
  256. data: get(data, cfg.readFrom, []),
  257. });
  258. break;
  259. }
  260. case 'table': {
  261. const cfg = table.shift();
  262. if (!cfg) break;
  263. const data = getData(refData, cfg.readFrom);
  264. arr.push({
  265. ...cfg,
  266. key,
  267. columns: cfg.columns,
  268. data: get(data, cfg.readFrom, []),
  269. });
  270. break;
  271. }
  272. default: {
  273. const cfg = preset.shift();
  274. if (!cfg) break;
  275. const data = getData(refData, cfg.readFrom);
  276. arr.push({
  277. key,
  278. data,
  279. config: cfg,
  280. });
  281. break;
  282. }
  283. }
  284. return arr;
  285. }, []);
  286. });
  287. onMounted(() => {
  288. fetchDevices();
  289. });
  290. </script>
  291. <style lang="less" scoped>
  292. @import '@/design/vent/color.less';
  293. /* Header 相关的样式 */
  294. .content__header {
  295. height: 30px;
  296. background-image: linear-gradient(90deg, #3df6ff44, transparent 20%, transparent 80%, #3df6ff44);
  297. }
  298. .content__header_left {
  299. border-left: 3px solid;
  300. border-right: 3px solid;
  301. border-image-source: linear-gradient(to top, #185f7188, #3df6ff, #185f7188);
  302. border-image-slice: 1;
  303. }
  304. .content__header_right {
  305. border-left: 3px solid;
  306. border-right: 3px solid;
  307. border-image-source: linear-gradient(to top, #185f7188, #3df6ff, #185f7188);
  308. border-image-slice: 1;
  309. min-width: 160px;
  310. }
  311. .content {
  312. height: calc(100% - 30px);
  313. position: relative;
  314. // z-index: -2;
  315. display: flex;
  316. flex-direction: column;
  317. }
  318. .content_without_header {
  319. height: 100%;
  320. }
  321. .content__background {
  322. width: 100%;
  323. height: 100%;
  324. position: absolute;
  325. top: 0;
  326. left: 0;
  327. z-index: -1;
  328. object-fit: fill;
  329. }
  330. .content__module {
  331. margin-top: 5px;
  332. margin-bottom: 5px;
  333. }
  334. // .content__module:first-of-type {
  335. // margin-top: 0;
  336. // }
  337. // .content__module:last-of-type {
  338. // margin-bottom: 0;
  339. // }
  340. ::v-deep .zxm-select:not(.zxm-select-customize-input) .zxm-select-selector {
  341. /* background-color: transparent; */
  342. color: #fff;
  343. }
  344. ::v-deep .zxm-select-arrow {
  345. color: #fff;
  346. }
  347. ::v-deep .zxm-select-selection-item {
  348. color: #fff !important;
  349. }
  350. ::v-deep .zxm-select-selection-placeholder {
  351. color: #fff !important;
  352. }
  353. </style>