Просмотр исходного кода

缓存刷新策略与页面微调

zhouzhendong 4 лет назад
Родитель
Сommit
13ee9fa51e

+ 11 - 23
app/Http/Controllers/LogisticController.php

@@ -7,8 +7,10 @@ use Exception;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Str;
 
 class LogisticController extends Controller
 {
@@ -60,26 +62,19 @@ class LogisticController extends Controller
             'delivery_fee' => ['nullable', 'numeric', 'min:0'],
         ]);
     }
-    /**
-     * Display the specified resource.
-     *
-     * @param Logistic $logistic
-     * @return Response
-     */
-    public function show(Logistic $logistic)
-    {
-        //
-    }
 
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param Logistic $logistic
-     * @return Response
-     */
     public function edit(Logistic $logistic)
     {
         if(!Gate::allows('承运商-编辑')){ return view("exception.authority");  }
+        $logistic = $logistic->toArray();
+        if ($logistic["tag"]){
+            $tag = explode(",",$logistic["tag"]);
+            $map = array_flip(Logistic::TAGS);
+            foreach ($tag as &$t)$t = $map[$t];
+            $logistic["tag"] = implode(",",$tag);
+        }
+        $key = 'LogisticAll_'.implode("",["id","name","tag"]).Str::studly("物流");
+        Cache::pull($key);
         return view('maintenance.logistic.edit',['logistic'=>$logistic]);
     }
 
@@ -94,13 +89,6 @@ class LogisticController extends Controller
         return redirect('maintenance/logistic/')->with('successTip',"成功修改承运商“{$logistic['name']}”!");
     }
 
-    /**
-     * Remove the specified resource from storage.
-     *
-     * @param Logistic $logistic
-     * @return array|Response
-     * @throws Exception
-     */
     public function destroy(Logistic $logistic)
     {
         if(!Gate::allows('承运商-删除')){ return view("exception.authority");  }

+ 30 - 11
resources/views/maintenance/logistic/edit.blade.php

@@ -2,19 +2,19 @@
 @section('title')编辑-承运商@endsection
 
 @section('content')
-    <div class="container-fluid">
+    <div class="container-fluid" id="container">
         <div class="card">
             <div class="card-body">
                 @if(Session::has('successTip'))
                     <div class="alert alert-success h1">{{Session::get('successTip')}}!</div>
                 @endif
-                <form method="POST" action='{{url("maintenance/logistic/{$logistic->id}")}}'>
+                <form method="POST" action='{{url("maintenance/logistic/{$logistic["id"]}")}}'>
                     @csrf
                     @method('PUT')
                     <div class="form-group row">
                         <label for="type" class="col-2 col-form-label text-right">承运商类型 <b class="text-danger">*</b></label>
                         <div class="col-5">
-                            <select id="type" name="type" class="form-control @error('type') is-invalid @enderror" value="@if(old('type')){{old('type')}}@else{{$logistic->type}}@endif" required>
+                            <select id="type" name="type" class="form-control @error('type') is-invalid @enderror" value="@if(old('type')){{old('type')}}@else{{$logistic["type"]}}@endif" required>
                                 <option value="快递">快递</option>
                                 <option value="物流">物流</option>
                                 <option value="全部">全部</option>
@@ -30,7 +30,7 @@
                         <label for="name" class="col-2 col-form-label text-right">承运商名称 <b class="text-danger">*</b></label>
                         <div class="col-8">
                             <input type="text" class="form-control @error('name') is-invalid @enderror"
-                                   name="name" autocomplete="off" value="@if(old('name')){{old('name')}}@else{{$logistic->name}}@endif" required>
+                                   name="name" autocomplete="off" value="@if(old('name')){{old('name')}}@else{{$logistic["name"]}}@endif" required>
                             @error('name')
                             <span class="invalid-feedback" role="alert">
                                 <strong>{{ $message }}</strong>
@@ -42,14 +42,14 @@
                         <label for="english_name" class="col-2 col-form-label text-right">承运商英文名称</label>
                         <div class="col-8">
                             <input id="english_name" type="text" class="form-control"
-                                   name="english_name" autocomplete="off" value="@if(old('name')){{old('name')}}@else{{$logistic->name}}@endif" >
+                                   name="english_name" autocomplete="off" value="@if(old('name')){{old('name')}}@else{{$logistic["name"]}}@endif" >
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="code" class="col-2 col-form-label text-right">承运商代码 <b class="text-danger">*</b></label>
                         <div class="col-8">
                             <input type="text" class="form-control @error('code') is-invalid @enderror"
-                                   name="code" autocomplete="off" value="@if(old('code')){{old('code')}}@else{{$logistic->code}}@endif" required>
+                                   name="code" autocomplete="off" value="@if(old('code')){{old('code')}}@else{{$logistic["code"]}}@endif" required>
                             @error('code')
                             <span class="invalid-feedback" role="alert">
                                 <strong>{{ $message }}</strong>
@@ -60,14 +60,14 @@
                     <div class="form-group row">
                         <label for="is_bunched" class="col-2 col-form-label text-right">是否子母单</label>
                         <div class="col-8">
-                            <input id="is_bunched" type="checkbox" name="is_bunched" class="switch" @if(old('is_bunched') ?? $logistic->is_bunched=='Y') checked @endif>
+                            <input id="is_bunched" type="checkbox" name="is_bunched" class="switch" @if(old('is_bunched') ?? $logistic["is_bunched"]=='Y') checked @endif>
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="mobile" class="col-2 col-form-label text-right">承运商电话</label>
                         <div class="col-8">
                             <input id="mobile" type="text" class="form-control @error('mobile') is-invalid @enderror"
-                                   name="mobile" autocomplete="off" value="@if(old('mobile')){{old('mobile')}}@else{{$logistic->mobile}}@endif" >
+                                   name="mobile" autocomplete="off" value="@if(old('mobile')){{old('mobile')}}@else{{$logistic["mobile"]}}@endif" >
                             @error('mobile')
                             <span class="invalid-feedback" role="alert">
                                 <strong>{{ $errors->first('mobile') }}</strong>
@@ -79,7 +79,7 @@
                         <label for="delivery_fee" class="col-2 col-form-label text-right">送货费</label>
                         <div class="col-8">
                             <input id="delivery_fee" type="text" class="form-control @error('delivery_fee') is-invalid @enderror"
-                                   name="delivery_fee" autocomplete="off" value="@if(old('delivery_fee')){{old('delivery_fee')}}@else{{$logistic->delivery_fee}}@endif" >
+                                   name="delivery_fee" autocomplete="off" value="@if(old('delivery_fee')){{old('delivery_fee')}}@else{{$logistic["delivery_fee"]}}@endif" >
                             @error('delivery_fee')
                             <span class="invalid-feedback" role="alert">
                                 <strong>{{ $errors->first('delivery_fee') }}</strong>
@@ -91,14 +91,23 @@
                         <label for="belong_company" class="col-2 col-form-label text-right">隶属公司</label>
                         <div class="col-8">
                             <input id="belong_company" type="text" class="form-control "
-                                   name="belong_company" autocomplete="off" value="@if(old('belong_company')){{old('belong_company')}}@else{{$logistic->belong_company}}@endif" >
+                                   name="belong_company" autocomplete="off" value="@if(old('belong_company')){{old('belong_company')}}@else{{$logistic["belong_company"]}}@endif" >
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="tag" class="col-2 col-form-label text-right">标签</label>
+                        <div class="col-8">
+                            <select id="tag" class="selectpicker" multiple title="标签(多选)" v-model="tag">
+                                @foreach(\App\Logistic::TAGS as $key=>$tag)<option value="{{$key}}">{{$tag}}</option>@endforeach
+                            </select>
+                            <input hidden name="tag" :value="tag"></input>
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="remark" class="col-2 col-form-label text-right">备注</label>
                         <div class="col-8">
                             <textarea id="remark" type="text" class="form-control "
-                                      name="remark" autocomplete="off" >@if(old('remark')){{old('remark')}}@else{{$logistic->remark}}@endif</textarea>
+                                      name="remark" autocomplete="off" >@if(old('remark')){{old('remark')}}@else{{$logistic["remark"]}}@endif</textarea>
                         </div>
                     </div>
                     <div class="form-group row">
@@ -111,3 +120,13 @@
         </div>
     </div>
 @endsection
+@section("lastScript")
+    <script>
+        new Vue({
+            el:"#container",
+            data:{
+                tag:"{{$logistic["tag"]}}".split(","),
+            },
+        });
+    </script>
+@endsection