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.

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