Skip to main content

业务提供特定业务级的API

业务开发文档,暂时客开用不到

自定义api

目前暂时只支持EntityName级别, 领域、产品包暂不考虑

如何贡献一个新的api

提供新的api其实就是对表单的插件贡献, 下面提供一个纯净的插件示例:

  1. 创建manifests.json
{
"$schema": "http://front.q7link.com:3000/json-schema/manifest.json",
"name": "form.feature.openApi.demo",
"publisher": "platform-tester",
"version": "1.0.0",
"activationEvents": [
"Construct"
],
"dependencies": {
"form.feature.openApi": "*"
},
"contributes": {
"commands": [
{
"name": "form.feature.openApi.demo.test"
}
] ,
"openApiRegister": [
{
"name": "commands",
"values": [
{
"openName": "ProjectSchedule_Test",
"commandName": "form.feature.openApi.demo.test",
"declarationType": "declare namespace Commands{const ProjectSchedule_Test: CommandType<{keyword: string}, void>;}",
"annotation": "测试"
}
]
}
]
}
}
  1. 插件实现
import { IExpansionImplement, IManifest } from '@q7/expansions';
import { IBizFormExpansionContext } from '../../../../type';
import { IFormActiveContext } from '../../../declare';
import manifest from './maifest.json';


class PluginDemoImpl implements IExpansionImplement<any> {

constructor(private formCtx: IBizFormExpansionContext) {
}

activate(ctx: IFormActiveContext): any {

//业务对api提供的方法以command方式提供
// 业务对外提供open api的实现
ctx.commands.registerCommand('form.feature.openApi.demo.test', async ({ keyword }) => {
const client = this.formCtx.bizFormApi.requestClient();
const resp = await client.query({
query: `
{ User(criteriaStr:"name like '%${keyword}%'") { name }}
`
})
return resp.data;
})

return {}
}

deactivate() {
}
}


export function createOpenApiDemoManifest(ctx: IBizFormExpansionContext): IManifest{
return {
...manifest,
localImpl: () => {
return new PluginDemoImpl(ctx)
}
}
}

  1. 提供编辑器的语法支持, 暂时先手动添加 apps/link/src/main/open-platform/custom-object/scripts/apis/front/frontScriptLib.ts 文件下, commandsLibSource下,添加新的声明
  //TODO 测试demo,上线删掉
declare namespace Commands{
/**
* 测试
*/
const ProjectSchedule_Test: CommandType<{keyword: string}, void>;
}
  1. 客开调用 ctx.executeCommand(name, params)方法
thisApp.formOnLoad = async (ctx) => {
ctx.getPageContext().getActionBar().addButton({
key: 'clickMe',
text: '点我',
onClick: async () => {
const result = await ctx.executeCommand(Commands.ProjectSchedule_Test, { keyword: '王' });
console.log(result);

},
})

};