DeviceDetail.vue 8.0 KB

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