Ver código fonte

station monitor查看

LD 5 anos atrás
pai
commit
9139ce7bc5

+ 7 - 2
app/Http/Controllers/StationController.php

@@ -10,11 +10,16 @@ class StationController extends Controller
     /**
      * Display a listing of the resource.
      *
-     * @return \Illuminate\Http\Response
+     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
      */
     public function index()
     {
-        //
+
+    }
+    public function monitorIndex()
+    {
+        $stations = Station::query()->paginate(100);
+        return view('station.monitor.index',compact('stations'));
     }
 
     /**

+ 7 - 0
app/Station.php

@@ -7,4 +7,11 @@ use Illuminate\Database\Eloquent\Model;
 class Station extends Model
 {
     protected $fillable=['name', 'code', 'station_type_id','sequence','parent_id'];
+
+    function type(){
+        return $this->belongsTo(StationType::class);
+    }
+    function parent(){
+        return $this->belongsTo(Station::class,'parent_id','id');
+    }
 }

+ 38 - 0
database/migrations/2020_12_03_144334_add_monitor_default_station_and_station_hardware_id_column.php

@@ -0,0 +1,38 @@
+<?php
+
+use App\Station;
+use App\StationType;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddMonitorDefaultStationAndStationHardwareIdColumn extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('stations', function (Blueprint $table) {
+            $table->string('remark')->nullable();
+        });
+        $stationType= StationType::query()->firstOrCreate(['name'=>'料箱监视器']);
+        $station= Station::query()->firstOrCreate(['name'=>'料箱监视器01']);
+        $station['sequence']=1;
+        $station['station_type_id']=$stationType['id'];
+        $station->save();
+    }
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('stations', function (Blueprint $table) {
+            $table->dropColumn('remark');
+        });
+    }
+}

+ 4 - 39
resources/views/station/monitor/index.blade.php

@@ -19,13 +19,14 @@
                         <th>显示器名称</th>
                         <th>父级设备</th>
                         <th>硬件ID</th>
+                        <th>备注</th>
                         <th>录入时间</th>
                     </tr>
                     <tr v-for="station in stations">
                         <td class="text-muted">@{{station.id}}</td>
                         <td>@{{station.name}}</td>
                         <td>@{{station.parent.name}}</td>
-                        <td>@{{station.delivery_fee}}</td>
+                        <td>@{{station.code}}</td>
                         <td>@{{station.remark}}</td>
                         <td class="text-muted">@{{station.created_at}}</td>
                         <td>
@@ -36,7 +37,7 @@
                         </td>
                     </tr>
                 </table>
-                {{$carriers->links()}}
+                {{$stations->links()}}
             </div>
         </div>
     </div>
@@ -47,44 +48,8 @@
         new Vue({
             el:"#list",
             data:{
-                carriers:[
-                        @foreach( $carriers as $carrier )
-                    {id:'{{$carrier->id}}',name:'{{$carrier->name}}',mobile:'{{$carrier->mobile}}',
-                        delivery_fee:'{{$carrier->delivery_fee}}',
-                        remark:'{{$carrier->remark}}',created_at:'{{$carrier->created_at}}'},
-                    @endforeach
-                ],
+                stations:{!! $stations??'' !!},
             },
-            methods:{
-                edit:function(id){
-                    location.href = "{{url('maintenance/carrier')}}/"+id+"/edit";
-                },
-                destroy:function(carrier){
-                    if(!confirm('确定要删除承运商“' + carrier.name + '”吗?')){return};
-                    let data=this;
-                    let url = "{{url('maintenance/carrier')}}/"+carrier.id;
-                    axios.delete(url,{id:carrier.id})
-                        .then(function (response) {
-                            if(response.data.success){
-                                for (let i = 0; i < data.carriers.length; i++) {
-                                    if (data.carriers[i].id===carrier.id){
-                                        data.carriers.splice(i,1);
-                                        break;
-                                    }
-                                }
-                                tempTip.setDuration(1000);
-                                tempTip.showSuccess('删除承运商"'+carrier.name+'"成功!')
-                            }else{
-                                tempTip.setDuration(1000);
-                                tempTip.show('删除承运商"'+carrier.name+'"失败!')
-                            }
-                        })
-                        .catch(function (err) {
-                            tempTip.setDuration(3000);
-                            tempTip.show('删除承运商失败!'+'网络错误:' + err);
-                        });
-                },
-            }
         });
     </script>
 @endsection

+ 2 - 2
routes/web.php

@@ -594,8 +594,8 @@ Route::group(['prefix'=>'customer'],function(){
 Route::group(['prefix'=>'station'],function(){
     Route::get('index',function (){return view('station.index');});
     Route::group(['prefix'=>'monitor'],function(){
-        Route::get('/',function (){return view('station.monitor.index');});
-        Route::get('/index',function (){return view('station.monitor.index');});
+        Route::get('/','StationController@monitorIndex');
+        Route::get('/index','StationController@monitorIndex');
     });
 });
 /** 控制台 */