Skip to content

Commit 13d125f

Browse files
committed
chore: done
1 parent b71f61f commit 13d125f

File tree

6 files changed

+118
-68
lines changed

6 files changed

+118
-68
lines changed

mock/system.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export default [
1111
username: "admin",
1212
nickname: "admin",
1313
avatar: "https://avatars.githubusercontent.com/u/44761321",
14-
mobile: "15888886789",
14+
phone: "15888886789",
15+
email: "@email",
1516
sex: 0,
1617
id: 1,
1718
status: 1,
@@ -28,7 +29,8 @@ export default [
2829
username: "common",
2930
nickname: "common",
3031
avatar: "https://avatars.githubusercontent.com/u/52823142",
31-
mobile: "18288882345",
32+
phone: "18288882345",
33+
email: "@email",
3234
sex: 1,
3335
id: 2,
3436
status: 1,
@@ -44,7 +46,7 @@ export default [
4446
list = list.filter(item =>
4547
String(item.status).includes(String(body?.status))
4648
);
47-
if (body.mobile) list = list.filter(item => item.mobile === body.mobile);
49+
if (body.phone) list = list.filter(item => item.phone === body.phone);
4850
if (body.deptId) list = list.filter(item => item.dept.id === body.deptId);
4951
return {
5052
success: true,

src/views/system/user/form/index.vue

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,30 @@ import { usePublicHooks } from "../../hooks";
77
88
const props = withDefaults(defineProps<FormProps>(), {
99
formInline: () => ({
10+
title: "新增",
1011
higherDeptOptions: [],
1112
parentId: 0,
12-
name: "",
13-
principal: "",
13+
nickname: "",
14+
username: "",
15+
password: "",
1416
phone: "",
1517
email: "",
16-
sort: 0,
18+
sex: "",
1719
status: 1,
1820
remark: ""
1921
})
2022
});
2123
24+
const sexOptions = [
25+
{
26+
value: 0,
27+
label: ""
28+
},
29+
{
30+
value: 1,
31+
label: ""
32+
}
33+
];
2234
const ruleFormRef = ref();
2335
const { switchStyle } = usePublicHooks();
2436
const newFormInline = ref(props.formInline);
@@ -39,57 +51,38 @@ defineExpose({ getRef });
3951
>
4052
<el-row :gutter="30">
4153
<re-col :value="12" :xs="24" :sm="24">
42-
<el-form-item label="用户昵称" prop="name">
54+
<el-form-item label="用户昵称" prop="nickname">
4355
<el-input
44-
v-model="newFormInline.name"
56+
v-model="newFormInline.nickname"
4557
clearable
46-
placeholder="请输入部门名称"
58+
placeholder="请输入用户昵称"
4759
/>
4860
</el-form-item>
4961
</re-col>
5062
<re-col :value="12" :xs="24" :sm="24">
51-
<el-form-item label="归属部门">
52-
<el-cascader
53-
class="w-full"
54-
v-model="newFormInline.parentId"
55-
:options="newFormInline.higherDeptOptions"
56-
:props="{
57-
value: 'id',
58-
label: 'name',
59-
emitPath: false,
60-
checkStrictly: true
61-
}"
62-
clearable
63-
filterable
64-
placeholder="请选择归属部门"
65-
>
66-
<template #default="{ node, data }">
67-
<span>{{ data.name }}</span>
68-
<span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
69-
</template>
70-
</el-cascader>
71-
</el-form-item>
72-
</re-col>
73-
74-
<re-col :value="12" :xs="24" :sm="24">
75-
<el-form-item label="用户名称" prop="name">
63+
<el-form-item label="用户名称" prop="username">
7664
<el-input
77-
v-model="newFormInline.name"
65+
v-model="newFormInline.username"
7866
clearable
7967
placeholder="请输入用户名称"
8068
/>
8169
</el-form-item>
8270
</re-col>
83-
<re-col :value="12" :xs="24" :sm="24">
84-
<el-form-item label="用户密码" prop="name">
71+
72+
<re-col
73+
:value="12"
74+
:xs="24"
75+
:sm="24"
76+
v-if="newFormInline.title === '新增'"
77+
>
78+
<el-form-item label="用户密码" prop="password">
8579
<el-input
86-
v-model="newFormInline.name"
80+
v-model="newFormInline.password"
8781
clearable
8882
placeholder="请输入用户密码"
8983
/>
9084
</el-form-item>
9185
</re-col>
92-
9386
<re-col :value="12" :xs="24" :sm="24">
9487
<el-form-item label="手机号" prop="phone">
9588
<el-input
@@ -99,6 +92,7 @@ defineExpose({ getRef });
9992
/>
10093
</el-form-item>
10194
</re-col>
95+
10296
<re-col :value="12" :xs="24" :sm="24">
10397
<el-form-item label="邮箱" prop="email">
10498
<el-input
@@ -108,18 +102,53 @@ defineExpose({ getRef });
108102
/>
109103
</el-form-item>
110104
</re-col>
111-
112105
<re-col :value="12" :xs="24" :sm="24">
113106
<el-form-item label="用户性别">
114-
<el-input-number
115-
v-model="newFormInline.sort"
116-
:min="0"
117-
:max="9999"
118-
controls-position="right"
119-
/>
107+
<el-select
108+
v-model="newFormInline.sex"
109+
placeholder="请选择用户性别"
110+
class="w-full"
111+
clearable
112+
>
113+
<el-option
114+
v-for="(item, index) in sexOptions"
115+
:key="index"
116+
:label="item.label"
117+
:value="item.value"
118+
/>
119+
</el-select>
120120
</el-form-item>
121121
</re-col>
122+
122123
<re-col :value="12" :xs="24" :sm="24">
124+
<el-form-item label="归属部门">
125+
<el-cascader
126+
class="w-full"
127+
v-model="newFormInline.parentId"
128+
:options="newFormInline.higherDeptOptions"
129+
:props="{
130+
value: 'id',
131+
label: 'name',
132+
emitPath: false,
133+
checkStrictly: true
134+
}"
135+
clearable
136+
filterable
137+
placeholder="请选择归属部门"
138+
>
139+
<template #default="{ node, data }">
140+
<span>{{ data.name }}</span>
141+
<span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
142+
</template>
143+
</el-cascader>
144+
</el-form-item>
145+
</re-col>
146+
<re-col
147+
:value="12"
148+
:xs="24"
149+
:sm="24"
150+
v-if="newFormInline.title === '新增'"
151+
>
123152
<el-form-item label="用户状态">
124153
<el-switch
125154
v-model="newFormInline.status"

src/views/system/user/index.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ const {
7474
class="!w-[160px]"
7575
/>
7676
</el-form-item>
77-
<el-form-item label="手机号码:" prop="mobile">
77+
<el-form-item label="手机号码:" prop="phone">
7878
<el-input
79-
v-model="form.mobile"
79+
v-model="form.phone"
8080
placeholder="请输入手机号码"
8181
clearable
8282
class="!w-[160px]"
@@ -148,6 +148,7 @@ const {
148148
</el-popconfirm>
149149
</div>
150150
<pure-table
151+
row-key="id"
151152
ref="tableRef"
152153
adaptive
153154
align-whole="center"
@@ -177,15 +178,17 @@ const {
177178
>
178179
修改
179180
</el-button>
180-
<el-popconfirm title="是否确认删除?">
181+
<el-popconfirm
182+
:title="`是否确认删除用户编号为${row.id}的这条数据`"
183+
@confirm="handleDelete(row)"
184+
>
181185
<template #reference>
182186
<el-button
183187
class="reset-margin"
184188
link
185189
type="primary"
186190
:size="size"
187191
:icon="useRenderIcon(Delete)"
188-
@click="handleDelete(row)"
189192
>
190193
删除
191194
</el-button>

src/views/system/user/utils/hook.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { zxcvbn } from "@zxcvbn-ts/core";
66
import { handleTree } from "@/utils/tree";
77
import { message } from "@/utils/message";
88
import croppingUpload from "../upload.vue";
9+
import { usePublicHooks } from "../../hooks";
910
import { addDialog } from "@/components/ReDialog";
1011
import { type PaginationProps } from "@pureadmin/table";
1112
import type { FormItemProps, RoleFormItemProps } from "../utils/types";
@@ -39,7 +40,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
3940
// 左侧部门树的id
4041
deptId: "",
4142
username: "",
42-
mobile: "",
43+
phone: "",
4344
status: ""
4445
});
4546
const formRef = ref();
@@ -49,6 +50,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
4950
// 上传头像信息
5051
const avatarInfo = ref();
5152
const switchLoadMap = ref({});
53+
const { switchStyle } = usePublicHooks();
5254
const higherDeptOptions = ref();
5355
const treeData = ref([]);
5456
const treeLoading = ref(true);
@@ -63,7 +65,8 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
6365
{
6466
label: "勾选列", // 如果需要表格多选,此处label必须设置
6567
type: "selection",
66-
fixed: "left"
68+
fixed: "left",
69+
reserveSelection: true // 数据刷新后保留选项
6770
},
6871
{
6972
label: "用户编号",
@@ -115,9 +118,9 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
115118
},
116119
{
117120
label: "手机号码",
118-
prop: "mobile",
121+
prop: "phone",
119122
minWidth: 90,
120-
formatter: ({ mobile }) => hideTextAtIndex(mobile, { start: 3, end: 6 })
123+
formatter: ({ phone }) => hideTextAtIndex(phone, { start: 3, end: 6 })
121124
},
122125
{
123126
label: "状态",
@@ -130,9 +133,10 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
130133
v-model={scope.row.status}
131134
active-value={1}
132135
inactive-value={0}
133-
active-text="已开启"
134-
inactive-text="已关闭"
136+
active-text="已启用"
137+
inactive-text="已停用"
135138
inline-prompt
139+
style={switchStyle.value}
136140
onChange={() => onChange(scope as any)}
137141
/>
138142
)
@@ -222,7 +226,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
222226
}
223227

224228
function handleDelete(row) {
225-
message(`您删除了角色名称为${row.name}的这条数据`, { type: "success" });
229+
message(`您删除了用户编号为${row.id}的这条数据`, { type: "success" });
226230
onSearch();
227231
}
228232

@@ -253,7 +257,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
253257
// 返回当前选中的行
254258
const curSelected = tableRef.value.getTableRef().getSelectionRows();
255259
// 接下来根据实际业务,通过选中行的某项数据,比如下面的id,调用接口进行批量删除
256-
message(`已删除id为 ${getKeyList(curSelected, "id")} 的数据`, {
260+
message(`已删除用户编号为 ${getKeyList(curSelected, "id")} 的数据`, {
257261
type: "success"
258262
});
259263
tableRef.value.getTableRef().clearSelection();
@@ -302,18 +306,20 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
302306
title: `${title}用户`,
303307
props: {
304308
formInline: {
309+
title,
305310
higherDeptOptions: formatHigherDeptOptions(higherDeptOptions.value),
306-
parentId: row?.parentId ?? 0,
307-
name: row?.name ?? "",
308-
principal: row?.principal ?? "",
311+
parentId: row?.dept.id ?? 0,
312+
nickname: row?.nickname ?? "",
313+
username: row?.username ?? "",
314+
password: row?.password ?? "",
309315
phone: row?.phone ?? "",
310316
email: row?.email ?? "",
311-
sort: row?.sort ?? 0,
317+
sex: row?.sex ?? "",
312318
status: row?.status ?? 1,
313319
remark: row?.remark ?? ""
314320
}
315321
},
316-
width: "40%",
322+
width: "46%",
317323
draggable: true,
318324
fullscreenIcon: true,
319325
closeOnClickModal: false,
@@ -322,7 +328,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
322328
const FormRef = formRef.value.getRef();
323329
const curData = options.props.formInline as FormItemProps;
324330
function chores() {
325-
message(`您${title}了用户名称为${curData.name}的这条数据`, {
331+
message(`您${title}了用户名称为${curData.username}的这条数据`, {
326332
type: "success"
327333
});
328334
done(); // 关闭弹框

src/views/system/user/utils/rule.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { isPhone, isEmail } from "@pureadmin/utils";
44

55
/** 自定义表单规则校验 */
66
export const formRules = reactive(<FormRules>{
7-
name: [{ required: true, message: "部门名称为必填项", trigger: "blur" }],
7+
nickname: [{ required: true, message: "用户昵称为必填项", trigger: "blur" }],
8+
username: [{ required: true, message: "用户名称为必填项", trigger: "blur" }],
9+
password: [{ required: true, message: "用户密码为必填项", trigger: "blur" }],
810
phone: [
911
{
1012
validator: (rule, value, callback) => {

src/views/system/user/utils/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
interface FormItemProps {
2+
id?: number;
3+
/** 用于判断是`新增`还是`修改` */
4+
title: string;
25
higherDeptOptions: Record<string, unknown>[];
36
parentId: number;
4-
name: string;
5-
principal: string;
7+
nickname: string;
8+
username: string;
9+
password: string;
610
phone: string | number;
711
email: string;
8-
sort: number;
12+
sex: string | number;
913
status: number;
14+
dept?: {
15+
id?: number;
16+
name?: string;
17+
};
1018
remark: string;
1119
}
1220
interface FormProps {

0 commit comments

Comments
 (0)