br_addon/
module.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::action::Action;
use crate::Tools;
use crate::PLUGIN_TOOLS;
use json::{array, object, JsonValue};
use std::any::type_name;
/// 模型配置
pub trait Module {
    /// =================基础配置=============================
    /// 插件名称
    fn _name(&self) -> &'static str {
        type_name::<Self>().split("::").collect::<Vec<&str>>()[3].to_lowercase().leak()
    }
    /// 模型标题
    fn title(&self) -> &'static str;
    /// 模型描述
    fn description(&self) -> &'static str {
        ""
    }
    /// =================视图配置=============================
    /// 模型icon
    fn icon(&self) -> &'static str {
        ""
    }
    /// =================数据库配置=============================
    /// 是否数据表
    fn table(&self) -> bool {
        false
    }
    /// 数据库表名称
    fn _table_name(&self) -> &'static str {
        let t = type_name::<Self>().split("::").collect::<Vec<&str>>();
        format!("{}_{}", t[2], t[3]).leak()
    }
    /// 主键
    fn table_key(&mut self) -> &'static str {
        "id"
    }
    /// 唯一索引
    fn table_unique(&self) -> &'static [&'static str] {
        &[]
    }
    /// 查询索引
    fn table_index(&mut self) -> &'static [&'static [&'static str]] {
        &[]
    }
    /// 是否分区
    fn table_partition(&mut self) -> bool {
        false
    }
    /// 分区配置
    /// *列名
    /// *分区key
    /// *实例 array![str, array![range1, range2, range3...]]
    /// *如果在已有分区的情况下想要修改分区的参照列,先要将当前分区代码删除后刷库,然后写新的分区规则再刷库
    fn table_partition_columns(&mut self) -> JsonValue {
        array![]
    }
    /// =================功能配置=============================
    /// 加载功能
    /// * name 功能名称
    fn action(&mut self, name: &str) -> Result<Box<dyn Action>, String>;
    /// 模型字段
    fn fields(&mut self) -> JsonValue {
        object! {}
    }
    /// 使用工具
    fn tools(&mut self) -> Tools {
        let tools = PLUGIN_TOOLS.lock().unwrap();
        let tools = tools.get("tools").unwrap().clone();
        tools
    }
}