wms_vue/src/view/user/index.vue

233 lines
7.0 KiB
Vue
Raw Normal View History

2025-08-07 15:16:23 +08:00
<template>
2025-11-06 14:25:31 +08:00
<a-list-layout ref="pageRef">
<template #search>
<pro-query :searchParam="searchParam" @on-search="search">
<template #test="{ data }">
<a-input v-model:value="data.test" type="text" />
</template>
</pro-query>
</template>
<pro-table ref="tableRef" :fetch="fetch" :columns="columns" :toolbar="toolbar" :operate="operate"
:param="state.param" :pagination="pagination"
:row-selection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }">
</pro-table>
<!-- 新增页面 -->
<save :visible="state.visibleSave" @close="closeSave" :record="state.record"></save>
<!-- 修改页面 -->
<edit :visible="state.visibleEdit" @close="closeEdit" :record="state.recordEdit"></edit>
<!-- 分配页面 -->
<give :visible="state.visibleGive" @close="closeGive" :record="state.recordGive"></give>
<!-- 详情页面 -->
<info :visible="state.visibleInfo" @close="closeInfo" :record="state.recordInfo"></info>
</a-list-layout>
2025-08-07 15:16:23 +08:00
</template>
<script>
2025-11-04 14:04:50 +08:00
import save from './modal/save.vue';
import edit from './modal/edit.vue';
import give from './modal/give.vue';
import info from './modal/info.vue';
2025-11-06 14:25:31 +08:00
import { message, Modal as modal } from '@hwork/ant-design-vue';
2025-08-07 15:16:23 +08:00
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { page, remove, removeBatch, resetPassword } from "@/api/module/user";
import { reactive, createVNode, ref } from 'vue';
const removeKey = "remove";
const removeBatchKey = "removeBatch";
export default {
components: {
save,
edit,
give,
info,
},
setup() {
const tableRef = ref();
/// 查询用户
const fetch = async (param) => {
var response = await page(param);
return {
total: response.data.total,
data: response.data.record,
};
};
const resetPasswordMethod = (record) => {
2025-11-06 14:25:31 +08:00
resetPassword({ "id": record.id }).then((response) => {
if (response.success) {
message.success({ content: "重置成功", key: removeKey, duration: 1 })
} else {
message.error({ content: "重置失败", key: removeKey, duration: 1 })
2025-08-07 15:16:23 +08:00
}
})
}
/// 删除用户
const removeMethod = (record) => {
2025-11-06 14:25:31 +08:00
modal.confirm({
2025-08-07 15:16:23 +08:00
title: '您是否确定要删除此用户?',
icon: createVNode(ExclamationCircleOutlined),
okText: '确定',
cancelText: '取消',
onOk() {
message.loading({ content: "提交中...", key: removeKey });
2025-11-06 14:25:31 +08:00
remove({ "id": record.id }).then((response) => {
if (response.success) {
message.success({ content: "删除成功", key: removeKey, duration: 1 }).then(() =>
2025-08-07 15:16:23 +08:00
tableRef.value.reload()
)
2025-11-06 14:25:31 +08:00
} else {
message.error({ content: "删除失败", key: removeKey, duration: 1 })
2025-08-07 15:16:23 +08:00
}
})
}
});
}
/// 批量删除
const removeBatchMethod = (ids) => {
2025-11-06 14:25:31 +08:00
modal.confirm({
2025-08-07 15:16:23 +08:00
title: '您是否确定要删除选择用户?',
icon: createVNode(ExclamationCircleOutlined),
okText: '确定',
cancelText: '取消',
onOk() {
message.loading({ content: "提交中...", key: removeBatchKey });
2025-11-06 14:25:31 +08:00
removeBatch({ "ids": ids }).then((response) => {
if (response.success) {
message.success({ content: "删除成功", key: removeBatchKey, duration: 1 }).then(() =>
2025-08-07 15:16:23 +08:00
tableRef.value.reload()
)
2025-11-06 14:25:31 +08:00
} else {
message.error({ content: "删除失败", key: removeBatchKey, duration: 1 })
2025-08-07 15:16:23 +08:00
}
})
}
});
}
/// 工具栏
const toolbar = [
2025-11-06 14:25:31 +08:00
{ label: "新增", event: function () { state.visibleSave = true } },
{ label: "删除", event: function () { removeBatchMethod(state.selectedRowKeys) } }
2025-08-07 15:16:23 +08:00
];
/// 行操作
const operate = [
2025-11-06 14:25:31 +08:00
{ label: "查看", event: function (record) { state.visibleInfo = true, state.recordInfo = record } },
{ label: "修改", event: function (record) { state.visibleEdit = true, state.recordEdit = record } },
{ label: "分配", event: function (record) { state.visibleGive = true, state.recordGive = record } },
{ label: "删除", event: function (record) { removeMethod(record) } },
{ label: '重置', event: function (record) { resetPasswordMethod(record) } }
2025-08-07 15:16:23 +08:00
];
/// 文本
2025-11-06 14:25:31 +08:00
const converFormat = [{ label: "男", value: "0" }, { label: "女", value: "1" }];
2025-08-07 15:16:23 +08:00
/// 开关
2025-11-06 14:25:31 +08:00
const switchFormat = {
yes: true, no: false, event: function (value, record) {
record.enable = !record.enable;
return value;
}
};
2025-08-07 15:16:23 +08:00
/// 头像
const avatarFormat = { size: 36, shape: "square" };
/// 配置
const columns = [
{ dataIndex: "deptName", key: "deptName", title: "部门" },
{ dataIndex: "avatar", key: "avatar", title: "头像", avatar: avatarFormat },
{ dataIndex: "nickname", key: "nickname", title: "名称" },
{ dataIndex: "username", key: "username", title: "账号" },
2025-11-06 14:25:31 +08:00
{ dataIndex: "gender", key: "gender", title: "性别", conver: converFormat },
{ dataIndex: "enable", key: "enable", title: "状态", switch: switchFormat },
2025-08-07 15:16:23 +08:00
{ dataIndex: "email", key: "email", title: "邮箱" },
{ dataIndex: "phone", key: "phone", title: "电话" },
{ dataIndex: "createTime", key: "createTime", title: "注册时间" }
];
/// 分页参数
2025-11-06 14:25:31 +08:00
const pagination = { pageNum: 1, pageSize: 10 }
2025-08-07 15:16:23 +08:00
/// 外置参数
2025-11-06 14:25:31 +08:00
const state = reactive({
2025-08-07 15:16:23 +08:00
selectedRowKeys: [],
param: {},
record: {},
visibleSave: false,
visibleEdit: false,
visibleGive: false,
visibleInfo: false,
recordEdit: {},
recordGive: {},
recordInfo: {},
})
/// 查询参数
const searchParam = [
2025-11-06 14:25:31 +08:00
{ key: "name", type: "input", label: "名称" },
{ key: "code", type: "input", label: "描述" },
{ key: "test", type: "custom", label: "插槽", customRender: "test" }
2025-08-07 15:16:23 +08:00
]
/// 选择操作
const onSelectChange = selectedRowKeys => {
state.selectedRowKeys = selectedRowKeys;
};
/// 查询操作
2025-11-06 14:25:31 +08:00
const search = function (value) {
2025-08-07 15:16:23 +08:00
state.param = value;
tableRef.value.reload();
}
/// 关闭新增
2025-11-06 14:25:31 +08:00
const closeSave = function () {
2025-08-07 15:16:23 +08:00
state.visibleSave = false;
tableRef.value.reload();
}
/// 关闭修改
2025-11-06 14:25:31 +08:00
const closeEdit = function () {
2025-08-07 15:16:23 +08:00
state.visibleEdit = false;
tableRef.value.reload();
}
/// 关闭分配
2025-11-06 14:25:31 +08:00
const closeGive = function () {
2025-08-07 15:16:23 +08:00
state.visibleGive = false;
tableRef.value.reload();
}
/// 关闭详情
2025-11-06 14:25:31 +08:00
const closeInfo = function () {
2025-08-07 15:16:23 +08:00
state.visibleInfo = false;
}
return {
state,
fetch,
search,
toolbar,
columns,
operate,
pagination,
searchParam,
onSelectChange,
closeSave,
closeEdit,
closeGive,
closeInfo,
tableRef
};
},
};
2025-11-06 14:25:31 +08:00
</script>