|
|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<div class="body">
|
|
|
- <!-- 头部区域 -->
|
|
|
|
|
|
+ <!-- 头部区域 -->
|
|
|
<div class="head">
|
|
|
<div class="head-img">
|
|
|
<img src="../../../public/images/img-1.png" />
|
|
|
@@ -10,12 +10,14 @@
|
|
|
</div>
|
|
|
|
|
|
<!-- 添加按钮区域 -->
|
|
|
-
|
|
|
<div class="switch">
|
|
|
<div class="switch-button">
|
|
|
<el-row>
|
|
|
- <el-button type="primary" size="small" @click="handleCreate"
|
|
|
- ><img src="../../../public/images/img-3.png" />添加
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ size="small"
|
|
|
+ @click="handleCreate"
|
|
|
+ ><img src="../../../public/images/img-3.png" />添加
|
|
|
</el-button>
|
|
|
</el-row>
|
|
|
</div>
|
|
|
@@ -24,64 +26,78 @@
|
|
|
<!-- 表格区域 -->
|
|
|
<div class="form">
|
|
|
<el-table :data="list">
|
|
|
- <el-table-column label="序列号" align="center">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <span>{{ row.serialNumber }}</span>
|
|
|
- </template>
|
|
|
+ <el-table-column
|
|
|
+ label="序列号"
|
|
|
+ align="center"
|
|
|
+ prop="serialNumber"
|
|
|
+ >
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="名称" width="300px" align="center">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <span>{{ row.name }}</span>
|
|
|
- </template>
|
|
|
+ <el-table-column
|
|
|
+ label="名称"
|
|
|
+ width="300px"
|
|
|
+ align="center"
|
|
|
+ prop="name"
|
|
|
+ >
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="厂家" align="center">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <span>{{ row.manufacturer }}</span>
|
|
|
- </template>
|
|
|
+ <el-table-column
|
|
|
+ label="厂家"
|
|
|
+ align="center"
|
|
|
+ prop="manufacturer"
|
|
|
+ >
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="型号" align="center">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <span>{{ row.model }}</span>
|
|
|
- </template>
|
|
|
+ <el-table-column
|
|
|
+ label="型号"
|
|
|
+ align="center"
|
|
|
+ prop="model"
|
|
|
+ >
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="IP地址" align="center">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <span>{{ row.ipAddress }}</span>
|
|
|
- </template>
|
|
|
+ <el-table-column
|
|
|
+ label="IP地址"
|
|
|
+ align="center"
|
|
|
+ prop="ipAddress"
|
|
|
+ >
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="开关" align="center">
|
|
|
- <template slot-scope="scope">
|
|
|
+ <el-table-column
|
|
|
+ label="开关"
|
|
|
+ align="center"
|
|
|
+ >
|
|
|
+ <template slot-scope="{ row }">
|
|
|
<el-switch
|
|
|
- v-model="scope.row.status"
|
|
|
+ v-model="row.status"
|
|
|
active-color="#3BAAFD"
|
|
|
inactive-color="#CCCCCC"
|
|
|
:active-value="1"
|
|
|
:inactive-value="0"
|
|
|
disabled
|
|
|
- @click.native="changeSwitch(scope.row)"
|
|
|
+ @click.native="changeSwitch(row)"
|
|
|
>
|
|
|
</el-switch>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="操作" width="180px" align="center">
|
|
|
+ <el-table-column
|
|
|
+ label="操作"
|
|
|
+ width="180px"
|
|
|
+ align="center"
|
|
|
+ >
|
|
|
<template slot-scope="{ row, $index }">
|
|
|
- <el-button type="text" size="small" @click="handleUpdate(row)"
|
|
|
- >编辑</el-button
|
|
|
- >
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ size="small"
|
|
|
+ @click="handleUpdate(row)"
|
|
|
+ >编辑</el-button>
|
|
|
|
|
|
<el-button
|
|
|
- @click="handleDelete(row, $index)"
|
|
|
type="text"
|
|
|
size="small"
|
|
|
class="button"
|
|
|
- ><img src="../../../public/images/img-2.png" />删除</el-button
|
|
|
- >
|
|
|
+ @click="handleDelete(row)"
|
|
|
+ ><img src="../../../public/images/img-2.png" />删除</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
@@ -100,14 +116,18 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 添加编辑按钮弹窗区域 -->
|
|
|
+ <!-- 添加编辑弹窗区域 -->
|
|
|
<el-dialog
|
|
|
:title="textMap[dialogStatus]"
|
|
|
:visible.sync="dialogVisible"
|
|
|
width="30%"
|
|
|
center
|
|
|
>
|
|
|
- <el-form ref="dataForm" :model="temp" :rules="rules">
|
|
|
+ <el-form
|
|
|
+ ref="dataForm"
|
|
|
+ :model="temp"
|
|
|
+ :rules="rules"
|
|
|
+ >
|
|
|
<el-form-item
|
|
|
style="white-space: pre"
|
|
|
label="序列号:"
|
|
|
@@ -187,8 +207,7 @@
|
|
|
<el-button
|
|
|
type="primary"
|
|
|
@click="dialogStatus === 'create' ? createData() : updateData()"
|
|
|
- >确 定</el-button
|
|
|
- >
|
|
|
+ >确 定</el-button>
|
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
</span>
|
|
|
</el-dialog>
|
|
|
@@ -252,25 +271,15 @@ export default {
|
|
|
this.getList();
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 获取列表数据
|
|
|
getList() {
|
|
|
fetchList(this.listQuery).then((response) => {
|
|
|
+ console.log(response);
|
|
|
this.list = response.data;
|
|
|
this.total = response.total;
|
|
|
});
|
|
|
},
|
|
|
- handleDelete(row, index) {
|
|
|
- if (confirm("是否删除?")) {
|
|
|
- deletDevice({ id: row.id }).then(() => {
|
|
|
- this.$notify({
|
|
|
- title: "删除成功",
|
|
|
- type: "success",
|
|
|
- duration: 2000,
|
|
|
- });
|
|
|
- this.list.splice(index, 1);
|
|
|
- });
|
|
|
- }
|
|
|
- this.getList();
|
|
|
- },
|
|
|
+ // 重置表单为空
|
|
|
resetTemp() {
|
|
|
this.temp = {
|
|
|
id: undefined,
|
|
|
@@ -282,6 +291,7 @@ export default {
|
|
|
status: "1",
|
|
|
};
|
|
|
},
|
|
|
+ // 添加按钮回调
|
|
|
handleCreate() {
|
|
|
this.resetTemp();
|
|
|
this.dialogStatus = "create";
|
|
|
@@ -290,6 +300,7 @@ export default {
|
|
|
this.$refs["dataForm"].clearValidate();
|
|
|
});
|
|
|
},
|
|
|
+ // 编辑按钮回调
|
|
|
handleUpdate(row) {
|
|
|
this.temp = Object.assign({}, row); // copy obj
|
|
|
this.dialogStatus = "update";
|
|
|
@@ -298,37 +309,51 @@ export default {
|
|
|
this.$refs["dataForm"].clearValidate();
|
|
|
});
|
|
|
},
|
|
|
+ // 删除按钮回调
|
|
|
+ handleDelete(row) {
|
|
|
+ this.$confirm(`此操作将永久删除 ${row.name}, 是否继续?`, "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning",
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ deletDevice({ id: row.id }).then(() => {
|
|
|
+ this.getList();
|
|
|
+ this.$notify({
|
|
|
+ title: "删除成功",
|
|
|
+ type: "success",
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.$message.info("已取消删除");
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 添加设备请求
|
|
|
createData() {
|
|
|
this.$refs["dataForm"].validate((valid) => {
|
|
|
if (valid) {
|
|
|
createDevice(this.temp).then(() => {
|
|
|
- this.list.push({
|
|
|
- serialNumber: this.temp.serialNumber,
|
|
|
- name: this.temp.name,
|
|
|
- manufacturer: this.temp.manufacturer,
|
|
|
- model: this.temp.model,
|
|
|
- ipAddress: this.temp.ipAddress,
|
|
|
- status: this.temp.status,
|
|
|
- });
|
|
|
this.dialogVisible = false;
|
|
|
this.$notify({
|
|
|
title: "添加成功",
|
|
|
type: "success",
|
|
|
duration: 1500,
|
|
|
});
|
|
|
+ this.getList();
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
- this.getList();
|
|
|
},
|
|
|
+ // 编辑设备请求
|
|
|
updateData() {
|
|
|
this.$refs["dataForm"].validate((valid) => {
|
|
|
if (valid) {
|
|
|
const tempData = Object.assign({}, this.temp);
|
|
|
updateDevice(tempData).then(() => {
|
|
|
- const index = this.list.findIndex((v) => v.id === this.temp.id);
|
|
|
- this.list.splice(index, 1, this.temp);
|
|
|
this.dialogVisible = false;
|
|
|
+ this.getList();
|
|
|
this.$notify({
|
|
|
title: "编辑成功",
|
|
|
type: "success",
|
|
|
@@ -338,17 +363,15 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ // 更换开关状态
|
|
|
changeSwitch(row) {
|
|
|
+ // console.log(row);
|
|
|
this.temp = Object.assign({}, row);
|
|
|
if (this.temp.status == 0) {
|
|
|
if (confirm("确定开启设备吗?")) {
|
|
|
- updateDevice({ id: this.temp.id, status: this.temp.status }).then(
|
|
|
- () => {
|
|
|
- const index = this.list.findIndex((v) => v.id === this.temp.id);
|
|
|
- this.temp.status = 1;
|
|
|
- this.list.splice(index, 1, this.temp);
|
|
|
- }
|
|
|
- );
|
|
|
+ updateDevice({ id: this.temp.id, status: 1 }).then(() => {
|
|
|
+ this.getList();
|
|
|
+ });
|
|
|
this.$notify({
|
|
|
title: "开启成功",
|
|
|
type: "success",
|
|
|
@@ -357,13 +380,9 @@ export default {
|
|
|
}
|
|
|
} else {
|
|
|
if (confirm("确定关闭设备吗?")) {
|
|
|
- updateDevice({ id: this.temp.id, status: this.temp.status }).then(
|
|
|
- () => {
|
|
|
- const index = this.list.findIndex((v) => v.id === this.temp.id);
|
|
|
- this.temp.status = 0;
|
|
|
- this.list.splice(index, 1, this.temp);
|
|
|
- }
|
|
|
- );
|
|
|
+ updateDevice({ id: this.temp.id, status: 0 }).then(() => {
|
|
|
+ this.getList();
|
|
|
+ });
|
|
|
this.$notify({
|
|
|
title: "关闭成功",
|
|
|
type: "success",
|