Browse Source

wap页面调整和一些bug跳转修复 no.2

laiguoran 5 years ago
parent
commit
68f0256d78

+ 12 - 2
app/controller/wap_controller.js

@@ -31,11 +31,17 @@ module.exports = app => {
             if (!ctx.app.config.is_debug) {
                 await ctx.service.maintain.syncMaintainData();
             }
+            let projectData = '';
+            if (ctx.session.wapTenderID) {
+                const tenderData = await ctx.service.tender.getDataById(ctx.session.wapTenderID);
+                if (tenderData) projectData = await ctx.service.project.getDataById(tenderData.project_id);
+            }
 
             const renderData = {
                 maintainData,
                 maintainConst,
                 errorMessage,
+                projectData,
             };
             await ctx.render('wap/login.ejs', renderData);
         }
@@ -69,7 +75,12 @@ module.exports = app => {
                 const url = needBoot ? '/boot' : '/wap/dashboard';
 
                 const query = URL.parse(ctx.request.header.referer, true).query;
-                ctx.redirect(query.referer ? query.referer : url);
+                let referer = '';
+                if (ctx.session.wapTenderID) {
+                    referer = query.referer ? query.referer + '#shenpi' : url;
+                    ctx.session.wapTenderID = null;
+                }
+                ctx.redirect(referer ? referer : url);
             } catch (error) {
                 this.log(error);
                 ctx.session.loginError = error;
@@ -106,7 +117,6 @@ module.exports = app => {
                 audit.end_qc_tp = ctx.helper.add(audit.qc_tp, audit.pre_qc_tp);
                 audit.end_gather_tp = ctx.helper.add(audit.end_contract_tp, audit.end_qc_tp);
                 audit.pre_gather_tp = ctx.helper.add(audit.pre_contract_tp, audit.pre_qc_tp);
-                console.log(audit);
             }
             const renderData = {
                 auditStages,

+ 9 - 0
app/extend/helper.js

@@ -973,4 +973,13 @@ module.exports = {
         const result = await this.sendRequest(apiUrl, data, 'get');
         return result && result.code && result.code === 1 ? result.ae_url : url;
     },
+
+    /**
+     * 判断是否wap访问
+     * @param request
+     * @returns {*}
+     */
+    isWap(request) {
+        return request.url.indexOf('/wap/') !== -1;
+    },
 }

+ 17 - 7
app/middleware/session_auth.js

@@ -50,14 +50,24 @@ module.exports = options => {
                     data: '',
                 };
             } else if (this.session === null) {
-                return this.redirect('/login?referer=' + this.url);
+                if (this.helper.isWap(this.request)) {
+                    this.session.wapTenderID = this.params.id ? this.params.id : null;
+                    return this.redirect('/wap/login?referer=' + this.url);
+                } else {
+                    return this.redirect('/login?referer=' + this.url);
+                }
             } else {
-                this.session.message = {
-                    type: messageType.ERROR,
-                    icon: 'exclamation-circle',
-                    message: '登录信息异常,请重新登录',
-                };
-                return this.redirect('/login?referer=' + this.url);
+                if (this.helper.isWap(this.request)) {
+                    this.session.wapTenderID = this.params.id ? this.params.id : null;
+                    return this.redirect('/wap/login?referer=' + this.url);
+                } else {
+                    this.session.message = {
+                        type: messageType.ERROR,
+                        icon: 'exclamation-circle',
+                        message: '登录信息异常,请重新登录',
+                    };
+                    return this.redirect('/login?referer=' + this.url);
+                }
             }
         }
         yield next;

+ 5 - 1
app/middleware/tender_check.js

@@ -93,7 +93,11 @@ module.exports = options => {
                 }));
             }
             // 重定向值标段管理
-            this.redirect('/list');
+            if (this.helper.isWap(this.request)) {
+                this.redirect('/wap/list');
+            } else {
+                this.redirect('/list');
+            }
         }
     };
 };

+ 97 - 0
app/public/js/wap/global.js

@@ -0,0 +1,97 @@
+/**
+ * 提示框
+ *
+ * @param string message
+ * @param string type
+ * @param string icon
+ * @return void
+ */
+function toast(message, type, icon) {
+    var toast = $(".toast");
+    toast.addClass(type);
+    toast.children('.message').html(message);
+    var iconClass = 'fa-' + icon;
+    toast.children('.icon').addClass(iconClass);
+    toast.fadeIn(500);
+
+    setTimeout(function() {
+        toast.fadeOut('fast');
+        toast.children('.message').text('');
+        toast.children('.icon').removeClass(iconClass);
+    }, 3000);
+}
+
+/**
+ * 获取url中参数
+ * @param variable
+ * @returns {*}
+ */
+function getQueryVariable(variable) {
+    var query = window.location.search.substring(1);
+    var vars = query.split("&");
+    for (var i=0;i<vars.length;i++) {
+        var pair = vars[i].split("=");
+        if(pair[0] == variable){return pair[1];}
+    }
+    return(false);
+}
+
+const zeroRange = 0.00000001;
+function checkZero(value) {
+    return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
+}
+function checkFieldChange(o, n) {
+    return o == n || ((!o || o === '') && (n === ''));
+}
+
+/**
+ * 设置本地缓存
+ *
+ * @param {String} key
+ * @param {String|Number} value
+ * @return {void}
+ */
+function setLocalCache(key, value) {
+    const storage = window.localStorage;
+    if (!storage || key === '' || value === '') {
+        return;
+    }
+
+    storage.setItem(key, value);
+}
+
+/**
+ * 获取本地缓存
+ *
+ * @param {String} key
+ * @return {String}
+ */
+function getLocalCache(key) {
+    const storage = window.localStorage;
+    if (!storage || key === '') {
+        return null;
+    }
+
+    return storage.getItem(key);
+}
+
+/**
+ * 移除本地缓存
+ * @param {String} key
+ * @returns {Boolean}
+ */
+function removeLocalCache(key) {
+    const storage = window.localStorage;
+    if (!storage || key === '') {
+        return null;
+    }
+    return storage.removeItem(key);
+}
+
+function trimInvalidChar(str) {
+    return $.trim(str).replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '');
+}
+
+function cleanSymbols(str) {
+    return $.trim(str).replace(/\\/g, '').replace(/\'/g, '').replace(/\"/g, '').replace(/\</g, '').replace(/\|/g, '');
+}

app/public/js/wap.js → app/public/js/wap/list.js


+ 57 - 0
app/public/js/wap/login.js

@@ -0,0 +1,57 @@
+$(document).ready(function() {
+    const lSPName = getLocalCache('project_name');
+    const lSPCode = getLocalCache('project_code');
+    if (lSPName !== null && $('#project').attr('readonly') === undefined) {
+        $('#project_name').text(lSPName);
+        $('#project').val(lSPCode);
+        $('#forget-project').val(lSPCode);
+        $('#account').focus();
+    }
+
+    if ($('#project').attr('readonly') !== undefined) {
+        setLocalCache('project_name', $('#project_name').text());
+        setLocalCache('project_code', $('#project').val());
+        $('#account').focus();
+    }
+
+    $('#project').blur(function () {
+        if ($(this).val() == '') {
+            $('#project_name').text('');
+            $('#forget-project').val('');
+            removeLocalCache('project_code');
+            removeLocalCache('project_name');
+        } else {
+            const pcode = getLocalCache('project_code');
+            if ($(this).val() !== pcode) {
+                const pc = $(this).val();
+                $.ajax({
+                    type: 'get',
+                    url: '/project/name',
+                    data: { code: pc },
+                    dataType: 'json',
+                    success: function (result) {
+                        setLocalCache('project_code', pc);
+                        if (result.err === 1) {
+                            $('#project_name').text('');
+                            $('#forget-project').val('');
+                            console.log(result.msg);
+                            toast(result.msg, 'error', 'exclamation-circle');
+                            removeLocalCache('project_name');
+                        } else {
+                            setLocalCache('project_name', result.data);
+                            $('#project_name').text(result.data);
+                            $('#forget-project').val(pc);
+                        }
+                    }
+                })
+            }
+        }
+    });
+
+    $('input').focus(function () {
+        if($(this).hasClass('is-invalid')) {
+            $(this).removeClass('is-invalid');
+            $(this).siblings('div.invalid-feedback').html('');
+        }
+    });
+});

+ 2 - 51
app/view/wap/list.ejs

@@ -70,60 +70,11 @@
 <script src="/public/js/lodash.js"></script>
 <script src="/public/js/lz-string/lz-string.js"></script>
 <script src="/public/js/number-precision.js"></script>
-<script>
-
-    const zeroRange = 0.00000001;
-    function checkZero(value) {
-        return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
-    }
-    /**
-     * 设置本地缓存
-     *
-     * @param {String} key
-     * @param {String|Number} value
-     * @return {void}
-     */
-    function setLocalCache(key, value) {
-        const storage = window.localStorage;
-        if (!storage || key === '' || value === '') {
-            return;
-        }
-
-        storage.setItem(key, value);
-    }
-
-    /**
-     * 获取本地缓存
-     *
-     * @param {String} key
-     * @return {String}
-     */
-    function getLocalCache(key) {
-        const storage = window.localStorage;
-        if (!storage || key === '') {
-            return null;
-        }
-
-        return storage.getItem(key);
-    }
-
-    /**
-     * 移除本地缓存
-     * @param {String} key
-     * @returns {Boolean}
-     */
-    function removeLocalCache(key) {
-        const storage = window.localStorage;
-        if (!storage || key === '') {
-            return null;
-        }
-        return storage.removeItem(key);
-    }
-</script>
+<script src="/public/js/wap/global.js"></script>
 <script src="/public/js/decimal.min.js"></script>
 <script src="/public/js/zh_calc.js"></script>
 <script src="/public/js/shares/tender_list_order.js"></script>
 <script src="/public/js/tender_showhide.js"></script>
-<script src="/public/js/wap.js"></script>
+<script src="/public/js/wap/list.js"></script>
 </body>
 </html>

+ 4 - 4
app/view/wap/login.ejs

@@ -31,10 +31,10 @@
         <div class="col-12">
             <form class="card m-3 mt-3" method="post" action="/wap/login">
                 <div class="card-body">
-                    <h5 class="text-center mb-4 text-muted" id="project_name"></h5>
+                    <h5 class="text-center mb-4 text-muted" id="project_name"><%- projectData ? projectData.name : '' %></h5>
                     <h4 class="text-center mb-4">账号登录</h4>
                     <div class="form-group mb-3 <% if (errorMessage !== undefined && errorMessage !== null) { %>has-danger<% } %>">
-                        <input id="project" class="form-control" name="project" placeholder="项目编号" autofocus="" />
+                        <input id="project" class="form-control" name="project" placeholder="项目编号" <% if (projectData) { %>readonly<% } %> value="<%- projectData ? projectData.code : '' %>" autofocus="" />
                     </div>
                     <div class="form-group mb-3 <% if (errorMessage !== undefined && errorMessage !== null) { %>has-danger<% } %>">
                         <input id="account" class="form-control" name="account" placeholder="输入账号" autofocus="" />
@@ -72,10 +72,10 @@
 <script src="/public/js/jquery/jquery-3.2.1.min.js"></script>
 <script src="/public/js/popper/popper.min.js"></script>
 <script src="/public/js/bootstrap/bootstrap.min.js"></script>
-<!--<script src="/public/js/global.js"></script>-->
+<script src="/public/js/wap/global.js"></script>
 <script>
     const csrf = '<%= ctx.csrf %>'
 </script>
-<!--<script src="/public/js/login.js"></script>-->
+<script src="/public/js/wap/login.js"></script>
 </body>
 </html>