mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
refactor(system): 移除岗位关联部门功能并优化岗位加载逻辑
- 删除岗位表单中的部门选择组件及相关联动逻辑 - 修改岗位接口调用为无参数版本,加载全部岗位数据 - 优化用户手机号字段验证规则,支持字符串和数字 - 用户界面中岗位选择不再依赖部门选择,初始化时加载全部岗位 - 移除岗位抽屉中部门树获取及展示逻辑,简化表单结构 - 调整岗位数据提交时移除部门字段,确保数据一致性 - 修正岗位选择组件占位符及禁用状态逻辑,提升用户体验
This commit is contained in:
@@ -72,6 +72,6 @@ export function postRemove(postIds: IDS) {
|
||||
* 获取岗位下拉列表
|
||||
* @returns 岗位
|
||||
*/
|
||||
export function postOptionSelect(deptId: string) {
|
||||
return requestClient.get<Post[]>(`${Api.postSelect}?keywords=${deptId}`);
|
||||
export function postOptionSelect() {
|
||||
return requestClient.get<Post[]>(Api.postSelect);
|
||||
}
|
||||
|
||||
@@ -79,15 +79,6 @@ export const drawerSchema: FormSchemaGetter = () => [
|
||||
fieldName: 'id',
|
||||
label: 'id',
|
||||
},
|
||||
{
|
||||
component: 'TreeSelect',
|
||||
componentProps: {
|
||||
getPopupContainer,
|
||||
},
|
||||
fieldName: 'deptId',
|
||||
label: '所属部门',
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'postName',
|
||||
|
||||
@@ -3,11 +3,10 @@ import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { addFullName, cloneDeep } from '@vben/utils';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { postAdd, postInfo, postUpdate } from '#/api/system/post';
|
||||
import { getDeptTree } from '#/api/system/user';
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
import { drawerSchema } from './data';
|
||||
@@ -32,25 +31,6 @@ const [BasicForm, formApi] = useVbenForm({
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
async function setupDeptSelect() {
|
||||
const deptTree = await getDeptTree();
|
||||
// 选中后显示在输入框的值 即父节点 / 子节点
|
||||
addFullName(deptTree, 'deptName', ' / ');
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
fieldNames: { label: 'deptName', value: 'id' },
|
||||
treeData: deptTree,
|
||||
treeDefaultExpandAll: true,
|
||||
treeLine: { showLeafIcon: false },
|
||||
// 选中后显示在输入框的值
|
||||
treeNodeLabelProp: 'fullName',
|
||||
},
|
||||
fieldName: 'deptId',
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
@@ -69,8 +49,6 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
drawerApi.drawerLoading(true);
|
||||
const { id } = drawerApi.getData() as { id?: string };
|
||||
isUpdate.value = !!id;
|
||||
// 初始化
|
||||
await setupDeptSelect();
|
||||
// 更新 && 赋值
|
||||
if (isUpdate.value && id) {
|
||||
const record = await postInfo(id);
|
||||
@@ -89,6 +67,8 @@ async function handleConfirm() {
|
||||
return;
|
||||
}
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
// 移除部门与岗位的关联字段(已不再维护关联部门功能)
|
||||
Reflect.deleteProperty(data, 'deptId');
|
||||
await (isUpdate.value ? postUpdate(data) : postAdd(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
|
||||
@@ -132,10 +132,15 @@ export const drawerSchema: FormSchemaGetter = () => [
|
||||
label: '手机号码',
|
||||
defaultValue: undefined,
|
||||
rules: z
|
||||
.string()
|
||||
.regex(/^1[3-9]\d{9}$/, '请输入正确的手机号码')
|
||||
.optional()
|
||||
.or(z.literal('')),
|
||||
.union([z.string(), z.number()])
|
||||
.refine(
|
||||
(val) => {
|
||||
if (val === '' || val === undefined || val === null) return true;
|
||||
return /^1[3-9]\d{9}$/.test(String(val));
|
||||
},
|
||||
{ message: '请输入正确的手机号码' },
|
||||
)
|
||||
.optional(),
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
|
||||
@@ -63,36 +63,19 @@ function genRoleOptionlabel(role: Role) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门ID加载岗位列表
|
||||
* @param deptId 部门ID
|
||||
* 加载岗位列表(不再强依赖部门选择)
|
||||
* @param deptId 部门ID(可选,不传时尝试加载全部)
|
||||
*/
|
||||
async function setupPostOptions(deptId?: string) {
|
||||
if (!deptId) {
|
||||
// 没有选择部门时,显示提示
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: '请先选择部门',
|
||||
},
|
||||
fieldName: 'postIds',
|
||||
},
|
||||
]);
|
||||
// 清空已选岗位
|
||||
formApi.setFieldValue('postIds', []);
|
||||
return;
|
||||
}
|
||||
|
||||
async function setupPostOptions() {
|
||||
try {
|
||||
const postListResp = await postOptionSelect(deptId);
|
||||
const postListResp = await postOptionSelect();
|
||||
// 确保返回的是数组
|
||||
const postList = Array.isArray(postListResp) ? postListResp : [];
|
||||
const options = postList.map((item) => ({
|
||||
label: item.postName,
|
||||
value: item.id,
|
||||
}));
|
||||
const placeholder = options.length > 0 ? '请选择岗位' : '该部门暂无岗位';
|
||||
const placeholder = options.length > 0 ? '请选择岗位' : '暂无岗位数据';
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
@@ -103,8 +86,6 @@ async function setupPostOptions(deptId?: string) {
|
||||
fieldName: 'postIds',
|
||||
},
|
||||
]);
|
||||
// 部门变化时清空已选岗位
|
||||
formApi.setFieldValue('postIds', []);
|
||||
} catch (error) {
|
||||
console.error('加载岗位信息失败:', error);
|
||||
formApi.updateSchema([
|
||||
@@ -151,10 +132,6 @@ async function setupDeptSelect() {
|
||||
treeNodeFilterProp: 'deptName',
|
||||
// 选中后显示在输入框的值
|
||||
treeNodeLabelProp: 'fullName',
|
||||
// 部门选择变化时加载对应岗位
|
||||
onChange: (value: string) => {
|
||||
setupPostOptions(value);
|
||||
},
|
||||
},
|
||||
fieldName: 'deptId',
|
||||
},
|
||||
@@ -204,13 +181,13 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
onConfirm: handleConfirm,
|
||||
async onOpenChange(isOpen) {
|
||||
if (!isOpen) {
|
||||
// 需要重置岗位选择
|
||||
// 重置岗位选择(不再提示必须先选部门)
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
disabled: false,
|
||||
options: [],
|
||||
placeholder: '请先选择部门',
|
||||
placeholder: '请选择岗位',
|
||||
},
|
||||
fieldName: 'postIds',
|
||||
},
|
||||
@@ -272,36 +249,22 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
// 部门选择、初始密码
|
||||
const promises = [
|
||||
setupDeptSelect(),
|
||||
// 岗位列表初始化加载(部门为空也可加载)
|
||||
setupPostOptions(),
|
||||
loadDefaultPassword(isUpdate.value),
|
||||
];
|
||||
|
||||
if (user) {
|
||||
// 编辑模式:使用用户已有的岗位数据
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
disabled: false,
|
||||
options: postOptions,
|
||||
placeholder: '请选择岗位',
|
||||
},
|
||||
fieldName: 'postIds',
|
||||
},
|
||||
]);
|
||||
// 处理用户数据,确保 phone 字段是字符串类型
|
||||
const userData = {
|
||||
...user,
|
||||
// 将数字类型的 phone 转换为字符串,null/undefined 转为空字符串
|
||||
phone: user.phone != null ? String(user.phone) : '',
|
||||
};
|
||||
promises.push(
|
||||
// 添加基础信息
|
||||
formApi.setValues(userData),
|
||||
// 添加角色和岗位
|
||||
formApi.setFieldValue('postIds', postIds),
|
||||
formApi.setFieldValue('roleIds', roleIds),
|
||||
);
|
||||
} else {
|
||||
// 新增模式:等待选择部门后再加载岗位
|
||||
// 新增模式:直接加载岗位(不依赖部门)
|
||||
await setupPostOptions();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user