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-03 18:21:17 +08:00
|
|
|
<TableCustom :columns="columns" :tableData="tableData" :total="paging.total" :refresh="getData" :currentPage="paging.page" :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="typeVisible = true">类型编辑</el-button>
|
2025-04-03 18:21:17 +08:00
|
|
|
<el-button type="primary" @click="handelRow('add')">新增用户</el-button>
|
2025-04-01 09:05:07 +08:00
|
|
|
<el-button @click="handleImp">批量创建用户</el-button>
|
2025-04-03 18:21:17 +08:00
|
|
|
<!-- <el-button>导出</el-button> -->
|
|
|
|
<!-- <el-button type="danger">删除</el-button> -->
|
2025-03-31 18:24:37 +08:00
|
|
|
</template>
|
2025-04-03 18:21:17 +08:00
|
|
|
|
2025-03-31 18:24:37 +08:00
|
|
|
<template #state="{ rows }">
|
2025-04-03 18:21:17 +08:00
|
|
|
<el-switch v-model="rows.state" :active-value="1" :inactive-value="0" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #roleId="{ rows }">
|
|
|
|
{{ roleEnum[rows.roleId] }}
|
2025-03-31 18:24:37 +08:00
|
|
|
</template>
|
2025-04-03 18:21:17 +08:00
|
|
|
|
|
|
|
<template #password="{ rows }">
|
|
|
|
<div v-if="rows.flag" @click="rows.flag = false">
|
|
|
|
{{ rows.password }}
|
|
|
|
<el-icon style="cursor: pointer"><View /></el-icon>
|
|
|
|
</div>
|
|
|
|
<div v-else @click="rows.flag = true">
|
|
|
|
******
|
|
|
|
<el-icon style="cursor: pointer"><Hide /></el-icon>
|
|
|
|
</div>
|
|
|
|
</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="handelRow('pwd', rows)"> 重置密码 </el-button>
|
|
|
|
<el-button link type="primary" size="small" @click="handelRow('edit', rows)"> 修改 </el-button>
|
2025-04-01 13:52:57 +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>
|
2025-04-03 18:21:17 +08:00
|
|
|
<el-dialog :title="dialogTitle" 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="options" :edit="isEdit" :update="updateData" @close="closeDialog" />
|
2025-04-01 13:52:57 +08:00
|
|
|
</el-dialog>
|
2025-04-01 18:07:18 +08:00
|
|
|
<el-dialog title="编辑类型" v-model="typeVisible" width="800px" destroy-on-close :close-on-click-modal="false" @close="closeDialog">
|
|
|
|
<UserType />
|
|
|
|
</el-dialog>
|
2025-03-31 18:24:37 +08:00
|
|
|
<BatchImp ref="batchImpRef" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts" name="basetable">
|
|
|
|
import { ref, reactive } from "vue";
|
2025-04-01 13:52:57 +08:00
|
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
2025-04-03 18:21:17 +08:00
|
|
|
import { accountAdd, accountModify, accountList, accountDeletet, passwordReset } from "@/api/index";
|
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";
|
|
|
|
import BatchImp from "@/components/batch-imp.vue";
|
2025-04-03 18:21:17 +08:00
|
|
|
import { useCommonStore } from "@/store/common";
|
2025-04-01 18:07:18 +08:00
|
|
|
import UserType from "./userType.vue";
|
2025-03-31 18:24:37 +08:00
|
|
|
import { TableItem } from "@/types/table";
|
|
|
|
import { FormOption, FormOptionList } from "@/types/form-option";
|
2025-04-03 18:21:17 +08:00
|
|
|
import { TAccount } from "@/api/index.d";
|
|
|
|
// import { Hide, View } from "@element-plus/icons-vue";
|
2025-03-31 18:24:37 +08:00
|
|
|
|
2025-04-03 18:21:17 +08:00
|
|
|
enum roleEnum {
|
|
|
|
管理员 = -1,
|
|
|
|
警察 = 1,
|
|
|
|
辅警 = 2,
|
|
|
|
协警 = 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
const comm = useCommonStore();
|
2025-04-01 18:07:18 +08:00
|
|
|
const visible = ref(false);
|
|
|
|
const typeVisible = ref(false);
|
|
|
|
const isEdit = ref(false);
|
2025-04-03 18:21:17 +08:00
|
|
|
const dialogTitle = ref("");
|
|
|
|
const rowData = ref<TAccount.IListRes | undefined>();
|
2025-03-31 18:24:37 +08:00
|
|
|
// 查询相关
|
|
|
|
const query = reactive({
|
|
|
|
name: "",
|
|
|
|
});
|
2025-04-01 13:52:57 +08:00
|
|
|
const batchImpRef = ref();
|
2025-04-03 18:21:17 +08:00
|
|
|
const paging = reactive({
|
|
|
|
page: 1,
|
2025-04-01 18:07:18 +08:00
|
|
|
size: 10,
|
2025-04-03 18:21:17 +08:00
|
|
|
total: 0,
|
2025-04-01 18:07:18 +08:00
|
|
|
});
|
2025-04-03 18:21:17 +08:00
|
|
|
const tableData = ref<TAccount.IListRes[]>([]);
|
2025-04-01 13:52:57 +08:00
|
|
|
|
2025-03-31 18:24:37 +08:00
|
|
|
const searchOpt = ref<FormOptionList[]>([
|
|
|
|
{ type: "input", label: "用户名:", prop: "name" },
|
|
|
|
{
|
|
|
|
type: "select",
|
|
|
|
label: "用户类型:",
|
|
|
|
prop: "name1",
|
|
|
|
opts: [
|
|
|
|
{ label: "管理员", value: "1" },
|
|
|
|
{ label: "警察", value: "2" },
|
|
|
|
{ label: "辅警", value: "3" },
|
|
|
|
{ label: "协警", value: "4" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ type: "daterange", label: "创建时间:", prop: "name2" },
|
|
|
|
{
|
|
|
|
type: "select",
|
|
|
|
label: "状态:",
|
|
|
|
prop: "name3",
|
|
|
|
opts: [
|
|
|
|
{ label: "启用", value: "1" },
|
|
|
|
{ label: "禁用", value: "0" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
// 表格相关
|
|
|
|
let columns = ref([
|
2025-04-03 18:21:17 +08:00
|
|
|
// { type: "selection" },
|
2025-03-31 18:24:37 +08:00
|
|
|
{ type: "index", label: "序号", width: 55, align: "center" },
|
|
|
|
{ prop: "name", label: "用户名称" },
|
2025-04-03 18:21:17 +08:00
|
|
|
{ prop: "username", label: "警员号" },
|
|
|
|
{ prop: "phone", label: "手机号" },
|
|
|
|
{ prop: "password", label: "密码", width: 120 },
|
|
|
|
{ prop: "roleId", label: "类型" },
|
|
|
|
{ prop: "createTime", label: "创建时间" },
|
2025-03-31 18:24:37 +08:00
|
|
|
{ prop: "state", label: "状态" },
|
|
|
|
{ prop: "operator", label: "操作", width: 250 },
|
|
|
|
]);
|
2025-04-01 18:07:18 +08:00
|
|
|
|
2025-04-03 18:21:17 +08:00
|
|
|
let addOpt = {
|
2025-04-01 18:07:18 +08:00
|
|
|
labelWidth: "100px",
|
|
|
|
span: 24,
|
|
|
|
list: [
|
2025-04-03 18:21:17 +08:00
|
|
|
{ placeholder: "请输入用户名称", type: "input", label: "用户名称", prop: "name", required: true },
|
|
|
|
{ placeholder: "请输入电话号码", type: "input", label: "电话号码", prop: "phone", required: true },
|
|
|
|
{ placeholder: "请输入警员号", type: "input", label: "警员号", prop: "username", required: true },
|
2025-04-01 18:07:18 +08:00
|
|
|
{
|
|
|
|
placeholder: "请选择类型",
|
|
|
|
type: "select",
|
|
|
|
label: "类型",
|
|
|
|
opts: [
|
2025-04-03 18:21:17 +08:00
|
|
|
{ label: "管理员", value: -1 },
|
|
|
|
{ label: "警察", value: 1 },
|
|
|
|
{ label: "辅警", value: 2 },
|
|
|
|
{ label: "协警", value: 3 },
|
2025-04-01 18:07:18 +08:00
|
|
|
],
|
2025-04-03 18:21:17 +08:00
|
|
|
prop: "roleId",
|
2025-04-01 18:07:18 +08:00
|
|
|
required: true,
|
|
|
|
},
|
2025-04-03 18:21:17 +08:00
|
|
|
{ placeholder: "请输入密码", type: "password", label: "密码", prop: "password", required: true },
|
|
|
|
{ type: "switch", label: "状态", prop: "status", activeValue: 1, inactiveValue: 0 },
|
|
|
|
// { placeholder: "请输入确认密码", type: "password", label: "确认密码", prop: "confirmpassword" },
|
|
|
|
// { placeholder: "请输入备注", type: "textarea", label: "备注", prop: "mon8ey" },
|
2025-04-01 18:07:18 +08:00
|
|
|
],
|
2025-04-03 18:21:17 +08:00
|
|
|
};
|
|
|
|
|
2025-04-01 18:07:18 +08:00
|
|
|
// 新增/编辑弹窗相关
|
2025-04-03 18:21:17 +08:00
|
|
|
let options = ref<FormOption>();
|
|
|
|
// 重置密码
|
|
|
|
let pwdOpt = {
|
2025-04-01 18:07:18 +08:00
|
|
|
labelWidth: "100px",
|
|
|
|
span: 24,
|
|
|
|
list: [
|
2025-04-03 18:21:17 +08:00
|
|
|
// { type: "password", label: "原始密码", prop: "name1", required: true },
|
|
|
|
{ type: "password", label: "新密码", prop: "password", required: true },
|
|
|
|
// { type: "password", label: "确认密码", prop: "money3", required: true },
|
2025-04-01 18:07:18 +08:00
|
|
|
],
|
2025-04-03 18:21:17 +08:00
|
|
|
};
|
2025-03-31 18:24:37 +08:00
|
|
|
|
|
|
|
const handleImp = () => {
|
|
|
|
batchImpRef.value.dialogVisible = true;
|
|
|
|
};
|
|
|
|
const handleSearch = () => {
|
2025-04-03 18:21:17 +08:00
|
|
|
paging.page = 1;
|
|
|
|
getData();
|
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-03 18:21:17 +08:00
|
|
|
const getData = async () => {
|
|
|
|
const res = await accountList(paging);
|
|
|
|
tableData.value = res.records.map((item) => {
|
|
|
|
item.flag = false;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
paging.total = res.total;
|
|
|
|
};
|
|
|
|
getData();
|
|
|
|
|
2025-04-01 13:52:57 +08:00
|
|
|
// 删除相关
|
|
|
|
const handelDel = (row: TableItem) => {
|
|
|
|
ElMessageBox.confirm("确定要删除吗?", "提示", {
|
|
|
|
type: "warning",
|
2025-04-03 18:21:17 +08:00
|
|
|
}).then(async () => {
|
|
|
|
accountDeletet({ id: row.id }).then((res) => {
|
|
|
|
ElMessage.success("删除成功");
|
|
|
|
getData();
|
|
|
|
});
|
|
|
|
});
|
2025-03-31 18:24:37 +08:00
|
|
|
};
|
2025-04-01 13:52:57 +08:00
|
|
|
|
2025-04-03 18:21:17 +08:00
|
|
|
const updateData = (res) => {
|
|
|
|
let api, msg, p;
|
|
|
|
if (dialogTitle.value == "重置密码") {
|
|
|
|
api = passwordReset;
|
|
|
|
p = { ...res, id: rowData.value.id };
|
|
|
|
msg = "重置成功";
|
|
|
|
} else {
|
|
|
|
p = { ...res, orgId: comm.user.orgId };
|
|
|
|
api = isEdit.value ? accountModify : accountAdd;
|
|
|
|
msg = isEdit.value ? "修改成功" : "新增成功";
|
|
|
|
}
|
|
|
|
|
|
|
|
api(p).then((res) => {
|
|
|
|
ElMessage.success(msg);
|
|
|
|
closeDialog();
|
|
|
|
getData();
|
|
|
|
});
|
2025-03-31 18:24:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const closeDialog = () => {
|
|
|
|
visible.value = false;
|
|
|
|
isEdit.value = false;
|
|
|
|
};
|
|
|
|
|
2025-04-03 18:21:17 +08:00
|
|
|
const handelRow = (name: string, row?: TAccount.IListRes) => {
|
|
|
|
if (name == "add") {
|
|
|
|
dialogTitle.value = "新增用户";
|
|
|
|
options.value = { ...addOpt };
|
|
|
|
rowData.value = undefined;
|
|
|
|
isEdit.value = false;
|
|
|
|
} else if (name == "pwd") {
|
|
|
|
dialogTitle.value = "重置密码";
|
|
|
|
options.value = { ...pwdOpt };
|
|
|
|
rowData.value = { ...row };
|
|
|
|
isEdit.value = true;
|
|
|
|
} else if (name == "edit") {
|
|
|
|
dialogTitle.value = "编辑";
|
|
|
|
isEdit.value = true;
|
|
|
|
options.value = { ...addOpt };
|
|
|
|
rowData.value = { ...row };
|
|
|
|
}
|
|
|
|
visible.value = true;
|
2025-03-31 18:24:37 +08:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.table-td-thumb {
|
|
|
|
display: block;
|
|
|
|
margin: auto;
|
|
|
|
width: 40px;
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
</style>
|