Browse Source

学校班级策略

gzb
guozhongbo 9 months ago
parent
commit
d087d4cb32
1 changed files with 171 additions and 30 deletions
  1. 171
    30
      src/views/schoolSection/strategy/publicStrategy.vue

+ 171
- 30
src/views/schoolSection/strategy/publicStrategy.vue View File

@@ -15,11 +15,18 @@
15 15
           >时间限制策略
16 16
         </div>
17 17
         <div>
18
-          <Checkbox v-if="curState === 1" v-model="strategyInfo.hastime"
18
+          <Checkbox v-if="curState === 2" v-model="strategyInfo.hastime"
19 19
             >启用</Checkbox
20 20
           >
21 21
         </div>
22 22
       </div>
23
+      <div style="margin-bottom: 10px" v-if="strategyInfo.hastime">
24
+        <TimeStrategy
25
+          :times="strategyInfo.padTimes"
26
+          @timesChange="timesChange"
27
+        ></TimeStrategy>
28
+      </div>
29
+      <div class="nodata" v-else>未设置时间限制策略</div>
23 30
     </div>
24 31
     <div class="strategy_list">
25 32
       <div class="strategy_title">
@@ -27,7 +34,7 @@
27 34
           <span class="ivu-icon iconfont icon-yingyongcelve"></span>应用策略
28 35
         </div>
29 36
         <div>
30
-          <Checkbox v-if="curState === 1" v-model="strategyInfo.hasapp"
37
+          <Checkbox v-if="curState === 2" v-model="strategyInfo.hasapp"
31 38
             >启用</Checkbox
32 39
           >
33 40
         </div>
@@ -62,14 +69,14 @@
62 69
       <div class="strategy_title">
63 70
         <div><span class="ivu-icon iconfont icon-shezhi"></span>设备策略</div>
64 71
         <div>
65
-          <Checkbox v-if="curState === 1" v-model="strategyInfo.hasdevice"
72
+          <Checkbox v-if="curState === 2" v-model="strategyInfo.hasdevice"
66 73
             >启用</Checkbox
67 74
           >
68 75
         </div>
69 76
       </div>
70
-      <div class="strategy_content">
77
+      <div class="strategy_content" v-if="strategyInfo.hasdevice">
71 78
         <div class="strategy_top">
72
-          <span>授权应用</span>
79
+          <span>设备功能管理</span>
73 80
         </div>
74 81
         <div class="strategy_bottom" style="min-height: 160px">
75 82
           <div
@@ -94,6 +101,7 @@
94 101
           </div>
95 102
         </div>
96 103
       </div>
104
+      <div class="nodata" v-else>未设置设备策略</div>
97 105
     </div>
98 106
     <div class="strategy_list">
99 107
       <div class="strategy_title">
@@ -105,12 +113,12 @@
105 113
           >Wifi白名单策略
106 114
         </div>
107 115
         <div>
108
-          <Checkbox v-if="curState === 1" v-model="strategyInfo.haswifi"
116
+          <Checkbox v-if="curState === 2" v-model="strategyInfo.haswifi"
109 117
             >启用</Checkbox
110 118
           >
111 119
         </div>
112 120
       </div>
113
-      <div class="strategy_content">
121
+      <div class="strategy_content" v-if="strategyInfo.haswifi">
114 122
         <div class="strategy_top">
115 123
           <span>SSID</span>
116 124
           <span v-if="curState === 2">
@@ -140,6 +148,7 @@
140 148
           </div>
141 149
         </div>
142 150
       </div>
151
+      <div class="nodata" v-else>未设置Wifi白名单</div>
143 152
     </div>
144 153
     <div class="strategy_list">
145 154
       <div class="strategy_title">
@@ -147,12 +156,17 @@
147 156
           <span class="ivu-icon iconfont icon-weiguiguanli"></span>违规处理
148 157
         </div>
149 158
         <div>
150
-          <Checkbox v-if="curState === 1" v-model="strategyInfo.hasviolate"
159
+          <Checkbox v-if="curState === 2" v-model="strategyInfo.hasviolate"
151 160
             >启用</Checkbox
152 161
           >
153 162
         </div>
154 163
       </div>
155
-      <Table class="table" :columns="columns" :data="strategyInfo.padViolates">
164
+      <Table
165
+        v-if="strategyInfo.hasviolate"
166
+        class="table"
167
+        :columns="columns"
168
+        :data="strategyInfo.padViolates"
169
+      >
156 170
         <template slot-scope="{ row }" slot="violationEvents">
157 171
           <Checkbox
158 172
             :disabled="curState === 1"
@@ -165,7 +179,10 @@
165 179
           }}</span>
166 180
         </template>
167 181
         <template slot-scope="{ row }" slot="violationHandling">
168
-          <CheckboxGroup v-model="row.handleMethod">
182
+          <CheckboxGroup
183
+            @on-change="checkboxChange(row)"
184
+            v-model="row.handleMethod"
185
+          >
169 186
             <Checkbox :disabled="curState === 1" label="通知管理员"></Checkbox>
170 187
             <Checkbox
171 188
               :disabled="curState === 1"
@@ -179,6 +196,7 @@
179 196
           </CheckboxGroup>
180 197
         </template>
181 198
       </Table>
199
+      <div class="nodata" v-if="!strategyInfo.hasviolate">未设置违规处理</div>
182 200
       <div
183 201
         class="footer"
184 202
         style="text-align: center; margin-top: 20px"
@@ -202,21 +220,30 @@
202 220
 </template>
203 221
 
204 222
 <script>
205
-import { stApp_detail_obj } from "@/api/stPad";
223
+import {
224
+  stApp_add,
225
+  stApp_detail_obj,
226
+  stApp_edit,
227
+  stPad_add, stPad_detail_obj,
228
+  stPad_edit
229
+} from "@/api/stPad";
206 230
 import { app_list } from "@/api/appgroup";
207
-
231
+import TimeStrategy from "@/components/TimeStrategy/TimeStrategy";
208 232
 export default {
233
+  components: {
234
+    TimeStrategy
235
+  },
209 236
   props: ["curClass"],
210 237
   data() {
211 238
     return {
212 239
       showLoading: false,
213 240
       curState: 1, //1查看/2编辑
214 241
       strategyInfo: {
215
-        hastime: false, // 是否开启时间策略:0否 1是
242
+        hastime: true, // 是否开启时间策略:0否 1是
216 243
         padTimes: [], // 平板策略时间
217
-        hasapp: false, //是否开启应用策略:0否 1是
244
+        hasapp: true, //是否开启应用策略:0否 1是
218 245
         padApps: [], //appid集合
219
-        hasdevice: false, //是否开启设备策略:0否 1是
246
+        hasdevice: true, //是否开启设备策略:0否 1是
220 247
         padDevices: [
221 248
           {
222 249
             id: 1,
@@ -279,9 +306,9 @@ export default {
279 306
             icon: "ivu-icon iconfont icon-icon-OTG"
280 307
           }
281 308
         ], //授权应用
282
-        haswifi: false, //是否开启wifi白名单策略:0否 1是
283
-        padWifis: ["wifi白名单"], //wifi白名单
284
-        hasviolate: false, //是否开启违规通知:0否 1是
309
+        haswifi: true, //是否开启wifi白名单策略:0否 1是
310
+        padWifis: ["xhkjedu"], //wifi白名单
311
+        hasviolate: true, //是否开启违规通知:0否 1是
285 312
         padViolates: [
286 313
           {
287 314
             title: "已ROOT",
@@ -322,7 +349,8 @@ export default {
322 349
           align: "center"
323 350
         }
324 351
       ],
325
-      ssidName: ""
352
+      ssidName: "",
353
+      hasSave: null
326 354
     };
327 355
   },
328 356
   watch: {
@@ -339,17 +367,124 @@ export default {
339 367
     }
340 368
   },
341 369
   created() {
342
-    this.curState = 1;
370
+    this.curState = 2;
343 371
     this.init();
344 372
   },
345 373
   methods: {
346
-    save() {},
374
+    timesChange(times) {
375
+      this.strategyInfo.padTimes = times;
376
+      console.log(this.strategyInfo.padTimes);
377
+    },
378
+    save() {
379
+      console.log(this.strategyInfo);
380
+
381
+      let padDevices = [],
382
+        padViolates = [],
383
+        padApps = [];
384
+      //获取授权应用
385
+      for (let item of this.strategyInfo.padApps) {
386
+        if (item.checked) {
387
+          padApps.push(item.appid);
388
+        }
389
+      }
390
+      //获取设备
391
+      let pdorder = 0;
392
+      for (let item of this.strategyInfo.padDevices) {
393
+        if (item.enabled === 1) {
394
+          pdorder++;
395
+          padDevices.push({ pdtype: item.title, pdorder });
396
+        }
397
+      }
398
+
399
+      //获取违规处理
400
+      for (let item of this.strategyInfo.padViolates) {
401
+        if (item.checked) {
402
+          let handleMethod = item.handleMethod.join(";");
403
+          padViolates.push({ violateType: item.violateType, handleMethod });
404
+        }
405
+      }
406
+      if (this.strategyInfo.hastime) {
407
+        if (this.strategyInfo.padTimes.length === 0) {
408
+          this.$Message.error("请选择时间限制!");
409
+          return;
410
+        }
411
+      }
412
+      if (this.strategyInfo.hasapp) {
413
+        if (padApps.length === 0) {
414
+          this.$Message.error("请选择授权应用!");
415
+          return;
416
+        }
417
+      }
418
+      if (this.strategyInfo.hasdevice) {
419
+        if (padDevices.length === 0) {
420
+          this.$Message.error("请选择设备!");
421
+          return;
422
+        }
423
+      }
424
+      if (this.strategyInfo.haswifi) {
425
+        if (this.strategyInfo.padWifis.length === 0) {
426
+          this.$Message.error("请输入SSID!");
427
+          return;
428
+        }
429
+      }
430
+      if (this.strategyInfo.hasviolate) {
431
+        if (padViolates.length === 0) {
432
+          this.$Message.error("请选择违规事件!");
433
+          return;
434
+        }
435
+        //违规处理选项
436
+        for (let item of padViolates) {
437
+          if (item.handleMethod.length === 0) {
438
+            this.$Message.error("请选择违规处理!");
439
+            return;
440
+          }
441
+        }
442
+      }
443
+      let form = {
444
+        sttype: this.curClass.type, //1学校策略 2班级策略 3个人策略
445
+        objectid: this.curClass.id,
446
+        hastime: this.strategyInfo.hastime ? 1 : 0,
447
+        hasapp: this.strategyInfo.hasapp ? 1 : 0,
448
+        hasdevice: this.strategyInfo.hasdevice ? 1 : 0,
449
+        haswifi: this.strategyInfo.haswifi ? 1 : 0,
450
+        hasviolate: this.strategyInfo.hasviolate ? 1 : 0,
451
+        padTimes: this.strategyInfo.hastime ? this.strategyInfo.padTimes : [],
452
+        padDevices: this.strategyInfo.hasdevice ? padDevices : [],
453
+        padViolates: this.strategyInfo.hasviolate ? padViolates : [],
454
+        padWifis: this.strategyInfo.haswifi ? this.strategyInfo.padWifis : [],
455
+        padApps: this.strategyInfo.hasapp ? padApps : []
456
+      };
457
+      let api = this.hasSave ? stPad_edit : stPad_add;
458
+      console.log(form);
459
+      api(form).then((res) => {
460
+        if (res.code === 0) {
461
+          console.log(res.obj);
462
+          this.$Message.success(res.msg);
463
+          this.detail();
464
+        } else {
465
+          this.$Message.error(res.msg);
466
+        }
467
+      });
468
+    },
469
+    checkboxChange(row) {
470
+      row.checked = row.handleMethod.length > 0 ? true : false;
471
+      this.strategyInfo.padViolates.forEach((item) => {
472
+        if (item.violateType === row.violateType) {
473
+          item.checked = row.handleMethod.length > 0 ? true : false;
474
+          item.handleMethod = row.handleMethod;
475
+        }
476
+      });
477
+    },
347 478
     //违规事件
348 479
     checkedChange(row) {
349
-      if (!row.checked) {
350
-        //清空违规处理
351
-        row.handleMethod = [];
352
-      }
480
+      this.strategyInfo.padViolates.forEach((item) => {
481
+        if (item.violateType === row.violateType) {
482
+          if (!row.checked) {
483
+            //清空违规处理
484
+            item.handleMethod = [];
485
+          }
486
+        }
487
+      });
353 488
     },
354 489
     delWifi(val) {
355 490
       //删除wifi白名单
@@ -368,21 +503,27 @@ export default {
368 503
       );
369 504
       console.log(this.strategyInfo.padWifis);
370 505
     },
371
-    async init() {
372
-      console.log(this.curClass);
506
+    async detail(){
373 507
       this.showLoading = true;
374 508
       //获取学校/班级策略详情
375
-      let res = await stApp_detail_obj({
509
+      let res = await stPad_detail_obj({
376 510
         rtype: this.powerParams.rtype,
377 511
         objectid: this.curClass.id,
378 512
         sttype: this.curClass.type
379 513
       });
380 514
       this.showLoading = false;
381 515
       if (res.code === 0) {
382
-        console.log(res.obj);
516
+        this.hasSave = res.obj;
517
+        if(this.hasSave){
518
+
519
+        }
520
+        console.log(this.hasSave);
383 521
       } else {
384 522
         this.$Message.error(res.msg);
385 523
       }
524
+    },
525
+    async init() {
526
+       await this.detail();
386 527
       //获取应用列表
387 528
       let res1 = await app_list({
388 529
         rtype: this.powerParams.rtype,
@@ -533,7 +674,7 @@ export default {
533 674
         }
534 675
       }
535 676
     }
536
-    .nodata{
677
+    .nodata {
537 678
       color: #798cb5;
538 679
       font-size: 16px;
539 680
       line-height: 30px;

Loading…
Cancel
Save