minitiger 9 лет назад
Родитель
Сommit
6a1b859a83

+ 67 - 0
VisualInspection/js/constant/constant.js

@@ -0,0 +1,67 @@
+var page=1;
+var size=10;
+function getConstant(){
+    var data = {
+        "flag_name": $("#keywords").val()
+    }
+    getConstantList("/constant/getConstantByName/1/10", data, function(data) {
+        updateTable(data.list);
+    }, function(error) {
+        alert(error);
+    });
+}
+
+function updateTable(tableData){
+    var cols = [
+                {width: 80, text: '序号', type: 'number', flex: false, field: 'num'},
+                {width: 80, text: '代码编号', type: 'date', flex: false, field: 'code_flag'},
+                {width: 80, text: '代码名称', type: 'string', flex: true, field: 'code_name'},
+                {width: 80, text: '有效标志', type: 'date', flex: false, field: 'valid'},
+                {width: 80, text: '代码标识', type: 'string', flex: true, field: 'code_flag'},
+                {width: 160, text: '标识名称', type: 'date', flex: false, field: 'flag_name'},
+                {width: 80, text: '备注', type: 'string', flex: true, field: 'remark'},
+                {width: 160, text: '操作', type: 'string', flex: true, field: 'id'}
+            ];
+    var rowData = formatTableData(tableData, cols);
+    clearTable(cols);
+    // 使用data参数更新数据:
+    $('.datatable').datatable('load',  {
+            cols: cols,
+            rows:rowData
+            // [
+            //     {checked: false, data: [1, '1','上行','1','DIRECTION','方向','未稽查','<a href="#" data-toggle="modal" data-target="#myModal"><i class="icon icon-edit"></i> 修改</a><a href="#"><i class="icon icon-remove-circle"></i> 删除</a>']},
+            //     {checked: false, data: [2, '2','下行','1','DIRECTION','方向','未稽查','<a href="#" data-toggle="modal" data-target="#myModal"><i class="icon icon-edit"></i> 修改</a><a href="#"><i class="icon icon-remove-circle"></i> 删除</a>']},
+            //     // 更多数据
+            // ]
+        }
+    );
+}
+function clearTable(cols){
+     $('.datatable').datatable( {
+        checkable:false,
+        sortable:false,
+        data: {
+            cols: cols,
+            rows:[]
+        }
+    });
+}
+function formatTableData(data,cols){
+    var rows = [];
+    // rows.push({checked: false, data: [1, '1','上行','1','DIRECTION','方向','未稽查','<a href="#" data-toggle="modal" data-target="#myModal"><i class="icon icon-edit"></i> 修改</a><a href="#"><i class="icon icon-remove-circle"></i> 删除</a>']});
+    for(var i=0;i<data.length;i++){
+        data[i].num=(page-1)*10+i+1;
+        rows.push(genRow(data[i],cols));
+    }
+    return rows;
+}
+
+function genRow(obj,cols){
+    var row = {checked: false, data:null};
+    var dArr=[];
+    for(var i=0;i<cols.length;i++){
+        dArr.push(obj[cols[i].field]);
+    }
+    row.data=dArr;
+    return row;
+}

+ 14 - 0
VisualInspection/js/util/service.js

@@ -42,4 +42,18 @@ function DeptGetAll(success, fail) {
     }, function(error) {
         fail("网络错误");
     });
+}
+
+function getConstantList(url, param, success, fail) {   
+    var url = base_server_url + url;
+    ajaxPost(url, param, function(response) {
+        var data = response;
+        if (data.result_code == 0) {
+            success(data.result_data)
+        } else {
+            fail(data.result_desc);
+        }
+    }, function(error) {
+        fail("网络错误");
+    });
 }

+ 46 - 107
VisualInspection/view/constant/constant.html

@@ -1,122 +1,61 @@
-<div class="container-fluid ">
-    <div class="row">
-        <div class="col-xs-3">
-            <div class="input-group">
-                <span class="input-group-addon">关键词</span>
-                <input class="form-control form-focus" autofocus type="text" placeholder="请输入关键词">
+ 
+<script src="/js/constant/constant.js"></script>   
+    <div class="container-fluid ">
+        <div class="row">
+            <div class="col-xs-3">
+                <div class="input-group">
+                    <span class="input-group-addon">关键词</span>
+                    <input class="form-control form-focus" id="keywords" autofocus type="text" placeholder="请输入关键词">
+                </div>
+            </div>
+            
+            <div class="col-xs-3">
+                 <div class="input-group">
+                    <button class="btn btn-primary " type="button" onclick="getConstant()">查询</button>
+                 </div>
+            </div>
+            <div style="float:right;">
+                <button class="btn btn-success" type="button" data-toggle="modal" data-target="#myModal"><i class="icon icon-plus-sign"></i> 添加</button>
             </div>
         </div>
+        <br>
 
-        <div class="col-xs-3">
-            <div class="input-group">
-                <button class="btn btn-primary " type="button">查询</button>
-            </div>
+        <div class="row">
+             <!-- 使用一个div来显示数据表格 -->
+            <div class="datatable" data-checkable="true" data-sortable="true"></div 
         </div>
-        <div style="float:right;">
-            <button class="btn btn-success" type="button" data-toggle="modal" data-target="#myModal"><i class="icon icon-plus-sign"></i> 添加</button>
+        <div class="row" style="text-align:center">
+            <ul class="pager center-block">
+                <li class="previous"><a href="#">« 上一页</a></li>
+                <li><a href="#">1</a></li>
+                <li><a href="#">2</a></li>
+                <li><a href="#">3</a></li>
+                <li><a href="#">4</a></li>
+                <li><a href="#">5</a></li>
+                <li class="next"><a href="#">下一页 »</a></li>
+            </ul>
         </div>
     </div>
-    <br>
-
-    <div class="row">
-        <!-- 使用一个div来显示数据表格 -->
-        <div class="datatable" data-checkable="true" data-sortable="true"></div>
-    </div>
-    <div class="row" style="text-align:center">
-        <ul class="pager center-block">
-            <li class="previous"><a href="#">« 上一页</a></li>
-            <li><a href="#">1</a></li>
-            <li class="active"><a href="#">2</a></li>
-            <li><a href="#">3</a></li>
-            <li><a href="#">4</a></li>
-            <li><a href="#">5</a></li>
-            <li class="next"><a href="#">下一页 »</a></li>
-        </ul>
-    </div>
-</div>
-<!-- 对话框HTML -->
-<div class="modal fade" id="myModal">
+    <!-- 对话框HTML -->
+    <div class="modal fade" id="myModal">
     <div class="modal-dialog">
         <div class="modal-content">
-
+            
         </div>
         <div class="modal-content">
-            <div class="modal-header">
-                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
-                <h4 class="modal-title">添加常量</h4>
-            </div>
-            <div class="modal-body">
-                <link rel="import" href="/view/constant/add.html?__inline">
-            </div>
-        </div>
+      <div class="modal-header">
+        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
+        <h4 class="modal-title">添加常量</h4>
+      </div>
+      <div class="modal-body">
+        <link rel="import" href="/view/constant/add.html?__inline">
+      </div>
     </div>
-</div>
+    </div>
+    </div>
+
 <script>
     $(document).ready(function() {
-        // 使用data参数更新数据:
-        $('.datatable').datatable({
-            checkable: false,
-            sortable: false,
-            data: {
-                cols: [{
-                    width: 80,
-                    text: '序号',
-                    type: 'number',
-                    flex: false,
-                    colClass: 'text-center'
-                }, {
-                    width: 80,
-                    text: '代码编号',
-                    type: 'date',
-                    flex: false,
-                    sort: 'down'
-                }, {
-                    width: 80,
-                    text: '代码名称',
-                    type: 'string',
-                    flex: true,
-                    colClass: ''
-                }, {
-                    width: 80,
-                    text: '有效标志',
-                    type: 'date',
-                    flex: false,
-                    sort: 'down'
-                }, {
-                    width: 80,
-                    text: '代码标识',
-                    type: 'string',
-                    flex: true,
-                    colClass: ''
-                }, {
-                    width: 160,
-                    text: '标识名称',
-                    type: 'date',
-                    flex: false,
-                    sort: 'down'
-                }, {
-                    width: 80,
-                    text: '备注',
-                    type: 'string',
-                    flex: true,
-                    colClass: ''
-                }, {
-                    width: 160,
-                    text: '操作',
-                    type: 'string',
-                    flex: true,
-                    colClass: ''
-                }],
-                rows: [{
-                        checked: false,
-                        data: [1, '1', '上行', '1', 'DIRECTION', '方向', '未稽查', '<a href="#" data-toggle="modal" data-target="#myModal"><i class="icon icon-edit"></i> 修改</a><a href="#"><i class="icon icon-remove-circle"></i> 删除</a>']
-                    }, {
-                        checked: false,
-                        data: [2, '2', '下行', '1', 'DIRECTION', '方向', '未稽查', '<a href="#" data-toggle="modal" data-target="#myModal"><i class="icon icon-edit"></i> 修改</a><a href="#"><i class="icon icon-remove-circle"></i> 删除</a>']
-                    },
-                    // 更多数据
-                ]
-            }
-        });
+        getConstant();
     });
 </script>

+ 98 - 0
VisualInspection/view/constant/util.js

@@ -0,0 +1,98 @@
+function doajax(method, dataurl, data, sucessCallBack, errorCallBack) {
+    var user_key = undefined;
+    var user = $.zui.store.get("user")
+    if (typeof(user) == "undefined" || user == null) {
+
+    } else {
+        user_key = "XinTong " + (user.token);
+    }
+    if (typeof(user_key) == "undefined" || user_key == null) {
+        $.ajax({
+            type: method,
+            url: dataurl,
+            contentType: "application/json",
+            dataType: "json",
+            async: true,
+            data: JSON.stringify(data),
+            success: sucessCallBack,
+            error: function(error) {
+                if (HandleError(error)) return;
+                errorCallBack(error);
+            }
+        })
+    } else {
+
+        $.ajax({
+            type: method,
+            url: dataurl,
+            contentType: "application/json",
+            dataType: "json",
+            beforeSend: function(xhr) {
+                xhr.setRequestHeader("token", user_key);
+            },
+            headers: {
+                'token': user_key
+            },
+            async: true,
+            data: JSON.stringify(data),
+            success: sucessCallBack,
+            error: function(error) {
+                if (HandleError(error)) return;
+                errorCallBack(error);
+            }
+        })
+    }
+
+}
+
+function ajaxGet(dataurl, data, sucessCallBack, errorCallBack) {
+
+    doajax("GET", dataurl, data, sucessCallBack, errorCallBack)
+}
+
+function ajaxPost(dataurl, data, sucessCallBack, errorCallBack) {
+
+    doajax("POST", dataurl, data, sucessCallBack, errorCallBack)
+
+}
+
+function ajaxPut(dataurl, data, sucessCallBack, errorCallBack) {
+
+    doajax("PUT", dataurl, data, sucessCallBack, errorCallBack)
+}
+
+function ajaxDelete(dataurl, data, sucessCallBack, errorCallBack) {
+
+    doajax("DELETE", dataurl, data, sucessCallBack, errorCallBack)
+
+}
+
+
+function HandleError(error) {
+    if (typeof(error) != "undefined" && error != null) {
+        if (typeof(error.status) != "undefined" && error.status != null) {
+            if (error.status == 403) {
+                //未登录退出
+                swal({
+                    title: "提示",
+                    text: "登陆已经过期,将重新登陆!",
+                    timer: 3000,
+                    showConfirmButton: false
+                }, function() {
+
+                    self.location = base_ui_url + UI_USER_LOGIN
+                });
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
+
+// var ViewMap = new HashMap()
+// ViewMap.set("/view/mytask/unchecked.html", __inline('/view/mytask/unchecked.html'));
+// ViewMap.set("/view/mytask/unexamined.html", __inline('/view/mytask/unexamined.html'));
+// ViewMap.set("/view/mytask/undispatched.html", __inline('/view/mytask/undispatched.html'));
+// ViewMap.set("/view/mytask/dispatched.html", __inline('/view/mytask/dispatched.html'));
+// ViewMap.set("/view/constant/constant.html", __inline('/view/constant/constant.html'));

+ 13 - 5
VisualInspection_server/src/main/java/com/xintong/visualinspection/controller/ConstantController.java

@@ -5,13 +5,17 @@ import java.util.List;
 import javax.validation.Valid;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.mysql.jdbc.StringUtils;
 import com.xintong.system.err.BusinessException;
 import com.xintong.visualinspection.bean.Constant;
+import com.xintong.visualinspection.bean.User;
 import com.xintong.visualinspection.service.ConstantService;
 
 /**
@@ -111,12 +115,16 @@ public class ConstantController extends BaseController {
      * @exception
      * @since  1.0.0
      */
-    @RequestMapping(value = "/getConstantByName")
-    public String getConstantByName(@RequestBody Constant constant){
+    @RequestMapping(value = "/getConstantByName/{page}/{size}")
+    public String getConstantByName(@PathVariable Integer page,@PathVariable Integer size, @RequestBody Constant constant){
+    	PageHelper.startPage(page, size); 
+    	List<Constant> constantList;
     	if(StringUtils.isNullOrEmpty(constant.getFlag_name())){
-    		throw new BusinessException(20103);
+//    		throw new BusinessException(20103);
+    		constantList = constantService.getAll();
+    	}else{
+    		constantList = constantService.getByName(constant.getFlag_name());
     	}
-    	List<Constant> constantList = constantService.getByName(constant.getFlag_name());
-    	return super.returnSuccessResult(constantList);
+    	return super.returnSuccessResult(new PageInfo(constantList));
     }
 }

+ 2 - 2
VisualInspection_server/src/main/java/com/xintong/visualinspection/mapper/master/ConstantMapper.xml

@@ -34,8 +34,8 @@
      <select id="getByName" parameterType="String" resultMap="BaseResultMap" >
         SELECT *
         FROM sys_code
-        WHERE flag_name like CONCAT('%',#{flag_name},'%') 
-          and valid!=0
+        WHERE valid!=0
+        	and flag_name like CONCAT('%',#{flag_name},'%')
     </select>
     
     <select id="getByFlagAndValue" parameterType="com.xintong.visualinspection.bean.Constant" resultMap="BaseResultMap" >