easyui框架和显示(一)

easyui框架和显示(一)

1、easyui介绍

easyui是一种基于jQuery的用户界面插件集合。

easyui为创建现代化,互动,JavaScript应用程序,提供必要的功能。

使用easyui你不需要写很多代码,只需要通过编写一些简单HTML标记,就可以定义用户界面。

easyui节省您网页开发的时间和规模。

2、easyui本次操作需要的工具和一些案例

1、一些工具名称
在这里插入图片描述
2、jQuery EasyUI 官方API文档中文版version 1.5
在这里插入图片描述
3、Easyui的导入
在这里插入图片描述

4、拷入之前的util类
在这里插入图片描述

6、从jQuery EasyUI 官方API文档中文版version 1.5导入EasyUI的CSS和Javascript文件到您的页面。

7、以及包
在这里插入图片描述

<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">   
<script type="text/javascript" src="easyui/jquery-1.7.2.min.js"></script>   
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>  

index.js

$(function() {
	$('#tt').tree({    
	    url:'tree_data1.json'   
	});  
})

3、easyui代码

1、jsp.页面显示:通过layout布局

<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/static/easyui5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/static/easyui5/themes/icon.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/easyui5/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/easyui5/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/js/index.js"></script>

<title>后台展示</title>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false"
		style="height: 60px; background: #B3DFDA; padding: 10px">north
		region</div>
	<div data-options="region:'west',split:true,title:'West'"
		style="width: 150px; padding: 10px;">
		菜单管理
		<ul id="tt"></ul>  
		</div>
	<div
		data-options="region:'east',split:true,collapsed:true,title:'East'"
		style="width: 100px; padding: 10px;">east region</div>
	<div data-options="region:'south',border:false"
		style="height: 50px; background: #A9FACD; padding: 10px;">south
		region</div>
	<div data-options="region:'center',title:'Center'"></div>
</body>

2、通过tree(树形菜单)加载菜单
树形(tree)的结构目录 (tree_data1.json)

[{
	"id":1,
	"text":"菜单管理",
	"children":[{
		"id":11,
		"text":"财务",
		"state":"closed",
		"children":[{
			"id":111,
			"text":"日常报销"
		},{
			"id":112,
			"text":"Wife"
		},{
			"id":113,
			"text":"Company"
		}]
	},{
		"id":12,
		"text":"后勤",
		"children":[{
			"id":121,
			"text":"Intel"
		},{
			"id":122,
			"text":"费用缴纳",
			"attributes":{
				"p1":"Custom Attribute1",
				"p2":"Custom Attribute2"
			}
		},{
			"id":123,
			"text":"Microsoft Office"
		},{
			"id":124,
			"text":"Games",
			"checked":true
		}]
	},{
		"id":13,
		"text":"index.html"
	},{
		"id":14,
		"text":"about.html"
	},{
		"id":15,
		"text":"welcome.html"
	}]
}]

TreeNode(实体类)

package com.DZY.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作用是通过TreeNode类转成
 * tree——data1.json的字符串
 * @author DZY
 *
 */
public class TreeNode {

	private String id;
	private String text;
	private List<TreeNode> children = new ArrayList<>();
    private Map<String, Object> attributes = new HashMap<>();
	
    
    public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public List<TreeNode> getChildren() {
		return children;
	}
	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}
	public Map<String, Object> getAttributes() {
		return attributes;
	}
	public void setAttributes(Map<String, Object> attributes) {
		this.attributes = attributes;
	}
	public TreeNode(String id, String text, List<TreeNode> children, Map<String, Object> attributes) {
		super();
		this.id = id;
		this.text = text;
		this.children = children;
		this.attributes = attributes;
	}
	public TreeNode() {
		super();
	}
	@Override
	public String toString() {
		return "TreeNode [id=" + id + ", text=" + text + ", children=" + children + ", attributes=" + attributes + "]";
	}
    
    
}

MenuDao(继承JsonBaseDao)

package com.DZY.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.DZY.entity.TreeNode;
import com.DZY.util.JsonBaseDao;
import com.DZY.util.JsonUtils;
import com.DZY.util.PageBean;
import com.DZY.util.StringUtils;

public class MenuDao extends JsonBaseDao {

	/**
	 * 给前台返回tree_data1.json的字符串
	 * @param paMap   从前台jsp传递过来的参数集合
	 * @param pageBean
	 * @return
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	
	public List<TreeNode> listTreeNode(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		List<Map<String, Object>> listMap = this.listMap(paMap, pageBean);
		List<TreeNode> listTreeNode = new ArrayList<>();
		this.listMapToListTreeNode(listMap, listTreeNode);
		
		return listTreeNode;
	}
	
	/**
	 * [{'menuId':001,'menuName':'学生管理'},{{'menuId':001,'menuName':'后勤管理'}}]
	 * @param paMap
	 * @param pageBean
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws SQLException
	 */
	public List<Map<String, Object>> listMap(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		String sql = "select * from t_easyui_menu where true";
		String menuId = JsonUtils.getParamVal(paMap, "Menuid");
		if(StringUtils.isNotBlank(menuId)) {
			sql += " and parentid="+menuId;
		}else {
			sql += " and parentid=-1";
		}
//		这里面存放的是数据库中的菜单信息
		List<Map<String, Object>> listMap = super.executeQuery(sql, pageBean);
		return listMap;
	}
	
	/**
	 * {'menuId':001,'menuName':'学生管理'}
	 * --->
	 * {id:....,text:....}
	 * @param map
	 * @param treeNode
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	private void mapToTreeNode(Map<String, Object> map, TreeNode treeNode) throws InstantiationException, IllegalAccessException, SQLException {
		treeNode.setId(map.get("Menuid")+"");
		treeNode.setText(map.get("Menuname")+"");
		treeNode.setAttributes(map);
//		将子节点添加到父节点当中,建立数据之间的父子关系
//		treeNode.setChildren(children);
		Map<String, String[]> childrenMap = new HashMap<>();
		childrenMap.put("Menuid", new String[] {treeNode.getId()});
		List<Map<String, Object>> listMap = this.listMap(childrenMap, null);
		List<TreeNode> listTreeNode = new ArrayList<>();
		this.listMapToListTreeNode(listMap, listTreeNode);
		treeNode.setChildren(listTreeNode);
	}
	/**
	 * [{'menuId':001,'menuName':'学生管理'},{{'menuId':001,'menuName':'后勤管理'}}]
	 * -->
	 * tree_data1.json
	 * @param listMap
	 * @param listTreeNode
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
   private void listMapToListTreeNode(List<Map<String, Object>> listMap, List<TreeNode> listTreeNode) throws InstantiationException, IllegalAccessException, SQLException {
		TreeNode treeNode = null;
		for (Map<String, Object> map : listMap) {
			treeNode = new TreeNode();
			mapToTreeNode(map, treeNode);
			listTreeNode.add(treeNode);
		}
	}
}

MenuAction (继承ActionSupport )

public class MenuAction extends ActionSupport {

	private MenuDao menuDao = new MenuDao();
	 
	public String menuTree(HttpServletRequest req,HttpServletResponse resp) {
		ObjectMapper om = new ObjectMapper();
		try {
//			获取到easyui框架所识别的json格式
			List<TreeNode> listTreeNode = this.menuDao.listTreeNode(req.getParameterMap(), null);
			ResponseUtil.write(resp, om.writeValueAsString(listTreeNode));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
}

mvc.xml配置

<config>
	<action path="/menuAction" type="com.DZY.web.MenuAction">
	</action>
	<action path="/userAction" type="com.DZY.web.UserAction">
		<forward name="index" path="/index.jsp" redirect="false" />
	</action>
</config>

界面效果:
在这里插入图片描述
3、Tabs(通过菜单去打开不同的tab页)
选项卡显示一批面板。但在同一个时间只会显示一个面板。每个选项卡面板都有头标题和一些小的按钮工具菜单,包括关闭按钮和其他自定义按钮。

<div data-options="region:'center',title:'Center'">
	   <div id="menuTab" class="easyui-tabs" style="width:500px;height:250px;">   
            <div title="首页" style="padding:20px;display:none;">欢迎界面</div>    
	</div>

index

$(function() {
	$('#tt').tree({    
	    url:'menuAction.action?methodName=menuTree',
	    	onClick: function(node){
	    		alert(node.text);  // 在用户点击的时候提示
	    		// add a new tab panel    $.extends
	    		var content = '<iframe scrolling="no" frameborder="0" src="'+node.attributes.menuURL+'" width="99%" height="99%"></iframe>';
	    		if($('#menuTab').tabs('exists',node.text)){
//	    			存在执行选项卡选中已有的选项卡操作
	    			$('#menuTab').tabs('select',node.text);
	    		}else{
//	    			不存在执行新增的操作
	    			$('#menuTab').tabs('add',{    
		    		    title:node.text,    
		    		    content:content,    
		    		    closable:true   
		    		}); 
	    		}    		
	    	}
	});  
})

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
最近比较忙,抽空做了最新版的API,本次的主要精力就是放在了pdf版的文档上面,看了上一版好多人反应说希望保留chm格式的,所以这一版继续提供chm格式的文档给大家了,现在的版本中包含了PDF、EXE和CHM 3种格式的文档,相信应该可以满足大家的需要了。此外我个人推荐大家使用PDF格式的文档,因为PDF是全新制作的,内容进行了完整校对,所以错漏的地方比EXE和CHM格式要少很多。其它废话就不多说了。更新内容自己看更新说明吧! jQuery EasyUI 1.5.1版本更新内容: Bug(修复) datagrid:修复在调用“updateRow”方法之后选中和复选行标志丢失的问题; tabs:修复在调用“update”方法的时候导致标签栏工具错位的问题; window:修复在窗体高度设置为“auto”时,当移动窗体后窗体会丢失的问题; messager:修复在现实进度消息窗口后立即关闭该窗口会导致程序发生异常的问题; form:修复“clear”方法无法清除combobox组件选择的下拉项的问题。 Improvement(改进) textbox:可以用“cls”属性添加自定义样式; numberbox:允许用户使用意大利货币格式; combo:添加“multivalue”属性,允许用户决定如何提交多个值; combobox:添加“reversed”属性; combobox:添加“onClick”事件; combogrid:添加“reversed”属性; treegrid:使用Shift键启用多值选择。 New Plugin(新组件) tagbox:允许用户在表单字段上添加标签。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值