command-issuance.vue
7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<template>
<view class="w-100 modal-content">
<view>
<view style="max-height: 560rpx; overflow-y: scroll">
<view class="header-title">命令下发</view>
<view class="u-flex">
<text class="type-text">下发类型:</text>
<u-radio-group v-model="commandType" placement="row" @change="handleCommand">
<u-radio :customStyle="{ marginRight: '20rpx' }" v-for="item in commandTypeList"
activeColor="#3388FF" :label="item.label" :name="item.value" :key="item.value"></u-radio>
</u-radio-group>
</view>
<view class="u-flex" style="margin-top: 28rpx" v-if="commandType == 0">
<text class="type-text">单向/双向:</text>
<u-radio-group v-model="callType" placement="row">
<u-radio activeColor="#3388FF" label="单向" name="OneWay"></u-radio>
<view style="margin: 0 20rpx"></view>
<u-radio activeColor="#3388FF" label="双向" name="TwoWay"></u-radio>
</u-radio-group>
</view>
<view class="u-flex" style="margin-top: 28rpx" v-else>
<text class="type-text">服务:</text>
<view @click="openService">
<u-input shape="circle" v-model="serviceName" placeholder="请选择服务" disabled disabledColor="#fff"
suffixIcon="arrow-down" />
</view>
</view>
<view class="u-flex" style="
margin-top: 28rpx;
flex-direction: column;
align-items: flex-start;
" v-if="isShowServiceFunctionName && commandType == 1">
<text class="type-text">输入参数:</text>
<seriesForm ref="seriesFormRef" :seriesInputData="seriesInputData" :isTCPTransport="isTCPTransport">
</seriesForm>
</view>
<view class="content-body" v-if="commandType == 0">
<div class="u-flex u-row-between">
<u--textarea :placeholder="`请输入下发内容${
isShowTCP ? '(字符串格式)' : '(json格式)'
}`" v-model="inputCommandVal" />
<u-icon v-if="!isShowTCP" @click="handleCopy(copyTextValue)" name="question-circle"
color="#2979ff" size="28" class="ml-10">
</u-icon>
</div>
</view>
</view>
<view class="button-group">
<view>
<u-button :customStyle="{ color: '#333' }" color="#e3e3e5" shape="circle" text="取消"
@click="cancelCommand"></u-button>
</view>
<view>
<u-button color="#3388ff" shape="circle" text="确认" @click="confirmCommand"></u-button>
</view>
</view>
</view>
<u-picker :show="isShowService" :columns="[
seriesList.map((item) => ({
label: item.functionName,
value: item.identifier,
callType: item.callType,
})),
]" keyName="label" closeOnClickOverlay @cancel="cancelTypeGap" @close="cancelTypeGap"
@confirm="handleSelect"></u-picker>
</view>
</template>
<script>
import {
useShowModal
} from "@/plugins/utils.js";
import seriesForm from "./seriesForm.vue";
import api from "@/api/index.js";
export default {
components: {
seriesForm,
},
props: {
showModal: Boolean,
isShowTCP: Boolean,
deviceDetail: Object,
},
data() {
return {
current: 0,
commandType: 0, //下发类型
callType: "OneWay", //单双向
serviceName: "", //服务
service: null, //服务
inputCommandVal: "", //自定义命令
isShowService: false, //服务下拉框
isShowServiceFunctionName: false, //选择服务过后的输入参数
copyTextValue: {
method: "methodThingskit",
params: {
pin: 7,
value: 1,
},
},
commandTypeList: [{
label: "自定义",
value: 0
}],
seriesList: [], //服务下拉框的数据
boolList: [],
enumList: [],
seriesInputData: [],
isTCPTransport: false,
};
},
mounted() {
this.getFormInfo();
},
watch: {
showModal: {
deep: true,
handler() {
this.commandType = 0;
this.serviceName = "";
this.isShowServiceFunctionName = false;
},
},
},
methods: {
cancelCommand() {
this.commandType = 0;
this.$emit("cancelCommand");
},
async confirmCommand() {
if (this.commandType == 0) {
this.$emit(
"confirmCommand",
this.commandType,
this.callType,
this.inputCommandVal
);
} else {
const result = this.$refs.seriesFormRef.handleValidate();
if (!result) {
return;
}
const value = this.$refs.seriesFormRef.getFormField();
const values = this.isTCPTransport ?
value.serviceCommand : {
[this.service]: value,
};
this.$emit("confirmCommand", this.commandType, this.callType, values);
}
},
handleCopy(value) {
useShowModal(JSON.stringify(value), "命令下发", "复制内容").then(
(res) => {
uni.setClipboardData({
data: JSON.stringify(value),
success: () => {
uni.showToast({
title: "复制成功",
});
},
});
}
);
},
async getFormInfo() {
const {
transportType,
deviceType,
deviceProfile
} =
this.deviceDetail || {};
const {
profileData: {
transportConfiguration: {
protocol
},
},
} = deviceProfile || {};
this.isTCPTransport = transportType === "TCP";
const isTCPModbus = this.isTCPTransport && protocol === "MODBUS_RTU";
if (isTCPModbus || (this.isTCPTransport && deviceType === "SENSOR")) {
this.commandTypeList =
this.commandTypeList.length == 2 ?
this.commandTypeList.pop() :
this.commandTypeList;
} else {
this.commandTypeList.push({
label: "服务",
value: 1
});
this.seriesList = await api.deviceApi.getModelServices(
this.deviceDetail
);
}
},
openService() {
this.isShowService = true;
},
handleSelect(e) {
this.isShowService = false;
const {
value
} = e || {};
this.serviceName = value[0].label;
this.service = value[0].value;
if (this.service) {
this.isShowServiceFunctionName = true;
const {
functionJson
} =
this.seriesList.filter(
(item) => item.identifier === this.service
)[0] || {};
const {
inputData
} = functionJson || {};
this.seriesInputData = inputData || [];
this.callType = value[0].callType === "ASYNC" ? "OneWay" : "TwoWay";
}
},
cancelModel() {
this.isShowService = false;
this.seriesInputData = [];
this.seriesList = [];
},
handleCommand(name) {
this.seriesInputData = [];
this.serviceName = "";
this.isShowServiceFunctionName = false;
if (this.commandType == 0) {
this.callType = "OneWay";
}
},
cancelTypeGap() {
this.isShowService = false;
},
reset() {
this.callType = "OneWay";
this.inputCommandVal = "";
},
},
};
</script>
<style lang="scss" scoped>
.modal-content {
width: 720rpx;
padding: 0 30rpx;
background-color: white;
.header-title {
text-align: center;
font-weight: 700;
margin-bottom: 40rpx;
}
.type-text {
color: #333;
font-size: 14px;
font-weight: 700;
margin-right: 30rpx;
}
.content-body {
margin-top: 28rpx;
width: 100%;
}
.button-group {
display: flex;
margin-top: 40rpx;
justify-content: space-between;
view {
width: 300rpx;
}
}
}
</style>