Ver Fonte

Signed-off-by: sgq <sgq@sugangqiang>

sgq há 2 anos atrás
pai
commit
f81639e6f9

+ 33 - 4
app/admin/controller/Dict.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller;
 
+use app\admin\common\AdminController;
 use app\common\api\DictApi;
 
 /**
@@ -9,20 +10,48 @@ use app\common\api\DictApi;
  *
  * @author sgq
  */
-class Dict {
+class Dict extends AdminController {
 
+    /**
+     * @auth {{/dict}}
+     * @return type
+     */
     public function index() {
-        
+        return view();
+    }
+
+    /**
+     * @auth {{/dict/list}}
+     * @return type
+     */
+    public function list() {
+        $res = DictApi::getList($this->request);
+        return json($res);
     }
 
+    /**
+     * @auth {{/dict/add}}
+     * @return type
+     */
     public function add() {
-        
+        if ($this->request->isPost()) {
+            return json(DictApi::create($this->request->param()));
+        }
+        return view();
     }
 
+    /**
+     * @auth {{/dict/update}}
+     * @return type
+     */
     public function edit() {
-        
+        return view();
     }
 
+    /**
+     * @auth {{/dict/delete}}
+     * @return type
+     */
     public function delete() {
         
     }

+ 74 - 0
app/admin/view/dict/add.html

@@ -0,0 +1,74 @@
+{extend name="layout/content"}
+{block name="content"}
+<div class="ibox float-e-margins">
+    <div class="ibox-content">
+        <div class="form-horizontal">
+
+            <input type="hidden" id="id" value="">
+
+            <div class="row">
+                <div class="col-sm-12" id="itemsArea">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">类型编码</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" id="dictCode" type="text">
+                        </div>
+                        <label class="col-sm-2 control-label">类型名称</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" id="dictName" type="text">
+                        </div>
+
+                        <div class="col-sm-2">
+                            <button type="button" class="btn btn-sm btn-info " onclick="DictInfoDlg.addItem()" id="">
+                                <i class="fa fa-plus"></i>&nbsp;增加
+                            </button>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">备注</label>
+                        <div class="col-sm-8">
+                            <input class="form-control" id="dictTips" type="text">
+                        </div>
+                    </div>
+                    <div class="hr-line-dashed"></div>
+
+                </div>
+            </div>
+            <div class="row btn-group-m-t">
+                <div class="col-sm-12" style="text-align: center">
+                    <button type="button" class="btn btn-sm btn-info " onclick="DictInfoDlg.addSubmit()" id="ensure">
+                        <i class="fa fa-check"></i>&nbsp;提交
+                    </button>
+                    <button type="button" class="btn btn-sm btn-danger " onclick="DictInfoDlg.close()" id="cancel">
+                        <i class="fa fa-eraser"></i>&nbsp;取消
+                    </button>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script type="text/template" id="itemTemplate">
+    <div class="form-group" name="dictItem" id="dictItem">
+            <label class="col-sm-1 control-label">值</label>
+            <div class="col-sm-2">
+                <input class="form-control" type="text" name="itemCode">
+            </div>
+            <label class="col-sm-1 control-label" >名称</label>
+            <div class="col-sm-2">
+                <input class="form-control" type="text" name="itemName">
+            </div>
+            <label class="col-sm-1 control-label" >序号</label>
+            <div class="col-sm-2">
+                <input class="form-control" type="text" name="itemNum">
+            </div>
+            <div class="col-sm-2">
+
+<button type="button" class="btn btn-sm btn-danger " onclick="DictInfoDlg.deleteItem(event)" id="cancel">
+    <i class="fa fa-remove"></i>&nbsp;删除
+</button>
+
+            </div>
+        </div>
+</script>
+<script src="/static/modular/system/dict/dict_info.js"></script>
+{/block}

+ 95 - 0
app/admin/view/dict/edit.html

@@ -0,0 +1,95 @@
+{extend name="layout/content"}
+{block name="content"}
+<div class="ibox float-e-margins">
+    <div class="ibox-content">
+        <div class="form-horizontal">
+
+            <input type="hidden" id="id" value="">
+
+            <div class="row">
+                <div class="col-sm-12" id="itemsArea">
+                    <input type="hidden" id="itemSize" value="{$childs|count}" />
+                    <div class="form-group">
+
+                        <label class="col-sm-2 control-label">类型编码</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" id="dictCode" type="text" value="{$dict.code}">
+                        </div>
+
+                        <label class="col-sm-2 control-label">类型名称</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" id="dictName" type="text" value="{$dict.name}">
+                            <input type="hidden" id="dictId" value="{$dict.id}">
+                        </div>
+
+                        <div class="col-sm-2">
+                            <button type="button" class="btn btn-sm btn-info " onclick="DictInfoDlg.addItem()" id="">
+                                <i class="fa fa-plus"></i>&nbsp;增加
+                            </button>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">备注</label>
+                        <div class="col-sm-8">
+                            <input class="form-control" id="dictTips" type="text" value="{$dict.tips}">
+                        </div>
+                    </div>
+                    <div class="hr-line-dashed"></div>
+                    {volist name="dict.children" id="item"}
+                    <div class="form-group" name="dictItem" id="dictItem">
+                        <label class="col-sm-1 control-label">值</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" type="text" name="itemCode" value="{$item.code}">
+                        </div>
+                        <label class="col-sm-1 control-label" >名称</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" type="text" name="itemName" value="{$item.name}">
+                        </div>
+                        <label class="col-sm-1 control-label" >序号</label>
+                        <div class="col-sm-2">
+                            <input class="form-control" type="text" name="itemNum" value="{$item.num}">
+                        </div>
+                        <div class="col-sm-2">
+                            <button type="button" class="btn btn-sm btn-danger " onclick="DictInfoDlg.deleteItem(event)" id="cancel">
+                                <i class="fa fa-remove"></i>&nbsp;删除
+                            </button>
+                        </div>
+                    </div>
+                    {/volist}
+                </div>
+                <div class="row btn-group-m-t">
+                    <div class="col-sm-12" style="text-align: center">
+                        <button type="button" class="btn btn-sm btn-info " onclick="DictInfoDlg.editSubmit()" id="ensure">
+                            <i class="fa fa-check"></i>&nbsp;提交
+                        </button>
+                        <button type="button" class="btn btn-sm btn-danger " onclick="DictInfoDlg.close()" id="cancel">
+                            <i class="fa fa-eraser"></i>&nbsp;取消
+                        </button>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script type="text/template" id="itemTemplate">
+    <div class="form-group" name="dictItem" id="dictItem">
+    <label class="col-sm-1 control-label">值</label>
+    <div class="col-sm-2">
+    <input class="form-control" type="text" name="itemCode">
+    </div>
+    <label class="col-sm-1 control-label" >名称</label>
+    <div class="col-sm-2">
+    <input class="form-control" type="text" name="itemName">
+    </div>
+    <label class="col-sm-1 control-label" >序号</label>
+    <div class="col-sm-2">
+    <input class="form-control" type="text" name="itemNum">
+    </div>
+    <div class="col-sm-2">
+    <#button btnCss="danger" name="删除" id="cancel" icon="fa-remove" clickFun="DictInfoDlg.deleteItem(event)"/>
+    </div>
+    </div>
+</script>
+
+<script src="/static/modular/system/dict/dict_info.js"></script>
+{/block}

+ 59 - 0
app/admin/view/dict/index.html

@@ -0,0 +1,59 @@
+{extend name="layout/content"}
+{block name="content"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-title">
+                <h5>字典管理</h5>
+            </div>
+            <div class="ibox-content">
+                <div class="row row-lg">
+                    <div class="col-sm-12">
+                        <div class="row">
+                            <div class="col-sm-3">
+                                <div class="input-group input-group-sm">
+                                    <div class="input-group-btn">
+                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">名称
+                                        </button>
+                                    </div>
+                                    <input type="text" class="form-control" id="condition" placeholder="">
+                                </div>                            
+                            </div>
+                            <div class="col-sm-3">
+                                <button type="button" class="btn btn-sm btn-primary " onclick="Dict.search()" id="">
+                                    <i class="fa fa-search"></i>&nbsp;搜索
+                                </button>
+                            </div>
+                        </div>
+                        <div class="hidden-xs" id="DictTableToolbar" role="group">
+                            {if condition="chkCommission('/admin/dict/add','/dict/add')"} 
+                            <button type="button" class="btn btn-sm btn-primary " onclick="Dict.openAddDict()" id="">
+                                <i class="fa fa-plus"></i>&nbsp;添加
+                            </button>
+                            {/if}  
+                            {if condition="chkCommission('/admin/dict/edit','/dict/update')"}   
+                            <button type="button" class="btn btn-sm btn-primary " onclick="Dict.openDictDetail()" id="">
+                                <i class="fa fa-plus"></i>&nbsp;修改
+                            </button>
+                            {/if}  
+                            {if condition="chkCommission('/admin/dict/delete','/dict/delete')"}   
+                            <button type="button" class="btn btn-sm btn-primary " onclick="Dict.delete()" id="">
+                                <i class="fa fa-plus"></i>&nbsp;删除
+                            </button>
+                            {/if}
+                        </div>
+                        <table id="DictTable" class="table-condensed" style="font-size: 10px;table-layout: fixed!important;" data-mobile-responsive="true" data-click-to-select="true">
+                            <thead>
+                                <tr>
+                                    <th data-field="selectItem" data-checkbox="true"></th>
+                                </tr>
+                            </thead>
+                        </table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="/static/modular/system/dict/dict.js"></script>
+{/block}

+ 73 - 0
app/common/api/DictApi.php

@@ -3,6 +3,7 @@
 namespace app\common\api;
 
 use app\common\model\Dict;
+use think\Facade\Db;
 
 /**
  * Description of DictApi
@@ -11,6 +12,78 @@ use app\common\model\Dict;
  */
 class DictApi {
 
+    public static function create($params) {
+        $data["code"] = $params["dictCode"];
+        $data["name"] = $params["dictName"];
+        $data["tips"] = $params["dictTips"];
+        $data["pid"] = 0;
+        $values = $params["dictValues"];
+        if (self::isExistByCode($data["code"]))
+            return ["msg" => sprintf("编码[%s]已经存在", $data["code"])];
+        $items = array_filter(explode(";", $values));
+        $id = Dict::table('sys_dict')->insertGetId($data);
+        $childs = [];
+        for ($i = 0; $i < count($items); $i++) {
+            $fields = array_filter(explode(":", $items[$i]));
+            $childs[] = ["pid" => $id, "code" => $fields[0], "name" => $fields[1], "num" => $fields[2]];
+        }
+        Dict::insertAll($childs);
+        return ["code" => 200, "msg" => "成功"];
+    }
+
+    public static function isExistByCode($code, $id = 0) {
+        $where = [];
+        if ($id > 0) {
+            $where[] = ["id", "<>", $id];
+        }
+        $where[] = ["code", "=", $code];
+        $dict = Dict::where($where)->findOrEmpty()->toArray();
+        return $dict;
+    }
+
+    /**
+     * 获取一条
+     * @param type $id
+     * @return type
+     */
+    public static function getOne($id) {
+        $info = Dict::where("id", $id)->findOrEmpty()->toArray();
+        if ($info) {
+            $items = Dict::where("pid", "=", $id)->select()->toArray();
+            $info["children"] = $items;
+        }
+        return $info;
+    }
+
+    /**
+     * 获取列表
+     * @param type $request
+     * @return type
+     */
+    public static function getList($request) {
+        $order = trim($request->param("order")) ?: "desc";
+        $offset = trim($request->param("offset")) ?: 0;
+        $limit = trim($request->param("limit")) ?: 10;
+        $name = trim($request->param("condition"));
+        $where = [];
+        $where[] = ["pid", "=", "0"];
+        if ($name) {
+            $where[] = ["name", "like", "%" . $name . "%"];
+        }
+        $count = Dict::where($where)->count();
+        $list = Dict::where($where)->limit($offset, $limit)->order("id " . $order)->select()->toArray();
+        foreach ($list as &$item) {
+            $items = Dict::where("pid", "=", $item["id"])->column("name");
+            $item["detail"] = implode(",", $items);
+        }
+        return ["total" => $count, "rows" => $list];
+    }
+
+    /**
+     * 
+     * @param type $code
+     * @return type
+     */
     public static function selectByParentCode($code) {
         $parent = Dict::where("code", $code)->findOrEmpty()->toArray();
         $dictList = Dict::where("pid", $parent["id"])->select()->toArray();

+ 4 - 4
public/static/modular/system/dict/dict.js

@@ -7,7 +7,7 @@ var Dict = {
     table: null,
     layerIndex: -1
 };
-
+Feng.ctxPath = "/admin";
 /**
  * 初始化表格的列
  */
@@ -44,7 +44,7 @@ Dict.openAddDict = function () {
         area: ['800px', '420px'], //宽高
         fix: false, //不固定
         maxmin: true,
-        content: Feng.ctxPath + '/dict/dict_add'
+        content: Feng.ctxPath + '/dict/add'
     });
     this.layerIndex = index;
 };
@@ -60,7 +60,7 @@ Dict.openDictDetail = function () {
             area: ['800px', '420px'], //宽高
             fix: false, //不固定
             maxmin: true,
-            content: Feng.ctxPath + '/dict/dict_edit/' + Dict.seItem.id
+            content: Feng.ctxPath + '/dict/edit/id/' + Dict.seItem.id
         });
         this.layerIndex = index;
     }
@@ -99,6 +99,6 @@ Dict.search = function () {
 $(function () {
     var defaultColunms = Dict.initColumn();
     var table = new BSTable(Dict.id, "/dict/list", defaultColunms);
-    table.setPaginationType("client");
+    table.setPaginationType("server");
     Dict.table = table.init();
 });

+ 28 - 24
public/static/modular/system/dict/dict_info.js

@@ -3,18 +3,18 @@
  */
 var DictInfoDlg = {
     count: $("#itemSize").val(),
-    dictName: '',			//字典的名称
-    dictCode: '',//字典类型编码
-    dictTips: '',//字典备注
-    mutiString: '',		//拼接字符串内容(拼接字典条目)
+    dictName: '', //字典的名称
+    dictCode: '', //字典类型编码
+    dictTips: '', //字典备注
+    mutiString: '', //拼接字符串内容(拼接字典条目)
     itemTemplate: $("#itemTemplate").html()
 };
-
+Feng.ctxPath = "/admin";
 /**
  * item获取新的id
  */
 DictInfoDlg.newId = function () {
-    if(this.count == undefined){
+    if (this.count == undefined) {
         this.count = 0;
     }
     this.count = this.count + 1;
@@ -48,11 +48,11 @@ DictInfoDlg.deleteItem = function (event) {
 /**
  * 清除为空的item Dom
  */
-DictInfoDlg.clearNullDom = function(){
-    $("[name='dictItem']").each(function(){
+DictInfoDlg.clearNullDom = function () {
+    $("[name='dictItem']").each(function () {
         var num = $(this).find("[name='itemNum']").val();
         var name = $(this).find("[name='itemName']").val();
-        if(num == '' || name == ''){
+        if (num == '' || name == '') {
             $(this).remove();
         }
     });
@@ -64,11 +64,11 @@ DictInfoDlg.clearNullDom = function(){
 DictInfoDlg.collectData = function () {
     this.clearNullDom();
     var mutiString = "";
-    $("[name='dictItem']").each(function(){
+    $("[name='dictItem']").each(function () {
         var code = $(this).find("[name='itemCode']").val();
         var name = $(this).find("[name='itemName']").val();
         var num = $(this).find("[name='itemNum']").val();
-        mutiString = mutiString + (code + ":" + name + ":"+ num+";");
+        mutiString = mutiString + (code + ":" + name + ":" + num + ";");
     });
     this.dictName = $("#dictName").val();
     this.dictCode = $("#dictCode").val();
@@ -84,16 +84,20 @@ DictInfoDlg.addSubmit = function () {
     this.collectData();
     //提交信息
     var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) {
-        Feng.success("添加成功!");
-        window.parent.Dict.table.refresh();
-        DictInfoDlg.close();
+        if (data.code == 200) {
+            Feng.success("添加成功!");
+            window.parent.Dict.table.refresh();
+            DictInfoDlg.close();
+        } else {
+            Feng.error(data.msg);
+        }
     }, function (data) {
         Feng.error("添加失败!" + data.responseJSON.message + "!");
     });
-    ajax.set('dictName',this.dictName);
-    ajax.set('dictCode',this.dictCode);
-    ajax.set('dictTips',this.dictTips);
-    ajax.set('dictValues',this.mutiString);
+    ajax.set('dictName', this.dictName);
+    ajax.set('dictCode', this.dictCode);
+    ajax.set('dictTips', this.dictTips);
+    ajax.set('dictValues', this.mutiString);
     ajax.start();
 };
 
@@ -102,17 +106,17 @@ DictInfoDlg.addSubmit = function () {
  */
 DictInfoDlg.editSubmit = function () {
     this.collectData();
-    var ajax = new $ax(Feng.ctxPath + "/dict/update", function (data) {
+    var ajax = new $ax(Feng.ctxPath + "/dict/edit", function (data) {
         Feng.success("修改成功!");
         window.parent.Dict.table.refresh();
         DictInfoDlg.close();
     }, function (data) {
         Feng.error("修改失败!" + data.responseJSON.message + "!");
     });
-    ajax.set('dictId',$("#dictId").val());
-    ajax.set('dictName',this.dictName);
-    ajax.set('dictCode',this.dictCode);
-    ajax.set('dictTips',this.dictTips);
-    ajax.set('dictValues',this.mutiString);
+    ajax.set('dictId', $("#dictId").val());
+    ajax.set('dictName', this.dictName);
+    ajax.set('dictCode', this.dictCode);
+    ajax.set('dictTips', this.dictTips);
+    ajax.set('dictValues', this.mutiString);
     ajax.start();
 };