yonbip-code-gen-mcp
Version:
YonBIP高级版代码生成MCP
238 lines (193 loc) • 5.36 kB
Markdown
# 参照开发步骤
1 开发后端action类,需要继承DefaultGridRefAction
2 开发前端js,使用平台提供的参照高阶组件Refer或者PopRefer
3 将前端js路径注册到脚本中
> 说明:
>
> 参照有三种: 表格型,树型,树表型
>
> 分别继承:
>
> nccloud.web.refer.DefaultGridRefAction
>
> nccloud.web.refer.DefaultTreeRefAction
>
> nccloud.web.refer.action.DefaultTreeGridRefAction
>
> 构建Meta
>
> 表格型使用:nccloud.framework.web.ui.meta.RefMeta
>
> 树形或树表使用:nccloud.framework.web.ui.meta.TreeRefMeta
以表格型举例,其余类似
# 开发后端action类
```
import nccloud.framework.web.processor.refgrid.RefQueryInfo;
import nccloud.framework.web.ui.meta.RefMeta;
import nccloud.pubitf.platform.db.SqlParameterCollection;
import nccloud.web.refer.DefaultGridRefAction;
/**
* Demo 表格参照
*/
public class DemoGridRef extends DefaultGridRefAction {
@Override
public RefMeta getRefMeta(RefQueryInfo refQueryInfo) {
//这种方式可以处理多表的参照,数据来源不仅是一张表的时候使用,单表的话直接使用已有的表名即可
StringBuffer sb = new StringBuffer();
sb.append(" ( select bd_currtype.pk_currtype as id,bd_currtype.name as name,bd_currtype.code as code from bd_currtype bd_currtype ");
sb.append(" left join org_orgs org_orgs on org_orgs.pk_org = bd_currtype.pk_org ) demotable");
RefMeta refMeta = new RefMeta();
refMeta.setCodeField("code");
refMeta.setNameField("name");
refMeta.setMutilLangNameRef(true);
refMeta.setPkField("id");
refMeta.setTableName(sb.toString());
return refMeta;
}
/**
* 此处的RefMeta不要替换,如果被替换了,自己改为RefMeta
* @param refQueryInfo 参照查询信息
* @param treeRefMeta 参照元数据信息
* @return
*/
@Override
public String getExtraSql(RefQueryInfo refQueryInfo, RefMeta refMeta) {
//demo 示例查询条件
StringBuffer whereCondition = new StringBuffer();
whereCondition.append(" 1 = 1 and dr = ? ");
return whereCondition.toString();
}
/**
* 此处的RefMeta不要替换,如果被替换了,自己改为RefMeta
* @param refQueryInfo 参照查询信息
* @param treeRefMeta 参照元数据信息
* @return
*/
@Override
public SqlParameterCollection getExtraSqlParameter(RefQueryInfo refQueryInfo, RefMeta refMeta) {
//demo 示例添加sql参数
SqlParameterCollection sqlParameterCollection = new SqlParameterCollection();
sqlParameterCollection.add(0);
return sqlParameterCollection;
}
}
```
# 鉴权action
```
xml version="1.0" encoding="UTF-8" standalone="no"
<actions>
<action>
<name>模块编码.组件编码.DemoGridRef</name>
<label>档案特性默认表型参照</label>
<clazz>参照类全路径</clazz>
</action>
</actions>
```
# 鉴权authorize
```
xml version="1.0" encoding="UTF-8" standalone="no"
<authorizes>
<authorize>
<appcode>*</appcode>
<actions>
<action>模块编码.组件编码.DemoGridRef</action>
</actions>
</authorize>
</authorizes>
```
# 开发前端参照js
```js
import {high} from 'nc-lightapp-front';
const {Refer} = high;
export default function (props = {}) {
var conf = {
multiLang: {
domainName: '领域编码',
currentLocale: 'zh-CN',
moduleId: '多语模块编码',
},
refType: 'grid',
refName: 'Demo参照',
placeholder: 'Demo参照',
columnConfig: [
{
name: ['编码', '名称'],
code: ['refcode', 'refname'],
width: {
refcode: 100
}
}
],
refCode: '参照action全路径',
//需要跟自己xml中配置的相同
queryGridUrl: '/nccloud/模块编码/组件编码/action类名.do',
};
return <Refer {...conf} {...props} />
}
```
# 注册脚本示例
```sql
INSERT INTO BD_REFINFO (
CODE,
DR,
ISTREELAZYLOAD,
ISNEEDPARA,
ISSPECIALREF,
LAYER,
METADATANAMESPACE,
METADATATYPENAME,
MOBILEREFPATH,
MODULENAME,
NAME,
PARA1,
PARA2,
PARA3,
PK_COUNTRY,
PK_INDUSTRY,
PK_REFINFO,
REFCLASS,
REFPATH,
REFSYSTEM,
REFTYPE,
RESERV1,
RESERV2,
RESERV3,
RESID,
RESIDPATH,
TS,
WHEREPART,
WORKFLOWCONDITIONUSEUNITORG
)
VALUES
(
'参照编码-自己定义-不重复即可',
0,
'N',
NULL,
NULL,
NULL,
'模块编码',
'元数据组件编码',
NULL,
'模块编码',
'示例参照',
NULL,
NULL,
NULL,
NULL,
NULL,
'需要生成一个主键,按照现有的主键规则,不重复即可',
NULL,
'前端JS路径 =》 比如 cca/refer/allocruleset/AllocRuleSetDefaultGridRef/index',
NULL,
0,
NULL,
NULL,
NULL,
'多语目录编码',
'多语文件编码',
'最新时间戳',
NULL,
NULL
);
```