You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

539 lines
14 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <script setup lang="ts">
  2. import { getContainerList } from 'apis/container'
  3. import { craftList } from 'apis/crafts'
  4. import { getSolsList } from 'apis/solution'
  5. import logoutIcon from 'assets/images/logout.svg'
  6. import CheckCraft from 'components/home/CheckCraft/index.vue'
  7. import Liquid from 'components/home/Liquid/index.vue'
  8. import Check from 'components/system/Check/index.vue'
  9. import EditDate from 'components/system/EditDate/index.vue'
  10. import Stop from 'components/system/Stop/index.vue'
  11. import { useActivateDebug } from 'hooks/useActivateDebug'
  12. import { useServerTime } from 'hooks/useServerTime'
  13. import { isClose } from 'libs/socket'
  14. import { authRoutes } from 'router/routes'
  15. import { useDebugStore } from 'stores/debugStore'
  16. import { useSystemStore } from 'stores/systemStore'
  17. import { computed, onMounted, ref, watch } from 'vue'
  18. import { useRouter } from 'vue-router'
  19. const { handleLogoClick } = useActivateDebug()
  20. const { currentTime } = useServerTime()
  21. const systemStore = useSystemStore()
  22. const router = useRouter()
  23. watch(() => currentTime.value, () => {
  24. systemStore.currentTime = currentTime.value
  25. })
  26. watch (() => isClose.value, async (newVal) => {
  27. if (newVal) {
  28. await checkCraft()
  29. }
  30. })
  31. watch(() => systemStore.systemStatus, () => {
  32. if (!systemStore.systemStatus.currentUser) {
  33. router.push('/login')
  34. }
  35. if (!systemStore.systemStatus.selfTest && systemStore.systemStatus.currentUser && systemStore.systemStatus.currentUser?.username !== 'test') {
  36. isCheck.value = true
  37. }
  38. })
  39. onMounted(async () => {
  40. console.log('systemStatus', systemStore.systemStatus)
  41. if (!systemStore.systemStatus.currentUser) {
  42. await router.push('/login')
  43. }
  44. solutionList.value = (await getSolsList()).list
  45. if (!systemStore.systemStatus.selfTest && systemStore.systemStatus.currentUser && systemStore.systemStatus.currentUser?.username !== 'test') {
  46. isCheck.value = true
  47. }
  48. await checkCraft()
  49. })
  50. const checkCraftVisible = ref(false)
  51. const checkCraft = async () => {
  52. const res = await craftList()
  53. systemStore.errorCraft = res && res.length > 0
  54. // if (res && res.length > 0) {
  55. // ElMessageBox.confirm(
  56. // '发现有异常工艺, 是否处理恢复? ',
  57. // '提示',
  58. // {
  59. // confirmButtonText: '确认',
  60. // cancelButtonText: '取消',
  61. // closeOnClickModal: false,
  62. // closeOnPressEscape: false,
  63. // type: 'warning',
  64. // customClass: 'init-message',
  65. // },
  66. // ).then(async () => {
  67. // await craftRestore(true)
  68. // checkCraftVisible.value = true
  69. // }).catch(async () => {
  70. // await craftRestore(false)
  71. // })
  72. // }
  73. }
  74. // meta的isDefault=true 并且 当isDebug=true时,把debug路由的页面也显示
  75. const menuList = computed(() => {
  76. return authRoutes.filter((item) => {
  77. if (item.meta?.isDefault) {
  78. return true
  79. }
  80. return (['/debug', '/positionDebug'].includes(item.path) && systemStore.isDebug)
  81. })
  82. })
  83. watch(() => systemStore.isDebug, () => {
  84. console.log('isDebug', systemStore.isDebug)
  85. if (!systemStore.isDebug && router.currentRoute.value.path === '/debug') {
  86. router.push('/')
  87. }
  88. })
  89. const isCheck = ref(false)
  90. const containerList = ref<Container.ContainerItem[]>()
  91. const solutionList = ref<Solution.SolutionItem[]>()
  92. const getContainer = async () => {
  93. containerList.value = await getContainerList()
  94. }
  95. const statusMap = {
  96. start: {
  97. type: 'primary',
  98. name: '指令开始执行',
  99. },
  100. success: {
  101. type: 'success',
  102. name: '指令执行成功',
  103. },
  104. fail: {
  105. type: 'danger',
  106. name: '指令执行异常',
  107. },
  108. }
  109. const commandHandle = async (command: string, params?: unknown) => {
  110. const data = {
  111. commandId: Date.now().toString(),
  112. command,
  113. params,
  114. }
  115. await useDebugStore().sendControl(data)
  116. }
  117. const editDateVisible = ref(false)
  118. const containerStatus = computed(() => {
  119. const empty = systemStore.systemStatus.solutionModule.solutionContainer.find(item => item.empty)
  120. if (empty) {
  121. return 'empty'
  122. }
  123. return 'full'
  124. // return 'empty'
  125. })
  126. </script>
  127. <template>
  128. <el-container class="main">
  129. <el-header class="header">
  130. <div class="logo">
  131. <img src="../assets/images/logo.svg" alt="" @click="handleLogoClick">
  132. <span class="title" @click="handleLogoClick">长春黄金研究院有限公司</span>
  133. <img :class="systemStore.menuExpand ? 'expand-icon' : 'fold-icon'" src="../assets/images/expand.svg" alt="" @click="systemStore.updateMenuExpand()">
  134. </div>
  135. <div class="header-right">
  136. <ft-button v-if="systemStore.isDebug" type="primary" :click-handle="() => commandHandle('stop_all_motor')">
  137. 停止所有电机
  138. </ft-button>
  139. <el-dropdown class="wifi-dropdown" trigger="click">
  140. <div class="wifi-icon">
  141. <img v-if="isClose" src="../assets/images/wifi.svg" alt="">
  142. <img v-else src="../assets/images/wifi-active.svg" alt="">
  143. </div>
  144. <template #dropdown>
  145. <el-dropdown-menu>
  146. <el-dropdown-item>
  147. <div class="logout">
  148. <span v-if="!isClose">已连接</span>
  149. <span v-else>已断开</span>
  150. </div>
  151. </el-dropdown-item>
  152. </el-dropdown-menu>
  153. </template>
  154. </el-dropdown>
  155. <div class="time" @click="editDateVisible = true">
  156. {{ currentTime }}
  157. </div>
  158. <div class="user">
  159. <el-dropdown class="user-dropdown" trigger="click">
  160. <div class="user-dropdown-item">
  161. <img src="../assets/images/user.svg" alt="">
  162. <span>{{ systemStore.systemStatus.currentUser?.nickname || systemStore.systemStatus.currentUser?.username }}</span>
  163. </div>
  164. <template #dropdown>
  165. <el-dropdown-menu>
  166. <el-dropdown-item @click="systemStore.logout()">
  167. <div class="logout">
  168. <img :src="logoutIcon" alt="">
  169. <span>退出登录</span>
  170. </div>
  171. </el-dropdown-item>
  172. </el-dropdown-menu>
  173. </template>
  174. </el-dropdown>
  175. </div>
  176. </div>
  177. </el-header>
  178. <el-container class="container">
  179. <el-aside class="aside" :class="{ 'aside-off': !systemStore.menuExpand }">
  180. <div
  181. v-for="item in menuList"
  182. :key="item.path"
  183. class="aside-item"
  184. :class="{ 'aside-item-active': router.currentRoute.value.path.includes(item.path) }"
  185. @click="router.push(item.path)"
  186. >
  187. <img class="swing-icon" :src="((router.currentRoute.value.path.includes(item.path) ? item.meta!.activeIcon : item.meta!.icon) as string)" alt="">
  188. <span class="text">{{ item.meta!.title }}</span>
  189. </div>
  190. </el-aside>
  191. <el-main>
  192. <router-view v-slot="{ Component }" class="content">
  193. <transition name="el-fade-in-linear">
  194. <component :is="Component" />
  195. </transition>
  196. </router-view>
  197. </el-main>
  198. </el-container>
  199. <el-footer class="footer" :class="{ 'footer-expand': !systemStore.menuExpand }">
  200. <el-row>
  201. <el-col :span="16">
  202. <div class="footer-left">
  203. <img src="../assets/images/run.svg" alt="">
  204. <span v-if="!systemStore.systemLogList.length" class="text">设备运行状态</span>
  205. <el-popover v-else width="auto" trigger="click" placement="top">
  206. <template #reference>
  207. <el-tag style="width: 100%" :type="statusMap[systemStore.systemLogList[0]?.status as keyof typeof statusMap].type">
  208. {{ systemStore.systemLogList[0]?.cmdName }}: {{ statusMap[systemStore.systemLogList[0]?.status as keyof typeof statusMap].name }}
  209. {{ systemStore.systemLogList[0]?.time }}
  210. </el-tag>
  211. </template>
  212. <template #default>
  213. <div class="log-box">
  214. <el-tag
  215. v-for="(item, key) in systemStore.systemLogList"
  216. :key
  217. :type="statusMap[item?.status as keyof typeof statusMap].type"
  218. >
  219. <div style="display: flex;justify-content: space-between;width: 100%">
  220. <span>
  221. <span>{{ item.cmdName }}: </span>
  222. <span>{{ statusMap[item.status as keyof typeof statusMap].name }}</span>
  223. </span>
  224. <span>{{ item.time }}</span>
  225. </div>
  226. <!-- {{ item.cmdName }}: {{ statusMap[item.status as keyof typeof statusMap].name }} -->
  227. <!-- {{ item.time }} -->
  228. </el-tag>
  229. </div>
  230. </template>
  231. </el-popover>
  232. </div>
  233. </el-col>
  234. <el-col :span="8">
  235. <el-popover
  236. placement="top-start"
  237. width="auto"
  238. trigger="click"
  239. @show="getContainer"
  240. >
  241. <template #reference>
  242. <div class="footer-right">
  243. <div class="status" :class="{ 'status-error': containerStatus === 'empty' }" />
  244. <span class="text">{{ containerStatus === 'empty' ? '容器溶液余量有空置' : '容器溶液余量正常' }}</span>
  245. </div>
  246. </template>
  247. <template #default>
  248. <div class="container-box">
  249. <div
  250. v-for="item in containerList"
  251. :key="item.id"
  252. class="container-main"
  253. >
  254. <Liquid
  255. :data="item"
  256. />
  257. <span>{{ solutionList?.find(s => s.id === item.solutionId)?.name }}</span>
  258. </div>
  259. </div>
  260. </template>
  261. </el-popover>
  262. </el-col>
  263. </el-row>
  264. </el-footer>
  265. <FtStream :visible="systemStore.streamVisible" />
  266. <Check v-if="isCheck" @close="isCheck = false" />
  267. <Stop v-if="systemStore.systemStatus.emergencyStop" />
  268. <CheckCraft v-if="checkCraftVisible" @close="checkCraftVisible = false" />
  269. <EditDate v-if="editDateVisible" @close="editDateVisible = false" @ok="editDateVisible = false" />
  270. </el-container>
  271. </template>
  272. <style scoped lang="scss">
  273. .main {
  274. box-sizing: border-box;
  275. height: 100%;
  276. background: #F6F6F6;
  277. .header, .footer {
  278. height: 50px;
  279. width: 100%;
  280. display: flex;
  281. align-items: center;
  282. justify-content: space-between;
  283. padding: 10px 15px;
  284. }
  285. .header {
  286. color: #393F46;
  287. .logo {
  288. height: 100%;
  289. display: flex;
  290. align-items: center;
  291. .title {
  292. margin:0 10px;
  293. color: #8799AB;
  294. font-weight: 600;
  295. }
  296. img {
  297. height: 100%;
  298. }
  299. .expand-icon {
  300. height: 15px;
  301. transition: all 0.3s;
  302. }
  303. .fold-icon {
  304. height: 15px;
  305. transform: rotate(90deg);
  306. transition: all 0.3s;
  307. }
  308. }
  309. .header-right {
  310. display: flex;
  311. align-items: center;
  312. height: 100%;
  313. .wifi-dropdown {
  314. height: 100%;
  315. .wifi-icon {
  316. width: 40px;
  317. height: 100%;
  318. background: #fff;
  319. border-radius: 5px;
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. img {
  324. height: 50%;
  325. }
  326. }
  327. }
  328. .time {
  329. margin:0 10px;
  330. height: 100%;
  331. padding: 0 10px;
  332. display: flex;
  333. align-items: center;
  334. background: #fff;
  335. border-radius: 5px;
  336. }
  337. }
  338. }
  339. .container {
  340. height: calc(100% - 100px);
  341. }
  342. }
  343. .aside {
  344. width: 170px;
  345. overflow: auto;
  346. padding-left: 10px;
  347. //transition: all 0.1s ease;
  348. .aside-item {
  349. width: 100%;
  350. height: 50px;
  351. border-radius: 10px;
  352. color: #1989FA;
  353. margin: 10px 0;
  354. padding: 0 10px;
  355. display: flex;
  356. align-items: center;
  357. overflow: hidden;
  358. img {
  359. height: 80%;
  360. margin-right: 20px;
  361. }
  362. .text {
  363. transition: opacity 0.3s ease;
  364. white-space: nowrap;
  365. }
  366. }
  367. .aside-item-active {
  368. background: #1989FA;
  369. color: #fff;
  370. }
  371. }
  372. .aside-off {
  373. width: 70px;
  374. //transition: all 0.1s ease;
  375. .aside-item {
  376. .text {
  377. opacity: 0
  378. }
  379. }
  380. .aside-item-active {
  381. background: rgba(0,0,0,0);
  382. color: #fff;
  383. }
  384. }
  385. .user-dropdown-item {
  386. display: flex;
  387. align-items: center;
  388. height: 100%;
  389. color: #393F46;
  390. font-weight: bold;
  391. img {
  392. height: 30px;
  393. margin-right: 10px;
  394. }
  395. }
  396. .el-main {
  397. padding: 0 15px;
  398. height: 100%;
  399. position: relative;
  400. }
  401. .content {
  402. width: 100%;
  403. height: 100%;
  404. background: #fff;
  405. border-radius: 10px;
  406. box-shadow: 0 0 1px rgba(0, 0, 0, 0.1);
  407. padding: 10px;
  408. }
  409. .footer-expand {
  410. padding: 10px 15px 10px 85px !important;
  411. }
  412. .main .footer {
  413. padding: 10px 15px 10px 185px;
  414. .el-row {
  415. width: 100%;
  416. height: 100%;
  417. .el-col {
  418. height: 100%;
  419. }
  420. }
  421. .footer-left, .footer-right {
  422. width: 100%;
  423. height: 100%;
  424. background: #fff;
  425. border-radius: 5px;
  426. display: flex ;
  427. align-items: center;
  428. padding: 0 20px;
  429. }
  430. .footer-left {
  431. border-right: 5px solid #F6F6F6;
  432. img {
  433. height: 60%;
  434. margin-right: 20px;
  435. }
  436. .text {
  437. color: #1C1C1C;
  438. margin-left: 10px;
  439. font-size: 14px;
  440. }
  441. }
  442. .footer-right {
  443. border-left: 10px solid #F6F6F6;
  444. .status-error {
  445. background: #F56C6C !important;
  446. }
  447. .status {
  448. width: 15px;
  449. height: 15px;
  450. border-radius: 50%;
  451. background: #4EE993;
  452. }
  453. .text {
  454. color: #1C1C1C ;
  455. margin-left: 10px;
  456. font-size: 14px;
  457. }
  458. }
  459. }
  460. .aside-item:hover {
  461. .swing-icon {
  462. animation: swing 1s ease-in-out;
  463. }
  464. }
  465. .logout {
  466. display: flex;
  467. img {
  468. width: 15px;
  469. margin-right: 10px;
  470. }
  471. }
  472. .container-box {
  473. width: 400px;
  474. display: grid;
  475. grid-template-columns: repeat(4, 1fr);
  476. grid-template-rows: repeat(1, 1fr);
  477. grid-gap: 10px;
  478. .container-main {
  479. display: flex;
  480. flex-direction: column;
  481. align-items: center;
  482. }
  483. }
  484. .log-box {
  485. width: 500px;
  486. height: 400px;
  487. overflow: auto;
  488. :deep(.el-tag) {
  489. margin: 5px 0;
  490. width: 100%;
  491. .el-tag__content {
  492. width: 100%;
  493. }
  494. }
  495. }
  496. @keyframes swing {
  497. 0% {
  498. transform: rotate(0deg);
  499. }
  500. 25% {
  501. transform: rotate(-30deg);
  502. }
  503. 50% {
  504. transform: rotate(30deg);
  505. }
  506. 75% {
  507. transform: rotate(-15deg);
  508. }
  509. 100% {
  510. transform: rotate(0deg);
  511. }
  512. }
  513. </style>