Commit 289d74b809369bd55405d78abaee0929a69a50d2

Authored by xp.Huang
2 parents 5066c03d 6473eaf9

Merge branch 'fix/device-GBT-show-tabs' into 'main_dev'

feat:GBT设备详情只展示基本信息

See merge request yunteng/thingskit-app!150
... ... @@ -17,7 +17,7 @@
17 17 </view>
18 18 </view>
19 19 <!-- 命令下发 设备在线并且不是网关子设备 -->
20   - <view class="mr-2" v-if="deviceDetail.deviceState === 'ONLINE'">
  20 + <view class="mr-2" v-if="deviceDetail.deviceState === 'ONLINE' && deviceDetail.transportType!==deviceTypeNum.GBT">
21 21 <!-- #ifdef MP -->
22 22 <u-button type="primary" shape="circle" size="mini" text="下发命令" @click="handleMpShowModal" />
23 23 <!-- #endif -->
... ... @@ -112,11 +112,11 @@
112 112
113 113 <script>
114 114 import {formatToDate} from '@/plugins/utils.js';
115   - import {issueCommand} from '../api/index.js';
116 115 import api from '@/api/index.js';
117 116 import mpCommandIssuance from './mp-command-issuance.vue';
118 117 import {commandTypeList} from '../config/data.js'
119 118 import {useShowModal} from '@/plugins/utils.js'
  119 + import {deviceTypeNum} from '../config/data'
120 120
121 121 export default {
122 122 components: {
... ... @@ -133,6 +133,7 @@
133 133 showNativeModal: false,
134 134 current: 0,
135 135 commandTypeList,
  136 + deviceTypeNum:deviceTypeNum,
136 137 commandTypeStr: 'OneWay',
137 138 inputCommandContent: '',
138 139 mpShowModal: false,
... ...
1   -const list = [{
2   - name: "基础信息",
3   - },
4   - {
5   - name: "实时数据",
6   - },
7   - {
8   - name: "历史数据",
9   - },
10   - {
11   - name: "告警记录",
12   - },
  1 +const list = [
  2 + {
  3 + name: '基础信息',
  4 + },
  5 + {
  6 + name: '实时数据',
  7 + },
  8 + {
  9 + name: '历史数据',
  10 + },
  11 + {
  12 + name: '告警记录',
  13 + },
13 14 ]
14 15
15   -const issueStatus = [{
16   - checked: true,
17   - name: '全部',
18   - type: ''
19   - },
20   - {
21   - checked: false,
22   - name: '队列中',
23   - type: 'QUEUED'
24   - },
25   - {
26   - checked: false,
27   - name: '已发送',
28   - type: 'SENT'
29   - },
30   - {
31   - checked: false,
32   - name: '发送成功',
33   - type: 'DELIVERED'
34   - },
35   - {
36   - checked: false,
37   - name: '响应成功',
38   - type: 'SUCCESSFUL'
39   - },
40   - {
41   - checked: false,
42   - name: '超时',
43   - type: 'TIMEOUT'
44   - },
45   - {
46   - checked: false,
47   - name: '已过期',
48   - type: 'EXPIRED'
49   - },
50   - {
51   - checked: false,
52   - name: '响应失败',
53   - type: 'FAILED'
54   - },
55   - {
56   - checked: false,
57   - name: '已删除',
58   - type: 'DELETED'
59   - }
  16 +const issueStatus = [
  17 + {
  18 + checked: true,
  19 + name: '全部',
  20 + type: '',
  21 + },
  22 + {
  23 + checked: false,
  24 + name: '队列中',
  25 + type: 'QUEUED',
  26 + },
  27 + {
  28 + checked: false,
  29 + name: '已发送',
  30 + type: 'SENT',
  31 + },
  32 + {
  33 + checked: false,
  34 + name: '发送成功',
  35 + type: 'DELIVERED',
  36 + },
  37 + {
  38 + checked: false,
  39 + name: '响应成功',
  40 + type: 'SUCCESSFUL',
  41 + },
  42 + {
  43 + checked: false,
  44 + name: '超时',
  45 + type: 'TIMEOUT',
  46 + },
  47 + {
  48 + checked: false,
  49 + name: '已过期',
  50 + type: 'EXPIRED',
  51 + },
  52 + {
  53 + checked: false,
  54 + name: '响应失败',
  55 + type: 'FAILED',
  56 + },
  57 + {
  58 + checked: false,
  59 + name: '已删除',
  60 + type: 'DELETED',
  61 + },
60 62 ]
61 63
62   -const commandTypeList = [{
63   - value: 'OneWay',
64   - name: '单向',
65   - },
66   - {
67   - value: 'TwoWay',
68   - name: '双向'
69   - },
  64 +const commandTypeList = [
  65 + {
  66 + value: 'OneWay',
  67 + name: '单向',
  68 + },
  69 + {
  70 + value: 'TwoWay',
  71 + name: '双向',
  72 + },
70 73 ]
71 74
  75 +const deviceTypeNum = {
  76 + GBT: 'GBT28181',
  77 +}
72 78
73   -export {
74   - list,
75   - issueStatus,
76   - commandTypeList
77   -}
\ No newline at end of file
  79 +export { list, issueStatus, commandTypeList, deviceTypeNum }
... ...
... ... @@ -3,229 +3,236 @@
3 3 <!-- 公共组件-每个页面必须引入 -->
4 4 <public-module></public-module>
5 5 <u-sticky :bgColor="bgColor">
6   - <u-tabs :list="list" :current="currentTab" @click="handleTabClick" :activeStyle="activeColor"
7   - :inactiveStyle="inActiveColor" :scrollable="isScrollable" />
  6 + <u-tabs :list="list" :current="currentTab" :lineWidth="transportType == deviceTypeNum.GBT?0:30" @click=" handleTabClick " :activeStyle="{activeColor}"
  7 + :inactiveStyle="inActiveColor" :scrollable="isScrollable" itemStyle="padding: 0 11px;display:flex;flex-direction:row;align-items:center;justify-content:start;height:44px" />
8 8 </u-sticky>
9 9 <view class="mt-3">
10   - <basic-info v-show="currentTab == 0" :deviceDetail="deviceDetail" />
11   - <realtime-data v-show="currentTab === 1" :recordList="recordList" />
12   - <history-data v-if="currentTab === 2" :keys="keys" :yesterday="yesterday" :today="today"
13   - :timeDiff="timeDiff" :historyData="historyData" :entityId="entityId" :start="startTs" :end="endTs"
14   - @update="handleUpdate" />
15   - <alarm-history v-show="currentTab === 3" :deviceId="deviceId" />
16   - <commond-record v-if="currentTab === 4" :tbDeviceId="entityId" />
  10 + <basic-info v-show=" currentTab == 0 " :deviceDetail=" deviceDetail " />
  11 + <realtime-data v-show=" currentTab === 1 " :recordList=" recordList " />
  12 + <history-data v-if=" currentTab === 2 " :keys=" keys " :yesterday=" yesterday " :today=" today " :timeDiff=" timeDiff "
  13 + :historyData=" historyData " :entityId=" entityId " :start=" startTs " :end=" endTs " @update=" handleUpdate " />
  14 + <alarm-history v-show=" currentTab === 3 " :deviceId=" deviceId " />
  15 + <commond-record v-if=" currentTab === 4 " :tbDeviceId=" entityId " />
17 16 </view>
18 17 </view>
19 18 </template>
20 19
21 20 <script>
22   - import fTabbar from "@/components/module/f-tabbar/f-tabbar";
23   - import basicInfo from "./components/basic-info.vue";
24   - import realtimeData from "./components/realtime-data.vue";
25   - import alarmHistory from "./components/alarm-history.vue";
26   - import historyData from "./components/history-data.vue";
27   - import commondRecord from "./components/command-record.vue";
28   - import { getDeviceKeys,getHistoryData } from "./api/index.js";
29   - import {formatToDate} from "@/plugins/utils.js";
30   - import MescrollCompMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-comp.js";
31   - import moment from "moment";
32   - import base from "@/config/baseUrl.js";
33   - import { list } from './config/data.js'
34   - import api from '@/api'
  21 +import fTabbar from "@/components/module/f-tabbar/f-tabbar";
  22 +import basicInfo from "./components/basic-info.vue";
  23 +import realtimeData from "./components/realtime-data.vue";
  24 +import alarmHistory from "./components/alarm-history.vue";
  25 +import historyData from "./components/history-data.vue";
  26 +import commondRecord from "./components/command-record.vue";
  27 +import { getDeviceKeys, getHistoryData } from "./api/index.js";
  28 +import { formatToDate } from "@/plugins/utils.js";
  29 +import MescrollCompMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-comp.js";
  30 +import moment from "moment";
  31 +import base from "@/config/baseUrl.js";
  32 +import { list } from './config/data.js'
  33 +import api from '@/api'
  34 +import { deviceTypeNum } from './config/data'
35 35
36   - export default {
37   - mixins: [MescrollCompMixin],
38   - components: {
39   - fTabbar,
40   - basicInfo,
41   - realtimeData,
42   - alarmHistory,
43   - historyData,
44   - commondRecord,
45   - },
46   - data() {
47   - return {
48   - bgColor: '#fff',
49   - activeColor: {
50   - fontWeight: 'bold',
51   - color: '#333',
52   - },
53   - inActiveColor: {
54   - color: '#999',
55   - },
56   - list,
57   - currentTab: 0,
58   - deviceId: "",
59   - deviceDetail: {},
60   - keys: [],
61   - yesterday: "",
62   - today: "",
63   - timeDiff: "",
64   - historyData: [],
65   - entityId: "",
66   - startTs: "",
67   - endTs: "",
68   - recordList: [], //实时数据
69   - isScrollable: false,
70   - attrList: [],
71   - getAttrList:[]
72   - };
73   - },
74   - onUnload() {
75   - // 页面关闭时,销毁webSocket连接,否则第二次会存在连接不到的情况
76   - uni.closeSocket();
77   - },
78   - async onLoad(options) {
79   - const {id,alarmStatus,lastOnlineTime,tbDeviceId,deviceProfileId} = options;
80   - this.deviceId = id;
81   - const res = await api.deviceApi.getDeviceDetail(this.deviceId)
82   - if(!res) return
83   - this.deviceDetail = {
84   - ...res,
85   - alarmStatus,
86   - lastOnlineTime,
87   - };
88   - // 设备类型不是网关子设备的添加一个命令记录的选项卡
89   - if (this.deviceDetail.deviceType !== "SENSOR") {
90   - this.list.push({
91   - name: "命令记录",
92   - });
93   - const res = new Map()
94   - this.list = this.list.filter((item) => !res.has(item.name) && res.set(item.name, 1))
95   - } else {
96   - this.list = this.list.filter(item => item.name !=='命令记录')
97   - }
98   - this.isScrollable = this.list.length > 4;
99   - if (res.deviceProfileId) {
100   - this.getAttrList = await api.deviceApi.getAttribute(res.deviceProfileId)
101   - if (Array.isArray(this.getAttrList)) {
102   - this.attrList = this.getAttrList?.map(m => {
103   - return m.identifier
104   - })
105   - }
106   - }
107   - // 连接webSockte
108   - const socketTask = uni.connectSocket({
109   - url: `${base.socketPrefix}://${base.baseWebSocketUrl}/api/ws/plugins/telemetry?token=` + uni.getStorageSync("userInfo").isToken, //仅为示例,并非真实接口地址。
110   - complete: () => {},
  36 +export default {
  37 + mixins: [MescrollCompMixin],
  38 + components: {
  39 + fTabbar,
  40 + basicInfo,
  41 + realtimeData,
  42 + alarmHistory,
  43 + historyData,
  44 + commondRecord,
  45 + },
  46 + data() {
  47 + return {
  48 + bgColor: '#fff',
  49 + activeColor: {
  50 + fontWeight: 'bold',
  51 + color: '#333',
  52 + },
  53 + inActiveColor: {
  54 + color: '#999',
  55 + },
  56 + list,
  57 + currentTab: 0,
  58 + deviceId: "",
  59 + deviceDetail: {},
  60 + keys: [],
  61 + yesterday: "",
  62 + today: "",
  63 + timeDiff: "",
  64 + historyData: [],
  65 + entityId: "",
  66 + startTs: "",
  67 + endTs: "",
  68 + recordList: [], //实时数据
  69 + isScrollable: false,
  70 + attrList: [],
  71 + getAttrList: [],
  72 + transportType:"",
  73 + deviceTypeNum,
  74 + };
  75 + },
  76 + onUnload() {
  77 + // 页面关闭时,销毁webSocket连接,否则第二次会存在连接不到的情况
  78 + uni.closeSocket();
  79 + },
  80 + async onLoad(options) {
  81 + const { id, alarmStatus, lastOnlineTime, tbDeviceId, deviceProfileId, transportType } = options;
  82 + this.deviceId = id;
  83 + this.transportType = transportType
  84 + const res = await api.deviceApi.getDeviceDetail(this.deviceId)
  85 + if (!res) return
  86 + this.deviceDetail = {
  87 + ...res,
  88 + alarmStatus,
  89 + lastOnlineTime,
  90 + transportType
  91 + };
  92 + // 设备类型不是网关子设备的添加一个命令记录的选项卡
  93 + if (this.deviceDetail.deviceType !== "SENSOR") {
  94 + this.list.push({
  95 + name: "命令记录",
111 96 });
112   - uni.onSocketOpen((header) => {
113   - socketTask.send({
114   - data: JSON.stringify({
115   - attrSubCmds: [],
116   - tsSubCmds: [{
117   - entityType: "DEVICE",
118   - entityId: tbDeviceId,
119   - scope: "LATEST_TELEMETRY",
120   - cmdId: 1,
121   - keys: this.attrList.join(','),
122   - }, ],
123   - historyCmds: [],
124   - entityDataCmds: [],
125   - entityDataUnsubscribeCmds: [],
126   - alarmDataCmds: [],
127   - alarmDataUnsubscribeCmds: [],
128   - entityCountCmds: [],
129   - entityCountUnsubscribeCmds: [],
130   - }),
131   - success() {},
132   - });
  97 + const res = new Map()
  98 + this.list = this.list.filter((item) => !res.has(item.name) && res.set(item.name, 1))
  99 + } else {
  100 + this.list = this.list.filter(item => item.name !== '命令记录')
  101 + }
  102 + if (transportType === deviceTypeNum.GBT) {
  103 + this.list = this.list.filter(item => item.name == '基础信息')
  104 + }
  105 + this.isScrollable = this.list.length > 4;
  106 + if (res.deviceProfileId) {
  107 + this.getAttrList = await api.deviceApi.getAttribute(res.deviceProfileId)
  108 + if (Array.isArray(this.getAttrList)) {
  109 + this.attrList = this.getAttrList?.map(m => {
  110 + return m.identifier
  111 + })
  112 + }
  113 + }
  114 + // 连接webSockte
  115 + const socketTask = uni.connectSocket({
  116 + url: `${base.socketPrefix}://${base.baseWebSocketUrl}/api/ws/plugins/telemetry?token=` + uni.getStorageSync("userInfo").isToken, //仅为示例,并非真实接口地址。
  117 + complete: () => { },
  118 + });
  119 + uni.onSocketOpen((header) => {
  120 + socketTask.send({
  121 + data: JSON.stringify({
  122 + attrSubCmds: [],
  123 + tsSubCmds: [{
  124 + entityType: "DEVICE",
  125 + entityId: tbDeviceId,
  126 + scope: "LATEST_TELEMETRY",
  127 + cmdId: 1,
  128 + keys: this.attrList.join(','),
  129 + },],
  130 + historyCmds: [],
  131 + entityDataCmds: [],
  132 + entityDataUnsubscribeCmds: [],
  133 + alarmDataCmds: [],
  134 + alarmDataUnsubscribeCmds: [],
  135 + entityCountCmds: [],
  136 + entityCountUnsubscribeCmds: [],
  137 + }),
  138 + success() { },
133 139 });
134   - socketTask.onMessage((msg) => {
135   - const { data } = JSON.parse(msg.data);
136   - const newArray = [];
137   - for (const key in data) {
138   - const [time, value] = data[key].flat(1);
139   - let obj = { key,time,value, };
140   - if (this.recordList.length === 0) {
141   - this.recordList.unshift(obj);
142   - } else {
143   - newArray.push(obj);
144   - }
  140 + });
  141 + socketTask.onMessage((msg) => {
  142 + const { data } = JSON.parse(msg.data);
  143 + const newArray = [];
  144 + for (const key in data) {
  145 + const [time, value] = data[key].flat(1);
  146 + let obj = { key, time, value, };
  147 + if (this.recordList.length === 0) {
  148 + this.recordList.unshift(obj);
  149 + } else {
  150 + newArray.push(obj);
145 151 }
146   - newArray.forEach((item) => {
147   - let flag = false;
148   - this.recordList.forEach((item1) => {
149   - if (item1.key === item.key) {
150   - item1.value = item.value;
151   - item1.time = item.time;
152   - flag = true;
153   - }
154   - });
155   - if (!flag) {
156   - this.recordList.unshift(item);
  152 + }
  153 + newArray.forEach((item) => {
  154 + let flag = false;
  155 + this.recordList.forEach((item1) => {
  156 + if (item1.key === item.key) {
  157 + item1.value = item.value;
  158 + item1.time = item.time;
  159 + flag = true;
157 160 }
158 161 });
159   - this.recordList = this.recordList?.map((item) => {
160   - return {
161   - ...item,
162   - time: formatToDate(item.time, "YYYY-MM-DD HH:mm:ss"),
163   - };
164   - });
165   - if(this.getAttrList){
166   - this.getAttrList.forEach(item=>{
167   - this.recordList?.forEach(item1=>{
168   - if(item.identifier===item1.key){
169   - item1.name=item.name
170   - }
171   - })
172   - })
  162 + if (!flag) {
  163 + this.recordList.unshift(item);
173 164 }
174 165 });
175   - const keys = await getDeviceKeys(tbDeviceId);
176   - this.keys=this.getAttrList || []
177   - // 昨天
178   - this.yesterday = moment().subtract(1, "days").format("YYYY-MM-DD");
179   - // 今天
180   - this.today = moment().format("YYYY-MM-DD");
181   - // 开始时间
182   - this.startTs = moment().subtract(1, "days").format("x");
183   - // 结束时间
184   - this.endTs = moment().format("x");
185   - this.entityId = tbDeviceId;
186   - const data = await getHistoryData({
187   - entityId: tbDeviceId,
188   - startTs: this.startTs,
189   - endTs: this.endTs,
190   - keys: keys[0],
191   - // interval: 1800000,
192   - limit: 7,
193   - agg: 'NONE'
  166 + this.recordList = this.recordList?.map((item) => {
  167 + return {
  168 + ...item,
  169 + time: formatToDate(item.time, "YYYY-MM-DD HH:mm:ss"),
  170 + };
194 171 });
195   - this.timeDiff = "30分钟";
196   - if (!Object.keys(data).length) return;
197   - this.historyData = data[keys[0]].map((item) => {
  172 + if (this.getAttrList) {
  173 + this.getAttrList.forEach(item => {
  174 + this.recordList?.forEach(item1 => {
  175 + if (item.identifier === item1.key) {
  176 + item1.name = item.name
  177 + }
  178 + })
  179 + })
  180 + }
  181 + });
  182 + const keys = await getDeviceKeys(tbDeviceId);
  183 + this.keys = this.getAttrList || []
  184 + // 昨天
  185 + this.yesterday = moment().subtract(1, "days").format("YYYY-MM-DD");
  186 + // 今天
  187 + this.today = moment().format("YYYY-MM-DD");
  188 + // 开始时间
  189 + this.startTs = moment().subtract(1, "days").format("x");
  190 + // 结束时间
  191 + this.endTs = moment().format("x");
  192 + this.entityId = tbDeviceId;
  193 + const data = await getHistoryData({
  194 + entityId: tbDeviceId,
  195 + startTs: this.startTs,
  196 + endTs: this.endTs,
  197 + keys: keys[0],
  198 + // interval: 1800000,
  199 + limit: 7,
  200 + agg: 'NONE'
  201 + });
  202 + this.timeDiff = "30分钟";
  203 + if (!Object.keys(data).length) return;
  204 + this.historyData = data[keys[0]].map((item) => {
  205 + return {
  206 + value: item.value,
  207 + ts: formatToDate(item.ts, "YYYY-MM-DD HH:mm:ss"),
  208 + };
  209 + });
  210 + },
  211 + methods: {
  212 + handleTabClick({
  213 + index
  214 + }) {
  215 + this.currentTab = index;
  216 + },
  217 + handleUpdate(data, e) {
  218 + if (!Array.isArray(data)) {
  219 + this.historyData = [];
  220 + return;
  221 + }
  222 + this.historyData = data.map((item) => {
198 223 return {
199 224 value: item.value,
200 225 ts: formatToDate(item.ts, "YYYY-MM-DD HH:mm:ss"),
201 226 };
202 227 });
203 228 },
204   - methods: {
205   - handleTabClick({
206   - index
207   - }) {
208   - this.currentTab = index;
209   - },
210   - handleUpdate(data, e) {
211   - if (!Array.isArray(data)) {
212   - this.historyData = [];
213   - return;
214   - }
215   - this.historyData = data.map((item) => {
216   - return {
217   - value: item.value,
218   - ts: formatToDate(item.ts, "YYYY-MM-DD HH:mm:ss"),
219   - };
220   - });
221   - },
222   - },
223   - };
  229 + },
  230 +};
224 231 </script>
225 232
226 233 <style lang="scss" scoped>
227   - .device-detail-page {
228   - height: 100vh;
229   - background-color: #f8f9fa;
230   - }
  234 +.device-detail-page {
  235 + height: 100vh;
  236 + background-color: #f8f9fa;
  237 +}
231 238 </style>
... ...
1 1 <template>
2 2 <view class="device-list">
3   - <view @click="$emit('openDeviceDetail',item.id, item.alarmStatus, item.lastOnlineTime, item.tbDeviceId)"
  3 + <view @click="$emit('openDeviceDetail',item)"
4 4 class="list-item" v-for="item in list" :key="item.id">
5 5 <view class="u-flex item">
6 6 <view class="item-text text-clip">
... ... @@ -122,4 +122,4 @@
122 122 }
123 123 }
124 124 }
125   -</style>
\ No newline at end of file
  125 +</style>
... ...
... ... @@ -58,8 +58,8 @@
58 58 });
59 59 },
60 60 resetFilter() {
61   - const {deviceStatus,alarmStatus,typeStatus} = this;
62   - [deviceStatus, alarmStatus, typeStatus].forEach(item => item.map((item, index) => (item.checked = index ===0)));
  61 + const {deviceStatus,alarmStatus,typeStatus,collectStatus} = this;
  62 + [deviceStatus, alarmStatus, typeStatus,collectStatus].forEach(item => item.map((item, index) => (item.checked = index ===0)));
63 63 },
64 64 confirmFilter() {
65 65 const deviceState = this.deviceStatus.find(item => item.checked);
... ...
... ... @@ -197,9 +197,10 @@
197 197 this.resetQuery();
198 198 })
199 199 },
200   - openDeviceDetail(id, alarmStatus, lastOnlineTime, tbDeviceId) {
  200 + openDeviceDetail(values) {
  201 + const {id, alarmStatus, lastOnlineTime, tbDeviceId,transportType} = values || {}
201 202 uni.navigateTo({
202   - url: `/device-subpackage/device-detail/device-detail?id=${id}&alarmStatus=${alarmStatus}&lastOnlineTime=${lastOnlineTime}&tbDeviceId=${tbDeviceId}`
  203 + url: `/device-subpackage/device-detail/device-detail?id=${id}&alarmStatus=${alarmStatus}&lastOnlineTime=${lastOnlineTime}&tbDeviceId=${tbDeviceId}&transportType=${transportType}`
203 204 });
204 205 },
205 206 }
... ...