Browse Source

手机端设备测试页面和功能优化

whj 4 năm trước cách đây
mục cha
commit
dacd695c11

+ 1 - 7
app/Admin/Controllers/LockController.php

xqd xqd
@@ -55,18 +55,12 @@ class LockController extends AdminController
 //        $res = (new DeviceServer())->sendMsg(868626044260472 ,$rule);
 //
         $lock_info = LockInfo::where(['status'=>1,'send_status'=>1])->orderBy('box_type','asc')->get()->GroupBy('device_id');
-dd($lock_info->toArray());
 //        $res = (new DeviceServer())->getProperty('rozl8eri3NwjyMrG6gYT000000 ');
 //        $res = (new DeviceServer())->getDeviceStatus('rozl8eri3NwjyMrG6gYT000000 ');//设备状态
 //        $res = (new DeviceServer())->switchDevice('rozl8eri3NwjyMrG6gYT000000 ',1);//启用禁用
 //        dd($res);
         $grid->disableCreateButton(false);
         $device_id = request('device_id');
-//Admin::script("$('input').combodate({
-//    minYear: 1975,
-//    maxYear: 2013,
-//    minuteStep: 10
-//}); ");
         if(!empty($device_id)){
             $grid->model()->where('device_id',$device_id)
                 ->orderBy('device_id','asc')
@@ -82,7 +76,7 @@ dd($lock_info->toArray());
             return $box_type[$t];
         });
         $grid->column('time_type', __('时间段'))->editable('select',[1=>'上午',2=>'下午']);
-        $grid->column('open_time', __('开门时间'))->editable('time');
+        $grid->column('open_time', __('开门时间'))->editable('time2');
         $grid->column('close_time', __('关门时间'))->editable('time2');
         $grid->column('start_time', __('启动时间'))->editable('datetime');
         $grid->column('type', __('类型'))->using(LockInfo::get_type());

+ 26 - 0
app/Admin/Controllers/Qrcode.php

xqd
@@ -0,0 +1,26 @@
+<?php
+
+
+namespace App\Admin\Controllers;
+
+use App\Model\DeviceInfo;
+use Illuminate\Contracts\Support\Renderable;
+class Qrcode implements  Renderable
+{
+    public function render($key = null)
+    {
+        $device = DeviceInfo::where(['id'=>$key])->first();
+        if(empty($device)){
+            return  '设备设置缺失!';
+        }
+        $url = env('APP_URL').'/test_op?id='.$device->device_name;
+        $html = <<<Script
+        <div id="qrcode"></div>
+        <script type="text/javascript">
+        new QRCode(document.getElementById("qrcode"), '$url');
+        </script>
+Script;
+        return $html;
+
+    }
+}

+ 0 - 1
app/Admin/routes.php

xqd
@@ -17,7 +17,6 @@ Route::group([
     $router->resource('device_type', DeviceTypeController::class);
     $router->resource('device_box', DeviceBoxController::class);
     $router->resource('device_type_box', DeviceTypeBoxController::class);
-    $router->get('get_box', 'ApiController@get_box');
 
     $router->get('/setting_form', 'Config\FormController@form');
     $router->post('/setting_form_save', 'Config\FormController@setting_form_save');

+ 24 - 16
app/Http/Controllers/IndexController.php

xqd xqd xqd xqd
@@ -17,12 +17,17 @@ class IndexController extends Controller
     {
 
         $id = $request->get('id');
-        $device = DeviceInfo::where(['id'=>$id])->first();
+        $device = DeviceInfo::where(['device_name'=>$id])->first();
+        if($device->type == 1){
+            $img = SystemConfig::get('lock_config','box_img_four');
+        } else {
+            $img = SystemConfig::get('lock_config','box_img_five');
+        }
         $rule = json_decode($device->lock_rule);
         foreach ($rule as $key=>$box){
             $device_box[] = $key;
         }
-        return view('test_opreation',['box'=>$device_box,'device'=>$device]);
+        return view('test_opreation',['img'=>$img,'id'=>$id]);
     }
 
     function object_array($array) {
@@ -43,12 +48,14 @@ class IndexController extends Controller
     {
         $type = request('type');
         $id = request('id');
-        $device  = DeviceInfo::where('id',$id)->first();
-        $cache_key = $device->device_name.'rule_type';
+        $device  = DeviceInfo::where('device_name',$id)->first();
+        $cache_key = $id .'rule_type';
         $re_type = Cache::get($cache_key);
 //        return json_encode(['code'=>200,'msg'=>'下发命令成功','data'=>[]]);
-
-        $time1 = 30;//3分钟定时
+//dd($re_type);
+        $time1 = 180;//3分钟定时
+        $opt = 180;
+        $cpt = 240;
         if(empty($type) || empty($id)){
             return json_encode(['code'=>601,'msg'=>'缺少必要参数']);
         }
@@ -68,16 +75,16 @@ class IndexController extends Controller
                 $rule = ['cmd'=>'start_test'];
                 break;
             case 2;
-                $rule = ['cmd'=>'stop_test'];
+                $rule = ["cmd"=>"stop_test"];
                 break;
             case 3;
-                $open_time = date('Y-m-d H:i:s',(time() + 180));
-                $close_time = date('Y-m-d H:i:s',(time() + 240));
+                $open_time = date('H:i',(time() + $opt));
+                $close_time = date('H:i',(time() + $cpt));
                 $start_time = date('Y-m-d H:i:s',(time() - 60));
                 $lock_rule = json_decode($device->lock_rule);
                 foreach ($lock_rule as $box_name){
                     sleep(22);
-                    $rule = [$box_name=>['type'=>1,'start_time'=>$start_time,'open_time'=>$open_time,'close_time'=>$close_time,'value'=>''],'query'=>3600];
+                    $rule = [$box_name=>[['type'=>1,'start'=>$start_time,'open'=>$open_time,'close'=>$close_time,'value'=>'']],'query'=>3600];
                     $res = (new DeviceServer())->sendMsg($device->device_name ,$rule);
                 }
                 break;
@@ -86,15 +93,16 @@ class IndexController extends Controller
                 if(empty($box_name)){
                     return json_encode(['code'=>601,'msg'=>'缺少必要参数']);
                 }
-                $open_time = date('Y-m-d H:i:s',(time() + 60));
-                $close_time = date('Y-m-d H:i:s',(time() + 120));
-                $start_time = date('Y-m-d H:i:s',(time() - 60));
-                $rule = ['box'.$box_name=>['type'=>1,'start_time'=>$start_time,'open_time'=>$open_time,'close_time'=>$close_time,'value'=>''],'query'=>3600];
+                $open_time = date('H:i',(time() + $opt));
+                $close_time = date('H:i',(time() + $cpt));
+                $start_time = date('Y-m-d H:i',(time() - 60));
+                $rule = ['box'.$box_name=>[['type'=>1,'start'=>$start_time,'open'=>$open_time,'close'=>$close_time,'value'=>''],],'query'=>3600];
                 break;
         }
-        //$rule = ['cmd'=>'stop_test'];
+//        $rule = ["cmd"=>"stop_test"];
+//        dd(json_encode($rule));
         if($type != 3){
-             $res = (new DeviceServer())->sendMsg($device->device_name,json_encode($rule));
+            $res = (new DeviceServer())->sendMsg($device->device_name,json_encode($rule));
         }
         if($res['Success'] == true){
             return json_encode(['code'=>200,'msg'=>'下发命令成功']);

+ 122 - 51
resources/views/test_opreation.blade.php

xqd xqd xqd xqd
@@ -4,7 +4,7 @@
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Document</title>
+    <title>设备调试</title>
     <style>
         * {
             padding: 0;
@@ -28,7 +28,6 @@
             outline: none;
             border: 0.01rem solid #efefef;
             padding: 0.2rem;
-            margin-top: 0.3rem;
         }
 
         .redbtn {
@@ -44,52 +43,56 @@
 </head>
 
 <body>
-<div id="main">
+<div id="main" style="margin-bottom: 2rem;">
     <nav class="bianhao">
-        设备编号:{{$device->device_name}}
+        设备编号:@{{arrdata.device_name}}
     </nav>
     <article>
         <div class="bianhao" style="padding-top: 0;">
-            全部锁位
+            设备型号:@{{xiangti}}
+        </div>
+        <div class="bianhao" style="padding-top: 0;">
+            示意图:
+        </div>
+        <div style="text-align: center;">
+            <img src="{{$img}}" alt="" style="width: 7rem;height: 4rem;">
+        </div>
+        <div class="bianhao" style="padding-top: 0;">
+            全部箱体
         </div>
         <div class="bianhao" style="padding-top: 0; border-bottom: 0.01rem solid #efefef;">
             <button @click="startbtn()" :class="classbtn" :disabled="startbtndib">@{{mssage}}</button>
+            <div style="font-size: .3rem;padding-top: .1rem;padding-bottom: .1rem;">点击【开始测试】,全部箱体立即锁死,每20秒锁位状态改变一次
+            </div>
+        </div>
+        <div class="bianhao" style="padding-top: 0; margin-top: .4rem; border-bottom: 0.01rem solid #efefef;">
             <button v-preventclick @click="dingshi()" class="" :disabled="dingshibtn">@{{time}}s定时</button>
+            <div style="font-size: .3rem;padding-top: .1rem;padding-bottom: .1rem;">
+                点击【定时测试】,2min后,锁位开启,3min后锁位关闭,设备配置后,无法点击调试</div>
         </div>
-        @foreach( $box as $key=>$bn)
-        <div  :key="{{$key}}">
-            <div class="bianhao" style="font-size: 0.4rem;">
-                {{$bn}}
-            </div>
-            <div class="bianhao" style="padding-top: 0;">
-                <button @click="suowei" :data-name="'box'+{{$key+1}}" v-preventclick class="suoweiList" :disabled="allbtn">180s定时</button>
+        <div v-for="(item,index) in boxarr" :key="index">
+            <div class="bianhao"
+                 style="font-size: 0.4rem;display: flex; align-items: center; justify-content: space-between;">
+                <div>@{{item.name}}</div>
+                <button @click="suowei(item,index)" :data-index="index" :data-id="item.id" :data-name="item.name"
+                        v-preventclick class="suoweiList" :disabled="allbtn">@{{item.time}}s定时</button>
             </div>
         </div>
-        @endforeach
     </article>
 </div>
 <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
+<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.min.js"></script>
 <script src="./js/auto-size.js"></script>
 <script>
+    var id = {{$id}}
     Vue.directive('preventclick', {
         inserted: function (button, bind) {
             button.addEventListener('click', () => {
-                let time = 180
                 if (!button.disabled) {
                     button.disabled = true;
                     setTimeout(() => {
                         button.disabled = false
-                        vm.startbtndib= false
-                        vm.dingshibtn = false
-                    }, 181000)
-                    let timer=setInterval(()=>{
-                        button.innerHTML = time+"s定时"
-                        time--
-                        if (time<=0){
-                            clearInterval(timer)
-                            button.innerHTML = "180s定时"
-                        }
-                    },1000)
+                    }, 180000)
                 }
             })
         }
@@ -104,40 +107,108 @@
             allbtn: false,
             startbtndib: false,
             dingshibtn: false,
+            arrdata: {},
+            boxarr: [],
+            type: 1,
+            dingshitype: 3,
+            alltype: 4,
+            startdata: "",
+            xiangti: ""
+        },
+        mounted() {
+            this.getData()
         },
         methods: {
             startbtn(e) {
                 //开始测试
-                this.isstart = !this.isstart
-                this.allbtn = !this.allbtn
-                this.dingshibtn = !this.dingshibtn
-                if (this.isstart) {
-                    var type = 1;
-                    this.mssage = "停止测试"
-                    this.classbtn = "redbtn"
-                } else {
-                    var type = 2;
-                    this.mssage = "开始测试"
-                    this.classbtn = ""
-                }
+                axios.get("http://172.31.31.199/send_protocol?id="+id+"&type=" + this.type).then(res => {
+                    if (res.data.code == 603) {
+                        alert(res.data.msg)
+                    } else {
+                        this.allbtn = !this.allbtn
+                        this.dingshibtn = !this.dingshibtn
+                        this.isstart = !this.isstart
+                        if (this.isstart) {
+                            this.mssage = "停止测试"
+                            this.classbtn = "redbtn"
+                            this.type = 2
+                        } else {
+                            this.mssage = "开始测试"
+                            this.classbtn = ""
+                            this.type = 1
+                        }
+                        console.log(this.type)
+                    }
+                })
             },
             dingshi() {
-                this.startbtndib = true
-                this.allbtn = true
-                let timestop = setInterval(() => {
-                    this.time--
-                    if (this.time == 0) {
-                        clearInterval(timestop)
-                        this.time = 180
-                        this.startbtndib = false
-                        this.allbtn = false
+                axios.get("http://172.31.31.199/send_protocol?id="+id+"&type=" + this.dingshitype).then(res => {
+                    if (res.data.code == 603) {
+                        alert(res.data.msg)
+                    } else {
+                        this.startbtndib = true
+                        this.allbtn = true
+                        let timestop = setInterval(() => {
+                            this.time--
+                            if (this.time == 0) {
+                                clearInterval(timestop)
+                                this.time = 180
+                                this.startbtndib = false
+                                this.allbtn = false
+                            }
+                        }, 1000)
+                    }
+                })
+            },
+            suowei(e, index) {
+                let el = document.querySelectorAll('.suoweiList')
+                el.forEach(item => {
+                    if (item.dataset.index != index && !item.disabled) {
+                        item.disabled = true
+                        setTimeout(() => {
+                            item.disabled = false
+                        }, 20000);
+                    }
+                });
+                axios.get("http://172.31.31.199/send_protocol?id="+id+"&type=" + this.alltype + "&box_name=" + e.id).then(res => {
+                    if (res.data.code == 603) {
+                        alert(res.data.msg)
+                    } else {
+                        this.reduceCount(index)
                     }
-                }, 1000)
+                })
             },
-            suowei(e){
-                this.startbtndib = true
-                this.dingshibtn = true
-                console.log(e.currentTarget.dataset.name)
+            getData: function () {
+                axios.get("http://172.31.31.199/get_boxname?id="+id).then(res => {
+                    console.log(res)
+                    if (res.data.code == 200) {
+                        let num = res.data.data.device_type == "1" ? 5 : 6
+                        this.arrdata = res.data.data
+                        this.xiangti = this.arrdata.device_type == "1" ? '四箱' : '五箱'
+                        for (let i = 0; i < num; i++) {
+                            let obj = {
+                                time: 180,
+                                status: false,
+                                name: i + 1 + "号箱体",
+                                id: i + 1
+                            }
+                            this.boxarr.push(obj)
+                        }
+
+                    }
+                })
+            },
+            reduceCount(index) {
+                let _index = index;
+                let time = setInterval(() => {
+                    if (this.boxarr[_index].time > 0) {
+                        this.boxarr[_index].time--;
+                    } else {
+                        clearInterval(time)
+                        this.boxarr[_index].time = 180;
+                    }
+                    Vue.set(this.boxarr[_index], this.boxarr[_index].time, this.boxarr[_index].time)
+                }, 1000);
             }
         },
     })