index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <el-row :gutter="0" class="overview-row">
  3. <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
  4. <div class="overview-left">
  5. <div class="overview-left-title">
  6. <span>报警总览</span>
  7. </div>
  8. <div class="overview-left-content">
  9. <ul v-loading="alarm_loading">
  10. <li v-for="(item, index) in varDictData" :key="index">
  11. <div v-if="item.value" class="content-item" :class="getColor(item.switch_type?.toString() ?? '')">
  12. <IconAlarm />
  13. <span style="width:120px; margin-left: 15px;">{{ item.crane_name }}</span>
  14. <span style="width: 2px;height: 60%;margin: 0px 30px;" :class="getColorSpan(item.switch_type?.toString() ?? '')" />
  15. <span>{{ item.var_name }}</span>
  16. </div>
  17. </li>
  18. </ul>
  19. <div v-if="!alarm_loading && !hasActiveAlarms" class="el-table-empty">
  20. <el-image :src="emptybg"></el-image>
  21. <span>当前无数据</span>
  22. </div>
  23. </div>
  24. </div>
  25. </el-col>
  26. <el-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
  27. <div class="overview-right">
  28. <div class="overview-right-title">
  29. <span>起重机总览</span>
  30. </div>
  31. <div class="overview-right-content">
  32. <pro-table :height="tabHeight" :loading="tab_loading" :data="craneData" :config="tableConfig">
  33. <template #default="{ row, label }">
  34. <div v-if="label === '操作'" style="width:100%;height:100%;display: flex;justify-content: center;">
  35. <div class="button-container" @click="handleClick(row)">
  36. 查看
  37. </div>
  38. </div>
  39. <div v-if="label === '在线状态'">
  40. <el-tag effect="dark" v-if="!row.work_status && row.work_status != '0'" type="warning">连接中</el-tag>
  41. <el-tag effect="dark" v-if="row.work_status == '0'" type="danger">离线</el-tag>
  42. <el-tag effect="dark" v-if="row.work_status == '1'" type="success">运行</el-tag>
  43. <el-tag effect="dark" v-if="row.work_status == '2'" type="info">停止</el-tag>
  44. <el-tag effect="dark" v-if="row.work_status == '3'" type="success">工作</el-tag>
  45. <el-tag effect="dark" v-if="row.work_status == '4'" type="primary">空闲</el-tag>
  46. </div>
  47. </template>
  48. </pro-table>
  49. </div>
  50. </div>
  51. </el-col>
  52. </el-row>
  53. </template>
  54. <script lang="ts" setup>
  55. import BizCraneAPI, { BizCranePageQuery, BizCraneTable } from '@/api/module_business/crane'
  56. import BizVarDictAPI, { BizVarDictPageQuery, BizVarDictTable } from '@/api/module_business/vardict'
  57. import emptybgUrl from '@/assets/images/empty-bg.png';
  58. import { onMounted, onUnmounted, ref, reactive, inject } from 'vue';
  59. import { useRouter } from 'vue-router';
  60. import MqttUtil, { MqttMessageCallback } from '@/utils/mqttUtil';
  61. // 路由 & 全局注入
  62. const router = useRouter()
  63. const receiveData = inject<(data: { craneName: string; isShowHomeButton: boolean }) => void>('receiveData');
  64. // 静态资源 & 样式相关
  65. const emptybg = ref(emptybgUrl)
  66. const tabHeight = ref('calc(100vh - 70px - 60px - 40px - 42px)')
  67. // 数据加载状态
  68. const alarm_loading = ref(true);
  69. const tab_loading = ref(true)
  70. // 业务数据
  71. const craneData = ref<BizCraneTable[]>([]);
  72. const varDictData = ref<BizVarDictTable[]>([])
  73. const hasActiveAlarms = computed(() => {
  74. return varDictData.value.some(item => item.value);
  75. });
  76. const mqttConfig = {
  77. wsUrl: import.meta.env.VITE_APP_WS_ENDPOINT || 'ws://127.0.0.1:9001',
  78. topics: ['cdc/+/alarm/#', 'cdc/+/status']
  79. };
  80. const mqttUtil = new MqttUtil(mqttConfig);
  81. // 表格配置
  82. const tableConfig = ref([
  83. {
  84. prop: 'crane_no',
  85. label: '编号'
  86. },
  87. {
  88. prop: 'crane_name',
  89. label: '起重机名称'
  90. },
  91. {
  92. prop: 'crane_model',
  93. label: '型号'
  94. },
  95. {
  96. prop: 'ip_address',
  97. label: 'IP地址'
  98. },
  99. {
  100. prop: 'online_status',
  101. label: '在线状态',
  102. slot: true
  103. },
  104. {
  105. label: '操作',
  106. slot: true
  107. }
  108. ])
  109. const queryFormCraneData = reactive<BizCranePageQuery>({
  110. page_no: 1,
  111. page_size: 100,
  112. crane_name: undefined,
  113. crane_no: undefined,
  114. crane_model: undefined,
  115. ip_address: undefined,
  116. status: undefined,
  117. created_time: undefined,
  118. updated_time: undefined,
  119. created_id: undefined,
  120. updated_id: undefined,
  121. });
  122. const queryFormVarDictData = reactive<BizVarDictPageQuery>({
  123. page_no: 1,
  124. page_size: 100,
  125. crane_no: undefined,
  126. var_code: undefined,
  127. var_name: undefined,
  128. mec_type: undefined,
  129. switch_type: '2',
  130. gateway_id: undefined,
  131. var_group: undefined,
  132. var_category: undefined,
  133. is_top_show: undefined,
  134. is_save: undefined,
  135. is_overview_top_show: undefined,
  136. is_home_page_show: undefined,
  137. status: undefined,
  138. created_time: undefined,
  139. updated_time: undefined,
  140. created_id: undefined,
  141. updated_id: undefined,
  142. is_api_request: 'True',
  143. });
  144. // 操作按钮点击事件
  145. const handleClick = (item: BizCraneTable) => {
  146. if (receiveData) {
  147. receiveData({ craneName: item.crane_name ?? '', isShowHomeButton: true });
  148. }
  149. localStorage.setItem('craneInfo', JSON.stringify(item))
  150. router.push('/detail');
  151. }
  152. // 获取起重机列表数据
  153. const getCraneListData = async () => {
  154. try {
  155. tab_loading.value = true
  156. const response = await BizCraneAPI.listBizCraneStatus(queryFormCraneData);
  157. craneData.value = response.data.data.items;
  158. } finally {
  159. tab_loading.value = false
  160. }
  161. }
  162. const getVarDictData = async () => {
  163. try {
  164. alarm_loading.value = true;
  165. const response = await BizVarDictAPI.listBizVarDictAlarms(queryFormVarDictData);
  166. varDictData.value = response.data.data.items;
  167. } finally {
  168. alarm_loading.value = false
  169. }
  170. }
  171. // 颜色样式处理
  172. const getColor = (type: string) => {
  173. switch (type) {
  174. case '2':
  175. return 'content-item-yellow';
  176. case '3':
  177. return 'content-item-orange';
  178. case '4':
  179. return 'content-item-red';
  180. }
  181. }
  182. const getColorSpan = (type: string) => {
  183. switch (type) {
  184. case '2':
  185. return 'content-item-span-yellow';
  186. case '3':
  187. return 'content-item-span-orange';
  188. case '4':
  189. return 'content-item-span-red';
  190. }
  191. }
  192. // 初始化业务数据
  193. const getData = () => {
  194. getCraneListData()
  195. getVarDictData()
  196. }
  197. const handleMqttMessage: MqttMessageCallback = (topic, payload) => {
  198. let topic_levels = topic.split('/')
  199. let crane_no = topic_levels[1]
  200. let suffix = topic_levels[2]
  201. if (suffix === 'alarm') {
  202. varDictData.value.forEach((item) => {
  203. if (item.crane_no === crane_no && item.var_code === payload.var_code) {
  204. item.value = payload.value
  205. }
  206. });
  207. } else if (suffix === 'status') {
  208. craneData.value.forEach((craneItem) => {
  209. if (craneItem.crane_no === crane_no) {
  210. craneItem.work_status = payload.status;
  211. }
  212. });
  213. }
  214. }
  215. onMounted(async () => {
  216. getData();
  217. mqttUtil.initConnect(handleMqttMessage);
  218. if (receiveData) {
  219. receiveData({ craneName: '', isShowHomeButton: false });
  220. }
  221. });
  222. onUnmounted(() => {
  223. mqttUtil.releaseResources();
  224. });
  225. </script>
  226. <style lang="less" scoped>
  227. .overview-row {
  228. padding: 20px 20px;
  229. }
  230. .overview-left {
  231. height: calc(100vh - 70px - 40px);
  232. margin-right: 20px;
  233. background: linear-gradient(to bottom, #14428C 0%, #121F34 12%);
  234. border: 1px solid #284988;
  235. display: flex;
  236. flex-direction: column;
  237. align-items: center;
  238. padding: 0px 20px;
  239. }
  240. .overview-left-title {
  241. width: 400px;
  242. height: 60px;
  243. background-image: url('../../../assets/images/overview-left-title.png');
  244. background-size: cover;
  245. background-position: center;
  246. background-repeat: no-repeat;
  247. display: flex;
  248. justify-content: center;
  249. align-items: center;
  250. color: #8ECAFF;
  251. font-size: 24px;
  252. }
  253. .overview-left-content {
  254. flex: 1;
  255. width: 100%;
  256. margin-top: 40px;
  257. overflow: auto;
  258. :deep(.el-loading-parent--relative) {
  259. height: 100%;
  260. --el-mask-color: rgba(255, 255, 255, 0.1);
  261. }
  262. }
  263. .content-item {
  264. width: 100%;
  265. height: 40px;
  266. margin-bottom: 10px;
  267. display: flex;
  268. align-items: center;
  269. padding: 0px 17px;
  270. font-size: 16px;
  271. }
  272. .content-item-red {
  273. background: linear-gradient(to right, rgba(249, 20, 61, 0.3) 0%, rgba(89, 105, 164, 0.3) 40%, rgba(23, 41, 68, 0.3) 80%);
  274. color: #F9143D;
  275. }
  276. .content-item-yellow {
  277. background: linear-gradient(to right, rgba(255, 216, 0, 0.3) 0%, rgba(89, 105, 164, 0.3) 40%, rgba(23, 41, 68, 0.3) 80%);
  278. color: #FFD800;
  279. }
  280. .content-item-orange {
  281. background: linear-gradient(to right, rgba(243, 153, 2, 0.3) 0%, rgba(89, 105, 164, 0.3) 40%, rgba(23, 41, 68, 0.3) 80%);
  282. color: #f39902;
  283. }
  284. .content-item-span-red {
  285. background-color: #F9143D;
  286. }
  287. .content-item-span-yellow {
  288. background-color: #FFD800;
  289. }
  290. .content-item-span-orange {
  291. background-color: #f39902;
  292. }
  293. .overview-right {
  294. height: calc(100vh - 70px - 40px);
  295. background: linear-gradient(to bottom, #14428C 0%, #121F34 12%);
  296. border: 1px solid #284988;
  297. display: flex;
  298. flex-direction: column;
  299. align-items: center;
  300. padding: 0px 20px;
  301. }
  302. .overview-right-title {
  303. width: 640px;
  304. height: 60px;
  305. background-image: url('../../../assets/images/overview-right-title.png');
  306. background-size: cover;
  307. background-position: center;
  308. background-repeat: no-repeat;
  309. display: flex;
  310. justify-content: center;
  311. align-items: center;
  312. color: #8ECAFF;
  313. font-size: 24px;
  314. }
  315. .overview-right-content {
  316. width: 100%;
  317. margin-top: 40px;
  318. overflow: auto;
  319. :deep(.el-table__header) {
  320. border-bottom: 1px solid #3E5487;
  321. }
  322. :deep(.el-table__body) {
  323. font-size: 16px;
  324. }
  325. .button-container {
  326. width: 80px;
  327. height: 35px;
  328. background: linear-gradient(to bottom, #0949C6, #0A8DD8);
  329. text-align: center;
  330. line-height: 35px;
  331. border-radius: 5px;
  332. font-size: 16px;
  333. cursor: pointer;
  334. }
  335. }
  336. .el-table-empty {
  337. width: 100%;
  338. height: 100%;
  339. display: flex;
  340. flex-direction: column;
  341. justify-content: center;
  342. align-items: center;
  343. color: #8ECAFF;
  344. img {
  345. width: 200px;
  346. height: auto;
  347. margin-bottom: 20px;
  348. }
  349. }
  350. ::-webkit-scrollbar {
  351. width: 5px;
  352. height: 5px;
  353. }
  354. ::-webkit-scrollbar-track {
  355. border-radius: 10px;
  356. }
  357. ::-webkit-scrollbar-thumb {
  358. border-radius: 7px;
  359. background-color: #798DAE;
  360. }
  361. </style>