feat(plugin): 集成 WASM 插件系统到主服务并修复链路问题
- 新增 erp-plugin crate:插件管理、WASM 运行时、动态表、数据 CRUD - 新增前端插件管理页面(PluginAdmin/PluginCRUDPage)和 API 层 - 新增插件数据迁移(plugins/plugin_entities/plugin_event_subscriptions) - 新增权限补充迁移(为已有租户补充 plugin.admin/plugin.list 权限) - 修复 PluginAdmin 页面 InstallOutlined 图标不存在的崩溃问题 - 修复 settings 唯一索引迁移顺序错误(先去重再建索引) - 更新 wiki 和 CLAUDE.md 反映插件系统集成状态 - 新增 dev.ps1 一键启动脚本
This commit is contained in:
83
crates/erp-plugin/src/module.rs
Normal file
83
crates/erp-plugin/src/module.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use axum::routing::{get, post, put};
|
||||
use erp_core::module::ErpModule;
|
||||
|
||||
pub struct PluginModule;
|
||||
|
||||
#[async_trait]
|
||||
impl ErpModule for PluginModule {
|
||||
fn name(&self) -> &str {
|
||||
"plugin"
|
||||
}
|
||||
|
||||
fn dependencies(&self) -> Vec<&str> {
|
||||
vec!["auth", "config"]
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl PluginModule {
|
||||
/// 插件管理路由(需要 JWT 认证)
|
||||
pub fn protected_routes<S>() -> Router<S>
|
||||
where
|
||||
crate::state::PluginState: axum::extract::FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
let admin_routes = Router::new()
|
||||
.route("/admin/plugins/upload", post(crate::handler::plugin_handler::upload_plugin::<S>))
|
||||
.route("/admin/plugins", get(crate::handler::plugin_handler::list_plugins::<S>))
|
||||
.route(
|
||||
"/admin/plugins/{id}",
|
||||
get(crate::handler::plugin_handler::get_plugin::<S>)
|
||||
.delete(crate::handler::plugin_handler::purge_plugin::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/schema",
|
||||
get(crate::handler::plugin_handler::get_plugin_schema::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/install",
|
||||
post(crate::handler::plugin_handler::install_plugin::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/enable",
|
||||
post(crate::handler::plugin_handler::enable_plugin::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/disable",
|
||||
post(crate::handler::plugin_handler::disable_plugin::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/uninstall",
|
||||
post(crate::handler::plugin_handler::uninstall_plugin::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/health",
|
||||
get(crate::handler::plugin_handler::health_check_plugin::<S>),
|
||||
)
|
||||
.route(
|
||||
"/admin/plugins/{id}/config",
|
||||
put(crate::handler::plugin_handler::update_plugin_config::<S>),
|
||||
);
|
||||
|
||||
// 插件数据 CRUD 路由
|
||||
let data_routes = Router::new()
|
||||
.route(
|
||||
"/plugins/{plugin_id}/{entity}",
|
||||
get(crate::handler::data_handler::list_plugin_data::<S>)
|
||||
.post(crate::handler::data_handler::create_plugin_data::<S>),
|
||||
)
|
||||
.route(
|
||||
"/plugins/{plugin_id}/{entity}/{id}",
|
||||
get(crate::handler::data_handler::get_plugin_data::<S>)
|
||||
.put(crate::handler::data_handler::update_plugin_data::<S>)
|
||||
.delete(crate::handler::data_handler::delete_plugin_data::<S>),
|
||||
);
|
||||
|
||||
admin_routes.merge(data_routes)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user