1
0

register.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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
  15. v-model="form.name"
  16. placeholder="填写写姓名,限15字"
  17. maxlength="15"
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item class="panel-form-item" label="手机号">
  21. <p class="err-info">{{ verification.phone }}</p>
  22. <el-input
  23. v-model="form.phone"
  24. placeholder="请输入手机号码"
  25. :maxlength="11"
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item class="panel-form-item" label="验证码">
  29. <p class="err-info">{{ verification.code }}</p>
  30. <el-input v-model="form.code" placeholder="请输入验证码">
  31. <template v-slot:suffix>
  32. <el-button
  33. type="primary"
  34. plain
  35. class="input-inner-btn"
  36. @click="sendCode"
  37. :disabled="msgStatus && msgStatus.status !== CountdownStuts.never"
  38. >
  39. {{
  40. msgStatus?.status === CountdownStuts.effective
  41. ? `${msgStatus.miss}S后可重新发送`
  42. : "获取验证码"
  43. }}
  44. </el-button>
  45. </template>
  46. </el-input>
  47. </el-form-item>
  48. <el-form-item class="panel-form-item" label="设置密码">
  49. <p class="err-info">{{ verification.psw }}</p>
  50. <el-input
  51. v-model="form.psw"
  52. :maxlength="16"
  53. placeholder="请输入8-16位数字、英文大小写组合密码"
  54. type="password"
  55. ></el-input>
  56. </el-form-item>
  57. <el-form-item class="panel-form-item" label="确认密码">
  58. <p class="err-info">{{ verification.regPsw }}</p>
  59. <el-input
  60. v-model="form.regPsw"
  61. placeholder="请确认密码"
  62. type="password"
  63. :maxlength="16"
  64. ></el-input>
  65. </el-form-item>
  66. <div class="panel-form-item">
  67. <el-button type="primary" class="fill" @click="submitClick">注册</el-button>
  68. </div>
  69. <div class="more">
  70. <a @click="$router.replace({ name: 'login' })">已注册,去登录</a>
  71. </div>
  72. </el-form>
  73. </template>
  74. <script setup lang="ts">
  75. import { reactive, ref, watch } from "vue";
  76. import { PHONE, PSW } from "@/constant/REG";
  77. import { openErrorMsg } from "@/request/errorMsg.js";
  78. import { RouteName, router } from "@/router";
  79. import { CountdownStore, CountdownStuts, register, sendPhoneCode } from "@/store/user";
  80. const form = reactive({
  81. organize: "",
  82. name: "",
  83. phone: "",
  84. code: "",
  85. psw: "",
  86. regPsw: "",
  87. });
  88. const verification = reactive({
  89. organize: "",
  90. name: "",
  91. phone: "",
  92. code: "",
  93. psw: "",
  94. regPsw: "",
  95. });
  96. // 表单验证
  97. const checkForm = (isForce = false) => {
  98. verification.organize = "";
  99. verification.name = "";
  100. verification.phone = "";
  101. verification.code = "";
  102. verification.psw = "";
  103. verification.regPsw = "";
  104. if (!form.phone) {
  105. isForce && (verification.phone = "请输入手机号");
  106. } else {
  107. verification.phone = PHONE.REG.test(form.phone) ? "" : PHONE.tip;
  108. }
  109. if (!form.name) {
  110. isForce && (verification.name = "请输入姓名");
  111. } else if (form.name.length > 15) {
  112. verification.name = "姓名不合法!";
  113. }
  114. if (!form.organize) {
  115. isForce && (verification.organize = "请选择组织架构");
  116. }
  117. if (!form.code) {
  118. isForce && (verification.code = "请输入验证码");
  119. } else if (form.code.length !== 6) {
  120. verification.code = "验证码不合法";
  121. }
  122. if (!form.psw) {
  123. isForce && (verification.psw = "请输入密码");
  124. } else {
  125. verification.psw = PSW.REG.test(form.psw) ? "" : PSW.tip;
  126. }
  127. if (!form.regPsw) {
  128. isForce && (verification.regPsw = "请输入确认密码");
  129. } else if (form.psw !== form.regPsw) {
  130. verification.regPsw = "密码不一致";
  131. }
  132. };
  133. watch(form, () => checkForm());
  134. // 表单提交
  135. const submitClick = async () => {
  136. checkForm(true);
  137. for (let val of Object.values(verification)) {
  138. if (val) return openErrorMsg(val);
  139. }
  140. await register({
  141. deptId: form.organize,
  142. nickName: form.name,
  143. userName: form.phone,
  144. code: form.code,
  145. password: form.psw,
  146. });
  147. router.replace({ name: RouteName.login });
  148. };
  149. // 发送手机验证码
  150. const msgStatus = ref<CountdownStore>();
  151. const sendCode = async () => {
  152. for (let val of Object.values(verification)) {
  153. if (val) return openErrorMsg(val);
  154. }
  155. msgStatus.value = await sendPhoneCode(form.phone);
  156. };
  157. </script>
  158. <style lang="sass">
  159. @import "./style.scss"
  160. </style>