mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix: improve code
This commit is contained in:
parent
1fc045e45c
commit
3f2612ec72
@ -46,6 +46,16 @@ export class APIResource<TData = any> extends FlowResource<TData> {
|
||||
this.setMeta({ loading: value });
|
||||
}
|
||||
|
||||
clearRequestParameters() {
|
||||
this.request.params = {};
|
||||
return this;
|
||||
}
|
||||
|
||||
setRequestParameters(params: Record<string, any>) {
|
||||
this.request.params = { ...this.request.params, ...params };
|
||||
return this;
|
||||
}
|
||||
|
||||
setRequestMethod(method: string) {
|
||||
this.request.method = method;
|
||||
return this;
|
||||
@ -59,6 +69,13 @@ export class APIResource<TData = any> extends FlowResource<TData> {
|
||||
return this;
|
||||
}
|
||||
|
||||
removeRequestHeader(key: string) {
|
||||
if (this.request.headers && key in this.request.headers) {
|
||||
delete this.request.headers[key];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
addRequestParameter(key: string, value: any) {
|
||||
if (!this.request.params) {
|
||||
this.request.params = {};
|
||||
@ -67,6 +84,20 @@ export class APIResource<TData = any> extends FlowResource<TData> {
|
||||
return this;
|
||||
}
|
||||
|
||||
getRequestParameter(key: string) {
|
||||
if (this.request.params && key in this.request.params) {
|
||||
return this.request.params[key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
removeRequestParameter(key: string) {
|
||||
if (this.request.params && key in this.request.params) {
|
||||
delete this.request.params[key];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
setRequestBody(data: any) {
|
||||
this.request.data = data;
|
||||
return this;
|
||||
|
@ -22,6 +22,13 @@ import { createJavaScriptLinter } from './linter';
|
||||
// 自定义自动补全函数
|
||||
const createCustomCompletion = () => {
|
||||
const contextVariables = [
|
||||
{
|
||||
label: 'request',
|
||||
type: 'function',
|
||||
info: 'Make an API request to NocoBase backend',
|
||||
detail: '(options: RequestOptions) => Promise<Response>',
|
||||
boost: 102,
|
||||
},
|
||||
{
|
||||
label: 'getModelById',
|
||||
type: 'function',
|
||||
|
@ -202,10 +202,12 @@ element.innerHTML = \`
|
||||
return ctx.globals.flowEngine.getModel(uid);
|
||||
};
|
||||
|
||||
const request = ctx.globals.api.request.bind(ctx.globals.api);
|
||||
|
||||
// Create a safe execution context for the code (as async function)
|
||||
// Wrap user code in an async function
|
||||
const wrappedCode = `
|
||||
return (async function(element, ctx, model, resource, requirejs, requireAsync, loadCSS, getModelById) {
|
||||
return (async function(element, ctx, model, resource, requirejs, requireAsync, loadCSS, getModelById, request) {
|
||||
${params.code}
|
||||
}).apply(this, arguments);
|
||||
`;
|
||||
@ -221,6 +223,7 @@ element.innerHTML = \`
|
||||
requireAsync,
|
||||
loadCSS,
|
||||
getModelById,
|
||||
request,
|
||||
);
|
||||
|
||||
ctx.model.setProps('loading', false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user