305 lines
9.5 KiB
Vue
Raw Normal View History

2025-03-31 18:24:37 +08:00
<template>
<div class="container">
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" />
<div class="table-container">
2025-04-12 18:35:54 +08:00
<TableCustom :selection-change="handleSelect" :columns="columns" :tableData="tableData" :paging="paging" :changePage="changePage">
2025-03-31 18:24:37 +08:00
<template #toolbarBtn>
2025-04-02 18:40:20 +08:00
<!-- <el-button type="primary" @click="handleAdd">新增</el-button> -->
2025-04-12 18:35:54 +08:00
<el-button @click="handleEdit()">设备关联</el-button>
2025-04-02 18:40:20 +08:00
<!-- <el-button>地图位置</el-button> -->
<!-- <el-button>导出</el-button> -->
2025-03-31 18:24:37 +08:00
</template>
2025-04-03 18:21:17 +08:00
2025-04-09 18:45:44 +08:00
<template #status="{ rows }">
<el-tag :type="statusColor[rows.status]">{{ statusEnum[rows.status] }}</el-tag>
2025-04-03 18:21:17 +08:00
</template>
2025-04-10 19:00:17 +08:00
<template #useStatus="{ rows }">
<el-switch v-model="rows.useStatus" :active-value="1" :inactive-value="0" @click="handelSwitch(rows, 1)" />
2025-04-03 18:21:17 +08:00
</template>
2025-04-09 18:45:44 +08:00
<template #deviceSwitch="{ rows }">
2025-04-10 19:00:17 +08:00
<el-switch v-model="rows.deviceSwitch" :active-value="1" :inactive-value="0" @click="handelSwitch(rows, 2)" />
</template>
<template #mode="{ rows }">
<el-tag :type="modeColor[rows.mode]">{{ modeEnum[rows.mode] }}</el-tag>
2025-03-31 18:24:37 +08:00
</template>
2025-04-03 18:21:17 +08:00
<template #battery="{ rows }"> {{ rows.battery }}% </template>
2025-04-01 13:52:57 +08:00
<template #operator="{ rows }">
2025-04-03 18:21:17 +08:00
<el-button link type="primary" size="small" @click="toPage('deviceInfo', rows)"> 详细信息 </el-button>
<el-button link type="primary" size="small" @click="toPage('mapLocation', rows)"> 地图位置 </el-button>
<el-button link type="primary" size="small" @click="toPage('setting', rows)"> 专项配置 </el-button>
<el-button link type="primary" size="small" @click="handelRow(rows)"> 设备控制 </el-button>
2025-04-01 13:52:57 +08:00
<el-button link type="primary" size="small" @click="handleEdit(rows)"> 修改 </el-button>
2025-04-02 18:40:20 +08:00
<!-- <el-button link type="danger" size="small" @click="handelDel(rows)"> 删除 </el-button> -->
2025-03-31 18:24:37 +08:00
</template>
</TableCustom>
</div>
<el-dialog :title="isEdit ? '编辑' : '新增'" v-model="visible" width="700px" destroy-on-close :close-on-click-modal="false" @close="closeDialog">
2025-04-02 18:40:20 +08:00
<TableEdit :form-data="rowData" :options="TableEditOptions" :edit="isEdit" :update="updateData" @close="closeDialog" />
</el-dialog>
2025-04-03 18:21:17 +08:00
2025-04-02 18:40:20 +08:00
<el-dialog title="设备控制" v-model="visible1" width="700px" destroy-on-close :close-on-click-modal="false" @close="closeDialog">
<!-- <TableEdit :form-data="rowData" :options="controlOptions" :update="updateData" /> -->
2025-04-23 17:23:03 +08:00
<DeviceControl :rowData="rowData" v-model="controlForm" @change="handelControl" />
2025-03-31 18:24:37 +08:00
</el-dialog>
2025-04-12 18:35:54 +08:00
<el-dialog title="设备关联" v-model="visible2" width="700px" destroy-on-close :close-on-click-modal="false" @close="closeDialog">
<BindArea :orgAllData="orgAllData" :selectDeviceList="selectDeviceList" @close="visible2 = false" :api="bindWebFn" />
</el-dialog>
2025-03-31 18:24:37 +08:00
</div>
</template>
<script setup lang="ts" name="basetable">
2025-04-09 18:45:44 +08:00
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
2025-04-23 17:23:03 +08:00
import { deviceList, setMode, deviceGetLocation, deviceControl, setUseStatus, setStatus, orgAllList, bindWeb, deviceOta } from "@/api/index";
2025-04-12 18:35:54 +08:00
import { TbindWeb, TDevice, TOrg } from "@/api/index.d";
2025-03-31 18:24:37 +08:00
import TableCustom from "@/components/table-custom.vue";
import TableSearch from "@/components/table-search.vue";
import TableEdit from "@/components/table-edit.vue";
2025-04-03 18:21:17 +08:00
import DeviceControl from "./deviceControl.vue";
2025-04-12 18:35:54 +08:00
import BindArea from "./bindArea.vue";
2025-03-31 18:24:37 +08:00
import { TableItem } from "@/types/table";
import { FormOption, FormOptionList } from "@/types/form-option";
import { useRouter } from "vue-router";
2025-04-07 18:35:54 +08:00
2025-04-09 18:45:44 +08:00
enum statusEnum {
2025-04-03 18:21:17 +08:00
"离线" = 0,
"在线",
"充电中",
}
2025-04-09 18:45:44 +08:00
2025-04-03 18:21:17 +08:00
enum modeEnum {
2025-04-09 18:45:44 +08:00
"常规",
"审讯模式",
"户外押送",
2025-04-03 18:21:17 +08:00
}
2025-04-09 18:45:44 +08:00
const statusColor = ["danger", "success", "warning"];
const modeColor = ["primary", "danger", "warning"];
2025-03-31 18:24:37 +08:00
const router = useRouter();
// 新增/编辑弹窗相关
let TableEditOptions = ref<FormOption>({
labelWidth: "100px",
span: 24,
list: [],
});
const addOp = [{ type: "input", label: "唯一编码", prop: "name", required: true }];
const editOp = [
{ type: "select", label: "选择手铐", prop: "name", required: true },
2025-04-12 18:35:54 +08:00
{ type: "select", label: "辖区列表", prop: "name2" },
{ type: "select", label: "账号列表", prop: "name3" },
2025-03-31 18:24:37 +08:00
];
// 查询相关
2025-04-11 18:46:52 +08:00
const query = reactive({});
2025-03-31 18:24:37 +08:00
const searchOpt = ref<FormOptionList[]>([
2025-04-29 18:31:02 +08:00
{ type: "input", label: "IMEI", prop: "deviceId" },
2025-04-11 18:46:52 +08:00
{ type: "input", label: "警察名称:", prop: "name" },
{
type: "select",
label: "当前模式:",
prop: "mode",
opts: [
{ label: "常规", value: "0" },
{ label: "审讯", value: "1" },
{ label: "户外押送", value: "2" },
],
},
{
type: "select",
label: "设备状态:",
prop: "status",
opts: [
{ label: "离线", value: "0" },
{ label: "在线", value: "1" },
{ label: "充电中", value: "2" },
],
},
{
type: "select",
label: "使用状态:",
prop: "useStatus",
opts: [
{ label: "未使用", value: "0" },
{ label: "使用中", value: "1" },
],
},
2025-03-31 18:24:37 +08:00
]);
const handleSearch = () => {
changePage(1);
};
2025-04-12 18:35:54 +08:00
const selectDeviceList = ref<TDevice.IListRes[]>([]);
2025-03-31 18:24:37 +08:00
// 表格相关
let columns = ref([
2025-04-12 18:35:54 +08:00
{ type: "selection", reserveSelection: true },
2025-03-31 18:24:37 +08:00
{ type: "index", label: "序号", width: 55, align: "center" },
2025-04-12 18:35:54 +08:00
{ prop: "deviceId", label: "IMEI", width: 120 },
2025-04-11 18:46:52 +08:00
{ prop: "adminName", label: "绑定警察名称", width: 180 },
{ prop: "adminUsername", label: "绑定警察账户", width: 120 },
2025-04-12 18:35:54 +08:00
{ prop: "orgName", label: "关联辖区", width: 120 },
2025-04-11 18:46:52 +08:00
{ prop: "battery", label: "电量", width: 100 },
{ prop: "deviceVersion", label: "版本号", width: 100 },
{ prop: "status", label: "设备状态", width: 100 },
{ prop: "mode", label: "当前模式", width: 100 },
{ prop: "useStatus", label: "使用状态", width: 100 },
{ prop: "deviceSwitch", label: "启用开关", width: 100 },
{ prop: "createTime", label: "最新通信时间", width: 180 },
{ prop: "createTime", label: "创建时间", width: 180 },
2025-04-12 18:35:54 +08:00
{ prop: "operator", label: "操作", width: 400, fixed: "right" },
2025-03-31 18:24:37 +08:00
]);
2025-04-03 18:21:17 +08:00
const paging = reactive({
page: 1,
2025-03-31 18:24:37 +08:00
size: 10,
2025-04-03 18:21:17 +08:00
total: 0,
2025-03-31 18:24:37 +08:00
});
2025-04-02 18:40:20 +08:00
const controlForm = reactive({
2025-04-09 18:45:44 +08:00
mode: 0,
2025-04-03 18:21:17 +08:00
location: 1,
2025-04-02 18:40:20 +08:00
});
2025-04-03 18:21:17 +08:00
const tableData = ref<TDevice.IListRes[]>([]);
2025-04-12 18:35:54 +08:00
const orgAllData = ref<TOrg.IOrgRecordRes[]>([]);
2025-03-31 18:24:37 +08:00
const getData = async () => {
2025-04-11 18:46:52 +08:00
const res = await deviceList({ ...paging, ...query });
2025-04-03 18:21:17 +08:00
tableData.value = res.records;
paging.total = res.total;
2025-03-31 18:24:37 +08:00
};
2025-04-12 18:35:54 +08:00
const bindWebFn = (val: TbindWeb) => {
bindWeb(val).then(() => {
ElMessage.success("操作成功");
visible2.value = false;
getData();
});
};
const handleSelect = (val: TDevice.IListRes[]) => {
selectDeviceList.value = val;
};
2025-03-31 18:24:37 +08:00
const changePage = (val: number) => {
2025-04-03 18:21:17 +08:00
paging.page = val;
2025-03-31 18:24:37 +08:00
getData();
};
2025-04-02 18:40:20 +08:00
const visible1 = ref(false);
2025-04-12 18:35:54 +08:00
const visible2 = ref(false);
2025-03-31 18:24:37 +08:00
const visible = ref(false);
const isEdit = ref(false);
2025-04-03 18:21:17 +08:00
const rowData = ref<TDevice.IListRes>();
2025-03-31 18:24:37 +08:00
const handleAdd = () => {
TableEditOptions.value.list = addOp;
visible.value = true;
};
2025-04-01 13:52:57 +08:00
// 编辑
2025-04-03 18:21:17 +08:00
const handleEdit = (row?: TDevice.IListRes) => {
2025-04-12 18:35:54 +08:00
if (row) {
selectDeviceList.value = [row];
}
if (selectDeviceList.value.length == 0) return ElMessage.warning("请选择设备");
visible2.value = true;
2025-03-31 18:24:37 +08:00
};
2025-04-03 18:21:17 +08:00
const handelRow = (row?: TDevice.IListRes) => {
rowData.value = { ...row };
2025-04-09 18:45:44 +08:00
controlForm.mode = row.mode;
2025-04-03 18:21:17 +08:00
visible1.value = true;
};
2025-04-10 19:00:17 +08:00
const handelSwitch = (val: TDevice.IListRes, type: number) => {
let api = type == 1 ? setUseStatus : setStatus;
api({
deviceId: val.deviceId,
status: type == 1 ? val.useStatus : val.deviceSwitch,
2025-04-15 10:51:12 +08:00
})
.then(() => {
getData();
ElMessage.success("操作成功");
})
.catch(() => {
getData();
});
2025-04-10 19:00:17 +08:00
};
2025-04-12 18:35:54 +08:00
const getOrgAllList = () => {
orgAllList().then((res) => {
orgAllData.value = res;
});
};
2025-04-02 18:40:20 +08:00
const handelControl = (type: number) => {
2025-04-28 17:18:11 +08:00
let api: Function;
let params: any = {};
if (type == 4) {
api = deviceGetLocation;
params = { deviceId: rowData.value.deviceId };
} else if (type == 5) {
api = setMode;
params = {
deviceId: rowData.value.deviceId,
mode: controlForm.mode,
};
} else if (type == 6) {
api = deviceOta;
params = rowData.value.deviceId;
} else {
let cmdEnum = {
1: "poweroff",
2: "restart",
3: "factory",
};
api = deviceControl;
params = {
deviceId: rowData.value.deviceId,
cmd: cmdEnum[type],
};
2025-04-02 18:40:20 +08:00
}
2025-04-28 17:18:11 +08:00
api(params).then(() => {
getData();
ElMessage.success("操作成功");
});
2025-04-03 18:21:17 +08:00
2025-04-02 18:40:20 +08:00
visible1.value = false;
};
2025-04-01 13:52:57 +08:00
2025-03-31 18:24:37 +08:00
const updateData = () => {
closeDialog();
getData();
};
const closeDialog = () => {
visible.value = false;
isEdit.value = false;
};
2025-04-09 18:45:44 +08:00
onMounted(() => {
getData();
2025-04-12 18:35:54 +08:00
getOrgAllList();
2025-04-09 18:45:44 +08:00
});
2025-03-31 18:24:37 +08:00
2025-04-03 18:21:17 +08:00
//
const toPage = (path: string, row: TDevice.IListRes) => {
let p;
if (path == "deviceInfo") {
p = { ...row };
} else if (path == "mapLocation") {
2025-04-10 19:00:17 +08:00
p = { deviceId: row.deviceId };
2025-04-03 18:21:17 +08:00
} else if (path == "setting") {
2025-04-09 18:45:44 +08:00
p = { deviceId: row.deviceId };
2025-04-03 18:21:17 +08:00
}
router.push({
path,
query: p,
});
};
2025-03-31 18:24:37 +08:00
</script>
<style scoped>
.table-td-thumb {
display: block;
margin: auto;
width: 40px;
height: 40px;
}
</style>