DeviceDetail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="device-detail">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="设备监测" @clickLeft="back"></uni-nav-bar>
  4. <view class="top-wrapper">
  5. <uni-section>
  6. <uni-easyinput prefixIcon="search" style="width: 460rpx" v-model="form.keyWord" placeholder="编码、名称、固资编码">
  7. </uni-easyinput>
  8. </uni-section>
  9. <view style="display: flex;">
  10. <button class="search_btn" @click="search">搜索</button>
  11. <view class="more_search">
  12. <image src="~@/static/moreSearch.svg" mode="" @click="handlScreen"></image>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="update-time">更新时间:{{ updateTime }}</view>
  17. <scroll-view scroll-y class="device-list">
  18. <view class="device-card" v-for="(item, index) in deviceList" :key="index">
  19. <view class="card-header">
  20. <view class="card-title">
  21. <text class="device-name">{{ item.name }}</text>
  22. <text v-if="item.status == 2" class="alarm-icon">🚨</text>
  23. </view>
  24. <u-tag
  25. :text="getStatusLabel(item.status)"
  26. :type="getStatusType(item.status, 1)"
  27. size="mini"
  28. :customStyle="{ marginLeft: 'auto' }"
  29. />
  30. </view>
  31. <view class="status-tag-wrap">
  32. <u-tag :text="getStatusText(item.iotList.length ? 1 : 0)" :type="getStatusType(item.iotList.length ? 1 : 0)" size="mini" />
  33. </view>
  34. <view class="data-grid">
  35. <view class="data-item" v-for="iotItem in item.iotList">
  36. <span class="data-label">{{ iotItem.name }}</span>
  37. <span class="data-value">{{
  38. iotItem.dataType.type == 'enum' ||
  39. iotItem.dataType.type == 'bool'
  40. ? iotItem.dataType.specs[iotItem.value]
  41. : iotItem.value +
  42. ' ' +
  43. ((iotItem.unit && iotItem.unit) || '')
  44. }}</span>
  45. </view>
  46. </view>
  47. </view>
  48. </scroll-view>
  49. <screen ref="screen" @succeed="handleFilter" :postId="form.postId" :postName="form.postName"></screen>
  50. </view>
  51. </template>
  52. <script>
  53. import screen from './deviceScreen.vue'
  54. import { getDeviceCount } from '@/api/home'
  55. import { businessStatus } from '@/enum/dict'
  56. export default {
  57. components: {
  58. screen
  59. },
  60. data() {
  61. return {
  62. deviceType: '',
  63. unit: '',
  64. updateTime: '',
  65. deviceList: [],
  66. form: {
  67. keyWord: '',
  68. postId: '',
  69. postName: ''
  70. }
  71. }
  72. },
  73. computed: {
  74. },
  75. created() {
  76. this.updateTime = this.formatDate(new Date())
  77. this.fetchDeviceData()
  78. },
  79. methods: {
  80. handlScreen() {
  81. this.$refs.screen.open()
  82. },
  83. async getData() {
  84. const res = await getDeviceCount({
  85. size: 9999
  86. })
  87. },
  88. handleFilter(data) {
  89. console.log('data---', data)
  90. for (let key of Object.keys(data)) {
  91. this.form[key] = data[key]
  92. }
  93. this.fetchDeviceData()
  94. },
  95. formatDate(date) {
  96. const y = date.getFullYear()
  97. const m = String(date.getMonth() + 1).padStart(2, '0')
  98. const d = String(date.getDate()).padStart(2, '0')
  99. const h = String(date.getHours()).padStart(2, '0')
  100. const min = String(date.getMinutes()).padStart(2, '0')
  101. const s = String(date.getSeconds()).padStart(2, '0')
  102. return `${y}-${m}-${d} ${h}:${min}:${s}`
  103. },
  104. // 获取状态文本
  105. getStatusText(status) {
  106. const textMap = {
  107. 1: '在线',
  108. 0: '离线',
  109. fault: '故障'
  110. };
  111. return textMap[status] || status;
  112. },
  113. getStatusType(status, type) {
  114. const typeMap = !type
  115. ? {
  116. 1: 'success',
  117. 0: 'info',
  118. fault: 'error'
  119. }
  120. : {
  121. 0: 'success',
  122. 1: 'success',
  123. 4: 'success',
  124. 5: 'warning',
  125. 2: 'error',
  126. 3: 'error'
  127. };
  128. return typeMap[status];
  129. },
  130. getStatusLabel(status) {
  131. return businessStatus.find(item => item.code == status)?.label
  132. },
  133. async fetchDeviceData() {
  134. const res = await getDeviceCount({
  135. ...this.form,
  136. size: 9999
  137. })
  138. let deviceData = res.list.map((item) => {
  139. let iotList = [];
  140. if (item.iotPointDataList) {
  141. item.iotPointDataList.forEach((element) => {
  142. let data = item.iotModel.properties.find(
  143. (iotModel) => iotModel.identifier == element.identifier
  144. );
  145. if (data) {
  146. iotList.push({
  147. ...element,
  148. dataType: data.dataType
  149. });
  150. }
  151. });
  152. }
  153. item['iotList'] = item.iotDashboardPoint.length
  154. ? iotList.filter((iotListItem) =>
  155. item.iotDashboardPoint.find(
  156. (Point) =>
  157. Point.identifier == iotListItem.identifier &&
  158. Point.checked1
  159. )
  160. )
  161. : iotList.filter((iotListItem, index) => index < 4);
  162. return item;
  163. });
  164. // TODO: 替换为实际接口调用
  165. this.deviceList = deviceData
  166. console.log(deviceData)
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .top-wrapper {
  173. display: flex;
  174. height: 88rpx;
  175. align-items: center;
  176. justify-content: space-between;
  177. padding: 20rpx;
  178. /deep/.uni-section {
  179. margin-top: 0px;
  180. }
  181. /deep/.uni-section-header {
  182. padding: 0px;
  183. }
  184. .search_btn {
  185. width: 120rpx;
  186. height: 70rpx;
  187. line-height: 70rpx;
  188. background: $theme-color;
  189. font-size: 28rpx;
  190. color: #fff;
  191. }
  192. .menu_icon {
  193. width: 44rpx;
  194. height: 44rpx;
  195. margin-left: 14rpx;
  196. }
  197. .more_search {
  198. display: flex;
  199. align-items: center;
  200. height: 70rpx;
  201. line-height: 70rpx;
  202. }
  203. /deep/.u-input {
  204. border: 1rpx solid #ccc;
  205. .u-input__content__field-wrapper__field {
  206. height: 40rpx !important;
  207. }
  208. }
  209. image {
  210. width: 52rpx;
  211. height: 52rpx;
  212. margin-left: 10rpx;
  213. }
  214. }
  215. .device-detail {
  216. // height: 100vh;
  217. display: flex;
  218. flex-direction: column;
  219. // background-color: #1a1b1f;
  220. // color: #fff;
  221. }
  222. .nav-bar {
  223. flex-shrink: 0;
  224. }
  225. .filter-bar {
  226. display: flex;
  227. align-items: center;
  228. padding: 16rpx 24rpx;
  229. // background-color: #22232a;
  230. .picker-text {
  231. font-size: 26rpx;
  232. color: #ccc;
  233. }
  234. .filter-btn {
  235. flex-shrink: 0;
  236. margin-left: auto;
  237. padding: 10rpx 28rpx;
  238. border: 1rpx solid #4caf50;
  239. border-radius: 8rpx;
  240. color: #4caf50;
  241. font-size: 26rpx;
  242. }
  243. }
  244. .update-time {
  245. padding: 12rpx 24rpx;
  246. font-size: 24rpx;
  247. color: #999;
  248. // background-color: #1a1b1f;
  249. }
  250. .device-list {
  251. flex: 1;
  252. padding: 20rpx 24rpx;
  253. }
  254. .device-card {
  255. // background-color: #25262c;
  256. border-radius: 16rpx;
  257. padding: 28rpx 24rpx;
  258. margin-bottom: 20rpx;
  259. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  260. border: 1rpx solid #ccc;
  261. }
  262. .card-header {
  263. display: flex;
  264. align-items: center;
  265. margin-bottom: 20rpx;
  266. justify-content: space-between;
  267. .device-name {
  268. font-size: 32rpx;
  269. font-weight: bold;
  270. color: #333;
  271. }
  272. .alarm-icon {
  273. margin-left: 12rpx;
  274. font-size: 32rpx;
  275. }
  276. }
  277. .status-tag-wrap {
  278. display: flex;
  279. margin-bottom: 16rpx;
  280. }
  281. .data-grid {
  282. display: flex;
  283. margin-top: 12rpx;
  284. flex-wrap: wrap;
  285. .data-item {
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. width: 50%;
  290. padding: 10rpx 20rpx;
  291. .data-label {
  292. font-size: 26rpx;
  293. color: #333;
  294. }
  295. .data-value {
  296. font-size: 28rpx;
  297. color: #333;
  298. font-family: monospace;
  299. }
  300. .text-red {
  301. color: #f44336;
  302. }
  303. }
  304. }
  305. </style>