搭建ThinkPHP+EasyUI+requirejs 管理框架

一、配置测试站点


二、下载 ThinkPHP3.3.3

解压到站点根目录。index.PHP初始内容:

[php]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?php  
  2. // +----------------------------------------------------------------------  
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]  
  4. // +----------------------------------------------------------------------  
  5. // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.  
  6. // +----------------------------------------------------------------------  
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )  
  8. // +----------------------------------------------------------------------  
  9. // | Author: liu21st <liu21st@gmail.com>  
  10. // +----------------------------------------------------------------------  
  11.   
  12. // 应用入口文件  
  13.   
  14. // 检测PHP环境  
  15. if(version_compare(PHP_VERSION,'5.3.0','<'))  die('require PHP > 5.3.0 !');  
  16.   
  17. // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false  
  18. define('APP_DEBUG',True);  
  19. //生成Home  
  20. define('BIND_MODULE','Home');  
  21. //common模块  
  22. define('COMMON_PATH','./Application/Common');  
  23. // 定义应用目录  
  24. define('APP_PATH','./Application/');  
  25.   
  26. // 引入ThinkPHP入口文件  
  27. require './ThinkPHP/ThinkPHP.php';  
  28.   
  29. // 亲^_^ 后面不需要任何代码了 就是如此简单  


在浏览器输入:http://localhost/index.php

代码会自动生成Application下Home目录,然后注释掉define('BIND_MODULE','Home');

三、下载 EasyUI、require.js,拷贝到Js/EasyUI

目录结构大概是这样的:


四、新建主体窗口框架

/Application/CommonConf/config.php
[php]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?php  
  2. return array(  
  3.     //'配置项'=>'配置值'  
  4.           
  5.         // 设置禁止访问的模块列表  
  6.         'MODULE_DENY_LIST' => array (  
  7.                 'Common',  
  8.                 'CommonConf',  
  9.                 'Runtime'  
  10.         ),  
  11.         'TMPL_PARSE_STRING' => array (  
  12.                 '__JS__' => '/Public/JS',        // 增加新的JS类库路径替换规则  
  13.                 '__CSS__' => '/Public/Css',  // 增加新的上传路径替换规则  
  14.                 '__EASYUI__' => '/Public/Js/jquery-easyui-1.4.1',  
  15.                 '__ADMIN__' => '/Public/Js/Admin'  
  16.         ),  
  17.         'TMPL_ENGINE_TYPE' =>'PHP'  
  18. );  


/Application/Home/Controller/IndexController.class.php
[php]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?php  
  2. namespace Admin\Controller;  
  3. use Think\Controller;  
  4. class IndexController extends Controller {  
  5.     public function index(){  
  6.         $this->display();  
  7.     }  
  8. }  


建立模板页 /Application/Home/View/Index/index.html
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <pre name="code" class="php"><!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>后台</title>  
  6.     <link id="skin" href="__EASYUI__/themes/default/easyui.css" rel="stylesheet" type="text/css" />  
  7.     <link href="__EASYUI__/themes/icon.css" rel="stylesheet" type="text/css" />  
  8.     <link href="__PUBLIC__/Css/App.css" rel="stylesheet" type="text/css" />  
  9. </head>  
  10. <body class="easyui-layout" >  
  11.     <div region="west" split="true" title="登陆姓名【系統名称】" style="width: 265px;overflow-x:hidden">  
  12.   
  13.         <div style="text-align: left; float: left; height: auto; overflow: hidden">  
  14.             <ul id="ul-menu" class="tab-link">  
  15.                 <li data-options="state:'open'"><span> 大菜单 </span>  
  16.                     <ul>  
  17.                         <li data-options="iconCls:''">  
  18.                             <span><a href="javascript:;" data-template="/Public/Js/Admin/Template/TestModule.html" data-js="/Public/Js/TestModule" data-method="TestMethod"> 子菜单</a></span>  
  19.                         </li>  
  20.                     </ul>  
  21.                 </li>  
  22.             </ul>  
  23.         </div>  
  24.     </div>  
  25.     <div region="center">  
  26.         <div id="div-tabs" class="easyui-tabs" fit="true" border="false" plain="true">  
  27.             <div title="工作台">  
  28.                 <div id="Portal-Default">  
  29.                     <div id="content" style="overflow-x: hidden">  
  30.                         <div style="width: 48%;"></div>  
  31.                         <div style="width: 52%;"></div>  
  32.                     </div>  
  33.                 </div>  
  34.             </div>  
  35.         </div>  
  36.     </div>  
  37.     <div region="south" id="south">  
  38.         <div style="height: 22px; float: right">欢迎使用。登陆时间: {$system_time} </div>  
  39.         <div class="tail-color">  
  40.             <span style="background: #E0ECFF" class="default"></span>   
  41.             <span style="background: #AED0EA" class="ui-cupertino"></span>   
  42.             <span style="background: #b1c242" class="ui-pepper-grinder"></span>   
  43.             <span style="background: #FEEEBD" class="ui-sunny"></span>   
  44.         </div>  
  45.     </div>  
  46. </body>  
  47.   
  48. <script src="__EASYUI__/jquery.min.js"></script>  
  49. <script src="__EASYUI__/jquery.easyui.min.js"></script>  
  50. <script src="__EASYUI__/locale/easyui-lang-zh_CN.js"></script>  
  51. <script src="__EASYUI__/jquery-easyui-edatagrid/jquery.edatagrid.js"></script>  
  52. <script src="__EASYUI__/jquery-easyui-portal/jquery.portal.js"></script>  
  53. <script src="__JS__/require-2.1.11.min.js"></script>  
  54. <script src="__JS__/jsUtil.js"></script>  
  55. <script src="__PUBLIC__/Home/Index/Js/index.js" type="text/javascript"></script>  
  56. </html>  

 在Public/Home/Index/Js/建立index.js,内容: 
 
[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. /// <reference path="/Js/jsUtil.js"/>   
  2. /** 
  3.  *  
  4.  */  
  5. (function() {  
  6.     var arg0, arg1;  
  7.     // 菜单  
  8.     $(document).on("click"".jsFunc"function() {  
  9.         var _win_ = $(this).attr("win");  
  10.         var _arg0_ = $(this).attr("arg0");  
  11.         var _arg1_ = $(this).attr("arg1");  
  12.         popMenu(_win_, _arg0_, _arg1_);  
  13.     });  
  14.       
  15.     function popMenu(_win_, _arg0_, _arg1_) {  
  16.         var _path = _win_; // js路径  
  17.         var _winName = _path.replaceAll("/"""); // 窗口名,就是无/的路径  
  18.   
  19.         arg0 = _arg0_;  
  20.         arg1 = _arg1_;  
  21.         var isRoot = (_path.indexOf("/") == 0);  
  22.         if (isRoot)  
  23.             _path = _path.substring(1, _path.length); // 去掉路径开头的/  
  24.         if ($("#" + _winName).height() == null) {  
  25.             $.getScript((isRoot ? "/" : "Js/") + _path + ".js?r="  
  26.                     + Math.random());  
  27.         } else  
  28.             $("#" + _winName).dialog("open");  
  29.     }  
  30.   
  31.     var StateKeys = {  
  32.         Normal : 'Normal',  
  33.         Stop : 'Stop',  
  34.         Delete : 'Delete',  
  35.         Already : 'Already',  
  36.         Duplicate : 'Duplicate'  
  37.     };  
  38.     var ServiceStateKeys = {  
  39.         TimeOut : 'TimeOut',  
  40.         Success : 'Success',  
  41.         Fail : 'Fail',  
  42.         NoPermiss : 'NoPermiss',  
  43.         Exists : 'Exists',  
  44.         NotExists : 'NotExists',  
  45.         InUse : 'InUse',  
  46.         NotInUse : 'NotInUse'  
  47.     }  
  48.     var OnLineState = {  
  49.         OnLine : 'OnLine',  
  50.         Leave : 'Leave',  
  51.         OffLine : 'OffLine'  
  52.     };  
  53.     var X_WFSTATE = [ "待办""完成""终止""删除""未通过" ];// "结束", "终止", "删除"];  
  54.     // 标准宽度  
  55.     var X_WIDTH = {  
  56.         Depart : 90,  
  57.         UserName : 55,  
  58.         Ip : 100,  
  59.         Time : 90,  
  60.         Building : 100,  
  61.         Sex : 30,  
  62.         Tel : 140,  
  63.         HardStr : 185,  
  64.         CheckStr : 185,  
  65.         Bool : 20,  
  66.         State : 30,  
  67.         Title : 300  
  68.     };  
  69.       
  70.     /// 皮肤  
  71.     // 从cookie加载皮肤  
  72.     var _skin = GetCookie("XSKIN");  
  73.     if (_skin) {  
  74.         loadSkin(_skin);  
  75.     }  
  76.   
  77.     $(".tail-color span").click(function() {  
  78.         var _skin = $(this).attr("class");  
  79.         if (_skin) {  
  80.             SetCookie("XSKIN", _skin);  
  81.             loadSkin(_skin);  
  82.         }  
  83.     });  
  84.     function loadSkin(path) {  
  85.         $("#skin").attr("href","/Public/Js/jquery-easyui-1.4.1/themes/{0}/easyui.css".format(path));  
  86.     }  
  87.     ///皮肤代码结束  
  88.   
  89.     // 菜单  
  90.     $('#ul-menu').tree({  
  91.         lines : true,  
  92.         animate : true  
  93.     });  
  94.   
  95.     /// tab 代码  
  96.     $(".tab-link").on("click""a"function() {  
  97.           
  98.         if ($(this).attr("data-template")) addTab($(this));  
  99.     });  
  100.   
  101.     $('#div-tabs').tabs({});  
  102.       
  103.     if ($('#content').length) {  
  104.         $('#content').portal({});  
  105.     }  
  106.     // /plugin1,有text(),并且有path属性,jquery对象,一般用a标签  
  107.     function addTab(plugin) {  
  108.         if ($('#div-tabs').tabs('exists', plugin.text().trim())) {  
  109.             $('#div-tabs').tabs('select', plugin.text().trim());  
  110.         } else {  
  111.             $('#div-tabs').tabs('add',{  
  112.                 title : plugin.text().trim(),  
  113.                 href : plugin.attr("data-template") ,  
  114.                 closable : true,  
  115.                 extractor : function(data) {  
  116.                     data = $.fn.panel.defaults.extractor(data);  
  117.                     var tmp = $('<div></div>').html(data);  
  118.                     data = tmp.html();  
  119.                     tmp.remove();  
  120.                     return data;  
  121.                 },  
  122.                 onLoad : function(panel) {  
  123.                       
  124.                 }  
  125.             });  
  126.         }  
  127.     }  
  128.     /// tab 结束  
  129.       
  130.   
  131.     // 退出  
  132.     $("#link-logout").click(function() {  
  133.         $.messager.progress({  
  134.             title : '提示信息',  
  135.             msg : '正在退出登陆'  
  136.         });  
  137.         $.post("RBAC/Services/RBAC_Users.asmx/Logout"function(v) {  
  138.             $.messager.progress("close");  
  139.             switch ($(v).find("boolean").text()) {  
  140.             case "true":  
  141.                 location.href = "/";  
  142.                 break;  
  143.             }  
  144.         });  
  145.     });  
  146.   
  147.     // 渲染用户控件,全是xclass-模块-功能  
  148.     function renderUserControls(target) {  
  149.   
  150.     }  
  151.   
  152.     function StateStrToJsonStr(v) {  
  153.         var str = styleHouseState(v);  
  154.         if (!str)  
  155.             return '{}';  
  156.         var arr = str.split(';');  
  157.         var result = "";  
  158.         for (var _j = 0; _j < arr.length; _j++) {  
  159.             var tempArr = arr[_j].split(':');  
  160.             if (result != "")  
  161.                 result += ",";  
  162.             result += '"' + tempArr[0] + '":"' + tempArr[1] + '"';  
  163.         }  
  164.         result = '{' + result + '}';  
  165.         return result;  
  166.     }  
  167.     // easyui扩展  
  168.     $.extend($.fn.validatebox.defaults.rules,{  
  169.                 minLength : {  
  170.                     validator : function(value, param) {  
  171.                         return value.length >= param[0];  
  172.                     },  
  173.                     message : '长度至少 {0} '  
  174.                 },  
  175.                 phone : {// 验证电话号码  
  176.                     validator : function(value) {  
  177.                         return /^(( \d2,3 )|(\d{3}\-))?( 0\d2,3 |0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i  
  178.                                 .test(value);  
  179.                     },  
  180.                     message : '格式不正确,请使用下面格式:010-88888888'  
  181.                 },  
  182.                 mobile : {  
  183.                     validator : function(value, param) {  
  184.                         // return  
  185.                         // /^(( \d2,3 )|(\d{3}\-))?13\d{9}$/.test(value);  
  186.                         return /^1[3|4|5|8][0-9]\d{8}$/.test(value);  
  187.                     },  
  188.                     message : '手机号码不正确'  
  189.                 },  
  190.                 phoneOrMobile : {  
  191.                     validator : function(value, param) {  
  192.                         return (/^1[3|4|5|8|7][0-9]\d{8}$/.test(value) || /^(( \d2,3 )|(\d{3}\-))?( 0\d2,3 |0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i  
  193.                                 .test(value));  
  194.                     },  
  195.                     message : '号码不正确'  
  196.                 },  
  197.                 CHS : {  
  198.                     validator : function(value, param) {  
  199.                         return /^[\u4e00-\u9fa5]+$/.test(value);  
  200.                     },  
  201.                     message : '请输入汉字'  
  202.                 },  
  203.                 safepass : {  
  204.                     validator : function(value, param) {  
  205.                         return safePassword(value);  
  206.                     },  
  207.                     message : '密码由字母和数字组成,至少6位'  
  208.                 },  
  209.                 number : {  
  210.                     validator : function(value, param) {  
  211.                         return /^[\+\-]?\d*?\.?\d*?$/.test(value);  
  212.                     },  
  213.                     message : '请输入数字'  
  214.                 },  
  215.                 equalTo : {  
  216.                     validator : function(value, param) {  
  217.                         return value == $(param[0]).val();  
  218.                     },  
  219.                     message : '两次输入的字符不一至'  
  220.                 },  
  221.                 IDNUMBER : {  
  222.                     validator : function(value, param) {  
  223.                         return /^(\d{18,18}|\d{15,15}|\d{17,17}[xX]?)$/  
  224.                                 .test(value);  
  225.                     },  
  226.                     message : '请输入正确的身份证号'  
  227.                 },  
  228.                 mustSelect : {  
  229.                     validator : function(value, param) {  
  230.                         return value != "-1";  
  231.                     },  
  232.                     message : '必需选择值'  
  233.                 }  
  234.             });  
  235.   
  236.     var safePassword = function(value) {  
  237.         return !(/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.
    \{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/  
  238.                 .test(value));  
  239.     }  
  240.   
  241.     function SystemGetString(module, key) {  
  242.         var _result;  
  243.         $.ajax({  
  244.             url : "SystemSet/Services/SystemSet.asmx/SystemGetString",  
  245.             data : {  
  246.                 module : module,  
  247.                 key : key  
  248.             },  
  249.             async : false,  
  250.             success : function(v) {  
  251.                 _result = $(v).find("string").text();  
  252.             }  
  253.         });  
  254.         return _result;  
  255.     }  
  256.   
  257.     function SystemGetBool(module, key) {  
  258.         var _result;  
  259.         $.ajax({  
  260.             url : "SystemSet/Services/SystemSet.asmx/SystemGetBool",  
  261.             data : {  
  262.                 module : module,  
  263.                 key : key  
  264.             },  
  265.             async : false,  
  266.             success : function(v) {  
  267.                 _result = $(v).find("boolean").text() == "true";  
  268.             }  
  269.         });  
  270.         return _result;  
  271.     }  
  272.   
  273.     function SystemGetInt(module, key) {  
  274.         var _result;  
  275.         $.ajax({  
  276.             url : "SystemSet/Services/SystemSet.asmx/SystemGetInt",  
  277.             data : {  
  278.                 module : module,  
  279.                 key : key  
  280.             },  
  281.             async : false,  
  282.             success : function(v) {  
  283.                 _result = parseInt($(v).find("int").text());  
  284.             }  
  285.         });  
  286.         return _result;  
  287.     }  
  288.     function CheckLimit(ResourceName, OperationName) {  
  289.         for ( var limit in X_SELFOPERATIONS) {  
  290.             if (X_SELFOPERATIONS[limit].ResourceName == ResourceName  
  291.                     && X_SELFOPERATIONS[limit].OperationName == OperationName)  
  292.                 return X_SELFOPERATIONS[limit].Value;  
  293.         }  
  294.         return false;  
  295.     }  
  296.     // /给combobox赋值,适用于ajax自动提示的  
  297.     function setComboboxValue(name, namespace, text, value) {  
  298.         var c1, c3;  
  299.         if (namespace) {  
  300.             c1 = $(".combo-f[comboname=" + name + "]""#" + namespace);  
  301.             c3 = $(".combo-value[name=" + name + "]""#" + namespace);  
  302.         } else {  
  303.             c1 = $(".combo-f[comboname=" + name + "]");  
  304.             c3 = $(".combo-value[name=" + name + "]");  
  305.         }  
  306.   
  307.         var c2 = c3.prev().prev();  
  308.         c1.val(value);  
  309.         c2.val(text);  
  310.         c3.val(value);  
  311.     }  
  312.     function setSpinnerValue(name, namespace, value) {  
  313.         var c1 = $(":hidden[name=" + name + "]""#" + namespace);  
  314.         var c2 = c1.prev();  
  315.         c1.val(value);  
  316.         c2.val(value);  
  317.     }  
  318.     function loadFilter(data) {  
  319.         if (!data.d) {  
  320.             data.d = {  
  321.                 Table : {}  
  322.             };  
  323.         }  
  324.         if (!data.d.Table)  
  325.             data.d.Table = {};  
  326.         if (data.d.Total)  
  327.             data.d.Table.total = data.d.Total;  
  328.         else  
  329.             data.d.Table.total = 0;  
  330.         if (!data.d.Table.rows)  
  331.             data.d.Table.rows = [];  
  332.         return data.d.Table;  
  333.     }  
  334.   
  335.     var oldHTML = $.fn.html;  
  336.     $.fn.formhtml = function() {  
  337.         if (arguments.length)  
  338.             return oldHTML.apply(this, arguments);  
  339.         $("input,textarea,button"this).each(function() {  
  340.             this.setAttribute('value'this.value);  
  341.         });  
  342.         $(":radio,:checkbox"this).each(function() {  
  343.             // im not really even sure you need to do this for "checked"  
  344.             // but what the heck, better safe than sorry  
  345.             if (this.checked)  
  346.                 this.setAttribute('checked''checked');  
  347.             else  
  348.                 this.removeAttribute('checked');  
  349.         });  
  350.         $("option"this).each(function() {  
  351.             // also not sure, but, better safe...  
  352.             if (this.selected)  
  353.                 this.setAttribute('selected''selected');  
  354.             else  
  355.                 this.removeAttribute('selected');  
  356.         });  
  357.         return oldHTML.apply(this);  
  358.     };  
  359. })();  

以后增加框架时,在index.html添加子菜单:
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <li data-options="iconCls:''">  
  2.     <span><a href="javascript:;" data-template="/Public/Js/Admin/Template/TestModule.html" data-js="/Public/Js/TestModule" data-method="TestMethod"> 子菜单</a></span>  
  3. </li>  


在Public/Home/Index/Js/下新增模块:TestModule.js
[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. define(function(){  
  2.     testMethod:function(){  
  3.         console.log("test");  
  4.     }  
  5. });  

在Public/Home/Templates下新增模板:TestModule.html
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <div id="content">模板</div>  

五、运行测试

/Home/Index/index

六、参考信息,模板变量:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. __ROOT__: 会替换成当前网站的地址(不含域名)   
  2. __APP__: 会替换成当前应用的URL地址 (不含域名)  
  3. __MODULE__:会替换成当前模块的URL地址 (不含域名)  
  4. __CONTROLLER__(__或者__URL__ 兼容考虑): 会替换成当前控制器的URL地址(不含域名)  
  5. __ACTION__:会替换成当前操作的URL地址 (不含域名)  
  6. __SELF__: 会替换成当前的页面URL  
  7. __PUBLIC__:会被替换成当前网站的公共目录 通常是 /Public/  

0
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值