提交 e14b4485 编写于 作者: 偏锋书生's avatar 偏锋书生

资源初步

上级 947c83b5
package net.wicp.tams.app.duckula.controller.bean.constant;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import net.wicp.tams.common.constant.dic.intf.IEnumCombobox;
/***
* 组织单位类型
*
* @author Administrator
*
*/
public enum ResType implements IEnumCombobox {
OPERATE("操作资源", "icon-position", null, false, null),
DATA("数据资源", "icon-group", null, false, null),
MODULE("模块", "icon-dept", OPERATE, false, null),
DIR("目录", "icon-org", OPERATE, true, new ResType[] { MODULE }),
URL("地址", "icon-dept", OPERATE, true, new ResType[] { MODULE, DIR });
private final String desc;
private final String icon;
private final ResType parent;// 资源的父类型
private final boolean isEdit;// 所定义的类型能否被修改,true,可以被修改,false:不能被修改
private final ResType[] parentTree;// 资源可以放在哪个类型的资源下面,如URL只能放在DIR目录下。
private ResType(String desc, String icon, ResType parent, boolean isEdit, ResType[] parentTree) {
this.desc = desc;
this.parent = parent;
this.icon = icon;
this.isEdit = isEdit;
this.parentTree = parentTree;
}
/***
* 当前类型的资源能否被拖拽到另一资源类型下面
*
* @param parent 要拖拽的目标资源类型
* @return
*/
public boolean canDrag(ResType parent) {
if (ArrayUtils.isEmpty(parentTree)) {
return false;
}
return ArrayUtils.contains(this.parentTree, parent);
}
/****
* 通过名字返回类型,默认返回 ORG
*
* @param name
* @return
*/
public static ResType findByName(String name) {
if (StringUtils.isEmpty(name)) {
return URL;
}
for (ResType ele : ResType.values()) {
if (ele.name().equals(name)) {
return ele;
}
}
return URL;
}
public String getDesc() {
return desc;
}
public String getIcon() {
return icon;
}
@Override
public String getName() {
return this.name();
}
@Override
public String getDesc_en() {
return this.desc;
}
@Override
public String getDesc_zh() {
return this.desc;
}
public ResType getParent() {
return parent;
}
public boolean isEdit() {
return isEdit;
}
}
......@@ -31,7 +31,7 @@ public class SysResource {
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.res_type
* @mbg.generated
*/
private Integer resType;
private String resType;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.icon
* @mbg.generated
......@@ -62,13 +62,59 @@ public class SysResource {
* @mbg.generated
*/
private String remark;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound1
* @mbg.generated
*/
private String bound1;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound2
* @mbg.generated
*/
private String bound2;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound3
* @mbg.generated
*/
private String bound3;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound4
* @mbg.generated
*/
private String bound4;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound5
* @mbg.generated
*/
private String bound5;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound6
* @mbg.generated
*/
private String bound6;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound7
* @mbg.generated
*/
private String bound7;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound8
* @mbg.generated
*/
private String bound8;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound9
* @mbg.generated
*/
private String bound9;
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table sys_resource
* @mbg.generated
*/
public SysResource(Long id, String resCode, String resName, String resValue, Integer resType, String icon,
Integer resLevel, String isEdit, Long parentId, Long showOrder, String remark) {
public SysResource(Long id, String resCode, String resName, String resValue, String resType, String icon,
Integer resLevel, String isEdit, Long parentId, Long showOrder, String remark, String bound1, String bound2,
String bound3, String bound4, String bound5, String bound6, String bound7, String bound8, String bound9) {
this.id = id;
this.resCode = resCode;
this.resName = resName;
......@@ -80,6 +126,15 @@ public class SysResource {
this.parentId = parentId;
this.showOrder = showOrder;
this.remark = remark;
this.bound1 = bound1;
this.bound2 = bound2;
this.bound3 = bound3;
this.bound4 = bound4;
this.bound5 = bound5;
this.bound6 = bound6;
this.bound7 = bound7;
this.bound8 = bound8;
this.bound9 = bound9;
}
/**
......@@ -167,7 +222,7 @@ public class SysResource {
* @return the value of sys_resource.res_type
* @mbg.generated
*/
public Integer getResType() {
public String getResType() {
return resType;
}
......@@ -176,7 +231,7 @@ public class SysResource {
* @param resType the value for sys_resource.res_type
* @mbg.generated
*/
public void setResType(Integer resType) {
public void setResType(String resType) {
this.resType = resType;
}
......@@ -287,4 +342,166 @@ public class SysResource {
public void setRemark(String remark) {
this.remark = remark;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound1
* @return the value of sys_resource.bound1
* @mbg.generated
*/
public String getBound1() {
return bound1;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound1
* @param bound1 the value for sys_resource.bound1
* @mbg.generated
*/
public void setBound1(String bound1) {
this.bound1 = bound1;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound2
* @return the value of sys_resource.bound2
* @mbg.generated
*/
public String getBound2() {
return bound2;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound2
* @param bound2 the value for sys_resource.bound2
* @mbg.generated
*/
public void setBound2(String bound2) {
this.bound2 = bound2;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound3
* @return the value of sys_resource.bound3
* @mbg.generated
*/
public String getBound3() {
return bound3;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound3
* @param bound3 the value for sys_resource.bound3
* @mbg.generated
*/
public void setBound3(String bound3) {
this.bound3 = bound3;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound4
* @return the value of sys_resource.bound4
* @mbg.generated
*/
public String getBound4() {
return bound4;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound4
* @param bound4 the value for sys_resource.bound4
* @mbg.generated
*/
public void setBound4(String bound4) {
this.bound4 = bound4;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound5
* @return the value of sys_resource.bound5
* @mbg.generated
*/
public String getBound5() {
return bound5;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound5
* @param bound5 the value for sys_resource.bound5
* @mbg.generated
*/
public void setBound5(String bound5) {
this.bound5 = bound5;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound6
* @return the value of sys_resource.bound6
* @mbg.generated
*/
public String getBound6() {
return bound6;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound6
* @param bound6 the value for sys_resource.bound6
* @mbg.generated
*/
public void setBound6(String bound6) {
this.bound6 = bound6;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound7
* @return the value of sys_resource.bound7
* @mbg.generated
*/
public String getBound7() {
return bound7;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound7
* @param bound7 the value for sys_resource.bound7
* @mbg.generated
*/
public void setBound7(String bound7) {
this.bound7 = bound7;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound8
* @return the value of sys_resource.bound8
* @mbg.generated
*/
public String getBound8() {
return bound8;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound8
* @param bound8 the value for sys_resource.bound8
* @mbg.generated
*/
public void setBound8(String bound8) {
this.bound8 = bound8;
}
/**
* This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound9
* @return the value of sys_resource.bound9
* @mbg.generated
*/
public String getBound9() {
return bound9;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound9
* @param bound9 the value for sys_resource.bound9
* @mbg.generated
*/
public void setBound9(String bound9) {
this.bound9 = bound9;
}
}
\ No newline at end of file
......@@ -40,12 +40,16 @@ public interface SysResourceMapper extends BaseMapper<SysResource>{
* @mbg.generated
*/
@Insert({ "insert into sys_resource (id, res_code, ", "res_name, res_value, ", "res_type, icon, res_level, ",
"is_edit, parent_id, ", "show_order, remark)",
"values (#{id,jdbcType=BIGINT}, #{resCode,jdbcType=VARCHAR}, ",
"is_edit, parent_id, ", "show_order, remark, ", "bound1, bound2, ", "bound3, bound4, ", "bound5, bound6, ",
"bound7, bound8, ", "bound9)", "values (#{id,jdbcType=BIGINT}, #{resCode,jdbcType=VARCHAR}, ",
"#{resName,jdbcType=VARCHAR}, #{resValue,jdbcType=VARCHAR}, ",
"#{resType,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, #{resLevel,jdbcType=INTEGER}, ",
"#{resType,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, #{resLevel,jdbcType=INTEGER}, ",
"#{isEdit,jdbcType=VARCHAR}, #{parentId,jdbcType=BIGINT}, ",
"#{showOrder,jdbcType=BIGINT}, #{remark,jdbcType=VARCHAR})" })
"#{showOrder,jdbcType=BIGINT}, #{remark,jdbcType=VARCHAR}, ",
"#{bound1,jdbcType=VARCHAR}, #{bound2,jdbcType=VARCHAR}, ",
"#{bound3,jdbcType=VARCHAR}, #{bound4,jdbcType=VARCHAR}, ",
"#{bound5,jdbcType=VARCHAR}, #{bound6,jdbcType=VARCHAR}, ",
"#{bound7,jdbcType=VARCHAR}, #{bound8,jdbcType=VARCHAR}, ", "#{bound9,jdbcType=VARCHAR})" })
int insert(SysResource record);
/**
......@@ -65,7 +69,8 @@ public interface SysResourceMapper extends BaseMapper<SysResource>{
* @mbg.generated
*/
@Select({ "select", "id, res_code, res_name, res_value, res_type, icon, res_level, is_edit, parent_id, ",
"show_order, remark", "from sys_resource", "where id = #{id,jdbcType=BIGINT}" })
"show_order, remark, bound1, bound2, bound3, bound4, bound5, bound6, bound7, ", "bound8, bound9",
"from sys_resource", "where id = #{id,jdbcType=BIGINT}" })
@ResultMap("net.wicp.tams.app.duckula.controller.dao.SysResourceMapper.BaseResultMap")
SysResource selectByPrimaryKey(Long id);
......@@ -93,9 +98,14 @@ public interface SysResourceMapper extends BaseMapper<SysResource>{
*/
@Update({ "update sys_resource", "set res_code = #{resCode,jdbcType=VARCHAR},",
"res_name = #{resName,jdbcType=VARCHAR},", "res_value = #{resValue,jdbcType=VARCHAR},",
"res_type = #{resType,jdbcType=INTEGER},", "icon = #{icon,jdbcType=VARCHAR},",
"res_type = #{resType,jdbcType=VARCHAR},", "icon = #{icon,jdbcType=VARCHAR},",
"res_level = #{resLevel,jdbcType=INTEGER},", "is_edit = #{isEdit,jdbcType=VARCHAR},",
"parent_id = #{parentId,jdbcType=BIGINT},", "show_order = #{showOrder,jdbcType=BIGINT},",
"remark = #{remark,jdbcType=VARCHAR}", "where id = #{id,jdbcType=BIGINT}" })
"remark = #{remark,jdbcType=VARCHAR},", "bound1 = #{bound1,jdbcType=VARCHAR},",
"bound2 = #{bound2,jdbcType=VARCHAR},", "bound3 = #{bound3,jdbcType=VARCHAR},",
"bound4 = #{bound4,jdbcType=VARCHAR},", "bound5 = #{bound5,jdbcType=VARCHAR},",
"bound6 = #{bound6,jdbcType=VARCHAR},", "bound7 = #{bound7,jdbcType=VARCHAR},",
"bound8 = #{bound8,jdbcType=VARCHAR},", "bound9 = #{bound9,jdbcType=VARCHAR}",
"where id = #{id,jdbcType=BIGINT}" })
int updateByPrimaryKey(SysResource record);
}
\ No newline at end of file
package net.wicp.tams.app.duckula.controller.service;
import javax.servlet.ServletContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;
import net.wicp.tams.app.duckula.controller.bean.models.SysGlobal;
import net.wicp.tams.app.duckula.controller.config.constant.ConfigGlobleName;
import net.wicp.tams.app.duckula.controller.dao.SysGlobalMapper;
@Service
public class ContextInit implements ApplicationContextAware {
public class ContextInit implements ApplicationContextAware, ServletContextAware {
public static volatile String pagePath;// page页面存放的根目录
public static volatile String webRootPath;// Webroot所在目录
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
......@@ -21,4 +27,13 @@ public class ContextInit implements ApplicationContextAware {
}
}
@Override
public void setServletContext(ServletContext servletContext) {
String realPath = servletContext.getRealPath("/");
ContextInit.webRootPath = realPath;// 配置根目录
String rootPath = Thread.currentThread().getContextClassLoader().getResource(".").getPath();
String appPackage = servletContext.getInitParameter("tapestry.app-package");
ContextInit.pagePath = String.format("%s%s/pages", rootPath, appPackage.replace(".", "/"));
}
}
package net.wicp.tams.app.duckula.controller.service.cas;
import java.util.List;
import net.wicp.tams.app.duckula.controller.bean.models.SysResource;
import net.wicp.tams.app.duckula.controller.bean.models.SysRole;
import net.wicp.tams.common.apiext.json.easyuibean.EasyUINode;
import net.wicp.tams.common.callback.IConvertValue;
/****
* 菜单相关服务
*
* @author Administrator
*
*/
public interface IMenuService {
/****
* 跟据角色查到所拥有的节点,由于要查孙子节点,不能传入moduleId进行查询
*
* @param roles
* @param isRoot true:只查询模块 false:查询模块以下的所有菜单
* @return
*/
public List<SysResource> findAllModule(List<SysRole> roles, boolean isRoot);
/***
* 查询指定模块下面指定角色所有子节节点
*
* @param moduleId
* @param roles
* @param I18NConvert
* @return
*/
public List<EasyUINode> findModuleMenuForRoles(int moduleId, List<SysRole> roles, IConvertValue I18NConvert);
/*****
* 查询所有模块及其子菜单,
*
* @param i18NConvert
* @param hasUnallot 是否需要“未分配的资源”虚拟模块
* @return
*/
public List<EasyUINode> findAllModuleMenu(IConvertValue i18NConvert, boolean hasUnallot);
/**
* 查找需要同步的资源
*
* @return
*/
public List<SysResource> findSyncRes();
}
package net.wicp.tams.app.duckula.controller.service.cas.impl;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.tapestry5.commons.util.CollectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.wicp.tams.app.duckula.controller.bean.constant.ResType;
import net.wicp.tams.app.duckula.controller.bean.models.SysResource;
import net.wicp.tams.app.duckula.controller.bean.models.SysRole;
import net.wicp.tams.app.duckula.controller.dao.SysResourceMapper;
import net.wicp.tams.app.duckula.controller.service.cas.IMenuService;
import net.wicp.tams.common.apiext.json.EasyUiAssist;
import net.wicp.tams.common.apiext.json.easyuibean.EasyUINode;
import net.wicp.tams.common.apiext.json.easyuibean.EasyUINodeConf;
import net.wicp.tams.common.callback.IConvertValue;
@Slf4j
@Service
public class MenuService implements IMenuService {
@Autowired
private SysResourceMapper sysResourceMapper;
@Override
public List<SysResource> findAllModule(List<SysRole> roles, boolean isRoot) {
if (CollectionUtils.isEmpty(roles)) {
return CollectionFactory.newList();
}
boolean isDev = isDev(roles);
QueryWrapper<SysResource> queryWrapper = new QueryWrapper<SysResource>();
if (isRoot) {
queryWrapper.eq("res_level", 1);
} else {
queryWrapper.gt("res_level", 1);
}
if (!isDev) {// 不是开发者
// criteria.add(Restrictions.in("crs.caRole", roles));
}
// criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
// criteria.addOrder(Order.asc("cr.showOrder"));
List<SysResource> retlist = sysResourceMapper.selectList(queryWrapper);
return retlist;
}
@Override
public List<EasyUINode> findModuleMenuForRoles(final int moduleId, List<SysRole> roles, IConvertValue I18NConvert) {
// 查询该用户的所有模块资源
List<SysResource> resList = this.findAllModule(roles, false);
EasyUINodeConf conf = new EasyUINodeConf("id", "resName", "caResource.id");
conf.setAttrCols("resValue", "caResType.id");
conf.setIsRoot(new Predicate() {
@Override
public boolean evaluate(Object object) {
int parentId = Integer.parseInt(String.valueOf(object));
return parentId == moduleId;
}
});
conf.setTextConvert(I18NConvert);
List<EasyUINode> ret = CollectionFactory.newList();
try {
ret = EasyUiAssist.getTreeRoot(resList, conf);
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
@Override
public List<EasyUINode> findAllModuleMenu(IConvertValue i18NConvert, boolean hasUnallot) {
QueryWrapper<SysResource> queryWrapper = new QueryWrapper<SysResource>();
queryWrapper.gt("res_level", 0);
if (!hasUnallot) {
queryWrapper.isNotNull("parent_id");// 父节点不能为空
}
List<SysResource> resList = sysResourceMapper.selectList(queryWrapper);
EasyUINodeConf conf = new EasyUINodeConf("id", "resName", "parentId", "showOrder");
// conf.setTextConvert(i18NConvert);
conf.setIconClsCol("icon");
conf.setAttrCols("isEdit","resType", "resLevel", "resCode", "resName", "resValue", "remark", "bound1", "bound2");
conf.setIsRoot(new Predicate() {
@Override
public boolean evaluate(Object object) {
long parentId = Long.parseLong(String.valueOf(object));
return parentId == 1;// 设置所有的模块为树的根
}
});
if (hasUnallot) {
// 构造虚拟的节点
SysResource unAllot = new SysResource();
unAllot.setId(-1l);
unAllot.setResName("未分配的资源");
unAllot.setResValue("0");
unAllot.setResType(ResType.DIR.name());
unAllot.setIcon("icon-folder-star");
unAllot.setResLevel(1);
unAllot.setParentId(1l);
unAllot.setShowOrder(10000l);
resList.add(unAllot);
// 把未分配的节点全放到它目录下
for (SysResource res : resList) {
if (res.getParentId() == null) {
res.setParentId(-1l);
}
}
}
List<EasyUINode> ret = CollectionFactory.newList();
try {
ret = EasyUiAssist.getTreeRoot(resList, conf);
} catch (Exception e) {
log.error("构造资源树出错", e);
}
return ret;
}
@Override
public List<SysResource> findSyncRes() {
QueryWrapper<SysResource> queryWrapper = new QueryWrapper<SysResource>();
queryWrapper.gt("res_level", 1);
queryWrapper.eq("res_type", 3);
return sysResourceMapper.selectList(queryWrapper);
}
private boolean isDev(List<SysRole> roles) {
boolean isDev = false;
for (SysRole role : roles) {
if (role.getId() == 0) {
isDev = true;
break;
}
}
return isDev;
}
}
package net.wicp.tams.duckula.ops.pages.cas;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.util.TextStreamResponse;
import org.w3c.dom.Document;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wicp.tams.app.duckula.controller.bean.constant.ResType;
import net.wicp.tams.app.duckula.controller.bean.models.SysResource;
import net.wicp.tams.app.duckula.controller.dao.SysResourceMapper;
import net.wicp.tams.app.duckula.controller.service.ContextInit;
import net.wicp.tams.app.duckula.controller.service.cas.IMenuService;
import net.wicp.tams.common.Result;
import net.wicp.tams.common.apiext.CollectionUtil;
import net.wicp.tams.common.apiext.StringUtil;
import net.wicp.tams.common.apiext.json.EasyUiAssist;
import net.wicp.tams.common.apiext.json.easyuibean.EasyUINode;
import net.wicp.tams.common.connector.XmlUtil;
import net.wicp.tams.common.constant.dic.YesOrNo;
import net.wicp.tams.component.tools.TapestryAssist;
import net.wicp.tams.duckula.ops.pages.ParentPageBean;
@Import(stack = "easyuistack")
public class ResManager extends ParentPageBean<SysResource> {
@Inject
private IMenuService menuService;
@Inject
private SysResourceMapper sysResourceMapper;
public TextStreamResponse onQueryMenu() throws Exception {
List<EasyUINode> roots = menuService.findAllModuleMenu(I18NConvert, true);
String retstr = EasyUiAssist.getTreeFromList(roots);
return retStream(retstr);
}
public TextStreamResponse onSaveRes() {
JSONObject params = TapestryAssist.packParams(request, false);
String id = params.getString("id");
String parentId = params.getString("parentId");
String icon = params.getString("icon");
String resLevel = params.getString("resLevel");
String caResType = params.getString("caResType");
String showOrder = params.getString("showOrder");
String resCode = params.getString("resCode");
String resName = params.getString("resName");
String resValue = params.getString("resValue");
String isEdit = params.getString("isEdit");
String remark = params.getString("remark");
String bound1 = params.getString("bound1");// app
String bound2 = params.getString("bound2");// 是否菜单
if (StringUtil.isNull(bound1)) {// bound1如果为空
bound1 = null;
if (Integer.parseInt(resLevel) == 2) {
bound1 = parentId;
} else if (Integer.parseInt(resLevel) == 3) {// 需要查一下数据库
SysResource parentObj = (SysResource) sysResourceMapper.selectById(Long.parseLong(parentId));
bound1 = String.valueOf(parentObj.getParentId());
}
}
SysResource rs = new SysResource();
if (StringUtils.isNotBlank(id)) {
rs.setId(Long.parseLong(id));
}
rs.setResCode(resCode);
rs.setResName(resName);
rs.setResValue(resValue);
rs.setResType(caResType);
rs.setIcon(icon);
rs.setResLevel(Integer.parseInt(resLevel));
rs.setIsEdit(isEdit);
rs.setParentId(Long.parseLong(parentId));
rs.setShowOrder(Long.parseLong(showOrder));
rs.setRemark(remark);
rs.setBound1(bound1);
rs.setBound2(bound2);
if (rs.getId() == null) {
sysResourceMapper.insert(rs);
} else {
sysResourceMapper.updateById(rs);
}
Result res = Result.getSuc();
com.alibaba.fastjson.JSONObject retobj = res.retJsonObj();
retobj.put("id", rs.getId());
JSONObject attributes = new JSONObject("resCode", resCode, "resName", resName, "resValue", resValue, "isEdit",
isEdit, "remark", remark, "bound1", bound1, "bound2", bound2);
retobj.put("attributes", attributes);
retobj.put("index", Integer.parseInt(showOrder));
retobj.put("text", I18NConvert.getStr(resName));
return retStream(retobj.toString());
}
/****
* 删除Res
*
* @return
*/
public TextStreamResponse onDelRes() {
String id = request.getParameter("id");
sysResourceMapper.deleteById(Long.parseLong(id));
return TapestryAssist.getTextStreamResponse(Result.getSuc());
}
/**
* 更新菜单列表,当前的方案是:扫描page目录下的TML文件及目录结构
*
* @return
*/
public TextStreamResponse onSyncRes() {
QueryWrapper<SysResource> queryWrapper = new QueryWrapper<SysResource>();
queryWrapper.eq("parent_id", 1);
List<SysResource> selectList = sysResourceMapper.selectList(queryWrapper);
Set<Long> mods = CollectionUtil.getColSetFromObj(selectList, "id");
Result ret = Result.getSuc();
try {
Collection<File> files = FileUtils.listFiles(new File(ContextInit.pagePath), fileFilter, dirFilter);
final List<SysResource> hasResList = new ArrayList<SysResource>();
for (File file : files) {
SysResource res = new SysResource();
res.setResType(ResType.URL.name());
String path = file.getPath();
int beginIndex = path.indexOf("pages" + File.separator);
int endIndex = path.indexOf(".tml");
path = path.substring(beginIndex + 5, endIndex);
res.setResValue(path.replaceAll("\\" + File.separator, "/"));// 资源值
res.setResCode(path.replaceAll("\\" + File.separator, "_"));
String fileContext = FileUtils.readFileToString(file, "utf-8");
int beginTitle = fileContext.indexOf("<title");
int endTitle = fileContext.indexOf("</title>");
boolean isMenu = false;
String value = "";
long module = -1;
if (beginTitle >= 0 && endTitle > beginTitle) {
try {
Document doc = XmlUtil.parserDocment(fileContext.substring(beginTitle, endTitle + 8));
if (doc != null && doc.getFirstChild() != null && doc.getFirstChild().getFirstChild() != null) {
value = doc.getFirstChild().getFirstChild().getNodeValue();
String isMenuStr = findAttrByName(doc, "isMenu");
isMenu = Boolean.parseBoolean(isMenuStr);
String moduleStr = findAttrByName(doc, "module");// 它可以没有
try {
module = Long.parseLong(moduleStr);
if (!mods.contains(module)) {// 页面设置的模块不在数据库中
module = -1;
}
} catch (Exception e) {
}
}
} catch (Exception e) {
}
}
if (!isMenu) {// 是菜单
continue;
}
if (module > 0) {
res.setParentId(module);
}
value = value.replace("$", "").replace("{", "").replace("}", "").replace("message:", "");
res.setResName(StringUtils.isEmpty(value) ? file.getName() : value);// 资源名称,国际化的key值,如果没拿到key值,就用文件名代替
hasResList.add(res);
}
final List<SysResource> dbResList = menuService.findSyncRes();// 查找数据库已有的菜单
// 数据库中有的,但已不存在此页面的,需要删除
List<SysResource> deleteList = (List<SysResource>) CollectionUtils.select(dbResList, new Predicate() {
@Override
public boolean evaluate(Object object) {
return !hasResList.contains(object);
}
});
for (SysResource ca_Resource : deleteList) {
sysResourceMapper.deleteById(ca_Resource.getId());
}
// dbResList 剩余的集合、更新
List<SysResource> updateList = (List<SysResource>) CollectionUtils.select(dbResList, new Predicate() {
@Override
public boolean evaluate(Object object) {
SysResource tempobj = (SysResource) object;
return hasResList.contains(object);
// && "yes".equals(tempobj.getisEdit());
}
});
for (SysResource ca_Resource : updateList) {
SysResource updateObj = hasResList.get(hasResList.indexOf(ca_Resource));
ca_Resource.setResCode(updateObj.getResCode());
ca_Resource.setResName(updateObj.getResName());
ca_Resource.setResValue(updateObj.getResValue());
ca_Resource.setRemark("程序自动更新");
}
for (SysResource caResource : updateList) {
sysResourceMapper.updateByPrimaryKey(caResource);
}
// 数据库没有的,但已存在的、需添加
List<SysResource> addList = (List<SysResource>) CollectionUtils.select(hasResList, new Predicate() {
@Override
public boolean evaluate(Object object) {
return !dbResList.contains(object);
}
});
for (SysResource caResource : addList) {
int secIndex = caResource.getResValue().indexOf("/", 1);
int threeIndex = caResource.getResValue().indexOf("/", secIndex + 1);
caResource.setIcon("icon-user");
caResource.setIsEdit(YesOrNo.yes.name());
caResource.setRemark("系统自动同步");
// caResource.setCaResource(defaulModel);
caResource.setResLevel(2);
sysResourceMapper.updateByPrimaryKeySelective(caResource);
}
} catch (Exception e) {
ret.setMessage(LK("tip.sys.error.sync") + e.getMessage());
}
return TapestryAssist.getTextStreamResponse(ret);
}
private String findAttrByName(Document doc, String nodeName) {
String retstr = null;
try {
retstr = doc.getFirstChild().getAttributes().getNamedItem(nodeName).getNodeValue();
} catch (Exception e) {
}
return retstr;
}
IOFileFilter fileFilter = new IOFileFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.endsWith(".tml")) {
return true;
} else {
return false;
}
}
@Override
public boolean accept(File file) {
String name = file.getName();
if (name.endsWith(".tml")) {
return true;
} else {
return false;
}
}
};
IOFileFilter dirFilter = new IOFileFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.endsWith(".tml")) {
return true;
} else {
return false;
}
}
@Override
public boolean accept(File file) {
return true;
}
};
@Override
public void doSave(SysResource t, boolean isInsert) {
// TODO Auto-generated method stub
}
@Override
public void doDel(String id) {
// TODO Auto-generated method stub
}
@Override
public BaseMapper<SysResource> getBaseMapper() {
// TODO Auto-generated method stub
return null;
}
@Override
public void packageQuery(SysResource t, QueryWrapper<SysResource> queryWrapper) {
// TODO Auto-generated method stub
}
}
......@@ -11,13 +11,22 @@
<arg column="res_code" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="res_name" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="res_value" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="res_type" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="res_type" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="icon" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="res_level" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="is_edit" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="parent_id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="show_order" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="remark" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound1" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound2" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound3" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound4" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound5" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound6" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound7" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound8" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="bound9" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor>
</resultMap>
<sql id="Example_Where_Clause">
......@@ -92,7 +101,8 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, res_code, res_name, res_value, res_type, icon, res_level, is_edit, parent_id,
show_order, remark
show_order, remark, bound1, bound2, bound3, bound4, bound5, bound6, bound7, bound8,
bound9
</sql>
<select id="selectByExample" parameterType="net.wicp.tams.app.duckula.controller.bean.models.SysResourceExample" resultMap="BaseResultMap">
<!--
......@@ -162,6 +172,33 @@
<if test="remark != null">
remark,
</if>
<if test="bound1 != null">
bound1,
</if>
<if test="bound2 != null">
bound2,
</if>
<if test="bound3 != null">
bound3,
</if>
<if test="bound4 != null">
bound4,
</if>
<if test="bound5 != null">
bound5,
</if>
<if test="bound6 != null">
bound6,
</if>
<if test="bound7 != null">
bound7,
</if>
<if test="bound8 != null">
bound8,
</if>
<if test="bound9 != null">
bound9,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
......@@ -177,7 +214,7 @@
#{resValue,jdbcType=VARCHAR},
</if>
<if test="resType != null">
#{resType,jdbcType=INTEGER},
#{resType,jdbcType=VARCHAR},
</if>
<if test="icon != null">
#{icon,jdbcType=VARCHAR},
......@@ -197,6 +234,33 @@
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="bound1 != null">
#{bound1,jdbcType=VARCHAR},
</if>
<if test="bound2 != null">
#{bound2,jdbcType=VARCHAR},
</if>
<if test="bound3 != null">
#{bound3,jdbcType=VARCHAR},
</if>
<if test="bound4 != null">
#{bound4,jdbcType=VARCHAR},
</if>
<if test="bound5 != null">
#{bound5,jdbcType=VARCHAR},
</if>
<if test="bound6 != null">
#{bound6,jdbcType=VARCHAR},
</if>
<if test="bound7 != null">
#{bound7,jdbcType=VARCHAR},
</if>
<if test="bound8 != null">
#{bound8,jdbcType=VARCHAR},
</if>
<if test="bound9 != null">
#{bound9,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="net.wicp.tams.app.duckula.controller.bean.models.SysResourceExample" resultType="java.lang.Long">
......@@ -229,7 +293,7 @@
res_value = #{record.resValue,jdbcType=VARCHAR},
</if>
<if test="record.resType != null">
res_type = #{record.resType,jdbcType=INTEGER},
res_type = #{record.resType,jdbcType=VARCHAR},
</if>
<if test="record.icon != null">
icon = #{record.icon,jdbcType=VARCHAR},
......@@ -249,6 +313,33 @@
<if test="record.remark != null">
remark = #{record.remark,jdbcType=VARCHAR},
</if>
<if test="record.bound1 != null">
bound1 = #{record.bound1,jdbcType=VARCHAR},
</if>
<if test="record.bound2 != null">
bound2 = #{record.bound2,jdbcType=VARCHAR},
</if>
<if test="record.bound3 != null">
bound3 = #{record.bound3,jdbcType=VARCHAR},
</if>
<if test="record.bound4 != null">
bound4 = #{record.bound4,jdbcType=VARCHAR},
</if>
<if test="record.bound5 != null">
bound5 = #{record.bound5,jdbcType=VARCHAR},
</if>
<if test="record.bound6 != null">
bound6 = #{record.bound6,jdbcType=VARCHAR},
</if>
<if test="record.bound7 != null">
bound7 = #{record.bound7,jdbcType=VARCHAR},
</if>
<if test="record.bound8 != null">
bound8 = #{record.bound8,jdbcType=VARCHAR},
</if>
<if test="record.bound9 != null">
bound9 = #{record.bound9,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
......@@ -264,13 +355,22 @@
res_code = #{record.resCode,jdbcType=VARCHAR},
res_name = #{record.resName,jdbcType=VARCHAR},
res_value = #{record.resValue,jdbcType=VARCHAR},
res_type = #{record.resType,jdbcType=INTEGER},
res_type = #{record.resType,jdbcType=VARCHAR},
icon = #{record.icon,jdbcType=VARCHAR},
res_level = #{record.resLevel,jdbcType=INTEGER},
is_edit = #{record.isEdit,jdbcType=VARCHAR},
parent_id = #{record.parentId,jdbcType=BIGINT},
show_order = #{record.showOrder,jdbcType=BIGINT},
remark = #{record.remark,jdbcType=VARCHAR}
remark = #{record.remark,jdbcType=VARCHAR},
bound1 = #{record.bound1,jdbcType=VARCHAR},
bound2 = #{record.bound2,jdbcType=VARCHAR},
bound3 = #{record.bound3,jdbcType=VARCHAR},
bound4 = #{record.bound4,jdbcType=VARCHAR},
bound5 = #{record.bound5,jdbcType=VARCHAR},
bound6 = #{record.bound6,jdbcType=VARCHAR},
bound7 = #{record.bound7,jdbcType=VARCHAR},
bound8 = #{record.bound8,jdbcType=VARCHAR},
bound9 = #{record.bound9,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
......@@ -292,7 +392,7 @@
res_value = #{resValue,jdbcType=VARCHAR},
</if>
<if test="resType != null">
res_type = #{resType,jdbcType=INTEGER},
res_type = #{resType,jdbcType=VARCHAR},
</if>
<if test="icon != null">
icon = #{icon,jdbcType=VARCHAR},
......@@ -312,6 +412,33 @@
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="bound1 != null">
bound1 = #{bound1,jdbcType=VARCHAR},
</if>
<if test="bound2 != null">
bound2 = #{bound2,jdbcType=VARCHAR},
</if>
<if test="bound3 != null">
bound3 = #{bound3,jdbcType=VARCHAR},
</if>
<if test="bound4 != null">
bound4 = #{bound4,jdbcType=VARCHAR},
</if>
<if test="bound5 != null">
bound5 = #{bound5,jdbcType=VARCHAR},
</if>
<if test="bound6 != null">
bound6 = #{bound6,jdbcType=VARCHAR},
</if>
<if test="bound7 != null">
bound7 = #{bound7,jdbcType=VARCHAR},
</if>
<if test="bound8 != null">
bound8 = #{bound8,jdbcType=VARCHAR},
</if>
<if test="bound9 != null">
bound9 = #{bound9,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
......
editRes=\u8d44\u6e90\u7f16\u8f91
\ No newline at end of file
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:r="tapestry-library:rjzjh"
xmlns:s="tapestry-library:tams"
xmlns:p="tapestry:parameter"
xmlns:c="tapestry-library:cas">
<head>
<title isMenu="true" module="3">资源管理</title>
</head>
<body class="easyui-layout">
<div data-options="region:'west'" style="width:400px">
<div class="easyui-layout" data-options="fit:true">
<div data-options="region:'north',split:false" style="height:31px;">
<a id="collapseAllBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-collapse-all'">收缩</a>
<a id="expandAllBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-expand-all'">展开</a>
<!-- a id="synBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">同步资源</a -->
</div>
<div data-options="region:'center'" style="height:100px;">
<r:tree id="menuTree" url="/cas/ResManager:queryMenu" lines="true" params="{onContextMenu:showContextMenu,onClick:selNode,onDblClick:editNode,onDragEnter:dragEnter,onBeforeDrag:beforeDrag,onBeforeDrop:beforeDrop,onStopDrag:stopDrag}"></r:tree>
<div id="mm" class="easyui-menu" style="width:120px;">
<!--
<div onclick="appendFold(1)" data-options="iconCls:'icon-folder-star'">添加模块</div>
-->
<div onclick="appendFold(2)" data-options="iconCls:'icon-folder-key'">添加目录</div>
<div onclick="appendFold(3)" data-options="iconCls:'icon-user'">添加地址</div>
</div>
<div id="mm2" class="easyui-menu" style="width:120px;">
<div onclick="deleteFold()" data-options="iconCls:'icon-folder-heart'">删除</div>
</div>
</div>
</div>
</div>
<div data-options="region:'center'">
<r:panel2 id="editPanel" title="editRes" needicon="false" needQuery="false" buts="[{id:'saveBut',iconCls:'icon-save',text:'common.button.save'},{id:'deleteBut',iconCls:'icon-remove',text:'common.button.delete'}]">
<form id="editForm">
<table class="frame_table_list_4">
<tr>
<td class="frame_table_list_4_righttext">资源ID</td>
<td>
<div id="idshow"></div>
<input id="id" name="id" type="hidden"/>
<input id="parentId" name="parentId" type="hidden"/>
<input id="resLevel" name="resLevel" type="hidden"/>
<input id="bound1" name="bound1" type="hidden"/>
</td>
<td class="frame_table_list_4_righttext">父资源</td>
<td><div id="parentIdShow"></div></td>
<td class="frame_table_list_4_righttext">显示顺序</td>
<td colspan="3">
<r:numberbox id="showOrder" name="showOrder" params="{readonly:true}"></r:numberbox>
</td>
</tr>
<tr>
<td class="frame_table_list_4_righttext">类型</td>
<td>
<r:comboboxenum id="caResType" name="caResType" enumClass="net.wicp.tams.app.duckula.controller.bean.constant.ResType" readonly="true" required="true" panelHeight="120"></r:comboboxenum>
</td>
<td class="frame_table_list_4_righttext">是否采集</td>
<td>
<r:comboboxenum id="isEdit" name="isEdit" enumClass="net.wicp.tams.common.constant.dic.YesOrNo" required="true" panelHeight="120"></r:comboboxenum>
</td>
<td class="frame_table_list_4_righttext">是否菜单</td>
<td>
<r:comboboxenum id="bound2" name="bound2" enumClass="net.wicp.tams.common.constant.dic.YesOrNo" required="true" panelHeight="120"></r:comboboxenum>
</td>
</tr>
<tr>
<td class="frame_table_list_4_righttext">图标</td>
<td colspan="3">
<r:validatebox id="icon" name="icon" style="width:300px"></r:validatebox>
</td>
<td class="frame_table_list_4_righttext">资源编码</td>
<td colspan="3">
<r:validatebox id="resCode" name="resCode" required="true" style="width:300px"></r:validatebox>
</td>
</tr>
<tr>
<td class="frame_table_list_4_righttext">资源名称</td>
<td colspan="3">
<r:validatebox id="resName" name="resName" required="true" style="width:300px"/>
</td>
<td class="frame_table_list_4_righttext">资源值</td>
<td colspan="3">
<r:validatebox id="resValue" name="resValue" style="width:300px"></r:validatebox>
</td>
</tr>
<tr>
<td class="frame_table_list_4_righttext">备注</td>
<td colspan="7">
<input id="remark" name="remark" class="easyui-textbox" data-options="multiline:true,height:50" style="width:300px;width:100%"/>
</td>
</tr>
</table>
</form>
</r:panel2>
</div>
<script>
function init($){
$('#collapseAllBtn').click(function(){
$('#menuTree').tree('collapseAll');
});
$('#expandAllBtn').click(function(){
$('#menuTree').tree('expandAll');
});
$('#synBtn').click(function(){
$.post(contextpath+'/cas/ResManager:syncRes',{},function(data){
//刷新页面,reload不会去远程拿数据,loadData也是需要load全部数据。
location.reload();
},'json');
});
$('#saveBut').unbind('click');
$('#saveBut').click(function(){
if(!jQuery('#editForm').form('validate')){
return false;
}
var restype= $('#caResType').combobox('getValue');
var resValue=$('#resValue').val();
if(and(restype=='URL',resValue=='')){
$.rjzjh.alert('地址类型资源需要填写地址到“资源值”');
return false;
}
var params=$('#editForm').serializeObject();
$.post(contextpath+'/cas/ResManager:saveRes',params,function(data){
if(data.result){//保存成功
$.rjzjh.alert('保存成功');
//更新一下ID,因为有新增的情况
$('#id').val(data.id);
$('#idshow').text(data.id);
//更新一下树
var node = $('#menuTree').tree('find', params.id);
if (node){
var attributes= $.rjzjh.extend(node.attributes,data.attributes);
$('#menuTree').tree('update', {
target: node.target,
attributes: attributes,
text:data.text,
index:data.index,
id:data.id,
isNew:false
});
}
}else{
$.rjzjh.alert('保存失败:'+data.msg);
}
},'json');
});
$('#deleteBut').click(function(){
var idvar=$('#id').val();
var node = $('#menuTree').tree('find', idvar);
if(!node){
$.rjzjh.alert('没有找到节点,不能删除');
return;
}
var childs;
try{
childs= $('#menuTree').tree('getChildren',node.target);
}catch(e){
}
if(childs.length!=0){
$.rjzjh.alert('此节点下有子节点,不能删除');
return;
}
$.rjzjh.confirm('您确定要删除此节点吗?',function(){
$.post(contextpath+'/cas/ResManager:delRes',{id:idvar},function(data){
if(data.result){//保存成功
$.rjzjh.alert('删除成功');
$('#menuTree').tree('remove',node.target);
$('#editPanel').css({"visibility":"hidden"});
}
},'json');
});
});
$('#editPanel').css({"visibility":"hidden"});
}
function showContextMenu(e, node){
e.preventDefault();
$('#menuTree').tree('select', node.target);
if(node.isNew){
$('#mm2').menu('show', {
left: e.pageX,
top: e.pageY
});
return;
}
if(node.attributes['resLevel']==1){//只有模块才能出现菜单
$('#mm').menu('show', {
left: e.pageX,
top: e.pageY
});
}
}
function dragEnter(target,source){
var targetNode = $('#menuTree').tree('getNode',target);
if(source.isNew||targetNode.isNew||source.id==-1){//新节点不能拖动,也不能拖入,虚拟节点不能拖动
return false;
}
return true;
}
function beforeDrop(target,source,point){
var targetNode=$('#menuTree').tree('getNode', target);
var parent = $('#menuTree').tree('getParent', target);
var isRoot=(source.attributes['resLevel']==1);
var isenter=(point=='append');
var isFold=targetNode.attributes['resType']=='DIR';
if(and(!isFold,isenter)){//只能拖到节点类型为“菜单(即目录)”的节点中,目标不是目录就不能进到里面
return false;
}
if(and(!isRoot,!parent,!isenter)){// 只能放到根节点的里面,不能放上边或下边成为新的根
return false;
}
//console.log('parent='+parent+' isRoot='+isRoot+' point='+point);
if(and(isRoot,!and(isRoot,!parent,!isenter))){//根节点只能在最上层拖动,除自己是根,目录也是根、且不是进到里面 情况外 都被挡住
return false;
}
return true;
}
function stopDrag(node){
try{//省得控制台不停报错
if(node.id==$('#id').val()){//如果拖动的刚好是正在编辑的节点,则重新赋值父节点
var parent = $('#menuTree').tree('getParent', node.target);
$('#parentId').val(parent.id);//父节点id
$('#parentIdShow').text(parent.id);
$('#resLevel').val(parseInt(parent.attributes['resLevel'])+1);
var index=countIndex(node);
$('#showOrder').numberbox('setValue',index);
}
}catch (e) {}
}
function selNode(node){
if($('#id').val()==node.id){
$('#editPanel').css({"visibility":"visible"});
}else{
$('#editPanel').css({"visibility":"hidden"});
}
}
/***计算节点排序*/
function countIndex(node){
var parent = $('#menuTree').tree('getParent', node.target);
var nodes=[];
if(!parent) {
nodes = $('#menuTree').tree('getRoots');
}else{
try{
nodes= $('#menuTree').tree('getChildren',parent.target);
}catch(e){
}
}
var maxindex=0;
$.each(nodes,function(i,n){
if(parent){
if( parent.id!=n.parentId){
return true;
}
}
if(n.id==node.id){
maxindex++;
//if(n.index){
// if(n.index!=99999){
// if(gt(n.index,maxindex)){
// maxindex=n.index;
// }
// }
// }
return false;
}else{
maxindex++;
if(n.index){
if(n.index!=99999){
if(gt(n.index,maxindex)){
maxindex=n.index;
}
}
}
}
});
return maxindex;
}
function editNode(node){
if(node.id==-1){//虚拟节点不能编辑
return;
}
$('#editPanel').css({"visibility":"visible"});
// $('#deleteBut').css({"visibility":"hidden"});
//由节点的真实情况定,排序的不用管,由总按钮决定
var parent = $('#menuTree').tree('getParent', node.target);
if(!parent) {
$('#parentId').val(1);//模块
$('#parentIdShow').text(1);
$('#resLevel').val(1);
}else{
$('#parentId').val(parent.id);//父节点id
$('#parentIdShow').text(parent.id);
$('#resLevel').val(parseInt(parent.attributes['resLevel'])+1);
}
var index=countIndex(node);
//alert(index);
$('#showOrder').numberbox('setValue',index);
$('#id').val(node.id);
$('#idshow').text(node.id);
$('#icon').val(node.iconCls)
$('#caResType').combobox('setValue',node.attributes['resType']);
var b2=node.attributes['bound2'];
if(b2!=null){
$('#bound2').combobox('setValue',b2);
}else{
$('#bound2').combobox('setValue','yes');
}
//resName
$('#resCode').val(node.attributes['resCode']);
$('#bound1').val(node.attributes['bound1']);
$('#resName').val(node.attributes['resName']);
$('#resValue').val(node.attributes['resValue']);
$('#isEdit').combobox('setValue',node.attributes['isEdit']);
$('#remark').textbox('setValue',node.attributes['remark']);
if(node.attributes['resType']=='DIR'){//如果是目录及模块,控制资源值
$('#resValue').val(0);
$('#resValue').attr('readonly','true');
}else{
$('#resValue').removeAttr('readonly');
}
jQuery('#editForm').form('validate');
//去数据库查询节点数据
// var butherf=$('#editResBut').attr('href');
//var index=butherf.indexOf('?');
// var butherf=(gt(index,0)?butherf.substring(0,index):butherf)+"?id="+node.id;
// $('#editResBut').attr('href',butherf);
// document.getElementById("editResBut").click();
}
function appendFold(foldtype){
var node = $('#menuTree').tree('getSelected');
if (!node) return;
if(foldtype===1){//不能设置attributes['resType']=6,先要保存完该节点才能设置此属性,这样才能按收URL拖到它目录下
var baseNodeIndex=(node.index)?node.index:99999;
var curIndex=baseNodeIndex>0? (baseNodeIndex-1):0;
$('#menuTree').tree('insert', {
before: node.target,
data: {
text: '新模块,请先保存',
index:curIndex,
attributes:{'resLevel':1,'resType':'MODULE'},
iconCls:'icon-folder-star',
isNew:true
}
});
}else if(foldtype===2){
var selected = $('#menuTree').tree('getSelected');
$('#menuTree').tree('append', {
parent: selected.target,
data: [{
text: '新目录,请先保存',
attributes:{'resType':'DIR'},
iconCls:'icon-folder-key',
isNew:true
}]
});
}else if(foldtype===3){
var selected = $('#menuTree').tree('getSelected');
$('#menuTree').tree('append', {
parent: selected.target,
data: [{
text: '新资源,请先保存',
attributes:{'resType':'URL'},
iconCls:'icon-user',
isNew:true
}]
});
}
}
function saveFold(){
alert(2);
}
function deleteFold(){
var selected = $('#menuTree').tree('getSelected');
$('#menuTree').tree('remove',selected.target);
}
function beforeDrag(node){
}
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册