Преглед изворни кода

1. 刷新指标数据
2. 单元指标对比

MaiXinRong пре 5 година
родитељ
комит
14f660827c

+ 2 - 1
app.js

@@ -25,6 +25,7 @@ module.exports = app => {
     app.libConst = libConst;
     app.nodeConst = nodeConst;
     app.paramConst = paramConst;
+    app.awaitRefresh = [];
 
     //压缩前端js
     if (app.config.min) {
@@ -38,4 +39,4 @@ module.exports = app => {
         };
         app.minify(['spreadjs_rela/spreadjs_zh.js', 'spreadjs_rela/extend_celltype.js', 'path_tree.js', 'compare.js', 'cookies.js', 'lib_detail.js', 'template.js']);
     }
-}
+};

+ 19 - 0
app/base/base_controller.js

@@ -34,6 +34,10 @@ class BaseController extends Controller {
      * @return {void}
      */
     async layout(view, data = {}, modal = '') {
+        // 获取消息提示
+        let message = this.ctx.session.message;
+        // 取出后删除
+        this.ctx.session.message = null;
         data.moment = moment;
 
         try {
@@ -44,6 +48,7 @@ class BaseController extends Controller {
                 min: this.app.config.min ? '.min' : '',
                 content: contentString,
                 modal: modalString,
+                message,
             };
 
             await this.ctx.render('layout/layout.ejs', renderData);
@@ -51,6 +56,20 @@ class BaseController extends Controller {
             console.log(err);
         }
     }
+
+    /**
+     * 设置提示
+     *
+     * @param {String} message - 提示信息
+     * @param {String} type - 提示类型
+     * @return {void}
+     */
+    setMessage(type, message) {
+        this.ctx.session.message = {
+            type,
+            message,
+        };
+    }
 }
 
 module.exports = BaseController;

+ 2 - 2
app/const/template_param.js

@@ -147,14 +147,14 @@ const defaultNodeParams = [
     }, {
         template_id: 1,
         param_id: 2,
-        code: 'b',
+        code: 'h',
         name: '子项数量1合计',
         match_type: matchType.child_gather,
         match_num: matchNum.dgn_quantity1,
     }, {
         template_id: 1,
         param_id: 3,
-        code: 'c',
+        code: 'i',
         name: '子项数量2合计',
         match_type: matchType.child_gather,
         match_num: matchNum.dgn_quantity2,

+ 33 - 3
app/controller/lib_controller.js

@@ -34,7 +34,7 @@ module.exports = app => {
                 status,
                 libList,
                 libConst,
-                libStatus
+                libStatus,
             };
             await this.layout('lib/index.ejs', renderData, 'lib/modal.ejs');
         }
@@ -118,6 +118,11 @@ module.exports = app => {
                 }
                 //获取指标源数据
                 const libInfo = await ctx.service.quotaLib.getLibDataById(lid);
+                if (libInfo.is_refresh) {
+                    this.setMessage('warning', '当前标段待刷新,暂无法查看');
+                    ctx.redirect('/lib');
+                    return;
+                }
 
                 //获取全局指标参数
                 const condition = {
@@ -125,7 +130,7 @@ module.exports = app => {
                         lib_id: lid,
                         node_id: 0,
                     }
-                }
+                };
                 const globalParams = await ctx.service.tenderParam.getAllDataByCondition(condition);
                 const renderData = {
                     libInfo,
@@ -156,6 +161,15 @@ module.exports = app => {
                 }
                 //获取指标源数据
                 const libInfo = await ctx.service.quotaLib.getLibDataById(lid);
+                if (libInfo.is_refresh) {
+                    if (this.ctx.service.awaitRefresh && this.ctx.service.awaitRefresh.indexOf(lid) >= 0) {
+                        this.setMessage('warning', '当前标段待刷新,暂无法查看');
+                        ctx.redirect('/lib');
+                        return;
+                    } else {
+                        this.setMessage('error', '当前标段刷新失败,可尝试选择该项目再次刷新');
+                    }
+                }
                 //改变是否第一次进入detail页
                 if(libInfo.openitem_tab === 0){
                     const reuslt = await ctx.service.quotaLib.updateOpenItemTab(lid);
@@ -313,7 +327,6 @@ module.exports = app => {
             ctx.body = responseData;
         }
 
-
         /**
          * 获取指标和参数信息
         *
@@ -347,6 +360,23 @@ module.exports = app => {
             ctx.body = responseData;
         }
 
+        async refresh (ctx) {
+            try {
+                const id = ctx.query.id ? parseInt(ctx.query.id) : -1;
+
+                if (isNaN(id) || id < 0) {
+                    await ctx.service.quotaLib.refreshAll();
+                } else {
+                    const lib = await ctx.service.quotaLib.getDataById(id);
+                    await ctx.service.quotaLib.refreshLib(lib);
+                }
+
+                ctx.redirect(ctx.request.headers.referer);
+            } catch (err) {
+                ctx.redirect(ctx.request.headers.referer);
+            }
+        }
+
     }
 
     return LibController;

+ 16 - 0
app/io/middleware/connection.js

@@ -0,0 +1,16 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+module.exports = app => {
+    return async (ctx, next) => {
+        ctx.socket.emit('res', 'connected!');
+        await next();
+    };
+};

Разлика између датотеке није приказан због своје велике величине
+ 233 - 0
app/public/css/toastr.css


+ 67 - 0
app/public/js/lib_socket.js

@@ -0,0 +1,67 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+window.onload = function() {
+    // init
+    const socket = io('/lib', {
+
+        // 实际使用中可以在这里传递参数
+        query: {
+            room: 'lib',
+            userId: `client_${Math.random()}`,
+        },
+
+        transports: ['websocket']
+    });
+
+    socket.on('connect', () => {
+        const id = socket.id;
+
+        console.log('#connect,', id, socket);
+
+        // 监听自身 id 以实现 p2p 通讯
+        socket.on(id, msg => {
+            console.log('#receive,', msg);
+        });
+    });
+
+    socket.on('refreshed', msg => {
+        if (msg.success) {
+            $('tr[lib_id="' + msg.id + '"]').removeClass('table-active');
+            toastr.success('造价文件"' + msg.filename + '"刷新完成');
+        } else {
+            $('tr[lib_id="' + msg.id + '"]').find('td:first').append('<a class="fa fa-refresh text-primary" href="/lib/refresh?id=' + msg.id + '" title="再次刷新"></a>');
+            toastr.error('造价文件"' + msg.filename + '"刷新失败,请重试');
+        }
+
+        if (msg.count === 0) {
+            $('#refresh-btn').show();
+            $('#refresh-hint').hide();
+        } else if (msg.count > 0) {
+            $('#refresh-btn').hide();
+            $('#refresh-hint').show().html('正在刷新全部造价文件,未刷新完成的造价文件,暂时无法查看(待刷新:' + msg.count + ')');
+        }
+    });
+
+    // 系统事件
+    socket.on('disconnect', msg => {
+        console.log('#disconnect', msg);
+    });
+
+    socket.on('disconnecting', () => {
+        console.log('#disconnecting');
+    });
+
+    socket.on('error', () => {
+        console.log('#error');
+    });
+
+    window.socket = socket;
+};

Разлика између датотеке није приказан због своје велике величине
+ 9 - 0
app/public/js/socket.io.js


Разлика између датотеке није приказан због своје велике величине
+ 7 - 0
app/public/js/toastr.min.js


+ 37 - 0
app/public/js/unit_compare.js

@@ -311,11 +311,39 @@ $(document).ready(() => {
             $('#generate-data').modal('hide');
         },
         loadParentNode: function () {
+            const compareCode = function (str1, str2, symbol = '-') {
+                if (!str1) {
+                    return -1;
+                } else if (!str2) {
+                    return 1;
+                }
+
+                const path1 = str1.split(symbol);
+                const path2 = str2.split(symbol);
+                const reg = /^[0-9]*$/;
+                for (let i = 0, iLen = Math.min(path1.length, path2.length); i < iLen; i++) {
+                    if (reg.test(path1[i]) && reg.test(path2[i])) {
+                        const num1 = parseInt(path1[i]);
+                        const num2 = parseInt(path2[i]);
+                        if (num1 !== num2)  {
+                            return num1 - num2;
+                        }
+                    } else if (path1[i] < path2[i]) {
+                        return -1;
+                    } else if (path1[i] > path2[i]) {
+                        return 1;
+                    }
+                }
+                return path1.length - path2.length;
+            };
             const history = compareObj.cacheList.find(function (l) {
                 return l.lib_id === compareObj.data.lib_id && l.className === compareObj.data.className;
             });
             if (!history) {
                 postData(window.location.pathname + '/parent', compareObj.data, function (result) {
+                    result.sort(function (x, y) {
+                        return compareCode(x.code, y.code);
+                    });
                     compareObj.cacheList.push({lib_id: compareObj.data.lib_id, className: compareObj.data.className, xList: result});
                     compareObj.generateXList(result);
                 });
@@ -399,4 +427,13 @@ $(document).ready(() => {
         }
         compareObj.load();
     });
+    $('#export-excel').click(function () {
+        const excelIo = new GC.Spread.Excel.IO();
+        const date = new Date();
+        const fileName = '单元对比.' + date.Format("yyyy.MM.dd.hh.mm.ss") + '.xlsx';
+        const sJson = JSON.stringify(spread.toJSON());
+        excelIo.save(sJson, function(blob) {
+            saveAs(blob, fileName);
+        });
+    });
 });

+ 1 - 0
app/router.js

@@ -24,6 +24,7 @@ module.exports = app => {
     app.post('/lib/getParamAndIndex', sessionAuth, 'libController.getParamAndIndex');
     app.post('/lib/delete', sessionAuth, 'libController.delete');
     app.post('/lib/enter', sessionAuth, 'libController.enter');
+    app.get('/lib/refresh', sessionAuth, 'libController.refresh');
 
     // 指标模板
     app.get('/template', sessionAuth, 'templateController.index');

+ 45 - 0
app/schedule/refresh_lib.js

@@ -0,0 +1,45 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+module.exports = {
+    schedule: {
+        // interval: '30s', // 30 seconds, for dev
+        interval: '5m', // 5 min, for opr
+        type: 'worker',
+    },
+    async task (ctx) {
+        if (!ctx.app.awaitRefresh || ctx.app.awaitRefresh.length === 0) return;
+
+        const lib = await ctx.service.quotaLib.getDataById(ctx.app.awaitRefresh.shift());
+        if (!lib) return;
+
+        const nsp = ctx.app.io.of('/lib');
+        try {
+            // test error
+            // throw '1';
+            await ctx.service.quotaLib.refreshLib(lib);
+
+            nsp.emit('refreshed', {
+                id: lib.id,
+                filename: lib.filename,
+                success: true,
+                count: ctx.app.awaitRefresh.length,
+            });
+        } catch(err) {
+            console.log(err);
+            nsp.emit('refreshed', {
+                id: lib.id,
+                filename: lib.filename,
+                success: false,
+                count: ctx.app.awaitRefresh.length,
+            });
+        }
+    }
+};

+ 47 - 1
app/service/match.js

@@ -260,7 +260,8 @@ module.exports = app => {
         }
 
         _getXMatchId(bills) {
-            const reg = /-([a-z])-/i;
+            //const reg = /-([a-z])-/i;
+            const reg = /-([a-z])/i;
             if (reg.test(bills.match_key)) {
                 const ruleParts = bills.match_key.split('-');
                 const charReg = /(^[a-z]+$)/i;
@@ -347,6 +348,51 @@ module.exports = app => {
                 delete b.match_key;
             }
         }
+
+        _syncCustomData(data, custom) {
+            if (!custom || custom.length === 0) return;
+
+            for (const d of data) {
+                const c = custom.find(function (x) {return x.name === d.name});
+                d.calc_value = c.calc_value;
+            }
+        }
+
+        async reMatchBills(lib, templateId = 1) {
+            const bills = await this.ctx.service.bills.getAllDataByCondition({ where: {lib_id: lib.id} });
+            this._init(bills);
+            for (const b of bills) {
+                b.match_node = null;
+            }
+            // 获取指标模板全部数据
+            await this._getTemplateData(templateId);
+            // 同步全局指标参数
+            this._syncNodeParam(paramConst.globalParamNodeId, paramConst.globalParamNodeId, this.bills[0]);
+            // 遍历模板中所有指标节点,匹配清单
+            for (const node of this.templateNodes) {
+                this._matchNode(node);
+            }
+            // 计算全部指标节点
+            const globalParams = this.params.filter(function (p) {
+                return p.node_id === paramConst.globalParamNodeId;
+            });
+            const ogp = await this.ctx.service.tenderParam.getAllDataByCondition({ where: {lib_id: lib.id} });
+            this._syncCustomData(globalParams, ogp);
+            for (const node of this.nodes) {
+                const nodeParams = this.params.filter(function (n) {
+                    return n.node_id === node.node_id;
+                });
+                const onp = await this.ctx.service.tenderParam.getParams(lib.id, node.bills_id);
+                this._syncCustomData(nodeParams, onp);
+                const nodeIndexes = this.indexes.filter(function (i) {
+                    return i.node_id === node.node_id;
+                });
+                this.ctx.service.indexCalc.calculate(nodeIndexes, globalParams, nodeParams);
+            }
+            for (const b of this.bills) {
+                delete b.match_key;
+            }
+        }
     }
 
     return Match;

+ 44 - 0
app/service/quota_lib.js

@@ -8,6 +8,7 @@
  * @version
  */
 const libConst = require('../const/lib');
+const _ = require('lodash');
 module.exports = app => {
 
     class QuotaLib extends app.BaseService {
@@ -198,7 +199,50 @@ module.exports = app => {
             }
         }
 
+        async _setRefreshAllTag() {
+            const sql = 'Update ' + this.tableName + ' set is_refresh = true';
+            await this.db.query(sql);
+        }
+
+        async refreshLib(lib) {
+            //const billsData = await this.ctx.service.bills.getAllDataByCondition({ where: {lib_id: lib.id} });
+
+            //const orgGlobalParam = await this.ctx.service.tenderParam.getParam(lib.id, paramConst.globalParamNodeId);
+            //const orgParam = await this.ctx.service.tenderParam.getParam(lib.id);
+            //const orgParam = await this.ctx.service.tenderParam.getAllDataByCondition({ where: {lib_id: lib.id} });
 
+            await this.ctx.service.match.reMatchBills(lib);
+
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.delete(this.ctx.service.tenderNode.tableName, {lib_id: lib.id});
+                if (this.ctx.service.match.nodes.length > 0) {
+                    const nodeResult = await this.ctx.service.tenderNode.insertData(this.ctx.service.match.nodes, conn);
+                }
+                await conn.delete(this.ctx.service.tenderIndex.tableName, {lib_id: lib.id});
+                if (this.ctx.service.match.indexes.length > 0) {
+                    const indexResult = await this.ctx.service.tenderIndex.insertData(this.ctx.service.match.indexes, conn);
+                }
+                await conn.delete(this.ctx.service.tenderParam.tableName, {lib_id: lib.id});
+                if (this.ctx.service.match.params.length > 0) {
+                    const paramResult = await this.ctx.service.tenderParam.insertData(this.ctx.service.match.params, conn);
+                }
+                await conn.update(this.tableName, {id: lib.id, is_refresh: false});
+                await conn.commit();
+            } catch(err) {
+                await conn.rollback();
+            }
+        }
+
+        async _refreshAll() {
+            const libs = await this.getAllDataByCondition({ where: { is_refresh: true } });
+            this.ctx.app.awaitRefresh = _.map(libs, 'id');
+        }
+
+        async refreshAll() {
+            await this._setRefreshAllTag();
+            this._refreshAll();
+        }
     }
 
     return QuotaLib;

+ 1 - 1
app/service/tender_node.js

@@ -46,7 +46,7 @@ module.exports = app => {
         async searchParent(tenderId, className) {
             const sql = 'SELECT tn.bills_xid, qb.code, qb.name, qb.units, qb.dgn_quantity1, qb.dgn_quantity2, qb.dgn_price, qb.total_price' +
                 '  FROM ' + this.tableName + ' As tn' +
-                '  LEFT JOIN ' + this.ctx.service.bills.tableName + ' As qb ON tn.bills_xid = qb.n_id' +
+                '  LEFT JOIN ' + this.ctx.service.bills.tableName + ' As qb ON tn.bills_xid = qb.n_id and tn.lib_id = qb.lib_id' +
                 '  WHERE tn.`lib_id` = ? and tn.class_name = ?' +
                 '  GROUP By tn.bills_xid' +
                 '  ORDER By qb.code ASC';

+ 9 - 0
app/service/tender_param.js

@@ -24,6 +24,15 @@ module.exports = app => {
             this.tableName = 'tender_param';
         }
 
+        async getParams(libId, billsId) {
+            const sql = 'Select p.*, n.bills_id From ' + this.tableName + ' p' +
+                '  LEFT JOIN ' + this.ctx.service.tenderNode.tableName + ' n' +
+                '  On p.node_id = n.node_id and p.lib_id = n.lib_id' +
+                '  Where p.lib_id = ? and n.bills_id = ?';
+            const sqlParam = [libId, billsId];
+            return await this.db.query(sql, sqlParam);
+        }
+
         /**
          * 计算指标节点下全部指标
          * @param transaction - 事务

+ 1 - 1
app/view/compare/index.ejs

@@ -29,7 +29,7 @@
                 </div>
             </div>
             <div>
-                <a href="javascript: void(0)" class="btn btn-primary btn-sm pull-right" target="_blank" id="export-excel"><i class="fa fa-file-excel-o"></i> 导出Excel</a>
+                <a href="javascript: void(0)" class="btn btn-primary btn-sm pull-right" id="export-excel"><i class="fa fa-file-excel-o"></i> 导出Excel</a>
             </div>
         </div>
     </div>

+ 32 - 0
app/view/layout/layout.ejs

@@ -15,6 +15,8 @@
     <link rel="stylesheet" href="/public/css/spreadjs/sheets/gc.spread.sheets.excelsmartcost.css">
     <!--jquery-contextmenu-->
     <link rel="stylesheet" href="/public/css/jquery-contextmenu/jquery.contextMenu.min.css">
+    <!--toastr-->
+    <link rel="stylesheet" href="/public/css/toastr.css">
 
     <script src="/public/js/jquery/jquery-3.2.1.min.js"></script>
     <script src="/public/js/popper/popper.min.js"></script>
@@ -24,6 +26,8 @@
     <!--jquery-contextmenu-->
     <script src="/public/js/jquery-contextmenu/jquery.ui.position.min.js"></script>
     <script src="/public/js/jquery-contextmenu/jquery.contextMenu.min.js"></script>
+    <!--toastr-->
+    <script src="/public/js/toastr.min.js"></script>
 </head>
 
 <body>
@@ -72,6 +76,34 @@
 <script src="/public/js/global.js"></script>
 <script type="text/javascript">
     autoFlashHeight();
+
+    toastr.options = {
+        "closeButton": false,
+        "debug": false,
+        "newestOnTop": false,
+        "progressBar": false,
+        "positionClass": "toast-top-center",
+        "preventDuplicates": false,
+        "onclick": null,
+        "showDuration": "300",
+        "hideDuration": "1000",
+        "timeOut": "5000",
+        "extendedTimeOut": "1000",
+        "showEasing": "swing",
+        "hideEasing": "linear",
+        "showMethod": "fadeIn",
+        "hideMethod": "fadeOut"
+    };
+    let toastInfo = '<%- JSON.stringify(message) %>';
+    try {
+        toastInfo = toastInfo !== '' && toastInfo !== 'null' ? JSON.parse(toastInfo) : '';
+    } catch (error) {
+        toastInfo = '';
+    }
+
+    if (toastInfo !== '') {
+        toastr[toastInfo.type](toastInfo.message);
+    }
 </script>
 </body>
 

+ 15 - 3
app/view/lib/index.ejs

@@ -26,6 +26,11 @@
             </div>
             <div>
                 <a href="#upload" data-toggle="modal" data-target="#upload" class="btn btn-primary btn-sm pull-right">导入造价文件</a>
+                <a href="#refresh" data-toggle="modal" data-target="#refresh" class="btn btn-info btn-sm pull-right"
+                   id="refresh-btn" <% if (ctx.app.awaitRefresh && ctx.app.awaitRefresh.length > 0) { %>style="display: none"<% } %>>刷新指标数据</a>
+                <div class="pull-right text-warning" id="refresh-hint" <% if (!ctx.app.awaitRefresh || ctx.app.awaitRefresh.length === 0) { %>style="display: none"<% } %>>
+                    正在刷新全部造价文件,未刷新完成的造价文件,暂时无法查看(待刷新:<%- ctx.app.awaitRefresh ? ctx.app.awaitRefresh.length : 0 %>)
+                </div>
             </div>
         </div>
     </div>
@@ -41,8 +46,13 @@
                     </tr>
                     <% if(libList.length > 0) { %>
                     <% libList.forEach(function(lib) { %>
-                    <tr>
-                        <td><a href="/lib/global/<%= lib.id %>"><%= lib.filename %></a></td>
+                    <tr <% if (lib.is_refresh) { %>class="table-active"<% } %> lib_id="<%- lib.id %>">
+                        <td>
+                            <a href="/lib/global/<%= lib.id %>"><%= lib.filename %></a>
+                            <% if (lib.is_refresh && ctx.app.awaitRefresh.indexOf(lib.id) < 0) { %>
+                            <a href="/lib/refresh?id=<%- lib.id %>" class="fa fa-refresh text-primary" title="再次刷新"></a>
+                            <% } %>
+                        </td>
                         <td><%= lib.create_time > 0 ? moment(lib.create_time * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' %> </td>
                         <td><% if(lib.status === 1) { %><a href="/lib/global/<%= lib.id %>" class="btn btn-sm btn-outline-primary">填写参数</a> <% } else { %><%= lib.enter_time > 0 ? moment(lib.enter_time * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' %> 入库<% } %></td>
                     </tr>
@@ -52,4 +62,6 @@
             </div>
         </div>
     </div>
-</div>
+</div>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
+<script src="/public/js/lib_socket.js"></script>

+ 17 - 0
app/view/lib/modal.ejs

@@ -21,6 +21,23 @@
         </div>
     </div>
 </div>
+<div id="refresh" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">刷新指标数据</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+            </div>
+            <div class="modal-body">
+                <h5>确认刷新所有指标数据?</h5>
+            </div>
+            <form class="modal-footer" action="/lib/refresh" method="GET">
+                <button class="btn btn-primary" type="submit">确认刷新</button>
+                <button class="btn btn-secondary" data-dismiss="modal" aria-hidden="true">关闭</button>
+            </form>
+        </div>
+    </div>
+</div>
 <script>
     function checkfileupload() {
         if($('#exampleFormControlFile1').val() == ''){

+ 1 - 1
app/view/unit_compare/index.ejs

@@ -19,7 +19,7 @@
             </div>
             <div class="ml-auto">
                 <div class="d-inline-block">
-                    <a href="search-Library-print.html" class="btn btn-primary btn-sm" target="_blank"><i class="fa fa-file-excel-o"></i> 导出Excel</a>
+                    <a href="javascript: void(0);" class="btn btn-primary btn-sm" id="export-excel"><i class="fa fa-file-excel-o"></i> 导出Excel</a>
                 </div>
             </div>
         </div>

+ 35 - 0
builder.js

@@ -0,0 +1,35 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const Uglyfy = require('uglify-es');
+const fs = require('fs');
+const path = require('path');
+const filePath = path.join(__dirname, 'app', 'public', 'js'); // __dirname + '/app/public/js';
+
+fs.readdir(filePath, function (err, files) {
+    if (err) {
+        console.warn(err)
+    } else {
+        for (const f of files) {
+            const file = filePath + '/' + f;
+            if (file.indexOf('.min.') >= 0) continue;
+
+            fs.stat(file, function (err, stats) {
+                const fileInfo = path.parse(file);
+                if (!err) {
+                    if (stats.isFile()) {
+                        const code = fs.readFileSync(file, 'utf8');
+                        fs.writeFileSync(path.join(fileInfo.dir, fileInfo.name + '.min.js'), Uglyfy.minify(code, {mangle: true}).code);
+                    }
+                }
+            });
+        }
+    }
+});

+ 26 - 1
config/config.default.js

@@ -17,7 +17,7 @@ module.exports = appInfo => {
             // 用户名
             user: 'root',
             // 密码
-            password: 'root',
+            password: 'VHbSBiBerJhgkJt3',
             // 数据库名
             database: 'index_sys',
         },
@@ -56,6 +56,31 @@ module.exports = appInfo => {
         fileSize: '10mb',
     };
 
+    //web-socket
+    config.io = {
+        init: {},
+        namespace: {
+            '/': {
+                connectionMiddleware: [],
+                packetMiddleware: [],
+            },
+            '/lib': {
+                connectionMiddleware: [],
+                packetMiddleware: [],
+            }
+        },
+        redis: {
+            // host
+            host: '127.0.0.1',
+            // 端口号
+            port: '6379',
+            // 用户名
+            auth_pass: '123456',
+            // 密码
+            db: '8',
+        }
+    };
+
     // 是否压缩替换前端js
     config.min = true;
 

+ 5 - 0
config/plugin.js

@@ -11,4 +11,9 @@ exports.ejs = {
 exports.mysql = {
     enable: true,
     package: 'egg-mysql',
+};
+// socket.io
+exports.io = {
+    enable: true,
+    package: 'egg-socket.io',
 };

+ 6 - 4
package.json

@@ -10,8 +10,10 @@
     "egg-mysql": "^3.0.0",
     "egg-redis": "^2.0.0",
     "egg-scripts": "^2.5.0",
+    "egg-socket.io": "^4.1.6",
     "egg-view": "^2.1.0",
     "egg-view-ejs": "^2.0.0",
+    "lodash": "^4.17.15",
     "mathjs": "^4.1.2",
     "node-xlsx": "^0.12.0",
     "stream-to-array": "^2.3.0",
@@ -32,11 +34,11 @@
     "node": ">=8.9.0"
   },
   "scripts": {
-    "start": "egg-scripts start --daemon --title=egg-server-index_sys --port 7003",
+    "start": "egg-scripts start --daemon --title=egg-server-index_sys --port 7003 --sticky",
     "stop": "egg-scripts stop --title=egg-server-index_sys",
-    "dev": "egg-bin dev --port 7003",
-    "dev-qa": "set EGG_SERVER_ENV=qa&&egg-bin dev --port 7003",
-    "dev-local": "set EGG_SERVER_ENV=local&&egg-bin dev --port 7003",
+    "dev": "egg-bin dev --port 7003 --sticky",
+    "dev-qa": "set EGG_SERVER_ENV=qa&&egg-bin dev --port 7003 --sticky",
+    "dev-local": "set EGG_SERVER_ENV=local&&egg-bin dev --port 7003 --sticky",
     "debug": "egg-bin debug",
     "test": "npm run lint -- --fix&&npm run test-local",
     "test-local": "egg-bin test",