Explorar el Código

封装POST请求语法糖来简化代码

Zhouzhendong hace 5 años
padre
commit
6b1e2d90df

+ 2 - 1
app/Http/Controllers/ProvincesController.php

@@ -79,6 +79,7 @@ class ProvincesController extends Controller
     }
 
     public function get(){
-        return Province::query()->select("id","name")->get();
+        $provinces = Province::query()->select("id","name")->get();
+        return ["success"=>true,"data"=>$provinces];
     }
 }

+ 1 - 1
resources/js/app.js

@@ -9,6 +9,6 @@ window.ElementUI=require('./utilities/tempTip');
 window.getGetVal=require('./utilities/getGetVal');
 window.scanner=require('./utilities/scanner');
 window.datetimeRelating=require('./utilities/datetimeRelating');
-window.Vue.use(window.ElementUI)
+window.Vue.use(window.ElementUI);
 require('bootstrap-select');
 

+ 18 - 0
resources/js/utilities/tempTip.js

@@ -117,6 +117,24 @@ const tempTip={
         $('body').append(tiper);
         $input.focus()
     },
+    postBasicRequest(url, params, successMsg, successExe, isPriority = false) {
+        if (isPriority)this.setIndex(1099);
+        window.axios.post(url,params).then(res=> {
+            if (res.data.success){
+                successExe(res.data.data);
+                if (successMsg){
+                    this.setDuration(2000);
+                    this.showSuccess(successMsg);
+                }
+                return;
+            }
+            this.setDuration(3000);
+            this.show(res.data.data);
+        }).catch(function (err) {
+            this.setDuration(3000);
+            this.show('网络异常:'+err);
+        });
+    }
 };
 module.exports=tempTip;
 

+ 10 - 5
resources/views/maintenance/priceModel/express/index.blade.php

@@ -83,14 +83,20 @@
                     window.axios.post("{{url('maintenance/priceModel/express/getDetail')}}", {id:model.id})
                         .then(res=>{
                             if (res.data.success){
-                                this.details[model.id] = res.data.data;
-                                this.$forceUpdate();
+                                if (res.data.data.length>0){
+                                    this.details[model.id] = res.data.data;
+                                    this.$forceUpdate();
+                                }else {
+                                    this.details[model.id] = [];
+                                    this.addDetail();
+                                }
                                 $("#detailModal").modal("show");
                                 return;
                             }
                             window.tempTip.setDuration(3000);
                             window.tempTip.show(res.data.data);
                         }).catch(err=>{
+                            console.log(err);
                         window.tempTip.setDuration(3000);
                         window.tempTip.show("网络错误:"+err);
                     });
@@ -132,9 +138,8 @@
                 },
                 addDetail(){
                     if (this.provinces === null){
-                        window.axios.post('{{url('maintenance/province/get')}}')
-                            .then(res=>{
-                                this.provinces = res.data;
+                        window.tempTip.postBasicRequest('{{url('maintenance/province/get')}}',{},undefined,data=>{
+                            this.provinces = data;
                         });
                     }
                     this.details[this.id].unshift({

+ 0 - 1
resources/views/order/index/delivering.blade.php

@@ -492,7 +492,6 @@
                             tempTip.show('标记勾选内容冻结失败,错误:'+response.data.fail_info);
                         }
                     }).catch(function (e) {
-                        alert('网络连接错误:'+e);
                         tempTip.setDuration(2500);
                         tempTip.show('标记勾选内容冻结失败,网络连接错误:'+e);
                     })