perf: 优化access授权支持remote-auto-complete

This commit is contained in:
xiaojunnuo
2026-02-09 19:19:26 +08:00
parent 02f89a9c9d
commit 2f40f795ee
3 changed files with 39 additions and 19 deletions

View File

@@ -23,7 +23,7 @@ defineOptions({
const props = defineProps<
{
watches: string[];
watches?: string[];
} & ComponentPropsType
>();
@@ -48,6 +48,18 @@ const message = ref("");
const hasError = ref(false);
const loading = ref(false);
function getInputFromForm(form: any, pluginType: string) {
let input: any = {};
if (pluginType === "plugin") {
input = form?.input || {};
} else if (pluginType === "access") {
input = form?.access || {};
} else {
input = form || {};
}
return input;
}
const getOptions = async () => {
if (loading.value) {
return;
@@ -63,15 +75,14 @@ const getOptions = async () => {
}
const pluginType = getPluginType();
const { form } = getScope();
const input = (pluginType === "plugin" ? form?.input : form) || {};
const input = getInputFromForm(form, pluginType);
for (let key in define.input) {
const inWatches = props.watches?.includes(key);
const inputDefine = define.input[key];
if (inWatches && inputDefine.required) {
const value = input[key];
if (value == null || value === "") {
console.log("remote-select required", key);
console.log("remote-auto-complete required", key);
return;
}
}
@@ -129,12 +140,14 @@ watch(
() => {
const pluginType = getPluginType();
const { form, key } = getScope();
const input = (pluginType === "plugin" ? form?.input : form) || {};
const watches = {};
for (const key of props.watches) {
//@ts-ignore
watches[key] = input[key];
const input = getInputFromForm(form, pluginType);
const watches: any = {};
if (props.watches && props.watches.length > 0) {
for (const key of props.watches) {
watches[key] = input[key];
}
}
return {
form: watches,
key,
@@ -144,6 +157,9 @@ watch(
const { form } = value;
const oldForm: any = oldValue?.form;
let changed = oldForm == null || optionsRef.value.length == 0;
if (!props.watches || props.watches.length === 0) {
return;
}
for (const key of props.watches) {
//@ts-ignore
if (oldForm && form[key] != oldForm[key]) {

View File

@@ -57,7 +57,7 @@ const VNodes = defineComponent({
const props = defineProps<
{
watches: string[];
watches?: string[];
search?: boolean;
pager?: boolean;
} & ComponentPropsType
@@ -201,11 +201,13 @@ watch(
const pluginType = getPluginType();
const { form, key } = getScope();
const input = (pluginType === "plugin" ? form?.input : form) || {};
const watches = {};
for (const key of props.watches) {
//@ts-ignore
watches[key] = input[key];
const watches: any = {};
if (props.watches && props.watches.length > 0) {
for (const key of props.watches) {
watches[key] = input[key];
}
}
return {
form: watches,
key,
@@ -215,11 +217,12 @@ watch(
const { form } = value;
const oldForm: any = oldValue?.form;
let changed = oldForm == null || optionsRef.value.length == 0;
for (const key of props.watches) {
//@ts-ignore
if (oldForm && form[key] != oldForm[key]) {
changed = true;
break;
if (props.watches && props.watches.length > 0) {
for (const key of props.watches) {
if (oldForm && form[key] != oldForm[key]) {
changed = true;
break;
}
}
}
if (changed) {

View File

@@ -53,6 +53,7 @@ export class HandleController extends BaseController {
const accessGetter = new AccessGetter(userId, this.accessService.getById.bind(this.accessService));
const access = await newAccess(body.typeName, inputAccess,accessGetter);
mergeUtils.merge(access, body.input);
const res = await access.onRequest(body);
return this.ok(res);