杨磊
4 天以前 ef37c59e055a990ce247b265b27d3fcef430a243
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
<template>
  <div class="registerPage">
    <div class="registerContent">
      <div class="registerBox">
        <div class="registerForm">
          <h1>注册通行证</h1>
          <div class="formItem flex">
            <el-select placeholder="请选择" v-model="registerForm.region">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <el-input
              placeholder="请输入手机号"
              class="ml10"
              clearable
              v-model="registerForm.phoneNumber"
            ></el-input>
          </div>
          <div class="formItem flex">
            <el-input
              placeholder="请输入图形验证码"
              class="flex1"
              v-model="registerForm.imgCode"
            ></el-input>
            <div class="imgCode ml10">
              <img :src="imgCode" alt="" @click="getImgCapcha" />
            </div>
          </div>
          <div class="formItem flex">
            <el-input
              placeholder="请输入短信验证码"
              class="flex1"
              v-model="registerForm.verificationCode"
            ></el-input>
            <el-button
              class="ml10"
              style="width: 140px"
              @click="getVerifyCode"
              :disabled="countDown != 0"
              >{{
                countDown == 0 ? "获取短信验证码" : "验证码(" + countDown + "s)"
              }}</el-button
            >
          </div>
          <!-- 手机号注册不需要填写用户名,先注释 -->
          <!-- <div class="formItem flex">
          <span>用户名</span>
          <el-input
            v-model="registerForm.username"
            placeholder="用户名长度3-64个字符,由字母、数字组成"
            clearable
          ></el-input>
        </div>
        <div class="formItem">
          <p class="tips">用户名称一旦注册成功不可修改</p>
        </div> -->
          <div class="formItem">
            <el-input
              v-model="registerForm.password"
              type="password"
              show-password
              placeholder="请输入密码"
            ></el-input>
          </div>
          <div class="formItem">
            <el-input
              v-model="registerForm.passwordAgain"
              type="password"
              show-password
              placeholder="确认密码"
            ></el-input>
          </div>
          <div class="formItem">
            <p class="tips">请将密码设置为8-16位,且不支持纯数字</p>
          </div>
          <div class="formItem">
            <el-button
              class="registerBtn"
              :class="{ isActive: registerForm.accept }"
              :disabled="!registerForm.accept"
              :loading="registerBtnLoading"
              @click="registerFun"
              >注册</el-button
            >
          </div>
          <div class="termsBox">
            <el-checkbox class="termsCheckBox" v-model="registerForm.accept">
            </el-checkbox>
            <span>我接受并同意</span>
            <span class="terms" @click="getClauseData(1)">《用户服务条款》</span>
            <span>和</span>
            <span class="terms" @click="getClauseData(0)">《隐私政策》</span>
          </div>
        </div>
        <div class="tipBox">
          <p>
            已有账号,请点击这里
            <span class="toLogin" @click="toLogin()">直接登录</span>
          </p>
          <p>使用第三方账号登录</p>
          <p>
            <img
              @click="toWxLogin()"
              src="@/assets/images/login/weChartIcon.png"
              alt
            />
          </p>
        </div>
      </div>
    </div>
    <!-- 弹框 -->
    <el-dialog
      title="《用户服务条款》"
      :visible.sync="dialogVisibleUserService"
      :close-on-click-modal="false"
      width="40%"
    >
    <div class="protocolBox" v-html="userProtocolTxt"></div>
 
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button
          type="primary"
          class="btn"
          @click="dialogVisibleUserService = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="《隐私政策条款》"
      :visible.sync="dialogVisibleprivacyPolicy"
      :close-on-click-modal="false"
      width="40%"
    >
    <div class="protocolBox" v-html="privacyPolicyTxt"></div>
 
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button
          type="primary"
          class="btn"
          @click="dialogVisibleUserService = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
export default {
  name: "register",
  data() {
    return {
      dialogVisibleprivacyPolicy:false,
      //用户协议dialog
      dialogVisibleUserService: false,
      //用户协议
      userProtocolTxt:"",
      //协议弹框title
      dialogTitle:"",
      //隐私政策条款
      privacyPolicyTxt:"",
      //当前条款富文本
      currentProtocolTxt:"",
      clauseDialog: {
        title: "",
        open: false,
      },
      clauseData: "",
      registerBtnLoading: false,
      options: [
        {
          value: "中国+86",
          label: "中国+86",
        },
      ],
      registerForm: {
        region: "中国+86",
        phoneNumber: "",
        imgCode: "",
        username: "",
        verificationCode: "",
        password: "",
        passwordAgain: "",
        accept: true,
      },
      countDown: 0,
      imgCode: "",
    };
  },
  mounted() {
    this.showTips();
    this.getImgCapcha();
    this.getProtocol();
  },
  methods: {
    showTips() {
      this.$confirm(
        "如果您已使用过中国农业大学出版社公众号样书申请服务,请使用微信扫码登录!",
        "温馨提示",
        {
          confirmButtonText: "去微信扫码登录",
          cancelButtonText: "继续注册全新账号",
          type: "warning",
        }
      )
        .then(() => {
          this.toWxLogin();
        })
        .catch(() => {});
    },
    getImgCapcha() {
      this.MG.identity.getImgCode().then((res) => {
        this.imgCode = "data:image/png;base64," + res;
      });
    },
    // 获取验证码(注册)
    getVerifyCode() {
      if (!this.config.reg_tel.test(this.registerForm.phoneNumber)) {
        this.$message({
          message: "请输入正确格式的手机号!",
          type: "error",
        });
        return false;
      } else if (
        this.registerForm.imgCode == "" ||
        this.registerForm.imgCode.length != 4
      ) {
        this.$message({
          message: "请输入正确格式的图形验证码",
          type: "error",
        });
        return false;
      } else {
        this.MG.identity
          .getPhoneCode({
            phoneNumber: this.registerForm.phoneNumber,
            imageCaptcha: this.registerForm.imgCode,
            appRefCode: this.config.appRefCode,
          })
          .then((res) => {
            if (res == "验证码发送成功") {
              this.$message({
                message: res,
                type: "success",
              });
              this.getSecond(60);
            } else {
              this.$message({
                message: res,
                type: "error",
              });
              this.getImgCapcha();
            }
          });
      }
    },
    //验证码倒计时
    getSecond(time) {
      if (!this.timer) {
        this.countDown = time;
        this.timer = setInterval(() => {
          this.countDown--;
          if (this.countDown == 0) {
            clearInterval(this.timer);
            this.timer = null;
          }
        }, 1000);
      }
    },
    // 绑定手机号弹框-绑定按钮-函数
    registerFun() {
      if (this.registerForm.phoneNumber == "") {
        this.$message({
          message: "手机号不能为空",
          type: "error",
        });
        return false;
      }
      if (this.registerForm.verificationCode == "") {
        this.$message({
          message: "短信验证码不能为空",
          type: "error",
        });
        return false;
      }
      if (this.registerForm.password == "") {
        this.$message({
          message: "密码不能为空",
          type: "error",
        });
        return false;
      }
      if (this.registerForm.password != this.registerForm.passwordAgain) {
        this.$message({
          message: "两次输入密码不一致",
          type: "error",
        });
        return false;
      }
      let pwdreg =
        // eslint-disable-next-line
        /^(?![A-Za-z]+$)(?![0-9]+$)(?![_!@#$%^&*`~()\-+=<>?:,./;'\|\\\{\}\[\]]+$)[a-zA-Z0-9_!@#$%^&*`~()\-+=<>?:,./;'\|\\\{\}\[\]]{8,32}$/;
      if (!this.config.reg_tel.test(this.registerForm.phoneNumber)) {
        this.$message({
          message: "请输入正确格式的手机号!",
          type: "error",
        });
      } else if (!pwdreg.test(this.registerForm.password)) {
        this.$message({
          message:
            "密码长度8-32个字符,必须由字母、数字、符号(-*/+_.~!@#$%^&*及括号)两种及以上组合!",
          type: "error",
        });
        return false;
      } else {
        this.registerBtnLoading = true;
        this.MG.identity
          .registerAppUserWithPhone({
            appRefCode: this.config.appRefCode,
            phoneNumber: this.registerForm.phoneNumber,
            phoneCaptcha: this.registerForm.verificationCode,
            passWord: this.registerForm.password,
          })
          .then((res) => {
            this.registerBtnLoading = false;
            if (res) {
              this.$confirm("注册成功!", {
                confirmButtonText: "去登录",
                cancelButtonText: "取消",
                type: "success",
              })
                .then(() => {
                  this.$router.push({
                    path: "/login",
                  });
                })
                .catch(() => {});
            }
          })
          .catch((e) => {
            this.$message({
              message: e.response.data.msg,
              type: "error",
            });
            this.registerBtnLoading = false;
          });
      }
    },
    //获取用户协议
    getProtocol() {
      var that = this;
      that.MG.resource
        .getItem({
          path: "caupress_protocol",
          fields: {
            caupress_content: [],
          },
        })
        .then((res) => {
          console.log(res);
          try {
            const data = res.datas.find(
              (e) => e.refCode == "caupress_userRegistrationAgreement"
            );
            this.userProtocolTxt = data ? data.caupress_content : "暂无协议";
            const privacy = res.datas.find(
              (e) => e.refCode == "caupress_privacyPolicy"
            );
            this.privacyPolicyTxt = privacy ? privacy.caupress_content : "暂无协议";
 
          } catch (error) {
            this.protocolTxt = "暂无协议";
          }
        });
    },
    getClauseData(type) {
      console.log(type);
      if(type == 1){
      this.dialogVisibleUserService = true
 
      }else{
      this.dialogVisibleprivacyPolicy = true
 
      }
      
    },
    toLogin() {
      this.$router.push({
        path: "/login",
      });
    },
    toWxLogin() {
      this.$router.push({
        path: "/login",
        query: {
          from: "weChatLogin",
        },
      });
    },
  },
};
</script>
<style lang="less" scoped>
@import "@/assets/css/theme.less";
.registerPage {
  width: 100%;
  height: 100%;
  background-image: url("@/assets/images/login/pageBg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: relative;
  padding: 50px 0;
  .registerContent {
    width: 1200px;
    background: #fff;
    margin: 0 auto;
    padding-bottom: 36px;
    box-shadow: 0 0 66px 0 hsl(0deg 0% 67% / 35%);
    display: flex;
    justify-content: center;
    .registerBox {
      display: flex;
      align-items: center;
      .registerForm {
        width: 420px;
        box-sizing: border-box;
        padding: 20px;
        margin: 20px;
        margin-left: 100px;
        h1 {
          font-size: 18px;
          color: @color;
          text-align: center;
          margin-bottom: 30px;
        }
        .formItem {
          margin-bottom: 10px;
          .imgCode {
            width: 140px;
            height: 40px;
            img {
              width: 100%;
              height: 100%;
              background: #efefef;
            }
          }
          span {
            display: inline-block;
            width: 80px;
            text-align: left;
            line-height: 40px;
          }
          .tips {
            font-size: 12px;
            margin: 0 0 10px 0;
            color: #666;
          }
          .registerBtn {
            width: 100%;
            background: #b1b6bd;
            color: #fff;
            cursor: not-allowed;
            margin-top: 15px;
            &.isActive {
              background: @color;
              cursor: pointer;
            }
          }
        }
        .termsBox {
          line-height: 20px;
          .termsCheckBox {
            vertical-align: text-bottom;
            margin-right: 8px;
          }
          span {
            vertical-align: middle;
          }
          .terms {
            color: @color;
            cursor: pointer;
          }
        }
      }
      .tipBox {
        padding-left: 30px;
        border-left: 1px solid #ddd;
        .toLogin {
          color: @color;
          cursor: pointer;
        }
        p {
          margin-bottom: 15px;
        }
        img {
          width: 30px;
          height: 30px;
          margin-left: 50px;
          cursor: pointer;
        }
      }
    }
  }
}
.ml10 {
  margin-left: 10px;
}
 
.clauseBox {
  height: 500px;
}
.protocolBox {
  text-align: left;
  line-height: 23px;
  z-index: 1;
  height: 500px;
  overflow-y: auto;
  margin-top: -20px;
  box-sizing: border-box;
  padding: 10px;
}
.el-dialog__footer button {
  margin-right: 43%;
  margin-top: 10px;
}
</style>