feat: 完成用户页面查询
This commit is contained in:
@@ -4,17 +4,17 @@ using Yi.Framework.Ddd.Application.Contracts;
|
|||||||
namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Config
|
namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Config
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
/// 配置查询参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConfigGetListInputVo : PagedAllResultRequestDto
|
public class ConfigGetListInputVo : PagedAllResultRequestDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
/// 配置名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ConfigName { get; set; }
|
public string? ConfigName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>
|
/// 配置键
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ConfigKey { get; set; }
|
public string? ConfigKey { get; set; }
|
||||||
|
|
||||||
|
|||||||
19
Yi.Pure.Vue3/src/api/result.ts
Normal file
19
Yi.Pure.Vue3/src/api/result.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export type ResultList = {
|
||||||
|
status: number;
|
||||||
|
data?: Array<any>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Result = {
|
||||||
|
status: number;
|
||||||
|
data?: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ResultPage = {
|
||||||
|
status: number;
|
||||||
|
data?: {
|
||||||
|
/** 列表数据 */
|
||||||
|
items: Array<any>;
|
||||||
|
/** 总条目数 */
|
||||||
|
totalCount?: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,38 +1,58 @@
|
|||||||
import { http } from "@/utils/http";
|
import { http } from "@/utils/http";
|
||||||
|
import type { Result, ResultList, ResultPage } from "./result.ts";
|
||||||
type Result = {
|
|
||||||
status: number;
|
|
||||||
data?: Array<any>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ResultTable = {
|
|
||||||
status: number;
|
|
||||||
data?: {
|
|
||||||
/** 列表数据 */
|
|
||||||
items: Array<any>;
|
|
||||||
/** 总条目数 */
|
|
||||||
totalCount?: number;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 获取系统管理-用户管理列表 */
|
/** 获取系统管理-用户管理列表 */
|
||||||
export const getUserList = (data?: object) => {
|
export const getUserList = (data?: object) => {
|
||||||
return http.request<ResultTable>("get", "/user", { params: data });
|
return http.request<ResultPage>("get", "/user", { params: data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 系统管理-用户管理-获取所有角色列表 */
|
/** 获取一个用户详细消息 */
|
||||||
export const getAllRoleList = () => {
|
export const getUser = (userId: string) => {
|
||||||
return http.request<Result>("get", "/list-all-role");
|
return http.request<Result>("get", `/user/${userId}`, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 系统管理-用户管理-根据userId,获取对应角色id列表(userId:用户id) */
|
/** 删除用户 */
|
||||||
export const getRoleIds = (data?: object) => {
|
export const delUser = (userIds: string[]) => {
|
||||||
return http.request<Result>("post", "/list-role-ids", { data });
|
return http.request<Result>("delete", `/user`, {
|
||||||
|
params: { id: userIds }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 用户密码重置 */
|
||||||
|
export const resetUserPwd = (id: string, password: string) => {
|
||||||
|
return http.request<Result>("put", `/account/rest-password/${id}`, {
|
||||||
|
data: { password }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 改变用户状态 */
|
||||||
|
export const changeUserStatus = (userId: string, state: boolean) => {
|
||||||
|
return http.request<Result>("put", `/user/${userId}/${state}`, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 修改用户 */
|
||||||
|
export const updateUser = (id: string, data: any) => {
|
||||||
|
return http.request<Result>("put", `/user/${id}`, { data });
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 获取角色选择框列表 */
|
||||||
|
export const getRoleOption = () => {
|
||||||
|
return http.request<ResultPage>("get", `/role`, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 新增角色 */
|
||||||
|
export const addUser = (data: any) => {
|
||||||
|
return http.request<Result>("post", `/user`, { data });
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 新增角色 */
|
||||||
|
export const addRole = (data: any) => {
|
||||||
|
return http.request<Result>("post", `/role`, { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统管理-角色管理列表 */
|
/** 获取系统管理-角色管理列表 */
|
||||||
export const getRoleList = (data?: object) => {
|
export const getRoleList = (data?: object) => {
|
||||||
return http.request<ResultTable>("post", "/role", { data });
|
return http.request<ResultPage>("post", "/role", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统管理-菜单管理列表 */
|
/** 获取系统管理-菜单管理列表 */
|
||||||
@@ -42,40 +62,40 @@ export const getMenuList = (data?: object) => {
|
|||||||
|
|
||||||
/** 获取系统管理-部门管理列表 */
|
/** 获取系统管理-部门管理列表 */
|
||||||
export const getDeptList = (data?: object) => {
|
export const getDeptList = (data?: object) => {
|
||||||
return http.request<ResultTable>("get", "/dept", { data });
|
return http.request<ResultPage>("get", "/dept", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统监控-在线用户列表 */
|
/** 获取系统监控-在线用户列表 */
|
||||||
export const getOnlineLogsList = (data?: object) => {
|
export const getOnlineLogsList = (data?: object) => {
|
||||||
return http.request<ResultTable>("post", "/online-logs", { data });
|
return http.request<ResultPage>("post", "/online-logs", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统监控-登录日志列表 */
|
/** 获取系统监控-登录日志列表 */
|
||||||
export const getLoginLogsList = (data?: object) => {
|
export const getLoginLogsList = (data?: object) => {
|
||||||
return http.request<ResultTable>("post", "/login-logs", { data });
|
return http.request<ResultPage>("post", "/login-logs", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统监控-操作日志列表 */
|
/** 获取系统监控-操作日志列表 */
|
||||||
export const getOperationLogsList = (data?: object) => {
|
export const getOperationLogsList = (data?: object) => {
|
||||||
return http.request<ResultTable>("post", "/operation-logs", { data });
|
return http.request<ResultPage>("post", "/operation-logs", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统监控-系统日志列表 */
|
/** 获取系统监控-系统日志列表 */
|
||||||
export const getSystemLogsList = (data?: object) => {
|
export const getSystemLogsList = (data?: object) => {
|
||||||
return http.request<ResultTable>("post", "/system-logs", { data });
|
return http.request<ResultPage>("post", "/system-logs", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取系统监控-系统日志-根据 id 查日志详情 */
|
/** 获取系统监控-系统日志-根据 id 查日志详情 */
|
||||||
export const getSystemLogsDetail = (data?: object) => {
|
export const getSystemLogsDetail = (data?: object) => {
|
||||||
return http.request<Result>("post", "/system-logs-detail", { data });
|
return http.request<ResultList>("post", "/system-logs-detail", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取角色管理-权限-菜单权限 */
|
/** 获取角色管理-权限-菜单权限 */
|
||||||
export const getRoleMenu = (data?: object) => {
|
export const getRoleMenu = (data?: object) => {
|
||||||
return http.request<Result>("post", "/role-menu", { data });
|
return http.request<ResultList>("post", "/role-menu", { data });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
|
/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
|
||||||
export const getRoleMenuIds = (data?: object) => {
|
export const getRoleMenuIds = (data?: object) => {
|
||||||
return http.request<Result>("post", "/role-menu-ids", { data });
|
return http.request<ResultList>("post", "/role-menu-ids", { data });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,15 +9,17 @@ const props = withDefaults(defineProps<FormProps>(), {
|
|||||||
formInline: () => ({
|
formInline: () => ({
|
||||||
title: "新增",
|
title: "新增",
|
||||||
higherDeptOptions: [],
|
higherDeptOptions: [],
|
||||||
parentId: 0,
|
deptId: "",
|
||||||
nick: "",
|
nick: "",
|
||||||
userName: "",
|
userName: "",
|
||||||
password: "",
|
password: "",
|
||||||
phone: "",
|
phone: "",
|
||||||
email: "",
|
email: "",
|
||||||
sex: "",
|
sex: "",
|
||||||
state: 1,
|
state: true,
|
||||||
remark: ""
|
remark: "",
|
||||||
|
roleIds: [],
|
||||||
|
roleOptions: []
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -123,7 +125,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-cascader
|
<el-cascader
|
||||||
v-model="newFormInline.parentId"
|
v-model="newFormInline.deptId"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
:options="newFormInline.higherDeptOptions"
|
:options="newFormInline.higherDeptOptions"
|
||||||
:props="{
|
:props="{
|
||||||
@@ -161,7 +163,26 @@ defineExpose({ getRef });
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</re-col>
|
</re-col>
|
||||||
|
<re-col>
|
||||||
|
<el-form-item label="角色列表" prop="ids">
|
||||||
|
<el-select
|
||||||
|
v-model="newFormInline.roleIds"
|
||||||
|
placeholder="请选择"
|
||||||
|
class="w-full"
|
||||||
|
clearable
|
||||||
|
multiple
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="(item, index) in newFormInline.roleOptions"
|
||||||
|
:key="index"
|
||||||
|
:value="item.id"
|
||||||
|
:label="item.roleName"
|
||||||
|
>
|
||||||
|
{{ item.roleName }}
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</re-col>
|
||||||
<re-col>
|
<re-col>
|
||||||
<el-form-item label="备注">
|
<el-form-item label="备注">
|
||||||
<el-input
|
<el-input
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref } from "vue";
|
|
||||||
import ReCol from "@/components/ReCol";
|
|
||||||
import { RoleFormProps } from "../utils/types";
|
|
||||||
|
|
||||||
const props = withDefaults(defineProps<RoleFormProps>(), {
|
|
||||||
formInline: () => ({
|
|
||||||
userName: "",
|
|
||||||
nick: "",
|
|
||||||
roleOptions: [],
|
|
||||||
ids: []
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const newFormInline = ref(props.formInline);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<el-form :model="newFormInline">
|
|
||||||
<el-row :gutter="30">
|
|
||||||
<re-col>
|
|
||||||
<el-form-item label="用户昵称" prop="nick">
|
|
||||||
<el-input v-model="newFormInline.nick" disabled />
|
|
||||||
</el-form-item>
|
|
||||||
</re-col>
|
|
||||||
<re-col>
|
|
||||||
<el-form-item label="角色列表" prop="ids">
|
|
||||||
<el-select
|
|
||||||
v-model="newFormInline.ids"
|
|
||||||
placeholder="请选择"
|
|
||||||
class="w-full"
|
|
||||||
clearable
|
|
||||||
multiple
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="(item, index) in newFormInline.roleOptions"
|
|
||||||
:key="index"
|
|
||||||
:value="item.id"
|
|
||||||
:label="item.name"
|
|
||||||
>
|
|
||||||
{{ item.name }}
|
|
||||||
</el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
</re-col>
|
|
||||||
</el-row>
|
|
||||||
</el-form>
|
|
||||||
</template>
|
|
||||||
@@ -42,7 +42,6 @@ const {
|
|||||||
handleDelete,
|
handleDelete,
|
||||||
handleUpload,
|
handleUpload,
|
||||||
handleReset,
|
handleReset,
|
||||||
handleRole,
|
|
||||||
handleSizeChange,
|
handleSizeChange,
|
||||||
onSelectionCancel,
|
onSelectionCancel,
|
||||||
handleCurrentChange,
|
handleCurrentChange,
|
||||||
@@ -110,11 +109,7 @@ const {
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<PureTableBar
|
<PureTableBar title="用户管理" :columns="columns" @refresh="onSearch">
|
||||||
title="用户管理(仅演示,操作后不生效)"
|
|
||||||
:columns="columns"
|
|
||||||
@refresh="onSearch"
|
|
||||||
>
|
|
||||||
<template #buttons>
|
<template #buttons>
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
@@ -231,18 +226,6 @@ const {
|
|||||||
重置密码
|
重置密码
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
<el-dropdown-item>
|
|
||||||
<el-button
|
|
||||||
:class="buttonClass"
|
|
||||||
link
|
|
||||||
type="primary"
|
|
||||||
:size="size"
|
|
||||||
:icon="useRenderIcon(Role)"
|
|
||||||
@click="handleRole(row)"
|
|
||||||
>
|
|
||||||
分配角色
|
|
||||||
</el-button>
|
|
||||||
</el-dropdown-item>
|
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</template>
|
</template>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import "./reset.css";
|
import "./reset.css";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import roleForm from "../form/role.vue";
|
|
||||||
import editForm from "../form/index.vue";
|
import editForm from "../form/index.vue";
|
||||||
import { zxcvbn } from "@zxcvbn-ts/core";
|
import { zxcvbn } from "@zxcvbn-ts/core";
|
||||||
import { handleTree } from "@/utils/tree";
|
import { handleTree } from "@/utils/tree";
|
||||||
@@ -10,7 +9,7 @@ import { usePublicHooks } from "../../hooks";
|
|||||||
import { addDialog } from "@/components/ReDialog";
|
import { addDialog } from "@/components/ReDialog";
|
||||||
import type { PaginationProps } from "@pureadmin/table";
|
import type { PaginationProps } from "@pureadmin/table";
|
||||||
import ReCropperPreview from "@/components/ReCropperPreview";
|
import ReCropperPreview from "@/components/ReCropperPreview";
|
||||||
import type { FormItemProps, RoleFormItemProps } from "../utils/types";
|
import type { FormItemProps } from "../utils/types";
|
||||||
import {
|
import {
|
||||||
getKeyList,
|
getKeyList,
|
||||||
isAllEmpty,
|
isAllEmpty,
|
||||||
@@ -18,10 +17,15 @@ import {
|
|||||||
deviceDetection
|
deviceDetection
|
||||||
} from "@pureadmin/utils";
|
} from "@pureadmin/utils";
|
||||||
import {
|
import {
|
||||||
getRoleIds,
|
|
||||||
getDeptList,
|
getDeptList,
|
||||||
getUserList,
|
getUserList,
|
||||||
getAllRoleList
|
getUser,
|
||||||
|
getRoleOption,
|
||||||
|
addUser,
|
||||||
|
delUser,
|
||||||
|
resetUserPwd,
|
||||||
|
changeUserStatus,
|
||||||
|
updateUser
|
||||||
} from "@/api/system";
|
} from "@/api/system";
|
||||||
import {
|
import {
|
||||||
ElForm,
|
ElForm,
|
||||||
@@ -96,7 +100,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
width: 90
|
width: 90
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "用户名称",
|
label: "用户账号",
|
||||||
prop: "userName",
|
prop: "userName",
|
||||||
minWidth: 130
|
minWidth: 130
|
||||||
},
|
},
|
||||||
@@ -128,7 +132,8 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
label: "手机号码",
|
label: "手机号码",
|
||||||
prop: "phone",
|
prop: "phone",
|
||||||
minWidth: 90,
|
minWidth: 90,
|
||||||
formatter: ({ phone }) => hideTextAtIndex(phone, { start: 3, end: 6 })
|
formatter: ({ phone }) =>
|
||||||
|
phone == null ? "-" : hideTextAtIndex(phone, { start: 3, end: 6 })
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "状态",
|
label: "状态",
|
||||||
@@ -174,7 +179,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
});
|
});
|
||||||
// 重置的新密码
|
// 重置的新密码
|
||||||
const pwdForm = reactive({
|
const pwdForm = reactive({
|
||||||
newPwd: ""
|
password: ""
|
||||||
});
|
});
|
||||||
const pwdProgress = [
|
const pwdProgress = [
|
||||||
{ color: "#e74242", text: "非常弱" },
|
{ color: "#e74242", text: "非常弱" },
|
||||||
@@ -190,7 +195,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
function onChange({ row, index }) {
|
function onChange({ row, index }) {
|
||||||
ElMessageBox.confirm(
|
ElMessageBox.confirm(
|
||||||
`确认要<strong>${
|
`确认要<strong>${
|
||||||
row.status === 0 ? "停用" : "启用"
|
row.state === 0 ? "停用" : "启用"
|
||||||
}</strong><strong style='color:var(--el-color-primary)'>${
|
}</strong><strong style='color:var(--el-color-primary)'>${
|
||||||
row.userName
|
row.userName
|
||||||
}</strong>用户吗?`,
|
}</strong>用户吗?`,
|
||||||
@@ -203,7 +208,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
draggable: true
|
draggable: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(async () => {
|
||||||
switchLoadMap.value[index] = Object.assign(
|
switchLoadMap.value[index] = Object.assign(
|
||||||
{},
|
{},
|
||||||
switchLoadMap.value[index],
|
switchLoadMap.value[index],
|
||||||
@@ -211,7 +216,9 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
loading: true
|
loading: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
|
||||||
|
await changeUserStatus(row.id, row.state);
|
||||||
|
|
||||||
switchLoadMap.value[index] = Object.assign(
|
switchLoadMap.value[index] = Object.assign(
|
||||||
{},
|
{},
|
||||||
switchLoadMap.value[index],
|
switchLoadMap.value[index],
|
||||||
@@ -222,10 +229,9 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
message("已成功修改用户状态", {
|
message("已成功修改用户状态", {
|
||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
}, 300);
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
row.status === 0 ? (row.status = 1) : (row.status = 0);
|
row.state === 0 ? (row.state = 1) : (row.state = 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +239,8 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
console.log(row);
|
console.log(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDelete(row) {
|
async function handleDelete(row) {
|
||||||
|
await delUser([row.id]);
|
||||||
message(`您删除了用户编号为${row.id}的这条数据`, { type: "success" });
|
message(`您删除了用户编号为${row.id}的这条数据`, { type: "success" });
|
||||||
onSearch();
|
onSearch();
|
||||||
}
|
}
|
||||||
@@ -263,11 +270,13 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 批量删除 */
|
/** 批量删除 */
|
||||||
function onbatchDel() {
|
async function onbatchDel() {
|
||||||
// 返回当前选中的行
|
// 返回当前选中的行
|
||||||
const curSelected = tableRef.value.getTableRef().getSelectionRows();
|
const curSelected = tableRef.value.getTableRef().getSelectionRows();
|
||||||
|
const delIds = getKeyList(curSelected, "id");
|
||||||
|
await delUser(delIds);
|
||||||
// 接下来根据实际业务,通过选中行的某项数据,比如下面的id,调用接口进行批量删除
|
// 接下来根据实际业务,通过选中行的某项数据,比如下面的id,调用接口进行批量删除
|
||||||
message(`已删除用户编号为 ${getKeyList(curSelected, "id")} 的数据`, {
|
message(`已删除用户编号为 ${delIds} 的数据`, {
|
||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
tableRef.value.getTableRef().clearSelection();
|
tableRef.value.getTableRef().clearSelection();
|
||||||
@@ -305,29 +314,36 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
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].state === 0 ? true : false;
|
||||||
formatHigherDeptOptions(treeList[i].children);
|
formatHigherDeptOptions(treeList[i].children);
|
||||||
newTreeList.push(treeList[i]);
|
newTreeList.push(treeList[i]);
|
||||||
}
|
}
|
||||||
return newTreeList;
|
return newTreeList;
|
||||||
}
|
}
|
||||||
|
async function openDialog(title = "新增", row?: FormItemProps) {
|
||||||
function openDialog(title = "新增", row?: FormItemProps) {
|
let data: any = null;
|
||||||
|
//打开弹窗之前,如果是修改,还需进行查询详情
|
||||||
|
if (title == "修改") {
|
||||||
|
const response = await getUser(row?.id);
|
||||||
|
data = response.data;
|
||||||
|
}
|
||||||
addDialog({
|
addDialog({
|
||||||
title: `${title}用户`,
|
title: `${title}用户`,
|
||||||
props: {
|
props: {
|
||||||
formInline: {
|
formInline: {
|
||||||
title,
|
title,
|
||||||
higherDeptOptions: formatHigherDeptOptions(higherDeptOptions.value),
|
higherDeptOptions: formatHigherDeptOptions(higherDeptOptions.value),
|
||||||
parentId: row?.deptId ?? 0,
|
deptId: data?.deptId ?? 0,
|
||||||
nick: row?.nick ?? "",
|
nick: data?.nick ?? "",
|
||||||
userName: row?.userName ?? "",
|
userName: data?.userName ?? "",
|
||||||
password: row?.password ?? "",
|
password: data?.password ?? "",
|
||||||
phone: row?.phone ?? "",
|
phone: data?.phone ?? "",
|
||||||
email: row?.email ?? "",
|
email: data?.email ?? "",
|
||||||
sex: row?.sex ?? "",
|
sex: data?.sex ?? "",
|
||||||
state: row?.state ?? false,
|
state: data?.state ?? true,
|
||||||
remark: row?.remark ?? ""
|
remark: data?.remark ?? "",
|
||||||
|
roleIds: data?.roles?.map(r => r.id),
|
||||||
|
roleOptions: roleOptions.value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
width: "46%",
|
width: "46%",
|
||||||
@@ -339,6 +355,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
beforeSure: (done, { options }) => {
|
beforeSure: (done, { options }) => {
|
||||||
const FormRef = formRef.value.getRef();
|
const FormRef = formRef.value.getRef();
|
||||||
const curData = options.props.formInline as FormItemProps;
|
const curData = options.props.formInline as FormItemProps;
|
||||||
|
|
||||||
function chores() {
|
function chores() {
|
||||||
message(`您${title}了用户名称为${curData.userName}的这条数据`, {
|
message(`您${title}了用户名称为${curData.userName}的这条数据`, {
|
||||||
type: "success"
|
type: "success"
|
||||||
@@ -346,15 +363,17 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
done(); // 关闭弹框
|
done(); // 关闭弹框
|
||||||
onSearch(); // 刷新表格数据
|
onSearch(); // 刷新表格数据
|
||||||
}
|
}
|
||||||
FormRef.validate(valid => {
|
|
||||||
|
FormRef.validate(async valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
console.log("curData", curData);
|
|
||||||
// 表单规则校验通过
|
// 表单规则校验通过
|
||||||
if (title === "新增") {
|
if (title === "新增") {
|
||||||
// 实际开发先调用新增接口,再进行下面操作
|
// 实际开发先调用新增接口,再进行下面操作
|
||||||
|
await addUser(curData);
|
||||||
chores();
|
chores();
|
||||||
} else {
|
} else {
|
||||||
// 实际开发先调用修改接口,再进行下面操作
|
// 实际开发先调用修改接口,再进行下面操作
|
||||||
|
await updateUser(row?.id, curData);
|
||||||
chores();
|
chores();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,6 +383,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cropRef = ref();
|
const cropRef = ref();
|
||||||
|
|
||||||
/** 上传头像 */
|
/** 上传头像 */
|
||||||
function handleUpload(row) {
|
function handleUpload(row) {
|
||||||
addDialog({
|
addDialog({
|
||||||
@@ -389,14 +409,14 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
pwdForm,
|
pwdForm,
|
||||||
({ newPwd }) =>
|
({ password }) =>
|
||||||
(curScore.value = isAllEmpty(newPwd) ? -1 : zxcvbn(newPwd).score)
|
(curScore.value = isAllEmpty(password) ? -1 : zxcvbn(password).score)
|
||||||
);
|
);
|
||||||
|
|
||||||
/** 重置密码 */
|
/** 重置密码 */
|
||||||
function handleReset(row) {
|
function handleReset(row) {
|
||||||
addDialog({
|
addDialog({
|
||||||
title: `重置 ${row.username} 用户的密码`,
|
title: `重置 ${row.userName} 用户的密码`,
|
||||||
width: "30%",
|
width: "30%",
|
||||||
draggable: true,
|
draggable: true,
|
||||||
closeOnClickModal: false,
|
closeOnClickModal: false,
|
||||||
@@ -405,7 +425,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
<>
|
<>
|
||||||
<ElForm ref={ruleFormRef} model={pwdForm}>
|
<ElForm ref={ruleFormRef} model={pwdForm}>
|
||||||
<ElFormItem
|
<ElFormItem
|
||||||
prop="newPwd"
|
prop="password"
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
@@ -418,7 +438,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
clearable
|
clearable
|
||||||
show-password
|
show-password
|
||||||
type="password"
|
type="password"
|
||||||
v-model={pwdForm.newPwd}
|
v-model={pwdForm.password}
|
||||||
placeholder="请输入新密码"
|
placeholder="请输入新密码"
|
||||||
/>
|
/>
|
||||||
</ElFormItem>
|
</ElFormItem>
|
||||||
@@ -449,15 +469,15 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
closeCallBack: () => (pwdForm.newPwd = ""),
|
closeCallBack: () => (pwdForm.password = ""),
|
||||||
beforeSure: done => {
|
beforeSure: done => {
|
||||||
ruleFormRef.value.validate(valid => {
|
ruleFormRef.value.validate(async valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
await resetUserPwd(row.id, pwdForm.password);
|
||||||
// 表单规则校验通过
|
// 表单规则校验通过
|
||||||
message(`已成功重置 ${row.username} 用户的密码`, {
|
message(`已成功重置 ${row.username} 用户的密码`, {
|
||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
console.log(pwdForm.newPwd);
|
|
||||||
// 根据实际业务使用pwdForm.newPwd和row里的某些字段去调用重置用户密码接口即可
|
// 根据实际业务使用pwdForm.newPwd和row里的某些字段去调用重置用户密码接口即可
|
||||||
done(); // 关闭弹框
|
done(); // 关闭弹框
|
||||||
onSearch(); // 刷新表格数据
|
onSearch(); // 刷新表格数据
|
||||||
@@ -467,35 +487,6 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 分配角色 */
|
|
||||||
async function handleRole(row) {
|
|
||||||
// 选中的角色列表
|
|
||||||
const ids = (await getRoleIds({ userId: row.id })).data ?? [];
|
|
||||||
addDialog({
|
|
||||||
title: `分配 ${row.username} 用户的角色`,
|
|
||||||
props: {
|
|
||||||
formInline: {
|
|
||||||
username: row?.username ?? "",
|
|
||||||
nickname: row?.nickname ?? "",
|
|
||||||
roleOptions: roleOptions.value ?? [],
|
|
||||||
ids
|
|
||||||
}
|
|
||||||
},
|
|
||||||
width: "400px",
|
|
||||||
draggable: true,
|
|
||||||
fullscreen: deviceDetection(),
|
|
||||||
fullscreenIcon: true,
|
|
||||||
closeOnClickModal: false,
|
|
||||||
contentRenderer: () => h(roleForm),
|
|
||||||
beforeSure: (done, { options }) => {
|
|
||||||
const curData = options.props.formInline as RoleFormItemProps;
|
|
||||||
console.log("curIds", curData.ids);
|
|
||||||
// 根据实际业务使用curData.ids和row里的某些字段去调用修改角色接口即可
|
|
||||||
done(); // 关闭弹框
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
treeLoading.value = true;
|
treeLoading.value = true;
|
||||||
onSearch();
|
onSearch();
|
||||||
@@ -507,7 +498,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
treeLoading.value = false;
|
treeLoading.value = false;
|
||||||
|
|
||||||
// 角色列表
|
// 角色列表
|
||||||
roleOptions.value = (await getAllRoleList()).data;
|
roleOptions.value = (await getRoleOption()).data.items;
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -530,7 +521,6 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
|
|||||||
handleDelete,
|
handleDelete,
|
||||||
handleUpload,
|
handleUpload,
|
||||||
handleReset,
|
handleReset,
|
||||||
handleRole,
|
|
||||||
handleSizeChange,
|
handleSizeChange,
|
||||||
onSelectionCancel,
|
onSelectionCancel,
|
||||||
handleCurrentChange,
|
handleCurrentChange,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ interface FormItemProps {
|
|||||||
/** 用于判断是`新增`还是`修改` */
|
/** 用于判断是`新增`还是`修改` */
|
||||||
title: string;
|
title: string;
|
||||||
higherDeptOptions: Record<string, unknown>[];
|
higherDeptOptions: Record<string, unknown>[];
|
||||||
parentId: string;
|
deptId?: string;
|
||||||
nick: string;
|
nick: string;
|
||||||
userName: string;
|
userName: string;
|
||||||
password: string;
|
password: string;
|
||||||
@@ -12,8 +12,10 @@ interface FormItemProps {
|
|||||||
sex: string | number;
|
sex: string | number;
|
||||||
state: boolean;
|
state: boolean;
|
||||||
deptName?: string;
|
deptName?: string;
|
||||||
deptId?: string;
|
|
||||||
remark: string;
|
remark: string;
|
||||||
|
|
||||||
|
roleIds: string[];
|
||||||
|
roleOptions: any[];
|
||||||
}
|
}
|
||||||
interface FormProps {
|
interface FormProps {
|
||||||
formInline: FormItemProps;
|
formInline: FormItemProps;
|
||||||
|
|||||||
Reference in New Issue
Block a user