插件开发
创建插件
使用以下脚本,可以直接从一个已有的插件中复制出一个新的插件,方便开发
node create_plugin.js --name={pluginName} --from={copyFrom}
插件开发
第一步:指定要开发的插件
修改.env 文件中的插件名称
第二步:安装要开发的插件的项目依赖
- 分别进入要开发的插件的项目下的 server、frontend 文件下
- 执行 yarn | npm i
第三步:启动开发
yarn dev
前端
引用主项目中的组件
使用 #
可以引用到主项目的组件如#/components/LayoutHeader.vue
全局变量 BPMAX
BPMAX
为全局变量,可以在插件中使用- 包含
app
,router
,Vue
BPMAX.router.addRoute
添加路由
// 在main.ts中
BPMAX.router.addRoute({
path: "/plugin/plugin_example",
component: index,
});
BPMAX.Vue.component
添加全局组件
// 在main.ts中
BPMAX.Vue.component("my-component", ComponentVue);
BPMAX.ui.register
注册 UI 控件
// 在main.ts中
BPMAX.ui.register("Path.To.Component", ComponentVue);
BPMAX.flow.metaComponent
注册流程配置组件
// 在main.ts中
BPMAX.flow.metaComponent({
field: "meta_config_field_name",
compoennt: ComponentVue,
defaultValue: "default_value",
});
BPMAX.flow.stepComponent
注册流程环节配置组件
// 在main.ts中
BPMAX.flow.stepComponent({
field: "meta_config_field_name",
compoennt: ComponentVue,
defaultValue: "default_value",
});
说明:流程配置相关组件可以使用主系统 dark 模式编辑器下标准组件的全部主要组件的调用,统一的 props 也已经注入,具体可用组件如下:
SectionItem,
YesNoOption,
StepOption,
ICollapseItem,
draggable,
DraggableList,
CodeEditorButton,
Biref,
FlowEditorMount,
RoleOption,
UserOption,
SelectOption,
MultiActions,
SectionList,
Description
最简单的组件模板示例:
<i-collapse-item title="基础配置aaa" name="基础配置aaa">
<section-item title="环节名称">{{ form.name }}</section-item>
<section-item title="排序(由高到低)">
<el-input v-model="form.order" size="small" type="number"></el-input>
</section-item>
</i-collapse-item>
后端
说明:目前后端项目结构采用与 thinkjs 一致的目录结构,安装的时候会覆盖对应的文件,所以一定要注意文件的命名,不要与主项目中的文件重名,否则会覆盖主项目中的文件。
安装和卸载时运行的脚本
在 src/install 文件夹中增加了两个文件
- {插件的 en_name}_install.js
- {插件的 en_name}_uninstall.js
step_active
流程环节激活钩子
事件对象:
data
流程环节数据
// 在src/hook/plugin_{pluginname}_hook.ts中
think.addPluginHook("step_active", async function (data) {
// 一般用于调起自动化场景
console.log("plugin_example_hook.js: step_active", data);
return data;
});
发布插件
BUILD_TARGET={插件的en_name} yarn upload
定时任务
src/config/crontab_job
文件夹下增加定时任务文件
export default {
interval: 3600 * 2 + 's',
enable: true,
handle: '/api/plugin_sync_feishu_users/sync'
}
插件配置
- 创建或修改配置
BPMAX.addSetting(name, setting)
- 获取配置
BPMAX.getSetting(name)
// 获取配置
const config = await BPMAX.getSetting('sync_feishu_users');
// 保存配置
await BPMAX.addSetting('sync_feishu_users', {
defaultRole: this.defaultRole,
autoUpdate: this.autoUpdate,
autoUpdateOwners: this.autoUpdateOwners
})