diff --git a/packages/core/pipeline/src/access/api.ts b/packages/core/pipeline/src/access/api.ts index 3d8c2f984..7cb5d380c 100644 --- a/packages/core/pipeline/src/access/api.ts +++ b/packages/core/pipeline/src/access/api.ts @@ -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 = { - id?: number; - title?: string; - access: T; -}; +// export type AccessRequestHandleReqInput = { +// id?: number; +// title?: string; +// access: T; +// }; -export type AccessRequestHandleReq = PluginRequestHandleReq>; +export type AccessRequestHandleReq = PluginRequestHandleReq; export type AccessInputDefine = FormItemProps & { title: string; diff --git a/packages/core/pipeline/src/plugin/api.ts b/packages/core/pipeline/src/plugin/api.ts index fec035cbd..bf5289cac 100644 --- a/packages/core/pipeline/src/plugin/api.ts +++ b/packages/core/pipeline/src/plugin/api.ts @@ -17,6 +17,7 @@ export type PluginRequestHandleReq = { action: string; input: T; data: any; + record: { id: number; type: string; title: string }; }; export type UserInfo = { diff --git a/packages/ui/certd-client/src/components/plugins/common/api-test.vue b/packages/ui/certd-client/src/components/plugins/common/api-test.vue index f82727da0..4a129a4b8 100644 --- a/packages/ui/certd-client/src/components/plugins/common/api-test.vue +++ b/packages/ui/certd-client/src/components/plugins/common/api-test.vue @@ -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) { diff --git a/packages/ui/certd-client/src/components/plugins/common/remote-auto-complete.vue b/packages/ui/certd-client/src/components/plugins/common/remote-auto-complete.vue index 114e7705c..d27f652ae 100644 --- a/packages/ui/certd-client/src/components/plugins/common/remote-auto-complete.vue +++ b/packages/ui/certd-client/src/components/plugins/common/remote-auto-complete.vue @@ -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) { diff --git a/packages/ui/certd-client/src/components/plugins/common/remote-input.vue b/packages/ui/certd-client/src/components/plugins/common/remote-input.vue index ccc2e4158..43517a78e 100644 --- a/packages/ui/certd-client/src/components/plugins/common/remote-input.vue +++ b/packages/ui/certd-client/src/components/plugins/common/remote-input.vue @@ -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); diff --git a/packages/ui/certd-client/src/components/plugins/common/remote-select.vue b/packages/ui/certd-client/src/components/plugins/common/remote-select.vue index 029697ca5..1da86000d 100644 --- a/packages/ui/certd-client/src/components/plugins/common/remote-select.vue +++ b/packages/ui/certd-client/src/components/plugins/common/remote-select.vue @@ -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) { diff --git a/packages/ui/certd-client/src/components/plugins/common/remote-tree-select.vue b/packages/ui/certd-client/src/components/plugins/common/remote-tree-select.vue index ca039db49..7efafade3 100644 --- a/packages/ui/certd-client/src/components/plugins/common/remote-tree-select.vue +++ b/packages/ui/certd-client/src/components/plugins/common/remote-tree-select.vue @@ -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) { diff --git a/packages/ui/certd-client/src/components/plugins/common/utils.ts b/packages/ui/certd-client/src/components/plugins/common/utils.ts new file mode 100644 index 000000000..2fd402e4e --- /dev/null +++ b/packages/ui/certd-client/src/components/plugins/common/utils.ts @@ -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, + }; +} diff --git a/packages/ui/certd-client/src/components/plugins/lib/index.ts b/packages/ui/certd-client/src/components/plugins/lib/index.ts index 922748e21..bf1086ce2 100644 --- a/packages/ui/certd-client/src/components/plugins/lib/index.ts +++ b/packages/ui/certd-client/src/components/plugins/lib/index.ts @@ -12,11 +12,12 @@ export type RequestHandleReq = { 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, }); diff --git a/packages/ui/certd-server/src/controller/user/pipeline/handle-controller.ts b/packages/ui/certd-server/src/controller/user/pipeline/handle-controller.ts index 2c4eaab53..a8a76ef5e 100644 --- a/packages/ui/certd-server/src/controller/user/pipeline/handle-controller.ts +++ b/packages/ui/certd-server/src/controller/user/pipeline/handle-controller.ts @@ -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, diff --git a/packages/ui/certd-server/src/plugins/plugin-plus/1panel/client.ts b/packages/ui/certd-server/src/plugins/plugin-plus/1panel/client.ts index 9cc4e6e2a..7aef0496f 100644 --- a/packages/ui/certd-server/src/plugins/plugin-plus/1panel/client.ts +++ b/packages/ui/certd-server/src/plugins/plugin-plus/1panel/client.ts @@ -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(); }