DeviceInfo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <template>
  2. <ContentWrap v-loading="formLoading" class="device-main-wrap" :body-style="{ padding: '0' }">
  3. <div class="device-main">
  4. <div class="device-media">
  5. <button class="device-image-frame" type="button" @click="imagePreview(defaultPicUrl)">
  6. <el-image :src="defaultPicUrl" class="device-image" fit="cover">
  7. <template #error>
  8. <div class="device-image__empty">
  9. <Icon icon="ep:picture" />
  10. </div>
  11. </template>
  12. </el-image>
  13. <span class="image-preview-mask">
  14. <Icon icon="ep:zoom-in" />
  15. <span>{{ t('action.preview') }}</span>
  16. </span>
  17. </button>
  18. </div>
  19. <div class="device-content">
  20. <div class="device-head">
  21. <div class="device-head__main">
  22. <div class="device-title-row">
  23. <h1 class="device-title">{{ formatValue(formData.deviceName) }}</h1>
  24. <el-tag class="device-status" effect="light" round>
  25. {{ statusLabel }}
  26. </el-tag>
  27. </div>
  28. <div class="device-subtitle">
  29. <Icon icon="ep:collection-tag" />
  30. <span>{{ assetPropertyLabel }}</span>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="device-info-grid">
  35. <div v-for="field in mainInfoFields" :key="field.prop" class="device-info-item">
  36. <span class="device-info-item__label">
  37. <Icon :icon="field.icon" />
  38. {{ field.label }}
  39. </span>
  40. <strong>{{ field.value }}</strong>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </ContentWrap>
  46. <ContentWrap
  47. v-loading="formLoading"
  48. class="device-detail-wrap"
  49. :body-style="{ padding: '0 18px 18px' }">
  50. <el-tabs v-model="activeName" class="device-tabs">
  51. <el-tab-pane :label="t('deviceInfo.basicInformation')" name="info">
  52. <DeviceBasicInfo :device="formData" :template-fields="templateFields" />
  53. </el-tab-pane>
  54. <el-tab-pane :label="t('deviceInfo.fileLibrary')" name="file">
  55. <DeviceFileLibrary
  56. v-if="activeName === 'file'"
  57. :device-id="deviceId"
  58. :device-name="formData.deviceName" />
  59. </el-tab-pane>
  60. <el-tab-pane :label="t('deviceInfo.deviceBOM')" name="bom">
  61. <DeviceBomLibrary
  62. v-if="activeName === 'bom'"
  63. :device-id="deviceId"
  64. :device-category-name="formData.assetClassName" />
  65. </el-tab-pane>
  66. <el-tab-pane :label="t('deviceInfo.operationRecords')" name="record">
  67. <DeviceOperationRecord v-if="activeName === 'record'" :device-id="deviceId" />
  68. </el-tab-pane>
  69. <el-tab-pane :label="t('deviceInfo.faultRecords')" name="failure">
  70. <DeviceFailureRecord v-if="activeName === 'failure'" :device-id="deviceId" />
  71. </el-tab-pane>
  72. <el-tab-pane :label="t('deviceInfo.repairRecords')" name="maintain">
  73. <DeviceMaintainRecord v-if="activeName === 'maintain'" :device-id="deviceId" />
  74. </el-tab-pane>
  75. <el-tab-pane :label="t('deviceInfo.maintenanceRecords')" name="maintenance">
  76. <DeviceMaintenanceRecord v-if="activeName === 'maintenance'" :device-id="deviceId" />
  77. </el-tab-pane>
  78. <el-tab-pane :label="t('deviceInfo.inspectionRecords')" name="inspect">
  79. <DeviceInspectRecord v-if="activeName === 'inspect'" :device-id="deviceId" />
  80. </el-tab-pane>
  81. <el-tab-pane :label="t('deviceInfo.transferRecords')" name="allot">
  82. <DeviceAllotRecord v-if="activeName === 'allot'" :device-id="deviceId" />
  83. </el-tab-pane>
  84. <el-tab-pane :label="t('deviceInfo.statusChangeRecords')" name="status">
  85. <DeviceStatusRecord v-if="activeName === 'status'" :device-id="deviceId" />
  86. </el-tab-pane>
  87. <el-tab-pane :label="t('deviceInfo.RPAdjustmentRecords')" name="person">
  88. <DevicePersonRecord v-if="activeName === 'person'" :device-id="deviceId" />
  89. </el-tab-pane>
  90. <el-tab-pane :label="t('deviceInfo.checkCert')" name="cert">
  91. <CheckCertificate v-if="activeName === 'cert'" :device-id="deviceId" />
  92. </el-tab-pane>
  93. <el-tab-pane :label="t('deviceInfo.associationDevice')" name="association">
  94. <DeviceAssociationRecord v-if="activeName === 'association'" :device-id="deviceId" />
  95. </el-tab-pane>
  96. </el-tabs>
  97. </ContentWrap>
  98. </template>
  99. <script setup lang="ts">
  100. import { computed, onMounted, ref } from 'vue'
  101. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  102. import { createImageViewer } from '@/components/ImageViewer'
  103. import { getAccessToken } from '@/utils/auth'
  104. import { DICT_TYPE, getDictLabel } from '@/utils/dict'
  105. import DeviceBasicInfo from './DeviceBasicInfo.vue'
  106. import DeviceAssociationRecord from './DeviceAssociationRecord.vue'
  107. import DeviceAllotRecord from './DeviceAllotRecord.vue'
  108. import DeviceBomLibrary from './DeviceBomLibrary.vue'
  109. import DeviceFailureRecord from './DeviceFailureRecord.vue'
  110. import DeviceFileLibrary from './DeviceFileLibrary.vue'
  111. import DeviceInspectRecord from './DeviceInspectRecord.vue'
  112. import DeviceMaintenanceRecord from './DeviceMaintenanceRecord.vue'
  113. import DeviceMaintainRecord from './DeviceMaintainRecord.vue'
  114. import DeviceOperationRecord from './DeviceOperationRecord.vue'
  115. import DevicePersonRecord from './DevicePersonRecord.vue'
  116. import DeviceStatusRecord from './DeviceStatusRecord.vue'
  117. import CheckCertificate from './CheckCertificate.vue'
  118. defineOptions({ name: 'DeviceInfo' })
  119. type DeviceDetail = Partial<
  120. Omit<
  121. IotDeviceVO,
  122. | 'model'
  123. | 'manDate'
  124. | 'expires'
  125. | 'plPrice'
  126. | 'plDate'
  127. | 'plYear'
  128. | 'plStartDate'
  129. | 'plMonthed'
  130. | 'plAmounted'
  131. | 'remainAmount'
  132. | 'monthAmount'
  133. | 'totalMonth'
  134. >
  135. > & {
  136. yfDeviceCode?: string
  137. brandName?: string
  138. assetClass?: number
  139. assetClassName?: string
  140. model?: string | number
  141. responsibleNames?: string
  142. devicePersons?: string
  143. zzName?: string
  144. supplierName?: string
  145. manufacturerName?: string
  146. manDate?: number | string | Date
  147. expires?: number | string | Date
  148. plDate?: number | string | Date
  149. plStartDate?: number | string | Date
  150. enableDate?: number | string | Date
  151. nameplate?: string
  152. plPrice?: number | string
  153. plYear?: number | string
  154. plMonthed?: number | string
  155. plAmounted?: number | string
  156. remainAmount?: number | string
  157. monthAmount?: number | string
  158. totalMonth?: number | string
  159. currency?: string
  160. templateJson?: string
  161. }
  162. interface TemplateField {
  163. sort?: number
  164. name?: string
  165. value?: string | number | null
  166. identifier?: string
  167. }
  168. interface MainInfoField {
  169. prop: keyof DeviceDetail | 'assetPropertyLabel' | 'responsibleNames'
  170. label: string
  171. value: string
  172. icon: string
  173. }
  174. const defaultDevicePic =
  175. import.meta.env.VITE_BASE_URL + '/admin-api/infra/file/29/get/IntegratedSolution.png'
  176. const { t } = useI18n()
  177. const { params, query } = useRoute()
  178. const formLoading = ref(false)
  179. const activeName = ref('info')
  180. const defaultPicUrl = ref(defaultDevicePic)
  181. const formData = ref<DeviceDetail>({})
  182. const deviceId = computed(() => {
  183. const id = params.id ?? query.id
  184. const normalizedId = Array.isArray(id) ? id[0] : id
  185. return normalizedId ? Number(normalizedId) : undefined
  186. })
  187. const formatValue = (value?: string | number | null) => {
  188. return value || value === 0 ? String(value) : '-'
  189. }
  190. const statusLabel = computed(() => {
  191. return (
  192. getDictLabel(DICT_TYPE.PMS_DEVICE_STATUS, formData.value.deviceStatus) ||
  193. formData.value.deviceStatusName ||
  194. '-'
  195. )
  196. })
  197. const assetPropertyLabel = computed(() => {
  198. return getDictLabel(DICT_TYPE.PMS_ASSET_PROPERTY, formData.value.assetProperty) || '-'
  199. })
  200. const responsibleNames = computed(() => {
  201. return formData.value.responsibleNames || formData.value.devicePersons || '-'
  202. })
  203. const templateFields = computed<TemplateField[]>(() => {
  204. if (!formData.value.templateJson) return []
  205. try {
  206. const fields = JSON.parse(formData.value.templateJson)
  207. return Array.isArray(fields) ? fields : []
  208. } catch {
  209. return []
  210. }
  211. })
  212. const mainInfoFields = computed<MainInfoField[]>(() => [
  213. {
  214. prop: 'yfDeviceCode',
  215. label: t('iotDevice.yfCode'),
  216. value: formatValue(formData.value.yfDeviceCode),
  217. icon: 'ep:postcard'
  218. },
  219. {
  220. prop: 'deviceCode',
  221. label: t('iotDevice.code'),
  222. value: formatValue(formData.value.deviceCode),
  223. icon: 'ep:ticket'
  224. },
  225. {
  226. prop: 'deviceName',
  227. label: t('iotDevice.name'),
  228. value: formatValue(formData.value.deviceName),
  229. icon: 'ep:cpu'
  230. },
  231. {
  232. prop: 'brandName',
  233. label: t('iotDevice.brand'),
  234. value: formatValue(formData.value.brandName),
  235. icon: 'ep:medal'
  236. },
  237. {
  238. prop: 'deptName',
  239. label: t('iotDevice.dept'),
  240. value: formatValue(formData.value.deptName),
  241. icon: 'ep:office-building'
  242. },
  243. {
  244. prop: 'assetClassName',
  245. label: t('info.deviceClass'),
  246. value: formatValue(formData.value.assetClassName),
  247. icon: 'ep:grid'
  248. },
  249. {
  250. prop: 'deviceStatus',
  251. label: '施工状态',
  252. value: statusLabel.value,
  253. icon: 'ep:operation'
  254. },
  255. {
  256. prop: 'assetPropertyLabel',
  257. label: t('iotDevice.assets'),
  258. value: assetPropertyLabel.value,
  259. icon: 'ep:collection-tag'
  260. },
  261. {
  262. prop: 'model',
  263. label: t('deviceForm.model'),
  264. value: formatValue(formData.value.model),
  265. icon: 'ep:set-up'
  266. },
  267. {
  268. prop: 'responsibleNames',
  269. label: t('devicePerson.rp'),
  270. value: responsibleNames.value,
  271. icon: 'ep:user'
  272. }
  273. ])
  274. const getDetail = async () => {
  275. if (!deviceId.value) return
  276. formLoading.value = true
  277. try {
  278. const detail = (await IotDeviceApi.getIotDevice(deviceId.value)) as DeviceDetail
  279. formData.value = detail || {}
  280. defaultPicUrl.value = detail?.picUrl || defaultDevicePic
  281. } finally {
  282. formLoading.value = false
  283. }
  284. }
  285. const imagePreview = (imgUrl: string) => {
  286. if (!imgUrl) return
  287. const token = getAccessToken()
  288. createImageViewer({
  289. urlList: [imgUrl],
  290. headers: {
  291. Authorization: `Bearer ${token}`
  292. }
  293. })
  294. }
  295. onMounted(() => {
  296. getDetail()
  297. })
  298. </script>
  299. <style scoped lang="scss">
  300. .device-main-wrap {
  301. overflow: hidden;
  302. border: 0;
  303. border-radius: 12px;
  304. box-shadow: 0 8px 24px rgb(31 45 61 / 7%);
  305. }
  306. .device-detail-wrap {
  307. margin-top: 14px;
  308. overflow: hidden;
  309. border: 0;
  310. border-radius: 12px;
  311. box-shadow: 0 8px 24px rgb(31 45 61 / 6%);
  312. }
  313. .device-main {
  314. display: grid;
  315. grid-template-columns: 292px minmax(0, 1fr);
  316. min-height: 286px;
  317. padding: 24px;
  318. background: radial-gradient(circle at 18px 22px, rgb(44 123 229 / 12%), transparent 30%),
  319. linear-gradient(135deg, #f7fbff 0%, var(--el-bg-color) 42%, #fbfcfe 100%);
  320. }
  321. .device-media {
  322. display: flex;
  323. align-items: stretch;
  324. justify-content: center;
  325. }
  326. .device-image-frame {
  327. position: relative;
  328. width: 260px;
  329. height: 226px;
  330. padding: 8px;
  331. overflow: hidden;
  332. font: inherit;
  333. cursor: zoom-in;
  334. background: var(--el-bg-color);
  335. border: 1px solid rgb(44 123 229 / 14%);
  336. border-radius: 12px;
  337. box-shadow: 0 14px 32px rgb(39 83 135 / 15%);
  338. appearance: none;
  339. &:hover {
  340. .device-image {
  341. transform: scale(1.035);
  342. }
  343. .image-preview-mask {
  344. opacity: 1;
  345. }
  346. }
  347. }
  348. .device-image {
  349. width: 100%;
  350. height: 100%;
  351. overflow: hidden;
  352. border-radius: 8px;
  353. transition: transform 0.3s ease;
  354. }
  355. .device-image__empty {
  356. display: flex;
  357. width: 100%;
  358. height: 100%;
  359. font-size: 34px;
  360. color: var(--el-text-color-placeholder);
  361. background: var(--el-fill-color-light);
  362. align-items: center;
  363. justify-content: center;
  364. }
  365. .image-preview-mask {
  366. position: absolute;
  367. right: 18px;
  368. bottom: 18px;
  369. display: flex;
  370. gap: 6px;
  371. padding: 7px 12px;
  372. font-size: 12px;
  373. line-height: 16px;
  374. color: #fff;
  375. pointer-events: none;
  376. background: rgb(20 29 43 / 74%);
  377. border: 1px solid rgb(255 255 255 / 22%);
  378. border-radius: 16px;
  379. opacity: 0.88;
  380. backdrop-filter: blur(6px);
  381. align-items: center;
  382. transition: opacity 0.2s ease;
  383. }
  384. .device-content {
  385. min-width: 0;
  386. padding: 2px 4px 0 30px;
  387. }
  388. .device-head {
  389. display: flex;
  390. gap: 24px;
  391. min-height: 78px;
  392. padding-bottom: 18px;
  393. border-bottom: 1px solid var(--el-border-color-lighter);
  394. align-items: flex-start;
  395. justify-content: space-between;
  396. }
  397. .device-head__main {
  398. min-width: 0;
  399. }
  400. .device-title-row {
  401. display: flex;
  402. gap: 12px;
  403. min-width: 0;
  404. align-items: center;
  405. }
  406. .device-title {
  407. max-width: 760px;
  408. margin: 0;
  409. overflow: hidden;
  410. font-size: 24px;
  411. font-weight: 700;
  412. line-height: 34px;
  413. color: var(--el-text-color-primary);
  414. text-overflow: ellipsis;
  415. white-space: nowrap;
  416. }
  417. .device-status {
  418. flex: none;
  419. padding: 0 12px;
  420. font-weight: 600;
  421. }
  422. .device-subtitle {
  423. display: flex;
  424. gap: 6px;
  425. margin-top: 9px;
  426. font-size: 13px;
  427. line-height: 20px;
  428. color: #7a5a13;
  429. align-items: center;
  430. }
  431. .device-info-grid {
  432. display: grid;
  433. grid-template-columns: repeat(5, minmax(132px, 1fr));
  434. gap: 0 22px;
  435. padding-top: 14px;
  436. }
  437. .device-info-item {
  438. display: flex;
  439. min-width: 0;
  440. min-height: 68px;
  441. padding: 11px 0;
  442. border-bottom: 1px dashed var(--el-border-color-lighter);
  443. flex-direction: column;
  444. justify-content: center;
  445. strong {
  446. margin-top: 7px;
  447. overflow: hidden;
  448. font-size: 14px;
  449. font-weight: 600;
  450. line-height: 21px;
  451. color: var(--el-text-color-primary);
  452. text-overflow: ellipsis;
  453. white-space: nowrap;
  454. }
  455. }
  456. .device-info-item__label {
  457. display: flex;
  458. gap: 6px;
  459. min-width: 0;
  460. font-size: 12px;
  461. line-height: 18px;
  462. color: var(--el-text-color-secondary);
  463. align-items: center;
  464. }
  465. .device-tabs {
  466. :deep(.el-tabs__header) {
  467. padding: 0 20px;
  468. margin: 0 -18px 18px;
  469. background: var(--el-bg-color);
  470. }
  471. :deep(.el-tabs__nav-wrap::after) {
  472. height: 1px;
  473. background-color: var(--el-border-color-lighter);
  474. }
  475. :deep(.el-tabs__item) {
  476. height: 54px;
  477. padding: 0 17px;
  478. font-weight: 500;
  479. color: var(--el-text-color-regular);
  480. }
  481. :deep(.el-tabs__item.is-active) {
  482. font-weight: 600;
  483. color: var(--el-color-primary);
  484. }
  485. :deep(.el-tabs__active-bar) {
  486. height: 3px;
  487. border-radius: 3px 3px 0 0;
  488. }
  489. }
  490. @media (width <= 1399px) {
  491. .device-main {
  492. grid-template-columns: 260px minmax(0, 1fr);
  493. }
  494. .device-image-frame {
  495. width: 232px;
  496. height: 208px;
  497. }
  498. .device-info-grid {
  499. grid-template-columns: repeat(4, minmax(132px, 1fr));
  500. }
  501. }
  502. @media (width <= 991px) {
  503. .device-main {
  504. grid-template-columns: 1fr;
  505. }
  506. .device-content {
  507. padding: 24px 0 0;
  508. }
  509. .device-info-grid {
  510. grid-template-columns: repeat(2, minmax(132px, 1fr));
  511. }
  512. }
  513. @media (width <= 575px) {
  514. .device-main {
  515. padding: 18px;
  516. }
  517. .device-head {
  518. gap: 12px;
  519. flex-direction: column;
  520. }
  521. .device-title {
  522. font-size: 20px;
  523. line-height: 30px;
  524. }
  525. .device-info-grid {
  526. grid-template-columns: 1fr;
  527. }
  528. }
  529. </style>