fix: 修复问题
This commit is contained in:
parent
498b4d866d
commit
873424e65a
@ -1,5 +1,5 @@
|
||||
<script setup lang="tsx">
|
||||
import { onMounted, ref, useAttrs } from 'vue';
|
||||
import { onMounted, ref, useAttrs, watch } from 'vue';
|
||||
import type { TreeSelectInst, TreeSelectProps } from 'naive-ui';
|
||||
import { useBoolean } from '@sa/hooks';
|
||||
import { fetchGetDeptTree } from '@/service/api/system/user';
|
||||
@ -48,6 +48,16 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
watch([expandAll, options], ([newVal]) => {
|
||||
if (newVal) {
|
||||
// 展开所有节点
|
||||
expandedKeys.value = getAllDeptIds(options.value);
|
||||
} else {
|
||||
// 折叠到只显示根节点
|
||||
expandedKeys.value = [100];
|
||||
}
|
||||
});
|
||||
|
||||
function getAllDeptIds(depts: any[]) {
|
||||
const deptIds: CommonType.IdType[] = [];
|
||||
depts.forEach(item => {
|
||||
@ -114,7 +124,6 @@ defineExpose({
|
||||
:loading="loading"
|
||||
virtual-scroll
|
||||
:check-strategy="cascade ? 'child' : 'all'"
|
||||
:default-expand-all="expandAll"
|
||||
v-bind="attrs"
|
||||
/>
|
||||
</NSpin>
|
||||
|
@ -51,19 +51,14 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
// 添加 watch 监听 expandAll 的变化,options有值后,计算expandedKeys
|
||||
watch(
|
||||
[expandAll, options],
|
||||
([newVal]) => {
|
||||
watch([expandAll, options], ([newVal]) => {
|
||||
if (newVal) {
|
||||
// 展开所有节点
|
||||
expandedKeys.value = getAllMenuIds(options.value);
|
||||
} else {
|
||||
// 折叠到只显示根节点
|
||||
expandedKeys.value = [0];
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
});
|
||||
|
||||
function renderPrefix({ option }: { option: TreeOption }) {
|
||||
const renderLocalIcon = String(option.icon).startsWith('icon-');
|
||||
|
2
src/typings/api/system.api.d.ts
vendored
2
src/typings/api/system.api.d.ts
vendored
@ -570,7 +570,7 @@ declare namespace Api {
|
||||
/** 备注 */
|
||||
remark: string;
|
||||
/** 菜单树选择项是否关联显示 */
|
||||
menuCheckStrictly: number;
|
||||
menuCheckStrictly: boolean;
|
||||
/** 状态(0正常 1停用) */
|
||||
status: string;
|
||||
/** 删除标志(0代表存在 1代表删除) */
|
||||
|
@ -56,14 +56,15 @@ function createDefaultModel(): Model {
|
||||
packageName: '',
|
||||
menuIds: [],
|
||||
remark: '',
|
||||
menuCheckStrictly: null
|
||||
menuCheckStrictly: true
|
||||
};
|
||||
}
|
||||
|
||||
type RuleKey = Extract<keyof Model, 'packageId'>;
|
||||
type RuleKey = Extract<keyof Model, 'packageId' | 'packageName'>;
|
||||
|
||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||
packageId: createRequiredRule('租户套餐id不能为空')
|
||||
packageId: createRequiredRule('租户套餐id不能为空'),
|
||||
packageName: createRequiredRule('租户套餐名称不能为空')
|
||||
};
|
||||
|
||||
async function handleUpdateModelWhenEdit() {
|
||||
@ -78,7 +79,7 @@ async function handleUpdateModelWhenEdit() {
|
||||
|
||||
if (props.operateType === 'edit' && props.rowData) {
|
||||
startMenuLoading();
|
||||
Object.assign(model, props.rowData);
|
||||
Object.assign(model, { ...props.rowData, menuIds: [] });
|
||||
const { data, error } = await fetchGetTenantPackageMenuTreeSelect(model.packageId!);
|
||||
if (error) return;
|
||||
model.menuIds = data.checkedKeys;
|
||||
@ -94,15 +95,14 @@ function closeDrawer() {
|
||||
async function handleSubmit() {
|
||||
await validate();
|
||||
|
||||
const { packageId, packageName, menuIds, remark, menuCheckStrictly } = model;
|
||||
// request
|
||||
if (props.operateType === 'add') {
|
||||
const { packageName, menuIds, remark, menuCheckStrictly } = model;
|
||||
const { error } = await fetchCreateTenantPackage({ packageName, menuIds, remark, menuCheckStrictly });
|
||||
if (error) return;
|
||||
}
|
||||
|
||||
if (props.operateType === 'edit') {
|
||||
const { packageId, packageName, menuIds, remark, menuCheckStrictly } = model;
|
||||
const { error } = await fetchUpdateTenantPackage({
|
||||
packageId,
|
||||
packageName,
|
||||
@ -144,7 +144,7 @@ watch(visible, () => {
|
||||
/>
|
||||
</NFormItem>
|
||||
<NFormItem label="备注" path="remark">
|
||||
<NInput v-model:value="model.remark" placeholder="请输入备注" />
|
||||
<NInput v-model:value="model.remark" placeholder="请输入备注" type="textarea" />
|
||||
</NFormItem>
|
||||
</NForm>
|
||||
<template #footer>
|
||||
|
Loading…
Reference in New Issue
Block a user