feat: ✨ 用户页面自定义导航栏和新增用户

This commit is contained in:
ray
2024-11-23 15:57:48 +08:00
parent 5cac38077e
commit 964276b7eb
2 changed files with 64 additions and 20 deletions

View File

@@ -40,7 +40,7 @@
{ {
"path": "pages/work/user/index", "path": "pages/work/user/index",
"style": { "style": {
"navigationBarTitleText": "用户管理" "navigationStyle": "custom"
} }
}, },
{ {

View File

@@ -1,4 +1,9 @@
<template> <template>
<wd-navbar title="用户管理" left-arrow>
<template #right>
<wd-icon name="add-circle" size="18" @click="handleOpenDialog()" />
</template>
</wd-navbar>
<view class="user"> <view class="user">
<!-- 排序筛选 --> <!-- 排序筛选 -->
<view class="mb-24rpx"> <view class="mb-24rpx">
@@ -51,18 +56,23 @@
</wd-cell-group> </wd-cell-group>
<template #footer> <template #footer>
<view class="flex-between"> <wd-swipe-action>
<view> <view class="flex-between">
<wd-text text="创建时间:" size="12px" /> <view>
<wd-text :text="item.createTime" size="12px" /> <wd-text text="创建时间:" size="12px" />
<wd-text :text="item.createTime" size="12px" />
</view>
<view>
<wd-button size="small" plain @click="handleOpenDialog(item.id)">编辑</wd-button>
</view>
</view> </view>
<view>
<wd-button size="small" plain @click="handleOpenDialog(item.id)">编辑</wd-button> <template #right>
<wd-button type="error" plain size="small" class="ml-2" @click="handleDelete(item.id)"> <wd-button type="error" plain size="small" @click="handleDelete(item.id)">
删除 删除
</wd-button> </wd-button>
</view> </template>
</view> </wd-swipe-action>
</template> </template>
</wd-card> </wd-card>
@@ -70,7 +80,7 @@
<wd-message-box /> <wd-message-box />
<!-- 编辑弹窗 --> <!-- 编辑弹窗 -->
<wd-popup v-model="dialog.visible" position="bottom"> <wd-popup v-model="dialog.visible" position="bottom" @close="hancleCloseDialog">
<wd-form ref="userFormRef" :model="formData" :rules="rules"> <wd-form ref="userFormRef" :model="formData" :rules="rules">
<wd-cell-group border> <wd-cell-group border>
<wd-input v-model="formData.username" label="用户名" :readonly="!formData.id" required /> <wd-input v-model="formData.username" label="用户名" :readonly="!formData.id" required />
@@ -98,6 +108,9 @@
<wd-button type="primary" block @click="handleSubmit">提交</wd-button> <wd-button type="primary" block @click="handleSubmit">提交</wd-button>
</view> </view>
</wd-popup> </wd-popup>
<wd-loading v-show="loading" />
<!-- <wd-fab position="left-bottom" :expandable="false" @click="handleOpenDialog" /> -->
</view> </view>
</template> </template>
@@ -113,6 +126,8 @@ import DeptAPI from "@/api/system/dept";
import VutPicker from "@/components/VutPicker.vue"; import VutPicker from "@/components/VutPicker.vue";
const message = useMessage(); const message = useMessage();
const loading = ref(false);
const state = ref<LoadMoreState>("loading"); const state = ref<LoadMoreState>("loading");
const dataList = ref<UserPageVO[]>([]); const dataList = ref<UserPageVO[]>([]);
@@ -135,9 +150,19 @@ const total = ref(0);
const dialog = reactive({ const dialog = reactive({
visible: false, visible: false,
}); });
const formData = reactive<UserForm>({
const initialFormData: UserForm = {
id: undefined,
roleIds: [], roleIds: [],
}); username: undefined,
nickname: undefined,
deptId: undefined,
mobile: undefined,
email: undefined,
status: 1,
};
const formData = reactive<UserForm>({ ...initialFormData });
const userFormRef = ref(); const userFormRef = ref();
const roleOptions = ref<Record<string, any>[]>([]); const roleOptions = ref<Record<string, any>[]>([]);
@@ -252,13 +277,20 @@ function loadmore() {
* 打开弹窗 * 打开弹窗
*/ */
async function handleOpenDialog(id?: number) { async function handleOpenDialog(id?: number) {
loading.value = true;
dialog.visible = true; dialog.visible = true;
roleOptions.value = await RoleAPI.getOptions(); roleOptions.value = await RoleAPI.getOptions();
deptOptions.value = await DeptAPI.getOptions(); deptOptions.value = await DeptAPI.getOptions();
if (id) { if (id) {
UserAPI.getFormData(id).then((data) => { UserAPI.getFormData(id)
Object.assign(formData, { ...data }); .then((data) => {
}); Object.assign(formData, { ...data });
})
.finally(() => {
loading.value = false;
});
} else {
loading.value = false;
} }
} }
@@ -266,19 +298,20 @@ async function handleOpenDialog(id?: number) {
* 提交保存 * 提交保存
*/ */
function handleSubmit() { function handleSubmit() {
hancleCloseDialog();
userFormRef.value.validate().then(({ valid }: { valid: boolean }) => { userFormRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (valid) { if (valid) {
const userId = formData.id; const userId = formData.id;
if (userId) { if (userId) {
UserAPI.update(userId, formData).then(() => { UserAPI.update(userId, formData).then(() => {
message.show("修改成功"); message.show("修改成功");
dialog.visible = false; hancleCloseDialog();
handleQuery(); handleQuery();
}); });
} else { } else {
UserAPI.add(formData).then(() => { UserAPI.add(formData).then(() => {
message.show("添加成功"); message.show("添加成功");
dialog.visible = false; hancleCloseDialog();
handleQuery(); handleQuery();
}); });
} }
@@ -286,6 +319,18 @@ function handleSubmit() {
}); });
} }
// 重置表单
function resetForm() {
userFormRef.value.reset();
Object.assign(formData, initialFormData);
}
// 关闭弹窗
function hancleCloseDialog() {
dialog.visible = false;
resetForm();
}
/** /**
* 删除 * 删除
* *
@@ -305,7 +350,7 @@ function handleDelete(id: number) {
}); });
} }
// 监听下拉菜单打开事件 // 触底事件
onReachBottom(() => { onReachBottom(() => {
if (queryParams.pageNum * queryParams.pageSize < total.value) { if (queryParams.pageNum * queryParams.pageSize < total.value) {
loadmore(); loadmore();
@@ -314,7 +359,6 @@ onReachBottom(() => {
} }
}); });
// 页面加载时执行查询
onLoad(() => { onLoad(() => {
handleQuery(); handleQuery();
}); });