fix: 修复1panel 请求失败的bug

This commit is contained in:
xiaojunnuo
2026-02-15 12:59:08 +08:00
parent 8387fe0d5b
commit 0283662931
11 changed files with 63 additions and 44 deletions

View File

@@ -4,13 +4,13 @@ import { HttpClient, ILogger, utils } from "@certd/basic";
import * as _ from "lodash-es";
import { PluginRequestHandleReq } from "../plugin/index.js";
export type AccessRequestHandleReqInput<T = any> = {
id?: number;
title?: string;
access: T;
};
// export type AccessRequestHandleReqInput<T = any> = {
// id?: number;
// title?: string;
// access: T;
// };
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<T>;
export type AccessInputDefine = FormItemProps & {
title: string;

View File

@@ -17,6 +17,7 @@ export type PluginRequestHandleReq<T = any> = {
action: string;
input: T;
data: any;
record: { id: number; type: string; title: string };
};
export type UserInfo = {

View File

@@ -13,6 +13,7 @@
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { ref, inject } from "vue";
import { Form } from "ant-design-vue";
import { getInputFromForm } from "./utils";
defineOptions({
name: "ApiTest",
@@ -45,13 +46,15 @@ const doTest = async () => {
message.value = "";
hasError.value = false;
loading.value = true;
const { input, record } = getInputFromForm(form, pluginType);
try {
const res = await doRequest(
{
type: pluginType,
typeName: form.type,
action: props.action,
input: pluginType === "plugin" ? form.input : form,
input,
record,
},
{
onError(err: any) {

View File

@@ -16,6 +16,7 @@
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
import { PluginDefine } from "@certd/pipeline";
import { getInputFromForm } from "./utils";
defineOptions({
name: "RemoteAutoComplete",
@@ -48,18 +49,6 @@ 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;
@@ -75,7 +64,7 @@ const getOptions = async () => {
}
const pluginType = getPluginType();
const { form } = getScope();
const input = getInputFromForm(form, pluginType);
const { input, record } = getInputFromForm(form, pluginType);
for (let key in define.input) {
const inWatches = props.watches?.includes(key);
const inputDefine = define.input[key];
@@ -99,6 +88,7 @@ const getOptions = async () => {
action: props.action,
input,
data: {},
record,
},
{
onError(err: any) {
@@ -140,7 +130,7 @@ watch(
() => {
const pluginType = getPluginType();
const { form, key } = getScope();
const input = getInputFromForm(form, pluginType);
const { input, record } = getInputFromForm(form, pluginType);
const watches: any = {};
if (props.watches && props.watches.length > 0) {
for (const key of props.watches) {

View File

@@ -9,6 +9,7 @@ import { doRequest } from "/@/components/plugins/lib";
import { inject, ref, useAttrs } from "vue";
import { useFormWrapper } from "@fast-crud/fast-crud";
import { notification } from "ant-design-vue";
import { getInputFromForm } from "./utils";
defineOptions({
name: "RemoteInput",
@@ -71,15 +72,18 @@ const doPluginFormSubmit = async (data: any) => {
}
loading.value = true;
try {
const pluginType = getPluginType();
const { form } = getScope();
const { input, record } = getInputFromForm(form, pluginType);
const res = await doRequest({
type: pluginType,
typeName: form.type,
action: props.action,
input: pluginType === "plugin" ? form.input : form,
input,
data: data,
record,
});
//获取返回值 填入到input中
emit("update:modelValue", res);

View File

@@ -38,6 +38,7 @@
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
import { PluginDefine } from "@certd/pipeline";
import { getInputFromForm } from "./utils";
defineOptions({
name: "RemoteSelect",
@@ -79,17 +80,6 @@ const getPluginType: any = inject("get:plugin:type", () => {
return "plugin";
});
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 searchKeyRef = ref("");
const optionsRef = ref([]);
const message = ref("");
@@ -115,7 +105,7 @@ const getOptions = async () => {
}
const pluginType = getPluginType();
const { form } = getScope();
const input = getInputFromForm(form, pluginType);
const { input, record } = getInputFromForm(form, pluginType);
for (let key in define.input) {
const inWatches = props.watches?.includes(key);
@@ -141,6 +131,7 @@ const getOptions = async () => {
typeName: form.type,
action: props.action,
input,
record,
data: {
searchKey: props.search ? searchKeyRef.value : "",
pageNo,
@@ -211,7 +202,7 @@ watch(
() => {
const pluginType = getPluginType();
const { form, key } = getScope();
const input = getInputFromForm(form, pluginType);
const { input, record } = getInputFromForm(form, pluginType);
const watches: any = {};
if (props.watches && props.watches.length > 0) {
for (const key of props.watches) {

View File

@@ -15,6 +15,7 @@
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
import { PluginDefine } from "@certd/pipeline";
import { getInputFromForm } from "./utils";
defineOptions({
name: "RemoteTreeSelect",
@@ -67,7 +68,7 @@ const getOptions = async () => {
}
const pluginType = getPluginType();
const { form } = getScope();
const input = (pluginType === "plugin" ? form?.input : form) || {};
const { input, record } = getInputFromForm(form, pluginType);
for (let key in define.input) {
const inWatches = props.watches?.includes(key);
@@ -98,6 +99,7 @@ const getOptions = async () => {
pageNo,
pageSize,
},
record,
},
{
onError(err: any) {

View File

@@ -0,0 +1,26 @@
import { cloneDeep } from "lodash-es";
export function getInputFromForm(form: any, pluginType: string) {
form = cloneDeep(form);
let input: any = {};
const record: any = form;
if (pluginType === "plugin") {
input = form?.input || {};
delete form.input;
} else if (pluginType === "access") {
input = form?.access || {};
delete form.access;
} else if (pluginType === "notification") {
input = form?.body || {};
delete form.body;
} else if (pluginType === "addon") {
input = form?.body || {};
delete form.body;
} else {
throw new Error(`pluginType ${pluginType} not support`);
}
return {
input,
record,
};
}

View File

@@ -12,11 +12,12 @@ export type RequestHandleReq<T = any> = {
action: string;
data?: any;
input: T;
record?: any;
};
export async function doRequest(req: RequestHandleReq, opts: any = {}) {
const url = `/pi/handle/${req.type}`;
const { typeName, action, data, input } = req;
const { typeName, action, data, input, record } = req;
const res = await request({
url,
method: "post",
@@ -25,6 +26,7 @@ export async function doRequest(req: RequestHandleReq, opts: any = {}) {
action,
data,
input,
record,
},
...opts,
});

View File

@@ -35,16 +35,16 @@ export class HandleController extends BaseController {
@Post('/access', { summary: Constants.per.authOnly })
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
const userId = this.getUserId();
let inputAccess = body.input.access;
if (body.input.id > 0) {
const oldEntity = await this.accessService.info(body.input.id);
let inputAccess = body.input;
if (body.record.id > 0) {
const oldEntity = await this.accessService.info(body.record.id);
if (oldEntity) {
if (oldEntity.userId !== this.getUserId()) {
throw new Error('access not found');
}
const param: any = {
type: body.typeName,
setting: JSON.stringify(body.input.access),
setting: JSON.stringify(body.input),
};
this.accessService.encryptSetting(param, oldEntity);
inputAccess = this.accessService.decryptAccessEntity(param);
@@ -53,7 +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);
// mergeUtils.merge(access, body.input);
const res = await access.onRequest(body);
return this.ok(res);
@@ -61,7 +61,7 @@ export class HandleController extends BaseController {
@Post('/notification', { summary: Constants.per.authOnly })
async notificationRequest(@Body(ALL) body: NotificationRequestHandleReq) {
const input = body.input.body;
const input = body.input;
const notification = await newNotification(body.typeName, input, {
http,

View File

@@ -125,7 +125,7 @@ export class OnePanelClient {
async getAccessToken() {
if (this.access.type === "apikey") {
return this.getAccessTokenByApiKey();
return await this.getAccessTokenByApiKey();
} else {
return await this.getAccessTokenByPassword();
}