register.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <el-form class="panel" :model="form" @submit.stop label-width="70px">
  3. <h2>注册</h2>
  4. <div class="stop-psw">
  5. <input type="text">
  6. <input type="password" name="" id="">
  7. </div>
  8. <el-form-item class="panel-form-item" label="选择架构">
  9. <p class="err-info">{{verification.organize}}</p>
  10. <com-company v-model="form.organize" hideAll />
  11. </el-form-item>
  12. <el-form-item class="panel-form-item" label="姓名">
  13. <p class="err-info">{{verification.name}}</p>
  14. <el-input v-model="form.name" placeholder="填写写姓名,限15字" maxlength="15"></el-input>
  15. </el-form-item>
  16. <el-form-item class="panel-form-item" label="手机号">
  17. <p class="err-info">{{verification.phone}}</p>
  18. <el-input v-model="form.phone" placeholder="请输入手机号码"></el-input>
  19. </el-form-item>
  20. <el-form-item class="panel-form-item" label="验证码">
  21. <p class="err-info">{{verification.code}}</p>
  22. <el-input v-model="form.code" placeholder="请输入验证码">
  23. <template v-slot:suffix>
  24. <el-button type="primary" plain class="input-inner-btn" @click="sendCode" :disabled="msgStatus.status !== 0">
  25. {{msgStatus.status === 2 ? `${msgStatus.miss}S后可重新发送` : '获取验证码' }}
  26. </el-button>
  27. </template>
  28. </el-input>
  29. </el-form-item>
  30. <el-form-item class="panel-form-item" label="设置密码">
  31. <p class="err-info">{{verification.psw}}</p>
  32. <el-input v-model="form.psw" placeholder="请输入8-16位数字、英文大小写组合密码" type="password"></el-input>
  33. </el-form-item>
  34. <el-form-item class="panel-form-item" label="确认密码">
  35. <p class="err-info">{{verification.regPsw}}</p>
  36. <el-input v-model="form.regPsw" placeholder="请确认密码" type="password"></el-input>
  37. </el-form-item>
  38. <div class="panel-form-item">
  39. <el-button type="primary" class="fill" @click="submitClick">注册</el-button>
  40. </div>
  41. <div class="more">
  42. <a @click="$router.replace({name: 'login'})">已注册,去登录</a>
  43. </div>
  44. </el-form>
  45. </template>
  46. <script>
  47. import { reactive, watch } from 'vue'
  48. import axios from 'axios'
  49. import { userReg, sendUserMsg } from '@/request/config'
  50. import comCompany from "@/components/company-select";
  51. import { PHONE, PSW } from '@/constant/REG'
  52. import { openErrorMsg } from '@/request/errorMsg.js'
  53. import { encryption } from '@/util'
  54. export default {
  55. name: 'login',
  56. setup() {
  57. const form = reactive({
  58. organize: '',
  59. name: '',
  60. phone: '',
  61. code: '',
  62. psw: '',
  63. regPsw: '',
  64. })
  65. const verification = reactive({
  66. organize: '',
  67. name: '',
  68. phone: '',
  69. code: '',
  70. psw: '',
  71. regPsw: '',
  72. })
  73. const msgStatus = reactive({status: 0, miss: 0})
  74. const checkForm = (isForce) => {
  75. verification.organize = ''
  76. verification.name = ''
  77. verification.phone = ''
  78. verification.code = ''
  79. verification.psw = ''
  80. verification.regPsw = ''
  81. if (!form.phone) {
  82. isForce && (verification.phone = '请输入手机号')
  83. } else {
  84. verification.phone = PHONE.REG.test(form.phone) ? '': PHONE.tip
  85. }
  86. if (!form.name) {
  87. isForce && (verification.name = '请输入姓名')
  88. } else if (form.name.length > 15) {
  89. verification.name = '姓名不合法!'
  90. }
  91. if (!form.organize) {
  92. isForce && (verification.organize = '请选择组织架构')
  93. }
  94. if (!form.code) {
  95. isForce && (verification.code = '请输入验证码')
  96. } else if (form.code.length !== 6){
  97. verification.code = '验证码不合法'
  98. }
  99. if (!form.psw) {
  100. isForce && (verification.psw = '请输入密码')
  101. } else {
  102. verification.psw = PSW.REG.test(form.psw) ? '': PSW.tip
  103. }
  104. if (!form.regPsw) {
  105. isForce && (verification.regPsw = '请输入确认密码')
  106. } else if (form.psw !== form.regPsw){
  107. verification.regPsw = '密码不一致'
  108. }
  109. }
  110. watch(form, () => checkForm())
  111. return {
  112. form,
  113. verification,
  114. checkForm,
  115. msgStatus
  116. }
  117. },
  118. methods: {
  119. async submitClick(ev) {
  120. this.checkForm(true)
  121. ev.stopPropagation()
  122. for (let val of Object.values(this.verification)) {
  123. if (val) return openErrorMsg(val, '提示')
  124. }
  125. let psw = encryption(this.form.psw)
  126. try {
  127. await axios.post(userReg, {
  128. deptId: this.form.organize,
  129. nickName: this.form.name,
  130. userName: this.form.phone,
  131. key: this.imgKey,
  132. code: this.form.code,
  133. password: psw,
  134. confirmPwd: psw,
  135. })
  136. this.$router.replace({ name: 'login' })
  137. } catch {
  138. // return this.refer()
  139. }
  140. },
  141. async sendCode() {
  142. for (let val of Object.values(this.verification)) {
  143. if (val) return openErrorMsg(val, '提示')
  144. }
  145. if (this.msgStatus.status !== 0) {
  146. return;
  147. }
  148. this.msgStatus.status = 1
  149. try {
  150. await axios.get(sendUserMsg, {
  151. params: {
  152. areaNum: 86,
  153. phoneNum: this.form.phone,
  154. type: 1
  155. }
  156. })
  157. this.msgStatus.status = 2
  158. this.msgStatus.miss = 60
  159. let interval = setInterval(() => {
  160. if (--this.msgStatus.miss < 0) {
  161. clearInterval(interval)
  162. this.msgStatus.status = 0
  163. }
  164. }, 1000)
  165. } catch {
  166. this.msgStatus.status = 0
  167. }
  168. }
  169. },
  170. components: {
  171. "com-company": comCompany,
  172. }
  173. }
  174. </script>
  175. <style lang="sass">
  176. @import "./style.scss"
  177. </style>