0.2.93 • Published 3 years ago

apd-renderer v0.2.93

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

App Designer Renderer By AntDesign

NPM Version NPM Downloads npm.io

image

image

文档已过期!!!

Demo

  import { App,AppBean } from 'apd-renderer/dist/index'

  const demoData = {
    app: [...],
    buttons: [...],
    actions: [...]
  };
  const library = [...];
  const lookups = [...];
  const menus = [...];

  const plugins = {
    "custom.js": React.lazy(() => import('./custom') ),
    "tableUploadBtn": React.lazy(() => import('./TableUploadButton') )
  };
  
  const customEvents = (appBean)=>{
    return {
      test: () => {
        console.log(appBean);
      }
    }
  };

  const query = (p,v):Promise => {...}
  
  const AppDemo = () => {
    const model = new AppBean({
      events: customEvents,
      query: query,
      appId: 'workorder',
      appName: '工单管理',
    });
    model.initLIBRARY(library);
    model.initLOOKUPS(lookups);
    model.initMENUS(menus);
    useEffect(()=>{
      model.init(demoData);
    },[]);
    return (
      <App model={model} plugins={plugins}/>
    );
  };

API

AppBean

属性

名称描述类型默认值
buttons应用主按钮IWidgetData[]
actions应用更多操作按钮内容IAppAction[]
widgets应用控件集合IWidgetData[]
LIBRARY公用控件集合IWidgetData[]
MENUS公用菜单集合IWidgetData[]
LOOKUPS公用查找框集合IWidgetData[]
rootWidget应用根控件(type='canvas')IWidgetData{type:'canvas',detail:{}}
items应用主数据集合any[][]
item应用当前选择的主数据any{}
total应用主数据总条数number0
modelName应用主模块名称string''
data应用当前选择主数据的变更数据any{}
tabId应用当前显示的标签栏IDstring''
tableSelectedRow应用所有表格的选择行存储对象IAppTableSelectedRow{}

事件

名称描述参数回调事件
find查找主应用数据集合$modelName:find:$tableId
findByQuery查找指定应用数据集合fields$modelName:findByQuery:$tableId
findOne查找主应用具体一条数据(value为id值)$modelName:findOne、itemUpdated
findByTable查找具体一个表格的数据$modelName:find:$tableId
findByDialog查找Dialog下的数据$modelName:findByDialog:$dialogId
findByTab查找主应用某个标签下的数据$modelName:findOne、itemUpdated
findList查找下拉框数据集合$modelName:findList:$comboboxId
findTree查找树数据集合$modelName:findTree:$treeId
selectRecord主应用选择一条数据(value为选择的record对象)findOne、changeAppTab
dialogOpen打开弹出框(eventValue为dialogId)widgetsUpdated
dialogOk弹出框确定(targetId为目标控件ID)widgetsUpdated
dialogClose打开弹出框(eventValue为dialogId)widgetsUpdated
changeDataByForm更新主应用选择数据的属性
changeDataByTable更新主应用选择数据的子表数据
selectTableRows更新一个表格的选择行数据(widgetId为表格控件ID)$modelName:selectedRows:$tableId
showLOOKUPS弹出一个查找表格框widgetId,lookupIdafterShowLOOKUPS
fetchLOOKUPS刷新一个查找表格框的数据widgetId,lookupIdafterFetchLOOKUPS
toggleLOOKUPS表格点击一列回填到主应用文本框widgetId,recordsetValue,afterHideLOOKUPS
insert主应用添加一条数据{}
save主应用保存数据{}
duplicate主应用复制一条数据{}
previous主应用翻到上一条数据{}
next主应用翻到下一条数据{}
routeWF主应用发送工作流{}
searchMore主应用弹出高级搜索对话框{}
bookmark主应用列表设置书签{}
reset主应用重置数据{}
itemUpdated更新主应用数据item:any
widgetsUpdated更新控件widgets:IWidgetData[]
setValue设置主应用当前选择数据值values:any
changeAppTab设置主应用按钮是否可点tab:IWidgetData
setAppBtnDisabled:$AppBtnId设置主应用按钮是否可点flag:boolean
afterSave保存后触发{}

回调事件

以 modelName:eventName:widgetId 形式表示, modelName代表触发该事件的模块名默认为主应用模块,widgetId代表触发该事件的控件ID

名称描述参数源组件
find刷新table数据items,totalTable
findByQuery用于在自定义组件中的定制查询items,totalCustom
findByDialog更新Dialog的item数据itemDialog,Table
selectedRows选择table数据rowsTable
updatedRows更新table数据rowsTable
findOne刷新主应用item数据itemTabGroup
findList刷新下拉框数据items,totalCombobox
findTree刷新树形数据itemsTree

方法

名称描述参数返回值
updateWidgets更新控件集widgets:IWidgetData[],updateLibrary:boolean
initLOOKUPS更新查找框控件集widgets:IWidgetData[]
initMENUS更新下拉菜单控件集widgets:IWidgetData[]
getMENUS获取指定id的菜单控件及其子级menuId:stringIWidgetData[]
initLIBRARY更新公用控件集widgets:IWidgetData[]
getWidgets获取全部控件
getRootWidget获取画布根控件
getModelName获取主应用ModelName
getTableSelectedRows获取一个表格的选择行集合tableId
getItem获取主应用选择的单条数据any
getAppButtons获取主应用按钮IWidgetData[]
getAppActions获取主应用ModelNameIAppAction[]
getValidation获取字段验证函数(...args: any[])=>Promise 或 undefined
needToSave判断离开时是否需要保存boolean

Plugins

const plugins = {
  "xxxx": React.lazy(() => import('./xxx/xxx') ),
  "xxxxx": React.lazy(() => import('./xx/xxxx/xxx') )
};
<AppRenderer model={model} plugins={plugins}/>

plugins属性名对应custom控件的fileName属性,属性值为懒加载的React组件,组件的props会自动注入model和widget属性

LOOKUPS

配置lookup.js

const lookups = [
  { type: 'table', id: 'selectEQ', title: '表格',detail: { pageSize:5,inputMode: 'readonly'}},
  { type: 'tablecol', parentId: 'selectEQ1', id: 'canvas_dialog2_table_EQ_col1', title: '表格列',
    detail: { label: '装备编号',dataAttribute:'eqNum',event:'toggleLOOKUPS'}},
  { type: 'tablecol', parentId: 'selectEQ1', id: 'canvas_dialog2_table_EQ_col2', title: '表格列',
    detail: { label: '装备描述',dataAttribute:'desc'}},

  { type: 'table', id: 'selectWO', title: '表格',detail: { pageSize:5,inputMode: 'readonly',width: 800}},
    { type: 'tablecol', parentId: 'selectWO', id: 'canvas_dialog2_table_WO_col1', title: '表格列',
      detail: { label: '工单编号',dataAttribute:'woNum',event:'toggleLOOKUPS'}},
    { type: 'tablecol', parentId: 'selectWO', id: 'canvas_dialog2_table_WO_col2', title: '表格列',
      detail: { label: '工单描述',dataAttribute:'desc'}},
    { type: 'tablecol', parentId: 'selectWO', id: 'canvas_dialog2_table_WO_col3', title: '表格列',
      detail: { label: '状态',dataAttribute:'status'}},
    { type: 'tablecol', parentId: 'selectWO', id: 'canvas_dialog2_table_WO_col4', title: '表格列',
      detail: { label: '创建时间',dataAttribute:'created_time'}}
];

通过AppBean构造函数或initLOOKUPS方法加载

const demoData = [
  ...
  { type: 'textbox', parentId: 'canvas_tabgroup1_tab2_row1_col2', id: 'canvas_tabgroup1_tab2_row1_col2_text1', title: '文本框',
     detail: {label:'主要装备',dataAttribute: 'eqNum', lookup: 'selectEQ', lookupKeyMap: [['eqNum','desc'],['eqNum','desc']]}},
  ...
];
const model = useMemo(()=> new AppBean(demoData),[]);
model.initLOOKUPS(lookups);

文本框、多部分文本、多行文本、表格列都可以配置lookup属性,配置了该属性后控件右侧会出现放大镜按钮 点击按钮弹出在LOOKUPS.js中配置的table,id对应lookup属性名, lookupKeyMap为二维数组,第一个数组为要赋值的源属性,第二个数组为table中包含的属性

Validation

  public getValidation(){
    return async (_rule, value, fieldName, record, _form) => {
      const response = await AppBean.validate({ ...record, [fieldName]: value }); // 远程请求
      if(response){
        const { status,message } = response;
        if(status === 2)
          return Promise.reject(message); // 输入值无效
        else
          return Promise.resolve(); // 输入值有效
      }
      else
        return Promise.resolve();
    }
  }

通过覆盖getValidation方法完成页面属性的校验,当该属性detail的validate为true时生效

0.2.93

3 years ago

0.2.87

3 years ago

0.2.79

3 years ago

0.2.78

3 years ago

0.2.74

3 years ago

0.2.72

3 years ago

0.2.71

3 years ago

0.2.70

3 years ago

0.2.50

3 years ago

0.2.46

3 years ago

0.2.41

3 years ago

0.2.40

3 years ago

0.2.43

3 years ago

0.2.42

3 years ago

0.2.37

3 years ago

0.2.33

3 years ago

0.2.32

3 years ago

0.2.30

3 years ago

0.2.31

3 years ago

0.2.29

3 years ago

0.2.28

3 years ago

0.2.26

3 years ago

0.2.24

3 years ago

0.2.23

3 years ago

0.2.20

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.154

4 years ago

0.1.153

4 years ago

0.1.150

4 years ago

0.1.151

4 years ago

0.1.149

4 years ago

0.1.148

4 years ago

0.1.139

4 years ago

0.1.138

4 years ago

0.1.135

4 years ago

0.1.134

4 years ago

0.1.132

4 years ago

0.1.133

4 years ago

0.1.129

4 years ago

0.1.131

4 years ago

0.1.130

4 years ago

0.1.128

4 years ago

0.1.127

4 years ago

0.1.126

4 years ago

0.1.124

4 years ago

0.1.123

4 years ago

0.1.122

4 years ago

0.1.121

4 years ago

0.1.119

4 years ago

0.1.118

4 years ago

0.1.117

4 years ago

0.1.116

4 years ago

0.1.114

4 years ago

0.1.115

4 years ago

0.1.112

4 years ago

0.1.111

4 years ago

0.1.110

4 years ago

0.1.109

4 years ago

0.1.107

4 years ago

0.1.106

4 years ago

0.1.105

4 years ago

0.1.103

4 years ago

0.1.104

4 years ago

0.1.102

4 years ago

0.1.101

4 years ago

0.1.100

4 years ago

0.1.98

4 years ago

0.1.99

4 years ago

0.1.97

4 years ago

0.1.96

4 years ago

0.1.95

4 years ago

0.1.94

4 years ago

0.1.93

4 years ago

0.1.91

4 years ago

0.1.92

4 years ago

0.1.90

4 years ago

0.1.89

4 years ago

0.1.88

4 years ago

0.1.86

4 years ago

0.1.87

4 years ago

0.1.83

4 years ago

0.1.82

4 years ago

0.1.81

4 years ago

0.1.80

4 years ago

0.1.78

4 years ago

0.1.79

4 years ago

0.1.77

4 years ago

0.1.76

4 years ago

0.1.75

4 years ago

0.1.71

4 years ago

0.1.72

4 years ago

0.1.73

4 years ago

0.1.70

4 years ago

0.1.67

4 years ago

0.1.69

4 years ago

0.1.66

4 years ago

0.1.65

4 years ago

0.1.64

4 years ago

0.1.63

4 years ago

0.1.62

4 years ago

0.1.61

4 years ago

0.1.60

4 years ago

0.1.58

4 years ago

0.1.59

4 years ago

0.1.57

4 years ago

0.1.56

4 years ago

0.1.55

4 years ago

0.1.54

4 years ago

0.1.53

4 years ago

0.1.52

4 years ago

0.1.51

4 years ago

0.1.50

4 years ago

0.1.49

4 years ago

0.1.45

4 years ago

0.1.46

4 years ago

0.1.47

4 years ago

0.1.48

4 years ago

0.1.43

4 years ago

0.1.44

4 years ago

0.1.41

4 years ago

0.1.42

4 years ago

0.1.40

4 years ago

0.1.39

4 years ago

0.1.38

4 years ago

0.1.37

4 years ago

0.1.36

4 years ago

0.1.35

4 years ago

0.1.33

4 years ago

0.1.34

4 years ago

0.1.32

4 years ago

0.1.31

4 years ago

0.1.30

4 years ago

0.1.28

4 years ago

0.1.29

4 years ago

0.1.27

4 years ago

0.1.26

4 years ago

0.1.25

4 years ago

0.1.23

4 years ago

0.1.24

4 years ago

0.1.22

4 years ago

0.1.21

4 years ago

0.1.20

4 years ago

0.1.19

4 years ago

0.1.17

4 years ago

0.1.18

4 years ago

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.37

4 years ago

0.0.38

4 years ago

0.0.35

4 years ago

0.0.36

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.29

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

5 years ago