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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<template>
<div class="device">
<el-card shadow="never">
<div slot="header">
<span>样表设备</span>
</div>
<TableHeader>
<div slot="left">
<!-- <el-button size="small" type="primary" @click="handleAdd"
>新 增</el-button
>
<el-dropdown class="ml15" @command="handleMore">
<el-button type="primary" size="small">
更多操作<i class="el-icon-arrow-down el-icon--right"></i>
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="1">模板下载</el-dropdown-item>
<el-dropdown-item command="2">导入</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
-->
</div>
<div slot="right" class="flex">
<el-select
class="select"
size="small"
v-model="type"
placeholder="请选择搜索类型"
>
<el-option label="按设备名称" :value="1"> </el-option>
<el-option label="按mac地址" :value="2"> </el-option>
<el-option label="按设备IP" :value="3"> </el-option>
</el-select>
<el-input
size="small"
v-model="searchVal"
class="ml10 mr10"
placeholder="请输入关键字搜索"
@keyup.native.enter="handleSearch"
></el-input>
<el-button size="small" type="primary" @click="handleSearch"
>搜 索</el-button
>
<el-button size="small" @click="searchReset">重 置</el-button>
</div>
</TableHeader>
<!-- 表格 -->
<div class="table-content">
<el-table
ref="multipleTable"
v-loading="loading"
border
:data="tableData"
tooltip-effect="dark"
style="width: 100%"
max-height="676px"
:row-key="(row) => row.id"
>
<el-table-column
type="index"
label="序号"
width="55"
align="center"
:index="(index) => (current - 1) * size + index + 1"
>
</el-table-column>
<el-table-column
show-overflow-tooltip
label="设备名称"
align="center"
prop="deviceName"
>
</el-table-column>
<el-table-column align="center" prop="deviceMac" label="mac地址">
</el-table-column>
<el-table-column align="center" label="设备位置">
<template slot-scope="scope">
<span
v-if="
scope.row.deviceInBuilding ||
scope.row.deviceInFloor ||
scope.row.lon ||
scope.row.lati
"
>{{
`${
scope.row.deviceInBuilding
? scope.row.deviceInBuilding
: "--"
}栋/${
scope.row.deviceInFloor ? scope.row.deviceInFloor : "--"
}楼/${scope.row.lon ? scope.row.lon : "--"},${
scope.row.lati ? scope.row.lati : "--"
}`
}}</span
>
<span v-else>--</span>
</template>
</el-table-column>
<el-table-column align="center" prop="resolution" label="分辨率">
</el-table-column>
<el-table-column align="center" prop="leadingOfficial" label="负责人">
</el-table-column>
<el-table-column
align="center"
prop="leadingOfficialTelephone"
label="联系电话"
>
</el-table-column>
<el-table-column align="center" label="状态">
<template slot-scope="scope">
<el-tag
size="small"
v-if="scope.row.deviceStatus == 2"
type="success"
>在线</el-tag
>
<el-tag
size="small"
v-else-if="scope.row.deviceStatus == 0"
type="danger"
>未激活</el-tag
>
<el-tag size="small" v-else type="danger">离线</el-tag>
</template>
</el-table-column>
<el-table-column align="center" prop="enabled" label="启用/停用">
<template slot-scope="scope">
<el-switch
class="tableScopeSwitch"
:active-value="1"
:inactive-value="0"
v-model="scope.row.enabled"
@change="handleChange(scope.row)"
inactive-text="停用"
active-text="启用"
>
</el-switch>
</template>
</el-table-column>
<el-table-column align="center" prop="deviceRemark" label="备注">
</el-table-column>
<el-table-column align="center" label="操作" width="160">
<template slot-scope="scope">
<div class="flex jca">
<span
v-if="scope.row.deviceStatus == 0"
class="primary pointer"
@click="handleActive(scope.row)"
>激活</span
>
<span
v-if="scope.row.active != 0"
style="opacity: 0"
class="primary"
>激活</span
>
<span class="primary pointer" @click="handleBound(scope.row)"
>绑定表单</span
>
<span class="primary pointer" @click="handleEdit(scope.row)"
>编辑</span
>
<!-- <span class="delete pointer" @click="handleDel(scope.row.id)"
>删除</span
> -->
</div>
</template>
</el-table-column>
</el-table>
</div>
<Pagination
:total="total"
:current="current"
:size="size"
@currentChange="changePagination"
@sizeChange="changeSize"
></Pagination>
</el-card>
<!-- 新增设备 -->
<AddDevice
:dict="dict"
:dialogVisible.sync="dialogVisible"
:title="title"
ref="AddDevice"
@addSuccess="getDeviceList"
></AddDevice>
<!-- 关联事项 -->
<AddMatter ref="AddMatter" :matterDrawer.sync="matterDrawer"></AddMatter>
</div>
</template>
<script>
import TableHeader from "@/components/TableHeader.vue";
import Pagination from "@/components/Pagination.vue";
import AddMatter from "./modal/AddMatter.vue";
import AddDevice from "./modal/AddDevice.vue";
import {
getDeviceList,
saveDeviceEnable,
saveDeviceActive,
} from "@/api/device";
import local from "@/utils/local";
export default {
components: {
TableHeader,
AddDevice,
AddMatter,
Pagination,
},
data() {
return {
searchVal: "",
siteId: local.getLocal("sampleSiteId")
? local.getLocal("sampleSiteId")
: "",
tableData: [],
total: 0,
current: 1,
size: 10,
dialogVisible: false,
title: "新增数字样表设备",
loading: false,
matterDrawer: false,
dict: {}, // 字典
type: 1,
};
},
created() {
this.getDeviceList();
},
methods: {
// 获取设备列表
async getDeviceList() {
this.loading = true;
let obj = {
siteId: this.siteId,
page: this.current,
size: this.size,
productName: "样表机",
};
if (this.type == 1) {
obj.deviceName = `%${this.searchVal}%`;
} else if (this.type == 2) {
obj.deviceMac = `%${this.searchVal}%`;
} else if (this.type == 3) {
obj.ip = `%${this.searchVal}%`;
}
let res = await getDeviceList(obj);
this.loading = false;
if (res.data.code == 1) {
let { data, total, dict } = res.data.data;
this.total = total;
this.tableData = data;
this.dict = dict;
this.$refs.multipleTable.bodyWrapper.scrollTop = 0;
}
},
// 新增
handleAdd() {
this.title = "新增数字样表设备";
this.$refs.AddDevice.onAdd();
this.dialogVisible = true;
},
// 搜索
handleSearch() {
this.current = 1;
this.getDeviceList();
},
// 重置
searchReset() {
this.searchVal = "";
this.current = 1;
this.type = 1;
this.getDeviceList();
},
// 翻页
changePagination(cur) {
this.current = cur;
this.getDeviceList();
},
// 改变每页显示数量
changeSize(size) {
this.size = size;
this.getDeviceList();
},
// 更多操作
handleMore(item) {
console.log(item);
},
// 激活
handleActive(row) {
this.$confirm("此操作将激活这台设备,是否继续?", "系统提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
cancelButtonClass: "btn-custom-cancel",
type: "warning",
})
.then(async () => {
let res = await saveDeviceActive({ deviceCode: row.deviceCode });
let { code, msg } = res.data;
if (code == 1) {
this.$message.success(msg);
this.getDeviceList();
}
})
.catch(() => {
console.log("取消成功!");
});
},
// 编辑
handleEdit(row) {
this.title = "编辑数字样表设备";
this.$refs.AddDevice.onEdit(row);
this.dialogVisible = true;
},
// 删除
handleDel(id) {
this.$confirm("此操作将删除该数字样表设备,是否继续?", "系统提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
cancelButtonClass: "btn-custom-cancel",
type: "warning",
})
.then(async () => {
console.log(id);
})
.catch(() => {
console.log("取消成功!");
});
},
// 启停用
async handleChange(row) {
let obj = {
id: row.id,
enabled: row.enabled,
};
let res = await saveDeviceEnable(obj);
let { code } = res.data;
if (code == 1) {
this.$message.success("修改成功");
this.getDeviceList();
}
},
// 绑定表单
handleBound(row) {
this.matterDrawer = true;
this.$nextTick(() => {
this.$refs.AddMatter.getDevInfo(row);
});
},
},
};
</script>
<style lang="less" scoped>
.device {
width: 100%;
min-height: 100%;
display: flex;
:deep(.el-card) {
height: auto;
}
.select {
width: 220px !important;
}
}
// .table-content {
// height: 550px;
// }
/deep/.tableScopeSwitch .el-switch__label {
position: absolute;
display: none;
color: #fff;
}
/*打开时文字位置设置*/
/deep/.tableScopeSwitch .el-switch__label--right {
z-index: 1;
left: 0px; /*不同场景下可能不同,自行调整*/
}
/*关闭时文字位置设置*/
/deep/.tableScopeSwitch .el-switch__label--left {
z-index: 1;
right: 0px; /*不同场景下可能不同,自行调整*/
}
/*显示文字*/
/deep/.tableScopeSwitch .el-switch__label.is-active {
display: block;
}
/deep/.tableScopeSwitch.el-switch .el-switch__core,
.el-switch .el-switch__label {
width: 60px !important; /*开关按钮的宽度大小*/
}
</style>