提交 a28f32c3 authored 作者: hejie's avatar hejie

feat: 用户管理联调

上级 8f2b4d69
...@@ -55,7 +55,7 @@ export type UserInfo = { ...@@ -55,7 +55,7 @@ export type UserInfo = {
export type UserInfoResult = { export type UserInfoResult = {
success: boolean; success: boolean;
data?: UserInfo; data?: UserInfo;
code?: number; code?: number | string;
}; };
type ResultTable = { type ResultTable = {
...@@ -96,3 +96,33 @@ export const getMineLogs = (data?: object) => { ...@@ -96,3 +96,33 @@ export const getMineLogs = (data?: object) => {
export const addUser = (data?: object) => { export const addUser = (data?: object) => {
return http.request<UserInfoResult>("post", "/api/user/add-user", { data }); return http.request<UserInfoResult>("post", "/api/user/add-user", { data });
}; };
/** 系统管理-用户管理-修改用户 */
export const updateUser = (data?: object) => {
return http.request<UserInfoResult>("post", "/api/user/modify-user", {
data
});
};
/** 系统管理-用户管理-删除用户 */
export const deleteUser = (data?: object) => {
return http.request<UserInfoResult>("post", "/api/user/delete-user", {
data
});
};
/** 系统管理-用户管理-重置密码 */
export const resetPassword = (data?: object) => {
return http.request<UserInfoResult>("post", "/api/user/reset-password", {
data
});
};
/** 系统管理-用户管理-获取用户列表 */
export const getUserList = (data?: object) => {
return http.request<ResultTable>("get", "/api/user/user-list", { data });
};
/** 系统管理-用户管理-获取用户详情 */
export const getUserDetail = (data?: object) => {
return http.request<UserInfoResult>("get", "/api/user/user-detail", {
data
});
};
...@@ -13,11 +13,12 @@ const props = withDefaults(defineProps<FormProps>(), { ...@@ -13,11 +13,12 @@ const props = withDefaults(defineProps<FormProps>(), {
nickname: "", nickname: "",
username: "", username: "",
password: "", password: "",
phone: "", mobile: "",
email: "", email: "",
sex: "", gender: "",
status: 1, status: 1,
remark: "" remark: "",
deptId: 0
}) })
}); });
...@@ -84,9 +85,9 @@ defineExpose({ getRef }); ...@@ -84,9 +85,9 @@ defineExpose({ getRef });
</el-form-item> </el-form-item>
</re-col> </re-col>
<re-col :value="12" :xs="24" :sm="24"> <re-col :value="12" :xs="24" :sm="24">
<el-form-item label="手机号" prop="phone"> <el-form-item label="手机号" prop="mobile">
<el-input <el-input
v-model="newFormInline.phone" v-model="newFormInline.mobile"
clearable clearable
placeholder="请输入手机号" placeholder="请输入手机号"
/> />
...@@ -105,7 +106,7 @@ defineExpose({ getRef }); ...@@ -105,7 +106,7 @@ defineExpose({ getRef });
<re-col :value="12" :xs="24" :sm="24"> <re-col :value="12" :xs="24" :sm="24">
<el-form-item label="用户性别"> <el-form-item label="用户性别">
<el-select <el-select
v-model="newFormInline.sex" v-model="newFormInline.gender"
placeholder="请选择用户性别" placeholder="请选择用户性别"
class="w-full" class="w-full"
clearable clearable
......
...@@ -76,9 +76,9 @@ const { ...@@ -76,9 +76,9 @@ const {
class="w-[180px]!" class="w-[180px]!"
/> />
</el-form-item> </el-form-item>
<el-form-item label="手机号码:" prop="phone"> <el-form-item label="手机号码:" prop="mobile">
<el-input <el-input
v-model="form.phone" v-model="form.mobile"
placeholder="请输入手机号码" placeholder="请输入手机号码"
clearable clearable
class="w-[180px]!" class="w-[180px]!"
......
...@@ -20,10 +20,11 @@ import { ...@@ -20,10 +20,11 @@ import {
import { import {
getRoleIds, getRoleIds,
getDeptList, getDeptList,
getUserList, getUserList
getAllRoleList // getAllRoleList
} from "@/api/system"; } from "@/api/system";
import { addUser } from "@/api/user"; import { addUser, updateUser } from "@/api/user";
import { getRoleList } from "@/api/role";
import { import {
ElForm, ElForm,
ElInput, ElInput,
...@@ -41,14 +42,15 @@ import { ...@@ -41,14 +42,15 @@ import {
reactive, reactive,
onMounted onMounted
} from "vue"; } from "vue";
// import { id } from "element-plus/es/locale/index.mjs";
export function useUser(tableRef: Ref, treeRef: Ref) { export function useUser(tableRef: Ref, treeRef: Ref) {
const form = reactive({ const form = reactive({
// 左侧部门树的id // 左侧部门树的id
deptId: "", // deptId: "",
username: "", // username: "",
phone: "", // mobile: "",
status: "", // status: "",
pageNum: 1, pageNum: 1,
pageSize: 10 pageSize: 10
}); });
...@@ -129,7 +131,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -129,7 +131,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
label: "手机号码", label: "手机号码",
prop: "mobile", prop: "mobile",
minWidth: 90 minWidth: 90
// formatter: ({ phone }) => hideTextAtIndex(phone, { start: 3, end: 6 }) // formatter: ({ mobile }) => hideTextAtIndex(mobile, { start: 3, end: 6 })
}, },
{ {
label: "状态", label: "状态",
...@@ -299,17 +301,17 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -299,17 +301,17 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
onSearch(); onSearch();
} }
function formatHigherDeptOptions(treeList) { // function formatHigherDeptOptions(treeList) {
// 根据返回数据的status字段值判断追加是否禁用disabled字段,返回处理后的树结构,用于上级部门级联选择器的展示(实际开发中也是如此,不可能前端需要的每个字段后端都会返回,这时需要前端自行根据后端返回的某些字段做逻辑处理) // // 根据返回数据的status字段值判断追加是否禁用disabled字段,返回处理后的树结构,用于上级部门级联选择器的展示(实际开发中也是如此,不可能前端需要的每个字段后端都会返回,这时需要前端自行根据后端返回的某些字段做逻辑处理)
if (!treeList || !treeList.length) return; // if (!treeList || !treeList.length) return;
const newTreeList = []; // const newTreeList = [];
for (let i = 0; i < treeList.length; i++) { // for (let i = 0; i < treeList.length; i++) {
treeList[i].disabled = treeList[i].status === 0 ? true : false; // treeList[i].disabled = treeList[i].status === 0 ? true : false;
formatHigherDeptOptions(treeList[i].children); // formatHigherDeptOptions(treeList[i].children);
newTreeList.push(treeList[i]); // newTreeList.push(treeList[i]);
} // }
return newTreeList; // return newTreeList;
} // }
function openDialog(title = "新增", row?: FormItemProps) { function openDialog(title = "新增", row?: FormItemProps) {
addDialog({ addDialog({
...@@ -317,16 +319,19 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -317,16 +319,19 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
props: { props: {
formInline: { formInline: {
title, title,
higherDeptOptions: formatHigherDeptOptions(higherDeptOptions.value), // higherDeptOptions: formatHigherDeptOptions(higherDeptOptions.value),
parentId: row?.dept.id ?? 0, deptId: row?.deptId ?? 0,
nickname: row?.nickname ?? "", nickname: row?.nickname ?? "",
username: row?.username ?? "", username: row?.username ?? "",
password: row?.password ?? "", password: row?.password ?? "",
phone: row?.phone ?? "", mobile: row?.mobile ?? "",
email: row?.email ?? "", email: row?.email ?? "",
gender: row?.gender ?? "", gender: row?.gender ?? "",
status: row?.status ?? 1, status: row?.status ?? 1,
remark: row?.remark ?? "" remark: row?.remark ?? "",
name: row?.username ?? "",
id: row?.id ?? 0,
avatar: row?.avatar ?? ""
} }
}, },
width: "46%", width: "46%",
...@@ -349,12 +354,32 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -349,12 +354,32 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
if (valid) { if (valid) {
console.log("curData", curData); console.log("curData", curData);
// 表单规则校验通过 // 表单规则校验通过
const {
avatar,
deptId,
email,
gender,
mobile,
name,
nickname,
username
} = curData;
const params = {
avatar,
deptId,
email,
gender,
mobile,
name,
nickname,
username,
id: title === "新增" ? null : curData.id
};
if (title === "新增") { if (title === "新增") {
// 实际开发先调用新增接口,再进行下面操作 // 实际开发先调用新增接口,再进行下面操作
// 新增用户 // 新增用户
curData.name = curData.username;
curData.deptId = curData.dept || ""; addUser(params).then(res => {
addUser(curData).then(res => {
if (res.code === 200) { if (res.code === 200) {
message("新增用户成功", { type: "success" }); message("新增用户成功", { type: "success" });
chores(); chores();
...@@ -362,10 +387,22 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -362,10 +387,22 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
message("新增用户失败", { type: "error" }); message("新增用户失败", { type: "error" });
} }
}); });
chores(); // chores();
} else { } else {
// 实际开发先调用修改接口,再进行下面操作 // 实际开发先调用修改接口,再进行下面操作
chores(); // 修改用户
// curData.name = curData.username;
console.log("curData", curData);
params.id = curData.id;
updateUser(params).then(res => {
if (res.code === "0") {
message("修改用户成功", { type: "success" });
chores();
} else {
message("修改用户失败", { type: "error" });
}
});
// chores();
} }
} }
}); });
...@@ -479,8 +516,8 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -479,8 +516,8 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
/** 分配角色 */ /** 分配角色 */
async function handleRole(row) { async function handleRole(row) {
// 选中的角色列表 // TODO 选中的角色列表
const ids = (await getRoleIds({ userId: row.id })).data ?? []; const ids = (await getRoleIds({ id: row.id })).data ?? [];
addDialog({ addDialog({
title: `分配 ${row.username} 用户的角色`, title: `分配 ${row.username} 用户的角色`,
props: { props: {
...@@ -517,7 +554,9 @@ export function useUser(tableRef: Ref, treeRef: Ref) { ...@@ -517,7 +554,9 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
treeLoading.value = false; treeLoading.value = false;
// 角色列表 // 角色列表
roleOptions.value = (await getAllRoleList()).data; roleOptions.value = (
await getRoleList({ pageNum: 1, pageSize: 100 })
).data.records;
}); });
return { return {
......
...@@ -18,6 +18,7 @@ interface FormItemProps { ...@@ -18,6 +18,7 @@ interface FormItemProps {
remark: string; remark: string;
name?: string; name?: string;
deptId?: number; deptId?: number;
avatar?: string;
} }
interface FormProps { interface FormProps {
formInline: FormItemProps; formInline: FormItemProps;
......
...@@ -28,10 +28,13 @@ export default ({ mode }: ConfigEnv): UserConfigExport => { ...@@ -28,10 +28,13 @@ export default ({ mode }: ConfigEnv): UserConfigExport => {
proxy: { proxy: {
"/api": { "/api": {
// 这里填写后端地址 // 这里填写后端地址
// 熊熊哥地址
// target: "http://192.168.1.194:5001", // 旭哥地址
// target: "http://192.168.1.180:5001",
// 服务器地址 // 服务器地址
target: "http://192.168.1.248:5001", // target: "http://192.168.1.248:5001",
// 熊熊哥地址
target: "http://192.168.1.194:5001",
changeOrigin: true, changeOrigin: true,
rewrite: path => path.replace(/^\/api/, "") rewrite: path => path.replace(/^\/api/, "")
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论