279 lines
7.1 KiB
Vue
279 lines
7.1 KiB
Vue
<template>
|
|
<el-card class="content-div">
|
|
<div class="all-content">
|
|
<div class="top-div">
|
|
<el-button type="primary" @click="addData">新增</el-button>
|
|
</div>
|
|
<el-table
|
|
:data="tableData"
|
|
height="730"
|
|
style="width: 100%"
|
|
border
|
|
stripe
|
|
:header-cell-style="{ background: '#F6F7FC' }"
|
|
>
|
|
<el-table-column type="index" label="序号" width="80" align="center" />
|
|
<el-table-column
|
|
prop="name"
|
|
label="通讯名称"
|
|
width="200"
|
|
align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
prop="description"
|
|
label="通讯描述"
|
|
width="200"
|
|
align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
prop="drive"
|
|
label="通讯驱动"
|
|
width="200"
|
|
align="center"
|
|
show-overflow-tooltip
|
|
>
|
|
<template #default="scope">
|
|
<span>{{ qudongOptions[scope.row.type]}}</span>
|
|
</template>
|
|
</el-table-column>
|
|
<!-- <el-table-column
|
|
prop="host"
|
|
label="主机地址"
|
|
width="200"
|
|
align="center"
|
|
show-overflow-tooltip
|
|
/> -->
|
|
<el-table-column
|
|
prop="status"
|
|
label="通讯状态"
|
|
width="200"
|
|
align="center"
|
|
>
|
|
<template #default="scope">
|
|
<span
|
|
class="txStatusDiv"
|
|
:style="{
|
|
background: scope.row.status == 1 ? '#13ce66' : '#f8cecc',
|
|
}"
|
|
>{{ scope.row.status == 1 ? "正常" : "未连接" }}</span
|
|
>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
prop="enable"
|
|
label="启用状态"
|
|
width="350"
|
|
align="center"
|
|
>
|
|
<template #default="scope">
|
|
<el-switch
|
|
v-model="scope.row.enable"
|
|
inline-prompt
|
|
active-text="启用"
|
|
inactive-text="停用"
|
|
:active-value="false"
|
|
:inactive-value="true"
|
|
active-color="#13ce66"
|
|
inactive-color="red"
|
|
@change="changeStatus(scope.row)"
|
|
/>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="操作" align="center" show-overflow-tooltip>
|
|
<template #default="scope">
|
|
<el-button type="primary" @click="editData(scope.row)">
|
|
编辑
|
|
</el-button>
|
|
<el-button type="danger" @click="delData(scope.row)">
|
|
删除
|
|
</el-button>
|
|
<el-button type="info" @click="manageData(scope.row)">
|
|
新增设备
|
|
</el-button>
|
|
<el-button type="info" @click="viewData(scope.row)">
|
|
设备查询
|
|
</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</div>
|
|
<AddData
|
|
:formData="formData"
|
|
:type="type"
|
|
:qudongOptions="qudongOptions"
|
|
:dialogVisible="dialogVisible"
|
|
v-if="dialogVisible"
|
|
@dialogClose="dialogClose"
|
|
@dialogSuccess="dialogSuccess"
|
|
></AddData>
|
|
<AddSet
|
|
:formData="formData"
|
|
:dialogVisible="dialogVisible1"
|
|
v-if="dialogVisible1"
|
|
@dialogClose="dialogClose"
|
|
@dialogSuccess="dialogSuccess"
|
|
>
|
|
</AddSet>
|
|
<ViewSet :formData="formData" :dialogVisible="dialogVisible2" v-if="dialogVisible2" @dialogClose="dialogClose"
|
|
@dialogSuccess="dialogSuccess">
|
|
</ViewSet>
|
|
</el-card>
|
|
</template>
|
|
|
|
<script>
|
|
import { onMounted, reactive, ref, toRefs } from "vue";
|
|
import infoApi from "@/api/infoApi.js";
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
import AddData from "@/components/AddData.vue";
|
|
import AddSet from "@/components/AddSet.vue";
|
|
import ViewSet from "@/components/ViewSet.vue";
|
|
export default {
|
|
name: "page",
|
|
components: {
|
|
AddData,
|
|
AddSet,
|
|
ViewSet
|
|
},
|
|
setup() {
|
|
const state = reactive({
|
|
qudongOptions: [],
|
|
tableData: [],
|
|
formData: {},
|
|
dialogVisible: false,
|
|
dialogVisible1: false,
|
|
dialogVisible2: false,
|
|
type: '0' // 0新增 1 编辑
|
|
});
|
|
|
|
onMounted(() => {
|
|
getTxSupport();
|
|
getTableData();
|
|
});
|
|
// 获取通讯驱动
|
|
const getTxSupport = async () => {
|
|
|
|
const res = await infoApi.getTxSupport();
|
|
if (res.code == 0) {
|
|
state.qudongOptions = res.data;
|
|
}
|
|
|
|
|
|
};
|
|
const getTableData = async () => {
|
|
const param = {
|
|
type: 0
|
|
}
|
|
const res = await infoApi.getTx(param);
|
|
if (res.code == 0) {
|
|
state.tableData = res.data;
|
|
}
|
|
};
|
|
const dialogClose = () => {
|
|
state.dialogVisible = false;
|
|
state.dialogVisible1 = false;
|
|
state.dialogVisible2 = false;
|
|
};
|
|
|
|
const dialogSuccess = () => {
|
|
state.dialogVisible = false;
|
|
state.dialogVisible1 = false;
|
|
state.dialogVisible2 = false;
|
|
getTableData();
|
|
};
|
|
|
|
const addData = () => {
|
|
state.formData = {
|
|
name: '',
|
|
type: 1,
|
|
description: '',
|
|
};
|
|
state.dialogVisible = true;
|
|
state.type = '0';
|
|
};
|
|
|
|
const editData = (item) => {
|
|
console.log(777, item)
|
|
state.formData = JSON.parse(JSON.stringify(item));
|
|
state.dialogVisible = true;
|
|
state.type = '1'
|
|
};
|
|
|
|
const delData = (item) => {
|
|
ElMessageBox.confirm("确定删除该数据?", "提示", {
|
|
confirmButtonText: "确定",
|
|
cancelButtonText: "取消",
|
|
type: "warning",
|
|
})
|
|
.then(async () => {
|
|
let param = {
|
|
name: state.formData.name
|
|
}
|
|
const res = await infoApi.delTx(param);
|
|
if (res.code == 0) {
|
|
ElMessage.success(res.message || "删除成功");
|
|
getTableData();
|
|
} else {
|
|
ElMessage.error(res.message | "删除失败");
|
|
}
|
|
})
|
|
.catch(() => {
|
|
ElMessage.info("已取消删除");
|
|
});
|
|
};
|
|
|
|
const manageData = (item) => {
|
|
state.formData = JSON.parse(JSON.stringify(item));
|
|
state.dialogVisible1 = true;
|
|
};
|
|
|
|
const viewData = (item) => {
|
|
state.dialogVisible2 = true;
|
|
state.formData = JSON.parse(JSON.stringify(item));
|
|
}
|
|
|
|
const changeStatus = async (item) => {
|
|
console.log(item.enable);
|
|
const param = {
|
|
name: item.name,
|
|
}
|
|
const res = item.enable ? await infoApi.startStatus(param) : await infoApi.stopStatus(param);
|
|
if (res.code == 0) {
|
|
ElMessage.success(res.msg || "请求成功");
|
|
getTableData();
|
|
} else {
|
|
ElMessage.error(res.msg);
|
|
}
|
|
};
|
|
|
|
return {
|
|
...toRefs(state),
|
|
addData,
|
|
editData,
|
|
delData,
|
|
manageData,
|
|
dialogClose,
|
|
dialogSuccess,
|
|
changeStatus,
|
|
viewData
|
|
};
|
|
},
|
|
};
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.all-content {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.top-div {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
}
|
|
.txStatusDiv {
|
|
padding: 0 15px;
|
|
border-radius: 10px;
|
|
color: #fff;
|
|
}
|
|
</style>
|