ajun 4 лет назад
Родитель
Сommit
465f8d60a9

+ 53 - 9
app/Http/Controllers/StationRuleBatchController.php

@@ -2,25 +2,69 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\AsyncResponse;
+use App\Http\Requests\Station\StationRuleBatchRequest;
+use App\Services\OwnerService;
+use App\Station;
 use App\StationRuleBatch;
+use Illuminate\Contracts\Foundation\Application;
+use Illuminate\Contracts\View\Factory;
 use Illuminate\Http\Request;
+use Illuminate\Http\Response;
+use Illuminate\View\View;
+
 
 class StationRuleBatchController extends Controller
 {
+    use AsyncResponse;
+
     /**
      * Display a listing of the resource.
      *
-     * @return \Illuminate\Http\Response
+     * @param Request $request
+     * @param OwnerService $ownerService
+     * @return Application|Factory|View
      */
-    public function index()
+    public function index(Request $request,OwnerService $ownerService)
     {
-        //
+        $stationRuleBatches = StationRuleBatch::query()->with('stationType','owner')->orderByDesc('id')->paginate($request['paginate'] ?? 50);
+        $owners = $ownerService->getAuthorizedOwners();
+        return view('station.rule.index',compact('stationRuleBatches','owners'));
+    }
+
+    /**
+     * store API
+     * @param StationRuleBatchRequest $request
+     */
+    public function storeApi(StationRuleBatchRequest $request)
+    {
+        $stationRuleBatch = StationRuleBatch::query()->create($request->only(['name','owner_id']));
+        $stationRuleBatch->load('stationType','owner');
+        $this->success($stationRuleBatch);
+    }
+
+    /**
+     * update API
+     * @param StationRuleBatchRequest $request
+     */
+    public function updateApi(StationRuleBatchRequest $request)
+    {
+        $stationRuleBatch = StationRuleBatch::query()->whereKey($request['id'])->first();
+        $stationRuleBatch->update($request->all());
+        $stationRuleBatch->load('stationType','owner');
+        $this->success($stationRuleBatch);
+    }
+
+    public function destroyApi(Request $request)
+    {
+        StationRuleBatch::query()->whereKey($request['id'])->delete();
+        $this->success();
     }
 
     /**
      * Show the form for creating a new resource.
      *
-     * @return \Illuminate\Http\Response
+     * @return Response
      */
     public function create()
     {
@@ -31,7 +75,7 @@ class StationRuleBatchController extends Controller
      * Store a newly created resource in storage.
      *
      * @param  \Illuminate\Http\Request  $request
-     * @return \Illuminate\Http\Response
+     * @return Response
      */
     public function store(Request $request)
     {
@@ -42,7 +86,7 @@ class StationRuleBatchController extends Controller
      * Display the specified resource.
      *
      * @param  \App\StationRuleBatch  $stationRuleBatch
-     * @return \Illuminate\Http\Response
+     * @return Response
      */
     public function show(StationRuleBatch $stationRuleBatch)
     {
@@ -53,7 +97,7 @@ class StationRuleBatchController extends Controller
      * Show the form for editing the specified resource.
      *
      * @param  \App\StationRuleBatch  $stationRuleBatch
-     * @return \Illuminate\Http\Response
+     * @return Response
      */
     public function edit(StationRuleBatch $stationRuleBatch)
     {
@@ -65,7 +109,7 @@ class StationRuleBatchController extends Controller
      *
      * @param  \Illuminate\Http\Request  $request
      * @param  \App\StationRuleBatch  $stationRuleBatch
-     * @return \Illuminate\Http\Response
+     * @return Response
      */
     public function update(Request $request, StationRuleBatch $stationRuleBatch)
     {
@@ -76,7 +120,7 @@ class StationRuleBatchController extends Controller
      * Remove the specified resource from storage.
      *
      * @param  \App\StationRuleBatch  $stationRuleBatch
-     * @return \Illuminate\Http\Response
+     * @return Response
      */
     public function destroy(StationRuleBatch $stationRuleBatch)
     {

+ 70 - 0
app/Http/Requests/Station/StationRuleBatchRequest.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace App\Http\Requests\Station;
+
+use App\Traits\RequestApiFormValidation;
+use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Support\Facades\Route;
+
+class StationRuleBatchRequest extends FormRequest
+{
+    use RequestApiFormValidation;
+
+    protected $storeApiRules = [
+        'name' => 'required',
+        'owner_id' => 'required'
+    ];
+    protected $updateApiRules = [
+        'name' => 'required',
+        'owner_id' => 'required'
+    ];
+    protected $storeApiMessage = [
+        'name.required' => '规则名称为必填项',
+        'owner_id.required' => '货主为必填项',
+    ];
+    protected $updateApiMessage = [
+        'name.required' => '规则名称为必填项',
+        'owner_id.required' => '货主为必填项',
+    ];
+
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules(): array
+    {
+        $routeName = Route::currentRouteName();
+        switch ($routeName) {
+            case 'station.rule.storeApi':
+                return $this->storeApiRules;
+            case 'station.rule.updateApi':
+                return $this->updateApiRules;
+            default:
+                return [];
+        }
+    }
+
+    public function messages(): array
+    {
+        $routeName = Route::currentRouteName();
+        switch ($routeName) {
+            case 'station.rule.storeApi':
+                return $this->storeApiMessage;
+            case 'station.rule.updateApi':
+                return $this->updateApiMessage;
+            default:
+                return [];
+        }
+    }
+}

+ 5 - 0
app/StationRuleBatch.php

@@ -18,4 +18,9 @@ class StationRuleBatch extends Model
     {
         return $this->belongsTo(StationType::class);
     }
+
+    public function owner() :BelongsTo
+    {
+        return $this->belongsTo(Owner::class);
+    }
 }

+ 38 - 0
database/migrations/2021_05_19_171047_add_station_rule_batch_author.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddStationRuleBatchAuthor extends Migration
+{
+    public $names = [
+        '站管理-栈规则',
+        '站管理-编辑',
+        '站管理-创建',
+        '站管理-删除',
+    ];
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        foreach ($this->names as $item) {
+            \App\Authority::query()->firstOrCreate(['name' => $item],['alias_name' => $item]);
+        }
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        foreach ($this->names as $item) {
+            \App\Authority::query()->where('name' , $item)->delete();
+        }
+    }
+}

+ 1 - 0
database/seeds/StationRuleBatchSeeder.php

@@ -12,5 +12,6 @@ class StationRuleBatchSeeder extends Seeder
     public function run()
     {
         //
+        factory(\App\StationRuleBatch::class)->times(3)->create();
     }
 }

+ 5 - 0
resources/views/station/menu.blade.php

@@ -10,6 +10,11 @@
                 <li class="nav-item">
                     <a target="station/cachingShelf/index" class="nav-link" href="{{url('station/cachingShelf/index')}}" :class="{active:isActive('cachingShelf',2)}">缓存架</a>
                 </li> @endcan
+            @can('站管理-栈规则')
+                <li class="nav-item">
+                    <a target="station/rule/index" class="nav-link" href="{{url('station/rule/index')}}" :class="{active:isActive('rule','2')}">栈规则</a>
+                </li>
+            @endcan
         </ul>
     </div>
 </div>

+ 51 - 0
resources/views/station/rule/_edit.blade.php

@@ -0,0 +1,51 @@
+<div class="modal face" id="box">
+    <div class="modal-dialog modal-lg boxClass" >
+        <div class="modal-content">
+            <div class="modal-header">
+                <div class="modal-title">
+                    <span v-show="tag==='update'">修改规则</span>
+                    <span v-show="tag==='create'">创建规则</span>
+                </div>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form>
+                    <div class="form-group row">
+                        <label for="owner-id" class="col-sm-3 col-form-label text-right">货主</label>
+                        <div class="col-sm-9 form-inline">
+                            <select id="owner-id" class="form-control col-sm-6"
+                                    :class="errors.owner_id?'is-invalid':''"
+                                    v-model="stationRuleBatch.owner_id" @input="setStationRuleBatchName($event)"
+                                    @change="errors.owner_id = null">
+                                <option value=""></option>
+                                <option :value="owner.id" v-for="owner in ownerFilters">@{{ owner.name }}</option>
+                            </select>
+                            <input type="text" name="material-code" id="owner-id" class="form-control col-sm-3" placeholder="货主" @input="filterOwner($event)" v-model="filterName">
+                            <div class="invalid-feedback" v-if="errors.owner_id">
+                                @{{ errors.owner_id ? errors.owner_id[0] : ''  }}
+                            </div>
+                        </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="rule-name" class="col-sm-3 col-form-label text-right">名称</label>
+                        <div class="col-sm-9 form-inline">
+                            <input type="text" name="phone" id="rule-name" class="form-control col-9"
+                                   :class="errors.name &&  !stationRuleBatch.name ?'is-invalid':''"
+                                   v-model="stationRuleBatch.name" @change="errors.name = null">
+                            <div class="invalid-feedback" v-if="errors.name">
+                                @{{ errors.name ? errors.name[0] : ''  }}
+                            </div>
+                        </div>
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button class="btn btn-primary" @click="_edit" v-show="tag==='update'">修改</button>
+                <button class="btn btn-primary" @click="_create" v-show="tag==='create'">创建</button>
+            </div>
+        </div>
+    </div>
+</div>
+

+ 47 - 0
resources/views/station/rule/_table.blade.php

@@ -0,0 +1,47 @@
+<table class="table table-striped table-md table-hover" id="table">
+    <thead>
+    <tr>
+        <th>
+            序号
+        </th>
+        <th>
+            货主
+        </th>
+        <th>
+            规则名称
+        </th>
+        <th>
+            设备类型
+        </th>
+        <th>
+            波次类型
+        </th>
+        <th>
+            操作
+        </th>
+    </tr>
+    <template v-if="stationRuleBatches.length > 0">
+        <tr v-for="(stationRuleBatch,i) in stationRuleBatches" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
+            <td>
+                @{{ i+1 }}
+            </td>
+            <td>
+                @{{ stationRuleBatch.owner ? stationRuleBatch.owner.name : '' }}
+            </td>
+            <td>
+                @{{ stationRuleBatch.name }}
+            </td>
+            <td>
+                @{{ stationRuleBatch.station_type ? stationRuleBatch.station_type.name  : ''}}
+            </td>
+            <td>
+                @{{ stationRuleBatch.batch_type ? stationRuleBatch.batch_type :'无'}}
+            </td>
+            <td>
+                @can('站管理-编辑')<button class="btn btn-sm btn-outline-primary" @click="editStationRuleBatch(stationRuleBatch,i)">编辑</button>@endcan
+                @can('站管理-删除')<button class="btn btn-sm btn-outline-danger" @click="deleteStationRuleBatch(stationRuleBatch,i)">删除</button>@endcan
+            </td>
+        </tr>
+    </template>
+    </thead>
+</table>

+ 140 - 0
resources/views/station/rule/index.blade.php

@@ -0,0 +1,140 @@
+@extends('layouts.app')
+
+@section('title','栈规则')
+
+@section('content')
+    <span id="nav2">
+        @component('station.menu')@endcomponent
+        @component('station.rule.menu')@endcomponent
+    </span>
+    <div class="container-fluid d-none" id="list">
+        @can('站管理-创建')
+            <button class="btn btn-md btn-outline-primary ml-1" @click="createStationRuleBatch">创建</button>
+        @endcan
+        @include('station.rule._table')
+        @include('station.rule._edit')
+    </div>
+@endsection
+
+@section('lastScript')
+    <script>
+        let vue = new Vue({
+            el: '#list',
+            data: {
+                selectTr: null,
+                stationRuleBatches: {!! $stationRuleBatches->toJson() !!}['data'],
+                owners:{!! $owners !!},
+                ownerFilters: [],
+                filterName: null,
+                tag: null,
+                tagIndex: null,
+                stationRuleBatch: {},
+                errors: {}
+            },
+            mounted() {
+                $('#list').removeClass('d-none');
+                this.filterOwner();
+            },
+            methods: {
+                createStationRuleBatch() {
+                    this.tag = 'create';
+                    this.filterOwner();
+                    this.stationRuleBatch = {};
+                    this.errors = {};
+                    $('#box').modal('show');
+                },
+                editStationRuleBatch(item, index) {
+                    this.stationRuleBatch = JSON.parse(JSON.stringify(item));
+                    this.tag = 'update';
+                    this.tagIndex = index;
+                    this.filterOwner();
+                    this.errors = {};
+                    $('#box').modal('show');
+                },
+                deleteStationRuleBatch(item, index) {
+                    if (!confirm("确定要删除对应的栈规则")) {
+                        return;
+                    }
+                    let url = '{{url('apiLocal/station/rule/destroy')}}' + '/?id=' + item['id'];
+                    window.axios.delete(url).then(res => {
+                        if (res.data.success) {
+                            window.tempTip.showSuccess('删除成功');
+                            this.$delete(this.stationRuleBatches, index);
+                            return;
+                        }
+                        window.tempTip.show('删除异常,刷新页面重试');
+                    }).catch(err => {
+                        window.tempTip.show('网络异常,' + err);
+                    });
+                },
+                _create() {
+                    let url = '{{url('apiLocal/station/rule/store')}}';
+                    console.log(this.stationRuleBatch);
+                    window.axios.post(url, this.stationRuleBatch).then(res => {
+                        if (res.data.success) {
+                            this.stationRuleBatches.unshift(res.data.data);
+                            window.tempTip.showSuccess('创建成功');
+                            $('#box').modal('hide');
+                            this.$forceUpdate();
+                            this.tag = null;
+                            this.tagIndex = null;
+                            this.stationRuleBatch = {};
+                            return;
+                        }else if(res.data.errors){
+                            this.errors = res.data.errors;
+                            this.$forceUpdate();
+                            return;
+                        }
+                        window.tempTip.show('创建异常');
+                    }).catch(err => {
+                        window.tempTip.show('网络异常,' + err);
+                    });
+                },
+                _edit() {
+                    let url = '{{url('apiLocal/station/rule/update')}}';
+                    window.axios.put(url, this.stationRuleBatch).then(res => {
+                        if (res.data.success) {
+                            this.$set(this.stationRuleBatches, this.tagIndex, res.data.data);
+                            window.tempTip.showSuccess('修改成功!');
+                            $('#box').modal('hide');
+                            this.tag = null;
+                            this.tagIndex = null;
+                            this.stationRuleBatch = {};
+                            this.$forceUpdate();
+                            return;
+                        }else if(res.data.errors){
+                            this.errors =res.data.errors;
+                            this.$forceUpdate();
+                            return;
+                        }
+                        window.tempTip.show('编辑异常,刷新页面重试');
+                    }).catch(err => {
+                        window.tempTip.show('网络异常,' + err);
+                    });
+                },
+                setStationRuleBatchName($e){
+                    let selectValue = $($e.target).find('option:selected').text();
+                    if(selectValue && !this.stationRuleBatch.name )
+                        this.$set(this.stationRuleBatch,'name',selectValue)
+                },
+                filterOwner($e = null) {
+                    let copyOwner = JSON.parse(JSON.stringify(this.owners));
+                    this.ownerFilters = copyOwner;
+                    if ($e !== null) {
+                        let value = $($e.target).val();
+                        this.ownerFilters = copyOwner.filter(function (owner) {
+                            return owner.name.indexOf(value) !== -1;
+                        });
+                        if (this.ownerFilters.length !== this.owners.length && this.ownerFilters.length > 0) {
+                            this.$set(this.stationRuleBatch,'owner_id',this.ownerFilters[0]['id']);
+                            this.$set(this.stationRuleBatch,'name',this.ownerFilters[0]['name']);
+                        } else {
+                            this.$set(this.stationRuleBatch,'owner_id',null);
+                        }
+                    }
+                    this.$forceUpdate();
+                }
+            }
+        })
+    </script>
+@endsection

+ 9 - 0
resources/views/station/rule/menu.blade.php

@@ -0,0 +1,9 @@
+<div class="container-fluid nav3">
+    <div class="card">
+        <ul class="nav nav-pills">
+            <li class="nav-item">
+                <a target="station/rule/index" class="nav-link" href="{{url('station/rule/index')}}" :class="{active:isActive('rule','2')}">查询</a>
+            </li>
+        </ul>
+    </div>
+</div>

+ 9 - 1
routes/apiLocal.php

@@ -182,14 +182,22 @@ Route::group(['prefix'=>'demand'],function(){
 
 Route::get('/authority/get','AuthorityController@getAuthoritiesApi')->name('authority.getAuthoritiesApi');
 
-/** 缓存架 */
+/** 栈管理 */
 Route::group(['prefix' => 'station'],function(){
+    /** 缓存架 */
     Route::group(['prefix'=>'cacheShelf'],function(){
         Route::post('pushTask','CacheShelfController@pushTaskApi')->name('station.cacheShelf.pushTaskApi');
         Route::post('clearTask','CacheShelfController@clearTaskApi')->name('station.cacheShelf.clearTaskApi');
         Route::post('lightOn','CacheShelfController@lightOnApi')->name('station.cacheShelf.lightOnApi');
         Route::get('getTasks/{id}','CacheShelfController@getTasksApi')->name('station.cacheShelf.getTasksApi');
     });
+
+    /** 栈规则 */
+    Route::group(['prefix'=>'rule'],function(){
+        Route::post('store','StationRuleBatchController@storeApi')->name('station.rule.storeApi');
+        Route::put('update','StationRuleBatchController@updateApi')->name('station.rule.updateApi');
+        Route::delete('destroy','StationRuleBatchController@destroyApi')->name('station.rule.destroyApi');
+    });
 });
 
 

+ 6 - 0
routes/web.php

@@ -801,14 +801,20 @@ Route::group(['prefix'=>'customer'],function(){
 /** 站管理 */
 Route::group(['prefix'=>'station'],function(){
     Route::get('index','StationController@monitorIndex');
+    /** 监视器 */
     Route::group(['prefix'=>'monitor'],function(){
         Route::get('/','StationController@monitorIndex');
         Route::get('/index','StationController@monitorIndex');
         Route::get('/{station}','StationController@monitorShow');
     });
+    /** 缓存架 */
     Route::group(['prefix'=>'cachingShelf'],function(){
         Route::get('/index','CacheShelfController@index');
     });
+    /** 栈规则 */
+    Route::group(['prefix'=>'rule'],function(){
+        Route::get('/index','StationRuleBatchController@index');
+    });
 });
 /** 控制台 */
 Route::group(['prefix'=>'control'],function () {