浏览代码

枚举下拉框

master
lip 2 年前
父节点
当前提交
c72e6198db
共有 1 个文件被更改,包括 64 次插入5 次删除
  1. +64
    -5
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java

+ 64
- 5
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java 查看文件

@@ -1,8 +1,20 @@
package cc.smtweb.system.bpm.web.sys.dev;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.AbstractEnum;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.framework.core.util.PubUtil;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;

/**
* Created by 1 at 2022-08-03 16:09:30
@@ -13,15 +25,62 @@ public class EnumComboService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
if (TYPE_LOAD.equals(type)) return new ComboHandler.EnumLoadHandler();
return super.createHandler(type);
}

/* demo
//自定义
public R demo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo());
public R loadOne(@SwBody SwMap params, UserSession us) {
SwListData swListData = buildListData(params.readString("cls"));
DynRetBean bean = DynRetBean.createList(swListData);
return R.success(bean);
}
*/

private SwListData buildListData(String cls) {
if (PubUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0);
List<SwMap> list = new ArrayList<>();
try {
Class tempClass ;
Class wantClass = null;
try {
tempClass = Class.forName(cls);
wantClass = tempClass;
}catch (Exception e){
e.printStackTrace();
//
int lIndex = cls.lastIndexOf(".");
if (lIndex > 0) {
String outClass = cls.substring(0, lIndex);
String innerClass = outClass + "$" + cls.substring(lIndex+1);
tempClass = Class.forName(outClass);
Class[] declaredClasses = tempClass.getDeclaredClasses();
for (Class declaredClass : declaredClasses) {
if (declaredClass.getName().equals(innerClass)) {
wantClass = declaredClass;
break;
}
}
}
}
Assert.notNull(wantClass,"classNotFound");
AbstractEnum e ;
try {
e = (AbstractEnum) wantClass.getDeclaredField("inst").get(null);
} catch (Exception e1) {
e = (AbstractEnum) wantClass.getDeclaredField("instance").get(null);
}
for (Object v : e.mapAll.values()) {
AbstractEnum.EnumBean bean = (AbstractEnum.EnumBean) v;
SwMap row = new SwMap();
row.put("value", bean.value.toString());
row.put("name", bean.name);
list.add(row);
}
} catch (Exception ue) {
return SwListData.create(new ArrayList(), 0);
}
return SwListData.create(list, 0);
}


}

正在加载...
取消
保存