Browse Source

提交版本控制相关

caiaolin 7 years ago
parent
commit
00f1636264

+ 6 - 0
config/menu.js

@@ -48,6 +48,12 @@ let menuData = {
             }
         }
     },
+    'version': {
+        title: '版本管理',
+        url: '/version',
+        name: 'version',
+        iconClass: 'glyphicon glyphicon-tag'
+    },
     'tool': {
         title: '工具',
         url: '/tool',

+ 1 - 1
modules/common/helper/mongoose_helper.js

@@ -54,7 +54,7 @@ class MongooseHelper {
         let self = this;
         let limit = 0;
         let skip = 0;
-        if (Object.keys(option).length > 0) {
+        if (option !== null && Object.keys(option).length > 0) {
             limit = option.pageSize !== undefined ? option.pageSize : limit;
             skip = option.offset !== undefined ? option.offset : skip;
         }

+ 128 - 0
modules/users/controllers/version_controller.js

@@ -0,0 +1,128 @@
+/**
+ * 版本控制控制器
+ *
+ * @author CaiAoLin
+ * @date 2017/7/28
+ * @version
+ */
+import BaseController from "../../common/base/base_controller";
+import VersionModel from "../models/version_model";
+
+class VersionController extends BaseController {
+
+    /**
+     * 版本控制页面
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async index(request, response) {
+        let id = request.query.id;
+
+        let versionList = [];
+        // @todo 后续从库中获取
+        let province = [
+            {id: 1, name: '重庆省'},
+            {id: 2, name: '广东省'},
+        ];
+
+        let billList = {
+            1: [
+                {id: '1', name: '重庆2017标准清单'},
+                {id: '2', name: '重庆2015标准清单'}
+            ],
+            2: [
+                {id: '3', name: '广东2017标准清单'},
+                {id: '4', name: '广东2015标准清单'},
+            ]
+        };
+
+        let rationList = {
+            1: [
+                {id: '1', name: '重庆2017定额'},
+                {id: '2', name: '重庆2015定额'}
+            ],
+            2: [
+                {id: '3', name: '广东2017定额'},
+                {id: '4', name: '广东2015定额'}
+            ]
+        };
+        let selectedVersion = {};
+        try {
+            let versionModel = new VersionModel();
+            versionList = await versionModel.getVersionList();
+
+            if (versionList.length <= 0) {
+                throw '没有数据';
+            }
+            // 循环查找数据
+            for (let tmp of versionList) {
+                if (tmp._id.toString() === id) {
+                    selectedVersion = tmp;
+                    break;
+                }
+            }
+
+            selectedVersion = Object.keys(selectedVersion).length <= 0 ? versionList[0] : selectedVersion;
+
+        } catch (error) {
+            console.log(error);
+        }
+
+        let renderData = {
+            id: id,
+            versionList: versionList,
+            selectedVersion: selectedVersion,
+            billList: JSON.stringify(billList),
+            rationList: JSON.stringify(rationList),
+            province: JSON.stringify(province),
+            layout: 'users/views/layout/layout'
+        };
+
+        response.render('users/views/version/index', renderData);
+    }
+
+    /**
+     * 新增版本操作
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async add(request, response) {
+        let name = request.body.name;
+        let standardBillId = request.body.standard_bill_id;
+        let standardBill = request.body.standard_bill;
+        let rationLibId = request.body.ration_lib_id;
+        let rationLib = request.body.ration_lib;
+
+        let responseData = {
+            err: 0,
+            msg: ''
+        };
+        try {
+            let insertData = {
+                name: name,
+                standard_bill: [{id: standardBillId, name: standardBill}],
+                ration_lib: [{id: rationLibId, name: rationLib}]
+            };
+
+            let versionModel = new VersionModel();
+            let result = await versionModel.add(insertData);
+
+            if (!result) {
+                throw '新增版本失败';
+            }
+        } catch (error) {
+            console.log(error);
+            responseData.err = 1;
+            responseData.msg = error;
+        }
+
+        response.json(responseData);
+    }
+
+}
+
+export default VersionController;

+ 26 - 0
modules/users/models/schemas/version.js

@@ -0,0 +1,26 @@
+/**
+ * 版本管理数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/7/28
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'version';
+let modelSchema = {
+    // 自增id
+    id: {
+        type: Number,
+        index: true
+    },
+    // 名称
+    name: String,
+    // 标准清单
+    standard_bill: Schema.Types.Mixed,
+    // 定额库
+    ration_lib: Schema.Types.Mixed
+};
+let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
+export {model as default, collectionName as collectionName};

+ 70 - 0
modules/users/models/version_model.js

@@ -0,0 +1,70 @@
+/**
+ * 版本管理业务逻辑模型
+ *
+ * @author CaiAoLin
+ * @date 2017/7/28
+ * @version
+ */
+import BaseModel from "../../common/base/base_model";
+import VersionSchema from "./schemas/version";
+
+class VersionModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = VersionSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取版本列表
+     *
+     * @return {Promise}
+     */
+    async getVersionList() {
+        let versionData = await this.findDataByCondition({name: {$ne: ''}}, null, false);
+
+        return versionData === null ? [] : versionData;
+    }
+
+    /**
+     * 设置场景
+     *
+     * @param {string} scene
+     * @return {void}
+     */
+    setScene(scene = '') {
+        switch (scene) {
+            // 新增
+            case 'add':
+                this.model.schema.path('name').required(true);
+                this.model.schema.path('standard_bill').required(true);
+                this.model.schema.path('ration_lib').required(true);
+                break;
+        }
+    }
+
+    /**
+     * 新增版本
+     *
+     * @param {Object} data
+     * @return {Promise}
+     */
+    async add(data) {
+        let result = false;
+        if (Object.keys(data).length <= 0) {
+            return result;
+        }
+
+        result = this.db.create(data);
+        return result;
+    }
+
+}
+
+export default VersionModel;

+ 20 - 0
modules/users/routes/version_route.js

@@ -0,0 +1,20 @@
+/**
+ * 版本管理路由
+ *
+ * @author CaiAoLin
+ * @date 2017/7/28
+ * @version
+ */
+import Express from "express";
+import VersionController from "../controllers/version_controller";
+
+const router = Express.Router();
+const versionController = new VersionController();
+
+module.exports =function (app) {
+    // action定义区域
+    router.get('/', versionController.auth, versionController.init, versionController.index);
+    router.post('/add', versionController.auth, versionController.init, versionController.add);
+
+    app.use("/version", router);
+};

+ 3 - 2
web/users/css/style.css

@@ -126,7 +126,8 @@ body{
   padding-left:124px
 }
 .panel-title>.title-bar{
-  padding-left: 20px
+  padding-left: 20px;
+  padding-right: 20px
 }
 .panel-title>.title-bar>h2,.panel-title>.title-main>h2{
   font-size: 16px;
@@ -293,4 +294,4 @@ body{
 }
 .mb-30 {
   margin-bottom:30px
-}
+}

+ 129 - 0
web/users/js/version.js

@@ -0,0 +1,129 @@
+/**
+ * 版本管理相关js
+ *
+ * @author CaiAoLin
+ * @date 2017/7/28
+ * @version
+ */
+$(document).ready(function() {
+    let isAdding = false;
+    // 初始化数据
+    initVersion();
+
+    // 新增版本
+    $("#add-version").click(function() {
+        try {
+            let [name, standardBill, rationLib, standardBillString, rationLibString] = getAndValidData();
+
+            $.ajax({
+                url: '/version/add',
+                type: 'post',
+                data: {name: name,standard_bill_id: standardBill, ration_lib_id: rationLib,
+                    standard_bill: standardBillString, ration_lib: rationLibString},
+                error: function() {
+                    isAdding = false;
+                },
+                beforeSend: function() {
+                    isAdding = true;
+                },
+                success: function(response) {
+                    isAdding = false;
+                    if (response.err === 0) {
+                        window.location.reload();
+                    } else {
+                        let msg = response.msg === undefined ? '未知错误' : response.msg;
+                        alert(msg);
+                    }
+                }
+            });
+
+        } catch (error) {
+            alert(error);
+        }
+    });
+
+    // 选择省份后读取数据
+    $("select[name='standard_bill_province'],select[name='ration_lib_province']").change(function() {
+        let name = $(this).attr('name');
+
+        let billListData = billList === undefined ? [] : JSON.parse(billList);
+        let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
+        if (billListData.length <= 0 || rationLibData.length <= 0) {
+            return false;
+        }
+        let sourceData = name === 'standard_bill_province' ? billListData : rationLibData;
+        let selectedId = $(this).val();
+        if (sourceData[selectedId] === undefined) {
+            return false;
+        }
+        let defaultString = name === 'standard_bill_province' ? '请选择标准清单' : '请选择定额库';
+        let html = '<option value="">' + defaultString + '</option>';
+        for(let tmp of sourceData[selectedId]) {
+            let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
+            html += tmpHtml;
+        }
+
+        // 渲染
+        let targetSelector = name === 'standard_bill_province' ? $("select[name='standard_bill']") : $("select[name='ration_lib']");
+        targetSelector.children('option').remove();
+        targetSelector.html(html);
+    });
+
+});
+
+/**
+ * 初始化
+ *
+ * @return {void|boolean}
+ */
+function initVersion() {
+    if (province === undefined) {
+        alert('初始化失败!');
+        return false;
+    }
+
+    province = JSON.parse(province);
+    if (province.length <= 0) {
+        alert('省份数据加载失败!');
+        return false;
+    }
+
+    let billProvinceElement = $("select[name='standard_bill_province']");
+    let rationProvinceElement = $("select[name='ration_lib_province']");
+    let html = '';
+    for (let tmp of province) {
+        let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
+        html += tmpHtml;
+    }
+
+    billProvinceElement.children('option').first().after(html);
+    rationProvinceElement.children('option').first().after(html);
+}
+
+/**
+ * 校验数据
+ *
+ * @return {Array}
+ */
+function getAndValidData() {
+    let name = $("input[name='version_name']").val();
+    let standardBill = $("select[name='standard_bill']").val();
+    let rationLib = $("select[name='ration_lib']").val();
+
+    if (name === '') {
+        throw '版本名字不能为空';
+    }
+
+    if (standardBill === '' || standardBill === undefined) {
+        throw '请选择标准清单库';
+    }
+
+    if (rationLib === '' || rationLib === undefined) {
+        throw '请选择定额库';
+    }
+
+    let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
+    let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
+
+    return [name, standardBill, rationLib, standardBillString, rationLibString];
+}

+ 55 - 2
web/users/views/layout/layout.html

@@ -55,12 +55,12 @@
         <%- body %>
     </div>
 </div>
-<div class="modal fade" id="edit-account" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
+<div class="modal fade" id="edit-account" tabindex="-1" role="dialog">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
-                <h4 class="modal-title" id="myModalLabel">编辑账号</h4>
+                <h4 class="modal-title">编辑账号</h4>
             </div>
             <div class="modal-body">
                 <div class="form-group">
@@ -98,4 +98,57 @@
         </div>
     </div>
 </div>
+
+<!-- 弹窗新增版本 -->
+<div class="modal fade" id="addversion" tabindex="-1" role="dialog">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                <h4 class="modal-title">添加新版本</h4>
+            </div>
+            <div class="modal-body">
+                <div class="form-group">
+                    <label>版本名称</label>
+                    <input class="form-control" placeholder="" name="version_name">
+                </div>
+                <div class="form-group">
+                    <label>标准清单</label>
+                    <div class="row">
+                        <div class="col-xs-4">
+                            <select class="form-control" name="standard_bill_province">
+                                <option value="">请选择省份</option>
+                            </select>
+                        </div>
+                        <div class="col-xs-8">
+                            <select class="form-control" name="standard_bill">
+                                <option value="">请选择标准清单</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
+                <div class="form-group">
+                    <label>定额库</label>
+                    <div class="row">
+                        <div class="col-xs-4">
+                            <select class="form-control" name="ration_lib_province">
+                                <option value="">请选择省份</option>
+                            </select>
+                        </div>
+                        <div class="col-xs-8">
+                            <select class="form-control" name="ration_lib">
+                                <option value="">请选择定额库</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
+                <button type="button" class="btn btn-primary" id="add-version">确定添加</button>
+            </div>
+        </div>
+    </div>
+</div>
+
 </body>

+ 99 - 0
web/users/views/version/index.html

@@ -0,0 +1,99 @@
+<div class="panel-sidebar">
+	<div class="panel-title">
+		<div class="title-bar">
+			<h2><a class="pull-right" title="添加新版本" href="javascript:void(0)" data-toggle="modal" data-target="#addversion"><span class="glyphicon glyphicon-plus"></span></a>版本管理</h2>
+		</div>
+	</div>
+	<div class="scrollbar-auto">
+		<div class="nav-box">
+			<ul class="nav-list list-unstyled" id="version-select">
+				<% versionList.forEach(function (version){ %>
+				<li <% if(selectedVersion._id === version._id) { %>class="active"<% } %>><a href="/version?id=<%= version._id %>"><span><%= version.name %></span></a></li>
+				<% }) %>
+			</ul>
+		</div>
+	</div>
+</div>
+<div class="panel-content">
+	<% if(Object.keys(selectedVersion).length > 0) { %>
+	<div class="panel-title">
+		<div class="title-main">
+			<h2><%= selectedVersion.name %><a href="" class="btn btn-primary btn-sm pull-right">确定修改</a></h2>
+		</div>
+	</div>
+	<div class="content-wrap container-fluid">
+		<div class="c-body row">
+			<div class="col-md-4">
+				<div class="form-group">
+					<label>标准清单</label>
+					<div id="bill-list">
+						<% selectedVersion.standard_bill.forEach(function (bill){ %>
+						<p class="form-control-static"><a class="pull-right text-danger" tlte="移除"><span class="glyphicon glyphicon-remove"></span></a><%= bill.name %></p>
+						<% }) %>
+					</div>
+					<a class="btn btn-link btn-sm" href="javascript:void(0)" data-toggle="modal" data-target="#addqingdan">添加</a>
+				</div>
+				<div class="form-group">
+					<label>定额库</label>
+					<div id="ration-list">
+						<% selectedVersion.ration_lib.forEach(function (bill){ %>
+						<p class="form-control-static"><a class="pull-right text-danger" tlte="移除"><span class="glyphicon glyphicon-remove"></span></a><%= bill.name %></p>
+						<% }) %>
+					</div>
+					<a href="#" class="btn btn-link btn-sm">添加</a>
+				</div>
+			</div>
+			<!--<div class="col-md-4">-->
+				<!--<div class="form-group">-->
+					<!--<label >文本选项</label>-->
+					<!--<input type="text" class="form-control" placeholder="输入内容">-->
+				<!--</div>-->
+				<!--<div class="form-group">-->
+					<!--<label >数字选项</label>-->
+					<!--<input type="number" class="form-control" placeholder="输入内容">-->
+				<!--</div>-->
+				<!--<div class="form-group">-->
+					<!--<label >下拉选项</label>-->
+					<!--<select class="form-control"><option>选择1</option><option>选择2</option></select>-->
+				<!--</div>-->
+			<!--</div>-->
+			<!--<div class="col-md-4">-->
+				<!--<div class="form-group">-->
+					<!--<label >多选</label>-->
+					<!--<div>-->
+						<!--<label class="checkbox-inline">-->
+							<!--<input type="checkbox" id="inlineCheckbox1" value="option1"> 1-->
+						<!--</label>-->
+						<!--<label class="checkbox-inline">-->
+							<!--<input type="checkbox" id="inlineCheckbox2" value="option2"> 2-->
+						<!--</label>-->
+						<!--<label class="checkbox-inline">-->
+							<!--<input type="checkbox" id="inlineCheckbox3" value="option3"> 3-->
+						<!--</label>-->
+					<!--</div>-->
+				<!--</div>-->
+				<!--<div class="form-group">-->
+					<!--<label >单选</label>-->
+					<!--<div>-->
+						<!--<label class="radio-inline">-->
+							<!--<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 1-->
+						<!--</label>-->
+						<!--<label class="radio-inline">-->
+							<!--<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> 2-->
+						<!--</label>-->
+						<!--<label class="radio-inline">-->
+							<!--<input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3"> 3-->
+						<!--</label>-->
+					<!--</div>-->
+				<!--</div>-->
+			<!--</div>-->
+		</div>
+	</div>
+	<% } %>
+</div>
+<script type="text/javascript">
+	let province = '<%- province %>';
+	let billList = '<%- billList %>';
+	let rationList = '<%- rationList %>';
+</script>
+<script type="text/javascript" src="/web/users/js/version.js"></script>