Parcourir la source

接口设置,调整

MaiXinRong il y a 4 ans
Parent
commit
23e1dd2e87
4 fichiers modifiés avec 93 ajouts et 84 suppressions
  1. 10 8
      app/controller/setting_controller.js
  2. 0 1
      app/service/tender.js
  3. 37 29
      app/view/setting/s2b.ejs
  4. 46 46
      package-lock.json

+ 10 - 8
app/controller/setting_controller.js

@@ -791,17 +791,19 @@ module.exports = app => {
                 if (projectData === null) throw '没有对应的项目数据';
                 if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
 
-                const tenderId = parseInt(ctx.query.tid);
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.tid) throw '提交数据错误';
+
                 const updateData = {};
-                if (ctx.query.gxbyLimit) updateData.s2b_gxby_limit = ctx.query.gxbyLimit === '1';
-                if (ctx.query.gxbyCheck) updateData.s2b_gxby_check = ctx.query.gxbyCheck === '1';
-                if (ctx.query.daglLimit) updateData.s2b_dagl_limit = ctx.query.daglLimit === '1';
-                if (ctx.query.daglCheck) updateData.s2b_dagl_check = ctx.query.daglCheck === '1';
-                await ctx.service.tender.saveApiRela(tenderId, updateData);
-                ctx.redirect('/setting/api');
+                if (data.gxby_limit !== undefined) updateData.s2b_gxby_limit = data.gxby_limit;
+                if (data.gxby_check !== undefined) updateData.s2b_gxby_check = data.gxby_check;
+                if (data.dagl_limit !== undefined) updateData.s2b_dagl_limit = data.dagl_limit;
+                if (data.dagl_check !== undefined) updateData.s2b_dagl_check = data.dagl_check;
+                await ctx.service.tender.saveApiRela(data.tid, updateData);
+                ctx.body = { err: 0, msg: '', data: null };
             } catch (error) {
                 ctx.helper.log(error);
-                ctx.redirect('/setting/api');
+                ctx.ajaxError(error, '保存数据错误');
             }
         }
     }

+ 0 - 1
app/service/tender.js

@@ -416,7 +416,6 @@ module.exports = app => {
         }
 
         async saveApiRela(tid, updateData) {
-            console.log(tid, updateData);
             await this.db.update(this.tableName, updateData, {where: { id: tid } });
         }
     }

+ 37 - 29
app/view/setting/s2b.ejs

@@ -27,43 +27,35 @@
                         </tr>
                         </thead>
                         <% for (const t of tenders) { %>
-                        <tr>
+                        <tr tid="<%- t.id %>">
                             <td><%- t.name %></td>
                             <td><%- t.measure_type_str %></td>
                             <td><%- t.stage_count_str %></td>
                             <td><%- t.user_str %></td>
                             <td><%- ctx.moment(t.show_time).format('YYYY-MM-DD HH:mm:ss') %></td>
                             <td class="text-center">
-                                <form action="api/update?tid=<%= t.id %>&gxbyCheck=<%- (t.s2b_gxby_check ? 0 : 1) %>" method="post">
-                                    <div class="form-check form-check-inline">
-                                        <input class="form-check-input" type="checkbox" id="inlineCheckbox1" <% if (t.s2b_gxby_check) { %>checked<% } %> name="gxby_check" onchange="submit();">
-                                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                        <label class="form-check-label" for="inlineCheckbox1">检查计量</label>
-                                    </div>
-                                </form>
-                                <form action="api/update?tid=<%= t.id %>&gxbyLimit=<%- (t.s2b_gxby_limit ? 0 : 1) %>" method="post">
-                                    <div class="form-check form-check-inline">
-                                        <input class="form-check-input" type="checkbox" id="inlineCheckbox2" <% if (t.s2b_gxby_limit) { %>checked<% } %> name="gxby_limit" onchange="submit();">
-                                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                        <label class="form-check-label" for="inlineCheckbox2">限制上报</label>
-                                    </div>
-                                </form>
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox1" <% if (t.s2b_gxby_check) { %>checked<% } %> name="gxby_check" onchange="updateS2bSetting(this);" value="<%- t.s2b_gxby_check %>">
+                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                    <label class="form-check-label" for="inlineCheckbox1">检查计量</label>
+                                </div>
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox2" <% if (t.s2b_gxby_limit) { %>checked<% } %> name="gxby_limit" onchange="updateS2bSetting(this);" value="<%- t.s2b_gxby_limit %>">
+                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                    <label class="form-check-label" for="inlineCheckbox2">限制上报</label>
+                                </div>
                             </td>
                             <td class="text-center">
-                                <form action="api/update?tid=<%= t.id %>&daglCheck=<%- (t.s2b_dagl_check ? 0 : 1) %>" method="post">
-                                    <div class="form-check form-check-inline">
-                                        <input class="form-check-input" type="checkbox" id="inlineCheckbox3" <% if (t.s2b_dagl_check) { %>checked<% } %> name="dagl_check" onchange="submit();">
-                                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                        <label class="form-check-label" for="inlineCheckbox3">检查计量</label>
-                                    </div>
-                                </form>
-                                <form action="api/update?tid=<%= t.id %>&daglLimit=<%- (t.s2b_dagl_limit ? 0 : 1) %>" method="post">
-                                    <div class="form-check form-check-inline">
-                                        <input class="form-check-input" type="checkbox" id="inlineCheckbox4" <% if (t.s2b_dagl_limit) { %>checked<% } %> name="dagl_limit" onchange="submit();">
-                                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                        <label class="form-check-label" for="inlineCheckbox4">限制上报</label>
-                                    </div>
-                                </form>
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox3" <% if (t.s2b_dagl_check) { %>checked<% } %> name="dagl_check" onchange="updateS2bSetting(this);" value="<%- t.s2b_dagl_check %>">
+                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                    <label class="form-check-label" for="inlineCheckbox3">检查计量</label>
+                                </div>
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox4" <% if (t.s2b_dagl_limit) { %>checked<% } %> name="dagl_limit" onchange="updateS2bSetting(this);" value="<%- t.s2b_dagl_limit %>">
+                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                    <label class="form-check-label" for="inlineCheckbox4">限制上报</label>
+                                </div>
                             </td>
                         </tr>
                         <% } %>
@@ -75,6 +67,22 @@
     </div>
 </div>
 <script>
+    const updateS2bSetting = function (obj) {
+        try {
+            const name = obj.getAttribute('name');
+            const tid = parseInt(obj.parentNode.parentNode.parentNode.getAttribute('tid'));
+            if (!name) return;
+            const data = { tid };
+            data[name] = obj.checked;
+            postData('api/update', data, function() {
+                obj.setAttribute('value', obj.checked);
+            }, function () {
+                obj.checked = obj.getAttribute('value') === true;
+            })
+        } catch (err) {
+            obj.checked = obj.getAttribute('value') === true;
+        }
+    }
     $(() => {
         autoFlashHeight();
     })

+ 46 - 46
package-lock.json

@@ -1050,7 +1050,7 @@
         },
         "isarray": {
           "version": "1.0.0",
-          "resolved": "https://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz?cache=0&sync_timestamp=1562592096220&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fisarray%2Fdownload%2Fisarray-1.0.0.tgz",
+          "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
           "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
         },
         "normalize-path": {
@@ -2984,7 +2984,7 @@
     },
     "charenc": {
       "version": "0.0.2",
-      "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
+      "resolved": "https://registry.npm.taobao.org/charenc/download/charenc-0.0.2.tgz",
       "integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc="
     },
     "chokidar": {
@@ -3215,12 +3215,12 @@
       "dependencies": {
         "sax": {
           "version": "0.6.1",
-          "resolved": "https://registry.npmjs.org/sax/-/sax-0.6.1.tgz",
+          "resolved": "http://registry.npm.taobao.org/sax/download/sax-0.6.1.tgz",
           "integrity": "sha1-VjsZx8HeiS4Jv8Ty/DDjwn8JUrk="
         },
         "xml2js": {
           "version": "0.4.4",
-          "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.4.tgz",
+          "resolved": "https://registry.npm.taobao.org/xml2js/download/xml2js-0.4.4.tgz?cache=0&sync_timestamp=1584990425260&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fxml2js%2Fdownload%2Fxml2js-0.4.4.tgz",
           "integrity": "sha1-MREBAAMAiuGSQOuhdJe1fHKcVV0=",
           "requires": {
             "sax": "0.6.x",
@@ -3256,7 +3256,7 @@
     },
     "co-wechat-oauth": {
       "version": "2.0.1",
-      "resolved": "https://registry.npmjs.org/co-wechat-oauth/-/co-wechat-oauth-2.0.1.tgz",
+      "resolved": "https://registry.npm.taobao.org/co-wechat-oauth/download/co-wechat-oauth-2.0.1.tgz",
       "integrity": "sha1-n/pS3fuTWdAwAYiBw/jWIQSKKVQ=",
       "requires": {
         "httpx": "^2.1.1"
@@ -3264,7 +3264,7 @@
     },
     "co-wechat-payment": {
       "version": "0.2.0",
-      "resolved": "https://registry.npmjs.org/co-wechat-payment/-/co-wechat-payment-0.2.0.tgz",
+      "resolved": "https://registry.npm.taobao.org/co-wechat-payment/download/co-wechat-payment-0.2.0.tgz",
       "integrity": "sha1-6V2uUqYEPHDZADDbHzPQFg0hEkA=",
       "requires": {
         "md5": "^2.1.0",
@@ -3750,7 +3750,7 @@
     },
     "crypt": {
       "version": "0.0.2",
-      "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
+      "resolved": "https://registry.npm.taobao.org/crypt/download/crypt-0.0.2.tgz",
       "integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="
     },
     "csrf": {
@@ -7064,8 +7064,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "delegates": "1.0.0",
-            "readable-stream": "2.3.6"
+            "delegates": "^1.0.0",
+            "readable-stream": "^2.0.6"
           }
         },
         "balanced-match": {
@@ -7078,7 +7078,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "balanced-match": "1.0.0",
+            "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
           }
         },
@@ -7148,14 +7148,14 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "aproba": "1.2.0",
-            "console-control-strings": "1.1.0",
-            "has-unicode": "2.0.1",
-            "object-assign": "4.1.1",
-            "signal-exit": "3.0.2",
-            "string-width": "1.0.2",
-            "strip-ansi": "3.0.1",
-            "wide-align": "1.1.3"
+            "aproba": "^1.0.3",
+            "console-control-strings": "^1.0.0",
+            "has-unicode": "^2.0.0",
+            "object-assign": "^4.1.0",
+            "signal-exit": "^3.0.0",
+            "string-width": "^1.0.1",
+            "strip-ansi": "^3.0.1",
+            "wide-align": "^1.1.0"
           }
         },
         "glob": {
@@ -7197,8 +7197,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "once": "1.4.0",
-            "wrappy": "1.0.2"
+            "once": "^1.3.0",
+            "wrappy": "1"
           }
         },
         "inherits": {
@@ -7322,10 +7322,10 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "are-we-there-yet": "1.1.5",
-            "console-control-strings": "1.1.0",
-            "gauge": "2.7.4",
-            "set-blocking": "2.0.0"
+            "are-we-there-yet": "~1.1.2",
+            "console-control-strings": "~1.1.0",
+            "gauge": "~2.7.3",
+            "set-blocking": "~2.0.0"
           }
         },
         "number-is-nan": {
@@ -7343,7 +7343,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "wrappy": "1.0.2"
+            "wrappy": "1"
           }
         },
         "os-homedir": {
@@ -7380,10 +7380,10 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "deep-extend": "0.6.0",
-            "ini": "1.3.5",
-            "minimist": "1.2.0",
-            "strip-json-comments": "2.0.1"
+            "deep-extend": "^0.6.0",
+            "ini": "~1.3.0",
+            "minimist": "^1.2.0",
+            "strip-json-comments": "~2.0.1"
           },
           "dependencies": {
             "minimist": {
@@ -7398,13 +7398,13 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "core-util-is": "1.0.2",
-            "inherits": "2.0.3",
-            "isarray": "1.0.0",
-            "process-nextick-args": "2.0.0",
-            "safe-buffer": "5.1.2",
-            "string_decoder": "1.1.1",
-            "util-deprecate": "1.0.2"
+            "core-util-is": "~1.0.0",
+            "inherits": "~2.0.3",
+            "isarray": "~1.0.0",
+            "process-nextick-args": "~2.0.0",
+            "safe-buffer": "~5.1.1",
+            "string_decoder": "~1.1.1",
+            "util-deprecate": "~1.0.1"
           }
         },
         "rimraf": {
@@ -7450,9 +7450,9 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "code-point-at": "1.1.0",
-            "is-fullwidth-code-point": "1.0.0",
-            "strip-ansi": "3.0.1"
+            "code-point-at": "^1.0.0",
+            "is-fullwidth-code-point": "^1.0.0",
+            "strip-ansi": "^3.0.0"
           }
         },
         "string_decoder": {
@@ -7460,7 +7460,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "safe-buffer": "5.1.2"
+            "safe-buffer": "~5.1.0"
           }
         },
         "strip-ansi": {
@@ -7468,7 +7468,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "ansi-regex": "2.1.1"
+            "ansi-regex": "^2.0.0"
           }
         },
         "strip-json-comments": {
@@ -7500,7 +7500,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "string-width": "1.0.2"
+            "string-width": "^1.0.2 || 2"
           }
         },
         "wrappy": {
@@ -10176,7 +10176,7 @@
     },
     "md5": {
       "version": "2.2.1",
-      "resolved": "https://registry.npmjs.org/md5/-/md5-2.2.1.tgz",
+      "resolved": "https://registry.npm.taobao.org/md5/download/md5-2.2.1.tgz",
       "integrity": "sha1-U6s41f48iJG6RlMp6iP6wFQBJvk=",
       "requires": {
         "charenc": "~0.0.1",
@@ -13542,7 +13542,7 @@
     },
     "sha1": {
       "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/sha1/-/sha1-1.1.1.tgz",
+      "resolved": "https://registry.npm.taobao.org/sha1/download/sha1-1.1.1.tgz",
       "integrity": "sha1-rdqnqTFo85PxnrKxUJFhjicA+Eg=",
       "requires": {
         "charenc": ">= 0.0.1",
@@ -14711,7 +14711,7 @@
     },
     "ueditor": {
       "version": "1.2.3",
-      "resolved": "https://registry.npmjs.org/ueditor/-/ueditor-1.2.3.tgz",
+      "resolved": "https://registry.npmjs.org/ueditor/-/ueditor-1.0.0.tgz",
       "integrity": "sha1-HsihLT8VutOkAReGpzpIZJY2twQ=",
       "requires": {
         "busboy": "^0.2.9",
@@ -15214,7 +15214,7 @@
     },
     "wechat-crypto": {
       "version": "0.0.2",
-      "resolved": "https://registry.npmjs.org/wechat-crypto/-/wechat-crypto-0.0.2.tgz",
+      "resolved": "https://registry.npm.taobao.org/wechat-crypto/download/wechat-crypto-0.0.2.tgz",
       "integrity": "sha1-pVRD7AgQ9MGZKik6J4YIOXAMY2k="
     },
     "whatwg-fetch": {