DeviceDetail.vue 8.1 KB

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