Commit 74e7ede35bd0335ae979d4872c2ebf7dad070dc2

Authored by xp.Huang
2 parents 51316321 a50e0c90

Merge branch 'sqy_dev' into 'main'

fix:调整设备的命令记录和修复bug

See merge request huang/thingskit-app!36
... ... @@ -4,8 +4,8 @@ import {
4 4 let baseUrl = "";
5 5 if (process.env.NODE_ENV === 'development') {
6 6 // 开发环境
7   - baseUrl = 'http://192.168.10.115:8080/api'
8   - // baseUrl = 'https://dev.thingskit.com/api'
  7 + // baseUrl = 'http://192.168.10.115:8080/api'
  8 + baseUrl = 'https://dev.thingskit.com/api'
9 9
10 10 } else if (process.env.NODE_ENV === 'production') {
11 11 // 生产环境
... ...
... ... @@ -14,6 +14,7 @@
14 14 :inactiveStyle="{
15 15 color: '#999'
16 16 }"
  17 + :scrollable="isScrollable"
17 18 />
18 19 </u-sticky>
19 20 <view style="margin-top:30rpx;">
... ... @@ -46,6 +47,7 @@ import historyData from './tabDetail/historyData.vue';
46 47 import commondRecord from './tabDetail/CommandRecord.vue';
47 48 import { getDeviceKeys, getHistoryData } from './api/index.js';
48 49 import { formatToDate } from '@/plugins/utils.js';
  50 +import moment from 'moment';
49 51 export default {
50 52 components: {
51 53 fTabbar,
... ... @@ -57,7 +59,7 @@ export default {
57 59 },
58 60 data() {
59 61 return {
60   - list: [{ name: '基础信息' }, { name: '实时数据' }, { name: '历史数据' }, { name: '告警记录' }, { name: '命令记录' }],
  62 + list: [{ name: '基础信息' }, { name: '实时数据' }, { name: '历史数据' }, { name: '告警记录' }],
61 63 currentTab: 0,
62 64 deviceId: '',
63 65 deviceDetail: {},
... ... @@ -69,10 +71,11 @@ export default {
69 71 entityId: '',
70 72 startTs: '',
71 73 endTs: '',
72   - recordList: []
  74 + recordList: [],
  75 + isScrollable: false
73 76 };
74 77 },
75   - onUnload(){
  78 + onUnload() {
76 79 // 页面关闭时,销毁webSocket连接,否则第二次会存在连接不到的情况
77 80 uni.closeSocket();
78 81 },
... ... @@ -81,6 +84,14 @@ export default {
81 84 this.deviceId = id;
82 85 const res = await uni.$u.http.get(`/yt/device/${id}`);
83 86 this.deviceDetail = { ...res, alarmStatus, lastOnlineTime };
  87 +
  88 + // 设备类型不是网关子设备的添加一个命令记录的选项卡
  89 + if (this.deviceDetail.deviceType !== 'SENSOR') {
  90 + this.list.push({
  91 + name: '命令记录'
  92 + });
  93 + }
  94 + this.isScrollable = this.list.length > 4;
84 95 // 连接webSockte
85 96 const socketTask = uni.connectSocket({
86 97 url: 'wss://dev.thingskit.com/api/ws/plugins/telemetry?token=' + uni.getStorageSync('userInfo').isToken, //仅为示例,并非真实接口地址。
... ... @@ -144,22 +155,24 @@ export default {
144 155
145 156 const keys = await getDeviceKeys(tbDeviceId);
146 157 this.keys = [keys];
147   - const date = new Date();
148   - const year = date.getFullYear(); //获取完整的年份(4位)
149   - const month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
150   - const day = date.getDate(); //获取当前日(1-31)
151   - const yesterday = `${year}-${month}-${day - 1}`;
152   - const today = `${year}-${month}-${day}`;
153   - this.yesterday = yesterday;
154   - this.today = today;
155   - this.startTs = formatToDate(yesterday, 'x');
156   - this.endTs = formatToDate(today, 'x');
  158 + // 昨天
  159 + this.yesterday = moment()
  160 + .subtract(1, 'days')
  161 + .format('YYYY-MM-DD');
  162 + // 今天
  163 + this.today = moment().format('YYYY-MM-DD');
  164 + // 开始时间
  165 + this.startTs = moment()
  166 + .subtract(1, 'days')
  167 + .format('x');
  168 + // 结束时间
  169 + this.endTs = moment().format('x');
157 170 this.entityId = tbDeviceId;
158   - console.log(this.entityId)
  171 +
159 172 const data = await getHistoryData({
160 173 entityId: tbDeviceId,
161   - startTs: formatToDate(yesterday, 'x'),
162   - endTs: formatToDate(today, 'x'),
  174 + startTs: this.startTs,
  175 + endTs: this.endTs,
163 176 keys: keys[0],
164 177 interval: 1800000
165 178 });
... ...
1 1 <template>
2 2 <view class="command-detail">
3   - <view class="detail-top">网关设备1</view>
  3 + <view class="detail-top">{{ commandDetail.deviceName }}</view>
4 4 <view class="detail">
5 5 <view class="detail-item">
6 6 <view class="detail-label">设备类型</view>
7   - <view class="detail-value">网关子设备</view>
  7 + <view class="detail-value">{{ commandDetail.deviceType }}</view>
8 8 </view>
9 9 <u-line length="90%" margin="0 auto"></u-line>
10 10 <view class="detail-item">
11 11 <view class="detail-label">设备编号</view>
12   - <view class="detail-value">SN98489123471829</view>
  12 + <view class="detail-value">{{ commandDetail.deviceSn }}</view>
13 13 </view>
14 14 <u-line length="90%" margin="0 auto"></u-line>
15 15 <view class="detail-item">
16 16 <view class="detail-label">所属组织</view>
17   - <view class="detail-value">云腾汽车</view>
  17 + <view class="detail-value">{{ commandDetail.organizationName }}</view>
18 18 </view>
19 19 <u-line length="90%" margin="0 auto"></u-line>
20 20 <view class="detail-item">
21 21 <view class="detail-label">命令下发时间</view>
22   - <view class="detail-value">2022-01-25 12:44:22</view>
  22 + <view class="detail-value">{{ commandDetail.createTime }}</view>
23 23 </view>
24 24 <u-line length="90%" margin="0 auto"></u-line>
25   - <view class="detail-item">
  25 + <view class="detail-item" v-if="commandDetail.additionalInfo.cmdType">
26 26 <view class="detail-label">命令类型</view>
27   - <view class="detail-value">Mqtt命令</view>
  27 + <view class="detail-value">{{ commandDetail.additionalInfo.cmdType }}</view>
28 28 </view>
29   - <u-line length="90%" margin="0 auto"></u-line>
  29 + <u-line length="90%" margin="0 auto" v-if="commandDetail.additionalInfo.cmdType"></u-line>
30 30 <view class="detail-item">
31 31 <view class="detail-label">响应类型</view>
32   - <view class="detail-value">OneWay</view>
  32 + <view class="detail-value"></view>
33 33 </view>
34 34 <u-line length="90%" margin="0 auto"></u-line>
35 35 <view class="detail-item">
... ... @@ -47,7 +47,20 @@
47 47 </view>
48 48 </template>
49 49
50   -<script></script>
  50 +<script>
  51 +export default {
  52 + data() {
  53 + return {
  54 + commandDetail: {}
  55 + };
  56 + },
  57 + onLoad(options) {
  58 + const { data } = options;
  59 + this.commandDetail = JSON.parse(data);
  60 + console.log(this.commandDetail, '---------');
  61 + }
  62 +};
  63 +</script>
51 64
52 65 <style lang="scss" scoped>
53 66 .command-detail {
... ... @@ -84,7 +97,7 @@
84 97 }
85 98 }
86 99 }
87   - .command{
  100 + .command {
88 101 margin: 30rpx 0;
89 102 }
90 103 }
... ...
... ... @@ -12,21 +12,21 @@
12 12 </view>
13 13 </view>
14 14 <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
15   - <view @click="openDeviceDetail(item)" class="list-item" v-for="(item, index) in list" :key="index">
  15 + <view @click="openCommandDetail(item)" class="list-item" v-for="(item, index) in list" :key="index">
16 16 <view class="item">
17 17 <view class="item-first">
18 18 <text>{{ item.deviceName }}</text>
19   - <view class="item-right">响应成功</view>
  19 + <!-- <view class="item-right">响应成功</view> -->
20 20 </view>
21   - <view>
  21 + <view v-if="item.additionalInfo.cmdType">
22 22 命令类型:
23   - <text style="margin-left: 16rpx;">MQTT命令</text>
  23 + <text style="margin-left: 16rpx;">{{ item.additionalInfo.cmdType }}</text>
24 24 </view>
25   - <view>
  25 + <view v-if="item.statusName">
26 26 命令状态:
27   - <text style="margin-left: 16rpx;">下发成功</text>
  27 + <text style="margin-left: 16rpx;">{{ item.statusName }}</text>
28 28 </view>
29   - <view class="time">{{ item.createdTime }}</view>
  29 + <view class="time">{{ format(item.createTime) }}</view>
30 30 </view>
31 31 </view>
32 32 </mescroll-body>
... ... @@ -34,10 +34,8 @@
34 34 <u-popup @close="close" closeable bgColor="#fff" :show="show" mode="bottom" :round="20">
35 35 <view class="filter">
36 36 <view class="filter-title"><text>筛选条件</text></view>
37   - <FilterItem :filterList="alarmStatus" title="告警状态" @clickTag="currentIndex => handleClickTag(currentIndex, alarmStatus)"></FilterItem>
38   - <FilterItem :filterList="typeStatus" title="设备类型" @clickTag="currentIndex => handleClickTag(currentIndex, typeStatus)"></FilterItem>
39   - <FilterItem :filterList="alarmLevelStatus" title="告警等级" @clickTag="currentIndex => handleClickTag(currentIndex, alarmLevelStatus)"></FilterItem>
40   - <FilterItem :filterList="timeStatus" title="选择时间" @clickTag="currentIndex => handleClickTag(currentIndex, timeStatus)"></FilterItem>
  37 + <FilterItem :filterList="issueStatus" title="下发状态" @clickTag="currentIndex => handleClickTag(currentIndex, issueStatus)"></FilterItem>
  38 + <FilterItem :filterList="responseWay" title="响应方式" @clickTag="currentIndex => handleClickTag(currentIndex, responseWay)"></FilterItem>
41 39 <view class="button-group">
42 40 <view><u-button :customStyle="{ color: '#333' }" color="#e3e3e5" shape="circle" text="重置" @click="resetFilter"></u-button></view>
43 41 <view><u-button color="#3388ff" shape="circle" text="确认" @click="confirmFilter"></u-button></view>
... ... @@ -59,6 +57,7 @@
59 57 <script>
60 58 import FilterItem from '@/pages/device/FilterItem.vue';
61 59 import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
  60 +import { formatToDate } from '@/plugins/utils.js';
62 61 export default {
63 62 mixins: [MescrollMixin],
64 63 components: {
... ... @@ -70,11 +69,6 @@ export default {
70 69 default: ''
71 70 }
72 71 },
73   - // mounted() {
74   - // this.loadData(1, {
75   - // tbDeviceId: this.tbDeviceId
76   - // });
77   - // },
78 72 data() {
79 73 return {
80 74 show: false,
... ... @@ -85,7 +79,7 @@ export default {
85 79 getTimeGap: ''
86 80 },
87 81 showCalendar: false,
88   - alarmStatus: [
  82 + issueStatus: [
89 83 {
90 84 checked: true,
91 85 name: '全部',
... ... @@ -93,80 +87,16 @@ export default {
93 87 },
94 88 {
95 89 checked: false,
96   - name: '激活未确认',
97   - type: 'ACTIVE_UNACK'
  90 + name: '成功',
  91 + type: 'success'
98 92 },
99 93 {
100 94 checked: false,
101   - name: '激活已确认',
102   - type: 'ACTIVE_ACK'
103   - },
104   - {
105   - checked: false,
106   - name: '清除未确认',
107   - type: 'CLEARED_UNACK'
108   - },
109   - {
110   - checked: false,
111   - name: '清除已确认',
112   - type: 'CLEARED_ACK'
113   - }
114   - ],
115   - typeStatus: [
116   - {
117   - checked: true,
118   - name: '全部',
119   - type: ''
120   - },
121   - {
122   - checked: false,
123   - name: '网关设备',
124   - type: 'GATEWAY'
125   - },
126   - {
127   - checked: false,
128   - name: '网关子设备',
129   - type: 'SENSOR'
130   - },
131   - {
132   - checked: false,
133   - name: '直连设备',
134   - type: 'DIRECT_CONNECTION'
135   - }
136   - ],
137   - alarmLevelStatus: [
138   - {
139   - checked: true,
140   - name: '全部',
141   - type: ''
142   - },
143   - {
144   - checked: false,
145   - name: '危险',
146   - type: 'CRITICAL'
147   - },
148   - {
149   - checked: false,
150   - name: '重要',
151   - type: 'MAJOR'
152   - },
153   - {
154   - checked: false,
155   - name: '次要',
156   - type: 'MINOR'
157   - },
158   - {
159   - checked: false,
160   - name: '警告',
161   - type: 'WARNING'
162   - },
163   - {
164   - checked: false,
165   - name: '不确定',
166   - type: 'INDETERMINATE'
  95 + name: '失败',
  96 + type: 'fail'
167 97 }
168 98 ],
169   - timeStatus: [
  99 + responseWay: [
170 100 {
171 101 checked: true,
172 102 name: '全部',
... ... @@ -174,23 +104,13 @@ export default {
174 104 },
175 105 {
176 106 checked: false,
177   - name: '30分钟',
178   - type: '1800000'
179   - },
180   - {
181   - checked: false,
182   - name: '一小时',
183   - type: '3600000'
184   - },
185   - {
186   - checked: false,
187   - name: '2小时',
188   - type: '7200000'
  107 + name: 'OneWay',
  108 + type: 'OneWay'
189 109 },
190 110 {
191 111 checked: false,
192   - name: '近一天',
193   - type: '1440000'
  112 + name: 'TowWay',
  113 + type: 'TowWay'
194 114 }
195 115 ],
196 116 downOption: {
... ... @@ -212,6 +132,9 @@ export default {
212 132 tbDeviceId: this.tbDeviceId
213 133 });
214 134 },
  135 + format(date) {
  136 + return formatToDate(date, 'YYYY-MM-DD HH:mm:ss');
  137 + },
215 138 /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
216 139 upCallback() {
217 140 //联网加载数据
... ... @@ -257,8 +180,8 @@ export default {
257 180 });
258 181 },
259 182 resetFilter() {
260   - const { alarmStatus, typeStatus, alarmLevelStatus, timeStatus } = this;
261   - [alarmStatus, typeStatus, alarmLevelStatus, timeStatus].forEach(item => item.map((item, index) => (item.checked = index === 0)));
  183 + const { issueStatus, responseWay } = this;
  184 + [issueStatus, responseWay].forEach(item => item.map((item, index) => (item.checked = index === 0)));
262 185 },
263 186 close() {
264 187 this.show = false;
... ... @@ -274,18 +197,11 @@ export default {
274 197 this.timeData.selectTime = `${e[0]} / ${e[e.length - 1]}`;
275 198 },
276 199 confirmFilter() {
277   - const alarmState = this.alarmStatus.find(item => item.checked);
278   - const typeState = this.typeStatus.find(item => item.checked);
279   - const alarmLevelState = this.alarmLevelStatus.find(item => item.checked);
280   - const timeState = this.timeStatus.find(item => item.checked);
281   - const endTs = Date.now();
282   - const startTs = endTs - timeState.type;
  200 + const issueStatus = this.issueStatus.find(item => item.checked);
  201 + const responseWay = this.responseWay.find(item => item.checked);
283 202 this.loadData(1, {
284   - status: alarmState.type ? alarmState.type : undefined,
285   - deviceType: typeState.type ? typeState.type : undefined,
286   - alarmType: alarmLevelState.type ? alarmLevelState.type : undefined,
287   - startTime: timeState.type ? startTs : undefined,
288   - endTime: timeState.type ? endTs : undefined,
  203 + status: issueStatus.type ? issueStatus.type : undefined,
  204 + responseWay: responseWay.type ? responseWay.type : undefined,
289 205 deviceId: this.deviceId
290 206 });
291 207 this.show = false;
... ... @@ -293,19 +209,9 @@ export default {
293 209 calendarClose() {
294 210 this.showCalendar = false;
295 211 },
296   - openDeviceDetail(item) {
297   - const { id, deviceName, severity, originatorType, details, createdTime, status } = item;
298   - let obj = {
299   - id,
300   - deviceName,
301   - severity,
302   - originatorType,
303   - details,
304   - createdTime,
305   - status
306   - };
  212 + openCommandDetail(item) {
307 213 uni.navigateTo({
308   - url: '/deviceSubPage/deviceDetailPage/tabDetail/CommandDetail'
  214 + url: '/deviceSubPage/deviceDetailPage/tabDetail/CommandDetail?data=' + JSON.stringify(item)
309 215 });
310 216 }
311 217 }
... ...
... ... @@ -301,7 +301,7 @@ export default {
301 301 this.loadData(1, {
302 302 status: alarmState.type ? alarmState.type : undefined,
303 303 deviceType: typeState.type ? typeState.type : undefined,
304   - alarmType: alarmLevelState.type ? alarmLevelState.type : undefined,
  304 + severity: alarmLevelState.type ? alarmLevelState.type : undefined,
305 305 startTime: timeState.type ? startTs : undefined,
306 306 endTime: timeState.type ? endTs : undefined,
307 307 deviceId: this.deviceId
... ...
... ... @@ -12,7 +12,9 @@
12 12 {{ deviceDetail.deviceState === 'INACTIVE' ? '待激活' : deviceDetail.deviceState === 'ONLINE' ? '在线' : '离线' }}
13 13 </view>
14 14 </view>
15   - <view style="margin-right: 20rpx;" v-if="deviceDetail.deviceState==='ONLINE'"><u-button type="primary" shape="circle" size="mini" text="下发命令" @click="showModal" /></view>
  15 + <view style="margin-right: 20rpx;" v-if="deviceDetail.deviceState === 'ONLINE' && deviceDetail.deviceType !== 'SENSOR'">
  16 + <u-button type="primary" shape="circle" size="mini" text="下发命令" @click="showModal" />
  17 + </view>
16 18 </view>
17 19 <view class="detail">
18 20 <view class="detail-item">
... ... @@ -126,7 +128,7 @@ export default {
126 128 async confirmCommand() {
127 129 try {
128 130 await issueCommand(this.commandType, this.deviceDetail.tbDeviceId, JSON.parse(this.commandValue));
129   - this.hiddenModal()
  131 + this.hiddenModal();
130 132 } catch (e) {
131 133 uni.$u.toast('下发失败~');
132 134 }
... ...
... ... @@ -34,7 +34,7 @@
34 34 </view>
35 35 <mescroll-empty v-if="!historyData.length"/>
36 36 </view>
37   - <view class="historyData-bottom">
  37 + <view class="historyData-bottom" v-show="historyData.length">
38 38 <view class="table">
39 39 <view class="tr bg-w" v-if="historyData.length">
40 40 <view class="th">变量值</view>
... ... @@ -44,7 +44,6 @@
44 44 <view class="td">{{ item.value }}</view>
45 45 <view class="td">{{ item.ts }}</view>
46 46 </view>
47   - <mescroll-empty v-if="!historyData.length"/>
48 47 </view>
49 48 </view>
50 49 <u-calendar
... ... @@ -134,11 +133,11 @@ export default {
134 133 maxDate: `${year}-${month}-${date + 1}`,
135 134 defaultDate: [this.yesterday, this.today],
136 135 chartData: {
137   - categories: this.historyData.map(item => item.ts),
  136 + categories: this.historyData.length && this.historyData.map(item => item.ts),
138 137 series: [
139 138 {
140 139 name: this.keys[0][0],
141   - data: this.historyData.map(item => Number(item.value))
  140 + data: this.historyData.length && this.historyData.map(item => Number(item.value))
142 141 }
143 142 ]
144 143 },
... ... @@ -187,7 +186,7 @@ export default {
187 186 this.chartData.series = [
188 187 {
189 188 name: this.keys[0][0],
190   - data: this.getHistoryData.map(item => Number(item.value))
  189 + data: newValue.map(item => Number(item.value))
191 190 }
192 191 ];
193 192 }
... ...
1 1 <template>
2 2 <view class="device-page">
3   - <!-- 公共组件-每个页面必须引入 -->
4   - <public-module></public-module>
5 3 <u-sticky>
6 4 <view class="device-top">
7 5 <view class="search">
... ... @@ -27,7 +25,7 @@
27 25 </view>
28 26 </view>
29 27 </u-sticky>
30   - <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
  28 + <mescroll-body ref="mescrollRef" @init="mescrollInit" :upOption="upOption" :down="downOption" @down="downCallback" @up="upCallback">
31 29 <view class="device-list">
32 30 <view @click="openDeviceDetail(item.id, item.alarmStatus, item.lastOnlineTime, item.tbDeviceId)" class="list-item" v-for="item in list" :key="item.id">
33 31 <view
... ... @@ -106,7 +104,6 @@ import fTabbar from '@/components/module/f-tabbar/f-tabbar';
106 104 import fNavbar from '@/components/module/f-navbar/f-navbar';
107 105 import FilterItem from './FilterItem.vue';
108 106 import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
109   -
110 107 import { debounce } from '@/plugins/throttle.js';
111 108 export default {
112 109 mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
... ... @@ -197,7 +194,9 @@ export default {
197 194 onLoad(e) {
198 195 // 隐藏原生的tabbar
199 196 uni.hideTabBar();
  197 + console.log('e', e);
200 198 if (e.type !== undefined) {
  199 + console.log(123)
201 200 const statusT = JSON.parse(e.type);
202 201 this.loadData(1, {
203 202 deviceState: statusT
... ...