| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- <template>
- <div class="body">
- <!-- 头部区域 -->
- <div class="head">
- <div class="head-img">
- <img src="../../../public/images/img-1.png" />
- </div>
- <div class="head-info">设备管理</div>
- </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>
- </el-row>
- </div>
- </div>
- <!-- 表格区域 -->
- <div class="form">
- <el-table :data="list">
- <el-table-column
- label="序列号"
- align="center"
- prop="serialNumber"
- >
- </el-table-column>
- <el-table-column
- label="名称"
- width="300px"
- align="center"
- prop="name"
- >
- </el-table-column>
- <el-table-column
- label="厂家"
- align="center"
- prop="manufacturer"
- >
- </el-table-column>
- <el-table-column
- label="型号"
- align="center"
- prop="model"
- >
- </el-table-column>
- <el-table-column
- label="IP地址"
- align="center"
- prop="ipAddress"
- >
- </el-table-column>
- <el-table-column
- label="开关"
- align="center"
- >
- <template slot-scope="{ row }">
- <el-switch
- v-model="row.status"
- active-color="#3BAAFD"
- inactive-color="#CCCCCC"
- :active-value="1"
- :inactive-value="0"
- disabled
- @click.native="changeSwitch(row)"
- >
- </el-switch>
- </template>
- </el-table-column>
- <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"
- class="button"
- @click="handleDelete(row)"
- ><img src="../../../public/images/img-2.png" />删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <!-- 底部分页区 -->
- <div class="block">
- <template>
- <pagination
- :total="total"
- :page.sync="listQuery.page"
- :limit.sync="listQuery.limit"
- @pagination="getList"
- />
- </template>
- </div>
- </div>
- <!-- 添加编辑弹窗区域 -->
- <el-dialog
- :title="textMap[dialogStatus]"
- :visible.sync="dialogVisible"
- width="30%"
- center
- >
- <el-form
- ref="dataForm"
- :model="temp"
- :rules="rules"
- >
- <el-form-item
- style="white-space: pre"
- label="序列号:"
- class="switch-button-item"
- prop="serialNumber"
- >
- <el-col :span="12">
- <el-input
- v-model="temp.serialNumber"
- autocomplete="off"
- placeholder="请输入序列号"
- ></el-input>
- </el-col>
- </el-form-item>
- <el-form-item
- style="white-space: pre"
- label="名 称:"
- class="switch-button-item"
- prop="name"
- >
- <el-col :span="12">
- <el-input
- v-model="temp.name"
- autocomplete="off"
- placeholder="请输入名称"
- ></el-input>
- </el-col>
- </el-form-item>
- <el-form-item
- style="white-space: pre"
- label="厂 家:"
- class="switch-button-item"
- prop="manufacturer"
- >
- <el-col :span="12">
- <el-input
- v-model="temp.manufacturer"
- autocomplete="off"
- placeholder="请输入厂家"
- ></el-input>
- </el-col>
- </el-form-item>
- <el-form-item
- style="white-space: pre"
- label="型 号:"
- class="switch-button-item"
- prop="model"
- >
- <el-col :span="12">
- <el-input
- v-model="temp.model"
- autocomplete="off"
- placeholder="请输入型号"
- ></el-input>
- </el-col>
- </el-form-item>
- <el-form-item
- style="white-space: pre"
- label="IP 地 址:"
- class="switch-button-item"
- prop="ipAddress"
- >
- <el-col :span="12">
- <el-input
- v-model="temp.ipAddress"
- autocomplete="off"
- placeholder="请输入IP地址"
- ></el-input>
- </el-col>
- </el-form-item>
- </el-form>
- <span slot="footer">
- <el-button
- type="primary"
- @click="dialogStatus === 'create' ? createData() : updateData()"
- >确 定</el-button>
- <el-button @click="dialogVisible = false">取 消</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import Pagination from "@/components/Pagination";
- import {
- fetchList,
- createDevice,
- updateDevice,
- deletDevice,
- } from "@/api/devicemanagement";
- export default {
- components: {
- Pagination,
- },
- data() {
- return {
- list: [],
- total: 0, //数据的总数//
- listQuery: {
- page: 1, //当前在第几页//
- limit: 8, //一页几条//
- },
- dialogVisible: false,
- dialogStatus: "",
- textMap: {
- update: "编辑门禁设备",
- create: "添加门禁设备",
- },
- temp: {
- id: "",
- serialNumber: "",
- name: "",
- manufacturer: "",
- model: "",
- ipAddress: "",
- status: "1",
- },
- rules: {
- serialNumber: [
- {
- required: true,
- message: "请输入序列号",
- trigger: "change",
- },
- ],
- name: [
- {
- required: true,
- message: "请输入名称",
- trigger: "change",
- },
- ],
- },
- };
- },
- created() {
- this.getList();
- },
- methods: {
- // 获取列表数据
- getList() {
- fetchList(this.listQuery).then((response) => {
- console.log(response);
- this.list = response.data;
- this.total = response.total;
- });
- },
- // 重置表单为空
- resetTemp() {
- this.temp = {
- id: undefined,
- serialNumber: "",
- name: "",
- manufacturer: "",
- model: "",
- ipAddress: "",
- status: "1",
- };
- },
- // 添加按钮回调
- handleCreate() {
- this.resetTemp();
- this.dialogStatus = "create";
- this.dialogVisible = true;
- this.$nextTick(() => {
- this.$refs["dataForm"].clearValidate();
- });
- },
- // 编辑按钮回调
- handleUpdate(row) {
- this.temp = Object.assign({}, row); // copy obj
- this.dialogStatus = "update";
- this.dialogVisible = true;
- this.$nextTick(() => {
- 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.dialogVisible = false;
- this.$notify({
- title: "添加成功",
- type: "success",
- duration: 1500,
- });
- this.getList();
- });
- }
- });
- },
- // 编辑设备请求
- updateData() {
- this.$refs["dataForm"].validate((valid) => {
- if (valid) {
- const tempData = Object.assign({}, this.temp);
- updateDevice(tempData).then(() => {
- this.dialogVisible = false;
- this.getList();
- this.$notify({
- title: "编辑成功",
- type: "success",
- duration: 1500,
- });
- });
- }
- });
- },
- // 更换开关状态
- changeSwitch(row) {
- // console.log(row);
- this.temp = Object.assign({}, row);
- if (this.temp.status == 0) {
- if (confirm("确定开启设备吗?")) {
- updateDevice({ id: this.temp.id, status: 1 }).then(() => {
- this.getList();
- });
- this.$notify({
- title: "开启成功",
- type: "success",
- duration: 1500,
- });
- }
- } else {
- if (confirm("确定关闭设备吗?")) {
- updateDevice({ id: this.temp.id, status: 0 }).then(() => {
- this.getList();
- });
- this.$notify({
- title: "关闭成功",
- type: "success",
- duration: 1500,
- });
- }
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .body {
- width: 1551px;
- margin: 29px 29px 0 31px;
- .head {
- display: flex;
- width: 1380px;
- height: 55px;
- margin-left: 40px;
- border-bottom: 1px solid #cccccc;
- .head-img {
- width: 30px;
- height: 30px;
- img {
- width: 30px;
- }
- }
- .head-info {
- width: 95px;
- height: 22px;
- margin-top: 5px;
- margin-left: 16px;
- font-weight: bold;
- }
- }
- .switch {
- display: flex;
- width: 1380px;
- line-height: 58px;
- margin-left: 40px;
- font-size: 9px;
- .switch-button {
- width: 50px;
- img {
- width: 10.5px;
- margin-right: 8px;
- }
- }
- }
- .form {
- margin-left: 40px;
- width: 1380px;
- .el-switch.is-disabled {
- opacity: 1;
- ::v-deep .el-switch__core {
- cursor: pointer;
- }
- }
- .button {
- color: red;
- }
- img {
- width: 8.5px;
- margin-right: 8px;
- }
- .block {
- float: right;
- }
- }
- .switch-button-item {
- margin-left: 120px;
- margin-top: 32px;
- }
- }
- </style>
|