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 * as _ from "lodash-es";
import { PluginRequestHandleReq } from "../plugin/index.js"; import { PluginRequestHandleReq } from "../plugin/index.js";
export type AccessRequestHandleReqInput<T = any> = { // export type AccessRequestHandleReqInput<T = any> = {
id?: number; // id?: number;
title?: string; // title?: string;
access: T; // access: T;
}; // };
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>; export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<T>;
export type AccessInputDefine = FormItemProps & { export type AccessInputDefine = FormItemProps & {
title: string; title: string;

View File

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

View File

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

View File

@@ -16,6 +16,7 @@
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib"; import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue"; import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
import { PluginDefine } from "@certd/pipeline"; import { PluginDefine } from "@certd/pipeline";
import { getInputFromForm } from "./utils";
defineOptions({ defineOptions({
name: "RemoteAutoComplete", name: "RemoteAutoComplete",
@@ -48,18 +49,6 @@ const message = ref("");
const hasError = ref(false); const hasError = ref(false);
const loading = 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 () => { const getOptions = async () => {
if (loading.value) { if (loading.value) {
return; return;
@@ -75,7 +64,7 @@ const getOptions = async () => {
} }
const pluginType = getPluginType(); const pluginType = getPluginType();
const { form } = getScope(); const { form } = getScope();
const input = getInputFromForm(form, pluginType); const { input, record } = getInputFromForm(form, pluginType);
for (let key in define.input) { for (let key in define.input) {
const inWatches = props.watches?.includes(key); const inWatches = props.watches?.includes(key);
const inputDefine = define.input[key]; const inputDefine = define.input[key];
@@ -99,6 +88,7 @@ const getOptions = async () => {
action: props.action, action: props.action,
input, input,
data: {}, data: {},
record,
}, },
{ {
onError(err: any) { onError(err: any) {
@@ -140,7 +130,7 @@ watch(
() => { () => {
const pluginType = getPluginType(); const pluginType = getPluginType();
const { form, key } = getScope(); const { form, key } = getScope();
const input = getInputFromForm(form, pluginType); const { input, record } = getInputFromForm(form, pluginType);
const watches: any = {}; const watches: any = {};
if (props.watches && props.watches.length > 0) { if (props.watches && props.watches.length > 0) {
for (const key of props.watches) { 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 { inject, ref, useAttrs } from "vue";
import { useFormWrapper } from "@fast-crud/fast-crud"; import { useFormWrapper } from "@fast-crud/fast-crud";
import { notification } from "ant-design-vue"; import { notification } from "ant-design-vue";
import { getInputFromForm } from "./utils";
defineOptions({ defineOptions({
name: "RemoteInput", name: "RemoteInput",
@@ -71,15 +72,18 @@ const doPluginFormSubmit = async (data: any) => {
} }
loading.value = true; loading.value = true;
try { try {
const pluginType = getPluginType(); const pluginType = getPluginType();
const { form } = getScope(); const { form } = getScope();
const { input, record } = getInputFromForm(form, pluginType);
const res = await doRequest({ const res = await doRequest({
type: pluginType, type: pluginType,
typeName: form.type, typeName: form.type,
action: props.action, action: props.action,
input: pluginType === "plugin" ? form.input : form, input,
data: data, data: data,
record,
}); });
//获取返回值 填入到input中 //获取返回值 填入到input中
emit("update:modelValue", res); emit("update:modelValue", res);

View File

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

View File

@@ -15,6 +15,7 @@
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib"; import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue"; import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
import { PluginDefine } from "@certd/pipeline"; import { PluginDefine } from "@certd/pipeline";
import { getInputFromForm } from "./utils";
defineOptions({ defineOptions({
name: "RemoteTreeSelect", name: "RemoteTreeSelect",
@@ -67,7 +68,7 @@ const getOptions = async () => {
} }
const pluginType = getPluginType(); const pluginType = getPluginType();
const { form } = getScope(); const { form } = getScope();
const input = (pluginType === "plugin" ? form?.input : form) || {}; const { input, record } = getInputFromForm(form, pluginType);
for (let key in define.input) { for (let key in define.input) {
const inWatches = props.watches?.includes(key); const inWatches = props.watches?.includes(key);
@@ -98,6 +99,7 @@ const getOptions = async () => {
pageNo, pageNo,
pageSize, pageSize,
}, },
record,
}, },
{ {
onError(err: any) { 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; action: string;
data?: any; data?: any;
input: T; input: T;
record?: any;
}; };
export async function doRequest(req: RequestHandleReq, opts: any = {}) { export async function doRequest(req: RequestHandleReq, opts: any = {}) {
const url = `/pi/handle/${req.type}`; const url = `/pi/handle/${req.type}`;
const { typeName, action, data, input } = req; const { typeName, action, data, input, record } = req;
const res = await request({ const res = await request({
url, url,
method: "post", method: "post",
@@ -25,6 +26,7 @@ export async function doRequest(req: RequestHandleReq, opts: any = {}) {
action, action,
data, data,
input, input,
record,
}, },
...opts, ...opts,
}); });

View File

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

View File

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