whj 4 rokov pred
rodič
commit
9451f0fec9

+ 93 - 30
app/Http/Controllers/IndexController.php

xqd
@@ -3,43 +3,106 @@
 namespace App\Http\Controllers;
 
 use App\Model\Communite;
+use App\Model\DeviceInfo;
+use App\Server\DeviceServer;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Blade;
 use QL\QueryList;
 
 class IndexController extends Controller
 {
-    public function index()
+    public function testOpreation()
     {
-//$domain = 'https://cd.lianjia.com/xiaoqu';
-        set_time_limit(1800);
-        for($i=1;$i<100;$i++){
-            $areas = QueryList::get('https://cd.lianjia.com/xiaoqu'.$i,null,[
-                'headers' => [
-                    'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
-                    'Accept-Encoding' => 'gzip, deflate, br',
-                ]
-            ])->find('.position a')->attrs('href');
-            dd($areas);
-            foreach ($areas as $area){
-                Communite::insert(['links'=>$area]);
+
+        $id = request('id');
+        $device = DeviceInfo::where(['id'=>$id])->first();
+        $rule = json_decode($device->lock_rule);
+        foreach ($rule as $key=>$box){
+            $device_box[] = $key;
+        }
+        return view('test_opreation',['box'=>$device_box,'device'=>$device]);
+    }
+
+    function object_array($array) {
+        if(is_object($array)) {
+            $array = (array)$array;
+        }
+        if(is_array($array)) {
+            foreach($array as $key=>$value) {
+                $array[$key] = object_array($value);
             }
         }
-dd($area);
-        $link = QueryList::get('https://cd.lianjia.com/xiaoqu/1611043165264', null, [
-            'headers' => [
-                'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
-                'Accept-Encoding' => 'gzip, deflate, br',
-            ]
-        ])->getHtml();
-        if($link)
-        dd($link->getHtml());
-        $info = QueryList::get('https://cd.lianjia.com/xiaoqu/1611043165264', null, [
-            'headers' => [
-                'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
-                'Accept-Encoding' => 'gzip, deflate, br',
-            ]
-        ])->find('.xiaoquDescribe')->htmls();
-
-        dd($info);
+        return $array;
+    }
+
+
+    //下发协议
+    public function send_protocol()
+    {
+        $type = request('type');
+        $id = request('id');
+        $box_name = request('box_name');
+        $device  = DeviceInfo::where('id',$id)->first();
+        if(empty($type) || empty($id)){
+            return json_encode(['code'=>601,'msg'=>'缺少必要参数']);
+        }
+        if(empty($device)){
+            return json_encode(['code'=>602,'msg'=>'设备不存在']);
+        }
+
+
+        $lock_rule = json_decode($device->lock_rule);
+        switch ($type){
+            case 1;
+                $rule = ['cmd'=>'start_test'];
+                break;
+            case 2;
+                $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));
+                $start_time = date('Y-m-d H:i:s',(time() - 60));
+                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]];
+                    $res = (new DeviceServer())->sendMsg($device->device_name ,$rule);
+                }
+                break;
+            case 4;
+                $open_time = date('Y-m-d H:i:s',(time() + 180));
+                $close_time = date('Y-m-d H:i:s',(time() + 240));
+                $start_time = date('Y-m-d H:i:s',(time() - 60));
+                $rule = [$box_name=>['type'=>1,'start_time'=>$start_time,'open_time'=>$open_time,'close_time'=>$close_time,'value'=>'','query'=>3600]];
+                break;
+        }
+
+        if(type != 3){
+            $res = (new DeviceServer())->sendMsg($device->device_name,$rule);
+        }
+        if($res['Success'] == true){
+            return json_encode(['code'=>200,'msg'=>'下发命令成功']);
+        } else {
+            return json_encode(['code'=>400,'msg'=>'下发命令失败']);
+        }
+
+
+    }
+
+
+    //获取设备信息
+    public function get_boxname()
+    {
+
+        $id = request('id');
+        $box_name = request('box_name');
+        $device  = DeviceInfo::where('id',$id)->first();
+        $rule = json_decode($device->lock_rule);
+        foreach ($rule as $key=>$box){
+            $device_box['box'][] = ['name'=>$key];
+        }
+        $device_box['id'] = $id;
+        $device_box['device_name'] = $device->device_name;
+        return json_encode(['code'=>200,'msg'=>'ok','data'=>$device_box]);
     }
 }

+ 4 - 0
public/index.php

xqd
@@ -20,6 +20,10 @@ define('LARAVEL_START', microtime(true));
 | loading any of our classes later on. It feels great to relax.
 |
 */
+header('Access-Control-Allow-Origin:*');
+header('Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, PATCH, DELETE');
+header('Access-Control-Allow-Credentials: true');
+header('Access-Control-Allow-Headers: Authorization, Content-Type, x-xsrf-token, x_csrftoken, Cache-Control, X-Requested-With');
 
 require __DIR__.'/../vendor/autoload.php';
 

+ 28 - 0
public/js/auto-size.js

xqd
@@ -0,0 +1,28 @@
+/**
+ * Created by lovo_bdk on 15-12-17.
+ */
+!(function(win, doc) {
+    function setFontSize() {
+        // 获取window 宽度
+        // zepto实现 $(window).width()就是这么干的
+        var winWidth = window.innerWidth;
+        console.log(winWidth);
+        doc.documentElement.style.fontSize = (winWidth / 1080) * 100 + 'px';
+    }
+    var evt = 'onorientationchange' in win ? 'orientationchange' : 'resize';
+    var timer = null;
+    win.addEventListener(evt, function() {
+        clearTimeout(timer);
+
+        timer = setTimeout(setFontSize, 300);
+    }, false);
+    win.addEventListener("pageshow", function(e) {
+        if (e.persisted) {
+            clearTimeout(timer);
+
+            timer = setTimeout(setFontSize, 300);
+        }
+    }, false);
+    //初始化
+    setFontSize();
+}(window, document));

+ 17 - 0
public/js/controlClickState.js

xqd
@@ -0,0 +1,17 @@
+export default {
+    install(Vue) {
+        // 禁止短时间内重复点击
+        Vue.directive('preventClick', {
+            inserted(button, bind) {
+                button.addEventListener('click', () => {
+                    if (!button.disabled) {
+                        button.disabled = true;
+                        setTimeout(() => {
+                            but.disabled = false
+                        }, 3000)
+                    }
+                })
+            }
+        })
+    }
+}

+ 147 - 0
resources/views/test_opreation.blade.php

xqd
@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        * {
+            padding: 0;
+            margin: 0;
+        }
+
+        #main {
+            padding: 0 .4rem;
+        }
+
+        #main .bianhao {
+            font-size: 0.5rem;
+            font-weight: bold;
+            color: black;
+            padding: .4rem;
+        }
+
+        button {
+            width: 2.3rem;
+            background-color: #fff;
+            outline: none;
+            border: 0.01rem solid #efefef;
+            padding: 0.2rem;
+            margin-top: 0.3rem;
+        }
+
+        .redbtn {
+            background-color: red !important;
+            color: white !important;
+        }
+
+        .whitebtn {
+            background-color: white;
+            color: black;
+        }
+    </style>
+</head>
+
+<body>
+<div id="main">
+    <nav class="bianhao">
+        设备编号:{{$device->device_name}}
+    </nav>
+    <article>
+        <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>
+            <button v-preventclick @click="dingshi()" class="" :disabled="dingshibtn">@{{time}}s定时</button>
+        </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>
+        </div>
+        @endforeach
+    </article>
+</div>
+<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
+<script src="./js/auto-size.js"></script>
+<script>
+    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)
+                }
+            })
+        }
+    })
+    const vm = new Vue({
+        el: '#main',
+        data: {
+            isstart: false,
+            mssage: "开始测试",
+            classbtn: "",
+            time: 180,
+            allbtn: false,
+            startbtndib: false,
+            dingshibtn: false,
+        },
+        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 = ""
+                }
+            },
+            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
+                    }
+                }, 1000)
+            },
+            suowei(e){
+                this.startbtndib = true
+                this.dingshibtn = true
+                console.log(e.currentTarget.dataset.name)
+            }
+        },
+    })
+</script>
+</body>
+
+</html>

+ 5 - 1
routes/web.php

xqd
@@ -12,7 +12,11 @@
 */
 
 Route::get('/', function () {
-    return view('welcome');
+    return redirect('/admin');
 });
 
 Route::get('/crawle', 'IndexController@index');
+Route::get('/test_op', 'IndexController@testOpreation');
+Route::get('get_boxname', 'IndexController@get_boxname');
+Route::get('send_protocol', 'IndexController@send_protocol');
+