heyujie
2022-02-09 211cd7469ebc7df813ffd320c90f64fd1c2f1aee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
<template>
  <div class="desktop">
    <d-frame
      v-for="item in this.$store.state.desktop.frames"
      :data="item"
      :key="item.id"
    ></d-frame>
    <safari
      :data="$store.state.desktop.safari"
      v-if="$store.state.desktop.safari.active"
    ></safari>
 
    <div class="warn-tag" v-if="showFreeVersion">
      <span v-if="!snExpire" class="text"
        >试用版尚未激活,仅支持部分功能使用,如需使用全部功能,请尽快激活系统。</span
      >
      <span v-else class="text">SmartAIOS 试用期已到期,请您尽快激活系统</span>
      <div>
        <span class="go-to" @click="gotoActive">前往激活</span>
        <span class="icon iconfont" @click="showFreeVersion = false"
          >&#xe61b;</span
        >
      </div>
    </div>
 
    <el-dialog
      title="激活SmartAI"
      :visible.sync="activeDialog"
      width="750px"
      :show-close="false"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-dialog
        width="30%"
        title="账户激活"
        :visible.sync="innerVisible"
        append-to-body
        class="inner-login-dialog"
      >
        <div class="info">
          请输入你在SmartAI商城账户的手机号并完成验证码校验,实现系统激活!
        </div>
        <div class="login-content">
          <el-form
            :model="phone"
            status-icon
            :rules="phoneCodeRule"
            :validate-on-rule-change="false"
            ref="phoneLogin"
            class="demo-ruleForm"
          >
            <el-form-item prop="phoneNum" style="margin-top: 20px">
              <el-input
                v-model="phone.phoneNum"
                style="width: 380px"
                placeholder="请输入手机号"
              >
                <i slot="prefix" class="el-icon-mobile-phone"></i>
              </el-input>
            </el-form-item>
            <el-form-item prop="verifyCode">
              <el-input
                @keyup.enter.native="phoneLogin"
                v-model="phone.verifyCode"
                autocomplete="off"
                style="width: 254px"
                placeholder="请输入验证码"
              >
                <i slot="prefix" class="el-icon-message"></i>
              </el-input>
              <el-button
                class="code-btn"
                style="margin-left: 15px"
                :disabled="codeDisabled"
                @click="getCode"
                >{{ codeMsg }}</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="cancelLogin">取消</el-button>
          <el-button type="primary" @click="loginShop">确定</el-button>
        </span>
      </el-dialog>
      <div class="ver">
        <span class="ver-text">版本:</span>{{ versionName }}
      </div>
      <div class="ver">
        <span class="ver-text">状态:</span>{{ versionState }}
      </div>
      <el-divider></el-divider>
      <div class="info" v-if="versionName == 'SmartAI正式版'">
        如果您已连接到Internet并且已购买产品密钥,可以尝试验证SmartAI商城账户激活系统。
        <div class="margin-top:10px;">
          <el-button type="primary" @click="innerVisible = true">
            账户激活
          </el-button>
        </div>
      </div>
      <div class="info" v-if="versionName == 'SmartAI正式版'">
        如果您未连接Internet或激活失败,可尝试离线激活,使用手机扫码购买产品或验证SmartAI商城账户激活系统。
      </div>
      <div class="info" v-if="versionName !== 'SmartAI正式版'">
        如果还没有产品密钥,你可以使用手机扫码或前往此链接
        <a href="http://apps.smartai.com" target="_blank"
          >http://apps.smartai.com</a
        >
        购买。
      </div>
      <img class="qr-code-img" src="/version/offline/qrcode" />
      <el-divider></el-divider>
      <div class="ask">
        如果你具有SmartAI提供的产品密钥,请在此处输入激活SmartAI。
      </div>
      <div class="validate">
        <form id="myForm">
          <el-input
            type="textarea"
            autosize
            style="width: 480px"
            placeholder="将产品密钥粘贴在此处"
            v-model="secrectKey"
          >
          </el-input>
        </form>
 
        <el-upload
          class="upload-demo"
          action
          :http-request="uploadKey"
          :limit="1"
          :show-file-list="false"
        >
          <el-button size="small" type="primary">导入产品密钥文件</el-button>
        </el-upload>
      </div>
 
      <span slot="footer" class="dialog-footer">
        <el-button
          v-if="!snExpire && versionName != 'SmartAI正式版'"
          @click="activeDialog = false"
          >继续试用</el-button
        >
        <el-button
          v-if="snExpire && versionName != 'SmartAI正式版'"
          @click="$emit('quit')"
          >退出登录</el-button
        >
        <el-button type="primary" @click="activateVersion">激活</el-button>
      </span>
    </el-dialog>
 
    <el-dialog
      title="我的订单"
      :visible.sync="innerDialog"
      width="750px"
      :show-close="false"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      custom-class="my-order"
    >
      <div class="tip">
        <i class="el-icon-info"></i>
        <span> 请检查订单信息,确认无误后再激活系统。 </span>
      </div>
 
      <div class="order-list" v-if="orderList.length">
        <div
          class="wrap"
          style="margin: 0 5px"
          v-for="(item, index) in orderList"
          :key="index"
        >
          <div class="order-card" v-for="(prod, i) in item.products" :key="i">
            <div class="head">
              <el-checkbox v-model="checked" @change="choseProd(item, prod)">
                <span>订单ID:{{ item.id }}</span>
              </el-checkbox>
 
              <span>{{ item.orderMoney }} 元</span>
            </div>
            <div class="desc">
              <div>系统版本:{{ prod.edition }}</div>
              <div>通道数量:{{ prod.ChCount }}</div>
              <div>摄像机数量:{{ prod.cameraCount }}</div>
              <div>服务时长:{{ prod.serveYear }} 年</div>
            </div>
          </div>
        </div>
        <!-- <div class="order-card" v-for="(item, index) in orderList" :key="index">
          <div class="head">
            <el-checkbox v-model="checked">
              <span>订单ID:{{ item.id }}</span>
            </el-checkbox>
 
            <span>¥{{ item.orderMoney }} 元</span>
          </div>
          <div class="desc">
            <div>系统版本:{{ item.products[0]&&item.products[0].productVersion }}</div>
            <div>通道数量:{{ item.products[0]&&item.products[0].ChCount }}</div>
            <div>摄像机数量:{{ item.products[0]&&item.products[0].cameraCount }}</div>
            <div>服务时长:{{ item.products[0]&&item.products[0].serveYear }} 年</div>
 
          </div>
        </div> -->
      </div>
      <div class="no-order-list" v-else>抱歉,没有查询到订单。</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('quit')">退出登录</el-button>
        <el-button type="primary" @click="activeVerByOrd">激活</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import DFrame from "./DFrame";
import Safari from "./Safari";
import { isPhone } from "../../../../scripts/validate.ts";
import {
  getActiveQrCode,
  getSN,
  activateVersion,
  uploadKey,
  getSmsCode,
  loginShopInSmart,
  getShopOrderList,
  activeByOrder,
} from "@/api/system";
export default {
  name: "Desktop",
  components: {
    DFrame,
    Safari,
  },
  data() {
    return {
      showFreeVersion: false,
      activeDialog: false,
      countdown: 60,
      innerDialog: false,
      versionName: "",
      codeMsg: "获取验证码",
      versionState: "尚未激活",
      secrectKey: "",
      curOrder: {},
      curProd: {},
      codeDisabled: false,
      innerVisible: false,
      snExpire: false,
      timer: null,
      token: "",
      orderList: [],
      phone: {
        phoneNum: "",
        verifyCode: "",
      },
      phoneCodeRule: {
        phoneNum: [{ validator: isPhone, trigger: "blur" }],
        verifyCode: [
          { required: true, message: "请输入验证码", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.validateSn();
  },
  methods: {
    activeVerByOrd() {
      activeByOrder({
        token: this.token,
        activateCode: this.curProd.activateCode,
        productId: this.curProd.productId,
        orderId: this.curOrder.id,
      }).then((res) => {
        if (res.code == 200) {
          this.$notify.success("激活成功");
          this.innerDialog = false;
          this.versionName = this.getVersionName(res.data.edition);
        } else {
          this.$notify.error("激活失败");
        }
      });
    },
    validateSn() {
      getSN().then((res) => {
        this.snExpire = res.data.expire;
        this.showFreeVersion = res.data.sn == "" || res.data.expire;
        this.versionName = this.getVersionName(res.data.edition);
      });
    },
    getValidStr() {
      if (this.countdown > 0 && this.countdown <= 60) {
        this.countdown--;
        if (this.countdown !== 0) {
          this.codeMsg = "重新发送(" + this.countdown + ")";
        } else {
          clearInterval(this.timer);
          this.codeMsg = "获取验证码";
          this.countdown = 60;
          this.timer = null;
          this.codeDisabled = false;
        }
      }
    },
    choseProd(order, prod) {
      debugger;
      this.curOrder = order;
      this.curProd = prod;
    },
    getVersionName(s) {
      switch (s) {
        case "alpha":
          return "SmartAI内测版";
        case "beta":
          return "SmartAI公测版";
        case "trial":
          return "SmartAI试用版";
        case "test":
          return "SmartAI测试版";
        case "official":
          return "SmartAI正式版";
        default:
          return "SmartAI定制版";
          break;
      }
    },
    loginShop() {
      // this.innerDialog = true
      //   this.activeDialog=false
      // getShopOrderList({
      //   token: "",
      // }).then((res) => {
      //   this.orderList=res.data.list
      // });
      this.$refs["phoneLogin"].validate((valid) => {
        if (valid) {
          let param = {
            phoneNum: this.phone.phoneNum,
            verifyCode: this.phone.verifyCode,
          };
          loginShopInSmart(param).then((res) => {
            this.innerDialog = true;
            this.activeDialog = false;
            this.token = res.data.access_token;
            getShopOrderList({ token: this.token })
              .then((res) => {
                if (res.code == 200) {
                  this.orderList = res.data.list;
                } else {
                  this.$notify.error("获取订单列表失败");
                }
              })
              .catch(() => {
                this.$notify.error("获取订单列表失败");
              });
          });
        } else {
          this.nullRule = {};
        }
      });
    },
    cancelLogin() {
      this.innerVisible = false;
    },
    getCode() {
      var pattern = /^1[345789]\d{9}$/;
      if (this.phone.phoneNum == "") {
        this.$refs["phoneLogin"].fields[0].validateMessage = "请输入手机号";
        this.$refs["phoneLogin"].fields[0].validateState = "error";
        return;
      }
      if (!pattern.test(this.phone.phoneNum)) {
        this.$refs["phoneLogin"].fields[0].validateMessage = "手机号码格式有误";
        this.$refs["phoneLogin"].fields[0].validateState = "error";
        return;
      }
      if (!this.timer) {
        this.codeDisabled = true;
        this.getValidStr();
        this.timer = setInterval(this.getValidStr, 1000);
        getSmsCode({ phoneNum: this.phone.phoneNum })
          .then((res) => {
            this.gotCode = true;
          })
          .catch((err) => {
            this.$refs["phoneLogin"].fields[0].validateMessage = err.data.msg;
            this.$refs["phoneLogin"].fields[0].validateState = "error";
          });
      }
    },
    activateVersion() {
      if (this.secrectKey.trim() == "") {
        this.$message.warning("请先填写产品密钥");
        return;
      }
      activateVersion({ code: this.secrectKey.trim() })
        .then((res) => {
          debugger;
          if (res.code == 200) {
            this.$notify.success("激活成功");
            this.validateSn();
            this.goToSysInfo();
            this.activeDialog = false;
          } else {
            this.$notify.error(res.msg);
          }
        })
        .catch((err) => {
          this.$notify.error(err.msg);
        });
    },
    goToSysInfo() {
      window.parent.postMessage({ msg: `toVindicate?menu=系统信息` }, "*");
    },
    gotoActive() {
      this.activeDialog = true;
    },
    uploadKey(params) {
      debugger;
      let param = new FormData();
      param.append("code", params.file);
      uploadKey(param).then(
        (res) => {
          if (res.code == 200) {
            this.$message.success("导入成功");
            this.secrectKey = res.data;
          } else {
            this.$message.error(res.msg);
          }
        },
        (err) => {
          this.$message.error(err.msg);
        }
      );
    },
    onInput(val) {
      if (this[`input${val}`].length == 4 && val < 5) {
        this.$refs[`input${val + 1}`].focus();
      }
      if (this[`input${val}`].length == 0 && val > 0) {
        this.$refs[`input${val - 1}`].focus();
      }
    },
  },
};
</script>
 
<style lang="scss" >
.desktop {
  width: 100%;
  height: 100%;
  .el-dialog__header {
    padding: 15px 20px 10px;
    text-align: left;
    font-weight: 600;
  }
  .el-dialog__body {
    text-align: left;
    padding: 30px 50px;
    padding-top: 20px;
  }
  .el-divider--horizontal {
    margin: 20px 0;
  }
  .validate {
    display: flex;
    align-items: baseline;
    margin-top: 15px;
  }
  #myForm {
    display: flex;
    align-items: center;
    margin-right: 10px;
    .single-input {
      margin: 0 8px;
      width: 60px;
    }
  }
  .ver {
    margin-bottom: 10px;
    font-size: 16px;
    .ver-text {
      font-weight: 600;
    }
  }
  .info {
    font-size: 15px;
    margin-bottom: 10px;
  }
  .qr-code-img {
    // width: 120px;
    // height: 120px;
  }
  .ask {
    margin-top: 20px;
    font-size: 15px;
  }
}
.inner-login-dialog {
  .info {
    padding: 0 30px;
  }
  .el-dialog__body {
    text-align: left;
  }
}
.login-content {
  box-sizing: border-box;
  padding: 0 30px;
  .el-input__inner {
    -webkit-appearance: none;
    background-color: #ffffff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
    height: 40px;
    line-height: 40px;
    outline: none;
    padding: 0 15px;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 100%;
  }
}
.el-dialog.my-order {
  .tip {
    width: auto;
    height: 40px;
    background: rgb(145, 213, 255, 0.2);
    box-sizing: border-box;
    border: 1px rgb(145, 213, 255) solid;
    display: flex;
    padding: 0 10px;
    border-radius: 5px;
    align-items: center;
    i {
      margin-right: 5px;
      font-size: 16px;
      color: rgb(24, 144, 255);
    }
    span {
      font-size: 14px;
    }
  }
  .no-order-list {
    margin-top: 20px;
    font-size: 16px;
    color: red;
  }
  .order-list {
    margin: 20px 0;
    height: 550px;
    overflow-y: auto;
    .order-card {
      height: 150px;
      background: #fff;
      margin-bottom: 15px;
 
      border-radius: 8px;
      box-shadow: 0px 0px 4px rgb(0 0 0 / 25%);
      .head {
        height: 40px;
        line-height: 40px;
        text-align: left;
        box-sizing: border-box;
        padding: 0 20px;
        border-bottom: 1px rgba(242, 242, 242, 1) solid;
        font-size: 14px;
        display: flex;
        justify-content: space-between;
      }
      .desc {
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        height: 110px;
        text-align: left;
        box-sizing: border-box;
        padding: 0 20px;
      }
    }
  }
}
.warn-tag {
  width: 630px;
  text-align: left;
  box-sizing: border-box;
  padding: 0 25px;
  height: 45px;
  background-color: rgba(255, 238, 230, 1);
  z-index: 99999;
  position: absolute;
  display: flex;
  justify-content: space-between;
  top: 55px;
  left: calc(50% - 315px);
  line-height: 45px;
  border-radius: 5px;
  .go-to {
    color: rgba(71, 153, 247, 1);
    cursor: pointer;
    text-decoration: underline;
    font-weight: 600;
    font-size: 14px;
  }
  .text {
    font-size: 14px;
  }
  .icon {
    font-size: 14px;
    cursor: pointer;
    margin-left: 25px;
  }
}
</style>