mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat:对接部门管理,优化菜单管理,共用handleTree方法
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
<script setup lang="tsx">
|
||||
import { NButton, NPopconfirm } from 'naive-ui';
|
||||
import { fetchBatchDeletePost, fetchGetPostList } from '@/service/api/system/post';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import { ref } from 'vue';
|
||||
import { fetchBatchDeletePost, fetchGetPostList } from '@/service/api/system/post';
|
||||
import { fetchGetDeptTree } from '@/service/api/system';
|
||||
import { $t } from '@/locales';
|
||||
import { useAuth } from '@/hooks/business/auth';
|
||||
@ -11,7 +12,6 @@ import { useTable, useTableOperate } from '@/hooks/common/table';
|
||||
import DictTag from '@/components/custom/dict-tag.vue';
|
||||
import PostOperateDrawer from './modules/post-operate-drawer.vue';
|
||||
import PostSearch from './modules/post-search.vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
defineOptions({
|
||||
name: 'PostList'
|
||||
@ -40,7 +40,7 @@ const {
|
||||
// the value can not be undefined, otherwise the property in Form will not be reactive
|
||||
postCode: null,
|
||||
postName: null,
|
||||
status: null,
|
||||
status: null
|
||||
},
|
||||
columns: () => [
|
||||
{
|
||||
@ -103,66 +103,58 @@ const {
|
||||
width: 130,
|
||||
render: row => {
|
||||
const editBtn = () => {
|
||||
if (!hasAuth('system:post:edit')) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<NButton type="primary" ghost size="small" onClick={() => edit(row.postId!)}>
|
||||
{$t('common.edit')}
|
||||
</NButton>
|
||||
);
|
||||
if (!hasAuth('system:post:edit')) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<NButton type="primary" ghost size="small" onClick={() => edit(row.postId!)}>
|
||||
{$t('common.edit')}
|
||||
</NButton>
|
||||
);
|
||||
};
|
||||
|
||||
const deleteBtn = () => {
|
||||
if (!hasAuth('system:post:remove')) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<NPopconfirm onPositiveClick={() => handleDelete(row.postId!)}>
|
||||
{{
|
||||
default: () => $t('common.confirmDelete'),
|
||||
trigger: () => (
|
||||
<NButton type="error" ghost size="small">
|
||||
{$t('common.delete')}
|
||||
</NButton>
|
||||
)
|
||||
}}
|
||||
</NPopconfirm>
|
||||
);
|
||||
if (!hasAuth('system:post:remove')) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<NPopconfirm onPositiveClick={() => handleDelete(row.postId!)}>
|
||||
{{
|
||||
default: () => $t('common.confirmDelete'),
|
||||
trigger: () => (
|
||||
<NButton type="error" ghost size="small">
|
||||
{$t('common.delete')}
|
||||
</NButton>
|
||||
)
|
||||
}}
|
||||
</NPopconfirm>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="flex-center gap-8px">
|
||||
{editBtn()}
|
||||
{deleteBtn()}
|
||||
</div>
|
||||
<div class="flex-center gap-8px">
|
||||
{editBtn()}
|
||||
{deleteBtn()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const {
|
||||
drawerVisible,
|
||||
operateType,
|
||||
editingData,
|
||||
handleAdd,
|
||||
handleEdit,
|
||||
checkedRowKeys,
|
||||
onBatchDeleted,
|
||||
onDeleted
|
||||
} = useTableOperate(data, getData);
|
||||
const { drawerVisible, operateType, editingData, handleAdd, handleEdit, checkedRowKeys, onBatchDeleted, onDeleted } =
|
||||
useTableOperate(data, getData);
|
||||
|
||||
async function handleBatchDelete() {
|
||||
// request
|
||||
const { error } = await fetchBatchDeletePost(checkedRowKeys.value)
|
||||
const { error } = await fetchBatchDeletePost(checkedRowKeys.value);
|
||||
if (error) return;
|
||||
onBatchDeleted();
|
||||
}
|
||||
|
||||
async function handleDelete(postId: CommonType.IdType) {
|
||||
// request
|
||||
const { error } = await fetchBatchDeletePost([postId])
|
||||
const { error } = await fetchBatchDeletePost([postId]);
|
||||
if (error) return;
|
||||
onDeleted();
|
||||
}
|
||||
@ -172,7 +164,7 @@ async function edit(postId: CommonType.IdType) {
|
||||
}
|
||||
|
||||
async function handleExport() {
|
||||
download('/system/post/export', searchParams, `岗位信息_${new Date().getTime()}.xlsx`);
|
||||
download('/system/post/export', searchParams, `岗位信息_${new Date().getTime()}.xlsx`);
|
||||
}
|
||||
|
||||
const { loading: treeLoading, startLoading: startTreeLoading, endLoading: endTreeLoading } = useLoading();
|
||||
@ -220,10 +212,10 @@ function handleResetTreeData() {
|
||||
<NInput v-model:value="deptPattern" clearable :placeholder="$t('common.keywordSearch')" />
|
||||
<NSpin class="dept-tree" :show="treeLoading">
|
||||
<NTree
|
||||
v-model:selected-keys="selectedKeys"
|
||||
block-node
|
||||
show-line
|
||||
:data="deptData as []"
|
||||
v-model:selected-keys="selectedKeys"
|
||||
:default-expanded-keys="deptData?.length ? [deptData[0].id!] : []"
|
||||
:show-irrelevant-nodes="false"
|
||||
:pattern="deptPattern"
|
||||
@ -282,7 +274,6 @@ function handleResetTreeData() {
|
||||
</TableSiderLayout>
|
||||
</template>
|
||||
|
||||
|
||||
<style scoped lang="scss">
|
||||
.dept-tree {
|
||||
.n-button {
|
||||
@ -346,4 +337,4 @@ function handleResetTreeData() {
|
||||
:deep(.n-card-header__main) {
|
||||
min-width: 69px !important;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
@ -1,9 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import { $t } from '@/locales';
|
||||
import { fetchCreatePost, fetchUpdatePost } from '@/service/api/system/post';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
defineOptions({
|
||||
name: 'PostOperateDrawer'
|
||||
});
|
||||
@ -56,15 +56,7 @@ function createDefaultModel(): Model {
|
||||
};
|
||||
}
|
||||
|
||||
type RuleKey = Extract<
|
||||
keyof Model,
|
||||
| 'postId'
|
||||
| 'deptId'
|
||||
| 'postCode'
|
||||
| 'postName'
|
||||
| 'postSort'
|
||||
| 'status'
|
||||
>;
|
||||
type RuleKey = Extract<keyof Model, 'postId' | 'deptId' | 'postCode' | 'postName' | 'postSort' | 'status'>;
|
||||
|
||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||
postId: createRequiredRule('岗位ID不能为空'),
|
||||
@ -72,7 +64,7 @@ const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||
postCode: createRequiredRule('岗位编码不能为空'),
|
||||
postName: createRequiredRule('岗位名称不能为空'),
|
||||
postSort: createRequiredRule('显示顺序不能为空'),
|
||||
status: createRequiredRule('状态不能为空'),
|
||||
status: createRequiredRule('状态不能为空')
|
||||
};
|
||||
|
||||
function handleUpdateModelWhenEdit() {
|
||||
@ -104,7 +96,16 @@ async function handleSubmit() {
|
||||
|
||||
if (props.operateType === 'edit') {
|
||||
const { postId, deptId, postCode, postCategory, postName, postSort, status, remark } = model;
|
||||
const { error } = await fetchUpdatePost({ postId, deptId, postCode, postCategory, postName, postSort, status, remark });
|
||||
const { error } = await fetchUpdatePost({
|
||||
postId,
|
||||
deptId,
|
||||
postCode,
|
||||
postCategory,
|
||||
postName,
|
||||
postSort,
|
||||
status,
|
||||
remark
|
||||
});
|
||||
if (error) return;
|
||||
}
|
||||
|
||||
@ -127,38 +128,33 @@ watch(visible, () => {
|
||||
<NForm ref="formRef" :model="model" :rules="rules">
|
||||
<NFormItem label="归属部门" path="deptId">
|
||||
<NTreeSelect
|
||||
v-model:value="model.deptId"
|
||||
:loading="deptLoading"
|
||||
clearable
|
||||
:options="deptData as []"
|
||||
label-field="label"
|
||||
key-field="id"
|
||||
:default-expanded-keys="deptData?.length ? [deptData[0].id] : []"
|
||||
placeholder="请选择归属部门"
|
||||
/>
|
||||
v-model:value="model.deptId"
|
||||
:loading="deptLoading"
|
||||
clearable
|
||||
:options="deptData as []"
|
||||
label-field="label"
|
||||
key-field="id"
|
||||
:default-expanded-keys="deptData?.length ? [deptData[0].id] : []"
|
||||
placeholder="请选择归属部门"
|
||||
/>
|
||||
</NFormItem>
|
||||
<NFormItem label="岗位编码" path="postCode">
|
||||
<NInput v-model:value="model.postCode" placeholder="请输入岗位编码" />
|
||||
<NInput v-model:value="model.postCode" placeholder="请输入岗位编码" />
|
||||
</NFormItem>
|
||||
<NFormItem label="类别编码" path="postCategory">
|
||||
<NInput v-model:value="model.postCategory" placeholder="请输入类别编码" />
|
||||
<NInput v-model:value="model.postCategory" placeholder="请输入类别编码" />
|
||||
</NFormItem>
|
||||
<NFormItem label="岗位名称" path="postName">
|
||||
<NInput v-model:value="model.postName" placeholder="请输入岗位名称" />
|
||||
<NInput v-model:value="model.postName" placeholder="请输入岗位名称" />
|
||||
</NFormItem>
|
||||
<NFormItem label="显示顺序" path="postSort">
|
||||
<NInputNumber v-model:value="model.postSort" placeholder="请输入显示顺序" />
|
||||
<NInputNumber v-model:value="model.postSort" placeholder="请输入显示顺序" />
|
||||
</NFormItem>
|
||||
<NFormItem label="状态" path="status">
|
||||
<DictRadio v-model:value="model.status" dict-code="sys_normal_disable" />
|
||||
</NFormItem>
|
||||
<NFormItem label="备注" path="remark">
|
||||
<NInput
|
||||
v-model:value="model.remark"
|
||||
:rows="3"
|
||||
type="textarea"
|
||||
placeholder="请输入备注"
|
||||
/>
|
||||
<NInput v-model:value="model.remark" :rows="3" type="textarea" placeholder="请输入备注" />
|
||||
</NFormItem>
|
||||
</NForm>
|
||||
<template #footer>
|
||||
|
@ -15,7 +15,6 @@ const emit = defineEmits<Emits>();
|
||||
|
||||
const { formRef, validate, restoreValidation } = useNaiveForm();
|
||||
|
||||
|
||||
const model = defineModel<Api.System.PostSearchParams>('model', { required: true });
|
||||
|
||||
const { options: sysCommonStatusOptions } = useDict('sys_normal_disable');
|
||||
|
Reference in New Issue
Block a user