detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="device-detail-container">
  3. <NavBar title="设备详情" @back="goBack" />
  4. <view class="basic-info-card">
  5. <view class="device-main-info">
  6. <view class="device-name-section">
  7. <text class="device-name">{{ deviceDetail.deviceName || '未知设备' }}</text>
  8. <text class="device-id">设备编号: {{ deviceDetail.shortId || '无' }}</text>
  9. </view>
  10. <view class="device-status" :style="getDeviceStatusStyle(deviceDetail.state)">
  11. <text class="status-dot"></text>
  12. <text>{{ getDeviceStatusText(deviceDetail.state) }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="info-card">
  17. <view class="card-title">基础信息</view>
  18. <view class="info-list">
  19. <view class="info-item">
  20. <text class="item-label">产品Key</text>
  21. <text class="item-value">{{ deviceDetail.productKey || '无' }}</text>
  22. </view>
  23. <view class="info-item">
  24. <text class="item-label">工位编号</text>
  25. <text class="item-value">{{ deviceDetail.seqName || '无' }}</text>
  26. </view>
  27. <view class="info-item">
  28. <text class="item-label">所属站点</text>
  29. <text class="item-value">{{ deviceDetail.stationName || '未分配' }}</text>
  30. </view>
  31. <view class="info-item">
  32. <text class="item-label">设备地址</text>
  33. <text class="item-value">{{ deviceDetail.address || '无' }}</text>
  34. </view>
  35. <view class="info-item">
  36. <text class="item-label">参数配置</text>
  37. <text class="item-value">{{ deviceDetail.deviceConfigName || '未绑定' }}</text>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="info-card">
  42. <view class="card-title">实时状态</view>
  43. <view class="info-list">
  44. <view class="info-item">
  45. <text class="item-label">核心温度</text>
  46. <text class="item-value">{{ deviceDetail.temperatureChip ? deviceDetail.temperatureChip + '°C' : '未知' }}</text>
  47. </view>
  48. <view class="info-item">
  49. <text class="item-label">是否有水</text>
  50. <text class="item-value">{{ fmtDictName('yes_no', deviceDetail.hasWater) }}</text>
  51. </view>
  52. <view class="info-item">
  53. <text class="item-label">是否有泡沫</text>
  54. <text class="item-value">{{ fmtDictName('yes_no', deviceDetail.hasFoam) }}</text>
  55. </view>
  56. <view class="info-item" v-if="isFault">
  57. <text class="item-label">故障原因</text>
  58. <text class="item-value item-value-danger">{{ deviceDetail.faultReason || '未知故障' }}</text>
  59. </view>
  60. <view class="info-item">
  61. <text class="item-label">运行时长</text>
  62. <text class="item-value">{{ formatDuration(deviceDetail.runningTime) || '0小时' }}</text>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="action-section">
  67. <button
  68. v-if="isOnline"
  69. class="stop-btn"
  70. @click="handleStopDevice"
  71. >
  72. 停止设备
  73. </button>
  74. <button
  75. v-if="!isOnline"
  76. class="start-btn"
  77. @click="handleStartDevice"
  78. >
  79. 启动设备
  80. </button>
  81. <button class="refresh-btn" @click="refreshDeviceInfo">
  82. 刷新信息
  83. </button>
  84. </view>
  85. <view class="loading-overlay" v-if="loading">
  86. <view class="loading-spinner"></view>
  87. <text class="loading-text">加载中...</text>
  88. </view>
  89. <view class="empty-state" v-if="!loading && !deviceDetail.id">
  90. <AppIcon name="smartphone" size="48" color="#BFBFBF" />
  91. <text class="empty-text">设备不存在</text>
  92. <button class="empty-refresh-btn" @click="loadDeviceDetail">刷新</button>
  93. </view>
  94. </view>
  95. </template>
  96. <script setup>
  97. import { ref, onMounted, computed } from 'vue'
  98. import { getDeviceDetail, stopDevice } from '../../api/device.js'
  99. import { formatTime, showToast, fmtDictName, getDictColor } from '../../utils/index.js'
  100. import dictUtil, { loadDicts } from '../../utils/dict.js'
  101. const deviceId = ref('')
  102. const deviceDetail = ref({})
  103. const loading = ref(true)
  104. const isOnline = computed(() => {
  105. const state = deviceDetail.value.state
  106. if (state === null || state === undefined) return false
  107. return state == dictUtil.getDictValue('WashDevice.status', '在线')
  108. })
  109. const isFault = computed(() => {
  110. const state = deviceDetail.value.state
  111. if (state === null || state === undefined) return false
  112. return state == dictUtil.getDictValue('WashDevice.status', '故障')
  113. })
  114. const getDeviceStatusText = (state) => fmtDictName('WashDevice.status', state)
  115. const getDeviceStatusStyle = (state) => {
  116. const color = getDictColor('WashDevice.status', state)
  117. if (color) {
  118. return { color: color, backgroundColor: `${color}1A` }
  119. }
  120. return {}
  121. }
  122. const formatDuration = (seconds) => {
  123. if (!seconds || isNaN(seconds)) return '0小时'
  124. const totalSeconds = parseInt(seconds)
  125. const hours = Math.floor(totalSeconds / 3600)
  126. const minutes = Math.floor((totalSeconds % 3600) / 60)
  127. if (hours > 0) return `${hours}小时${minutes}分钟`
  128. return `${minutes}分钟`
  129. }
  130. const loadDeviceDetail = async () => {
  131. if (!deviceId.value) {
  132. showToast('设备ID不存在')
  133. loading.value = false
  134. return
  135. }
  136. loading.value = true
  137. try {
  138. const res = await getDeviceDetail(deviceId.value)
  139. if (res && res.code === 200) {
  140. deviceDetail.value = res.data || {}
  141. } else {
  142. showToast(res.msg || '获取设备详情失败')
  143. }
  144. } catch (error) {
  145. showToast('获取设备详情失败')
  146. } finally {
  147. loading.value = false
  148. }
  149. }
  150. const handleStopDevice = () => {
  151. uni.showModal({
  152. title: '停止设备',
  153. content: `确定要停止设备「${deviceDetail.value.deviceName || deviceDetail.value.shortId}」吗?此操作将中断当前运行。`,
  154. success: async (res) => {
  155. if (res.confirm) {
  156. try {
  157. await stopDevice(deviceDetail.value.shortId)
  158. showToast('设备已停止', 'success')
  159. loadDeviceDetail()
  160. } catch (error) {
  161. showToast('停止设备失败')
  162. }
  163. }
  164. }
  165. })
  166. }
  167. const handleStartDevice = () => {
  168. showToast('启动设备功能开发中')
  169. }
  170. const refreshDeviceInfo = () => {
  171. loadDeviceDetail()
  172. }
  173. const goBack = () => {
  174. uni.navigateBack()
  175. }
  176. onMounted(async () => {
  177. await loadDicts()
  178. const pages = getCurrentPages()
  179. const currentPage = pages[pages.length - 1]
  180. const receivedDeviceId = currentPage.options.id || ''
  181. if (!receivedDeviceId) {
  182. showToast('设备ID不存在,无法加载详情')
  183. loading.value = false
  184. return
  185. }
  186. deviceId.value = receivedDeviceId
  187. loadDeviceDetail()
  188. })
  189. </script>
  190. <style scoped>
  191. .device-detail-container {
  192. min-height: 100vh;
  193. background-color: #F5F7FA;
  194. padding-bottom: 160rpx;
  195. }
  196. /* ===== Basic Info Card ===== */
  197. .basic-info-card {
  198. margin: 20rpx 28rpx;
  199. padding: 28rpx 28rpx;
  200. background: #FFFFFF;
  201. border-radius: 24rpx;
  202. }
  203. .device-main-info {
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: flex-start;
  207. }
  208. .device-name-section {
  209. flex: 1;
  210. }
  211. .device-name {
  212. font-size: 32rpx;
  213. font-weight: 600;
  214. color: #1A1A1A;
  215. display: block;
  216. margin-bottom: 10rpx;
  217. }
  218. .device-id {
  219. font-size: 24rpx;
  220. color: #999999;
  221. }
  222. .device-status {
  223. display: flex;
  224. align-items: center;
  225. font-size: 22rpx;
  226. font-weight: 600;
  227. padding: 8rpx 20rpx;
  228. border-radius: 100px;
  229. flex-shrink: 0;
  230. }
  231. .status-dot {
  232. display: inline-block;
  233. width: 10rpx;
  234. height: 10rpx;
  235. border-radius: 50%;
  236. margin-right: 8rpx;
  237. background-color: currentColor;
  238. }
  239. /* ===== Info Cards ===== */
  240. .info-card {
  241. margin: 0 28rpx 20rpx;
  242. background: #FFFFFF;
  243. border-radius: 24rpx;
  244. overflow: hidden;
  245. }
  246. .card-title {
  247. padding: 24rpx 28rpx 20rpx;
  248. font-size: 28rpx;
  249. font-weight: 600;
  250. color: #1A1A1A;
  251. border-bottom: 1px solid #F0F0F0;
  252. }
  253. .info-list {
  254. padding: 8rpx 28rpx 16rpx;
  255. }
  256. .info-item {
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. padding: 18rpx 0;
  261. border-bottom: 1px solid #F5F7FA;
  262. }
  263. .info-item:last-child {
  264. border-bottom: none;
  265. }
  266. .item-label {
  267. font-size: 26rpx;
  268. color: #666666;
  269. }
  270. .item-value {
  271. font-size: 26rpx;
  272. color: #1A1A1A;
  273. font-weight: 500;
  274. text-align: right;
  275. }
  276. .item-value-danger {
  277. color: #F44336;
  278. }
  279. /* ===== Action Section ===== */
  280. .action-section {
  281. position: fixed;
  282. bottom: 0;
  283. left: 0;
  284. right: 0;
  285. padding: 20rpx 28rpx;
  286. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  287. background: #FFFFFF;
  288. border-top: 1px solid #F0F0F0;
  289. box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
  290. z-index: 100;
  291. display: flex;
  292. gap: 20rpx;
  293. }
  294. .stop-btn {
  295. flex: 1;
  296. padding: 22rpx 0;
  297. background: #C6171E;
  298. color: #FFFFFF;
  299. border: none;
  300. border-radius: 16rpx;
  301. font-size: 28rpx;
  302. font-weight: 600;
  303. transition: background 0.25s, transform 0.15s;
  304. }
  305. .stop-btn:active {
  306. background: #A81212;
  307. transform: scale(0.97);
  308. }
  309. .start-btn {
  310. flex: 1;
  311. padding: 22rpx 0;
  312. background: #52C41A;
  313. color: #FFFFFF;
  314. border: none;
  315. border-radius: 16rpx;
  316. font-size: 28rpx;
  317. font-weight: 600;
  318. transition: background 0.25s, transform 0.15s;
  319. }
  320. .start-btn:active {
  321. opacity: 0.85;
  322. transform: scale(0.97);
  323. }
  324. .refresh-btn {
  325. flex: 1;
  326. padding: 22rpx 0;
  327. background: #FFFFFF;
  328. color: #1A1A1A;
  329. border: 1px solid #E0E0E0;
  330. border-radius: 16rpx;
  331. font-size: 28rpx;
  332. font-weight: 500;
  333. transition: border-color 0.25s, color 0.25s;
  334. }
  335. .refresh-btn:active {
  336. border-color: #C6171E;
  337. color: #C6171E;
  338. }
  339. /* ===== Loading ===== */
  340. .loading-overlay {
  341. position: fixed;
  342. top: 0;
  343. left: 0;
  344. right: 0;
  345. bottom: 0;
  346. background: rgba(0, 0, 0, 0.4);
  347. display: flex;
  348. flex-direction: column;
  349. align-items: center;
  350. justify-content: center;
  351. z-index: 999;
  352. }
  353. .loading-spinner {
  354. width: 64rpx;
  355. height: 64rpx;
  356. border: 4rpx solid rgba(255, 255, 255, 0.3);
  357. border-top-color: #FFFFFF;
  358. border-radius: 50%;
  359. animation: spin 0.8s linear infinite;
  360. margin-bottom: 24rpx;
  361. }
  362. @keyframes spin {
  363. to { transform: rotate(360deg); }
  364. }
  365. .loading-text {
  366. font-size: 28rpx;
  367. color: #FFFFFF;
  368. }
  369. /* ===== Empty ===== */
  370. .empty-state {
  371. display: flex;
  372. flex-direction: column;
  373. align-items: center;
  374. justify-content: center;
  375. padding: 120rpx 0;
  376. }
  377. .empty-text {
  378. font-size: 28rpx;
  379. color: #999999;
  380. margin: 24rpx 0 32rpx;
  381. }
  382. .empty-refresh-btn {
  383. padding: 16rpx 48rpx;
  384. background: #C6171E;
  385. color: #FFFFFF;
  386. border: none;
  387. border-radius: 44rpx;
  388. font-size: 28rpx;
  389. font-weight: 500;
  390. }
  391. </style>