register.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="register">
  3. <div class="contents">
  4. <!-- 头部logo -->
  5. <div class="header">
  6. <img src="@/assets/hongqi.png" alt="logo" />
  7. </div>
  8. <!-- 欢迎注册标题 -->
  9. <div class="welcome-title">欢迎注册</div>
  10. <!-- 主体表单 -->
  11. <div class="form-container">
  12. <div class="main">
  13. <wInput
  14. type="text"
  15. maxlength="11"
  16. placeholder="请输入您的手机号码"
  17. v-model="phoneData"
  18. ></wInput>
  19. <wInput
  20. type="text"
  21. maxlength="20"
  22. placeholder="请输入您的姓名"
  23. v-model="name"
  24. ></wInput>
  25. <wInput
  26. type="password"
  27. maxlength="20"
  28. placeholder="请输入您的密码"
  29. v-model="passData"
  30. :isShowPass="true"
  31. ></wInput>
  32. <wInput
  33. type="text"
  34. maxlength="20"
  35. placeholder="请输入邀请码"
  36. v-model="inviteCode"
  37. ></wInput>
  38. <div class="verify-code-container">
  39. <wInput
  40. type="text"
  41. maxlength="4"
  42. placeholder="请输入验证码"
  43. v-model="captchaInput"
  44. class="verify-input"
  45. ></wInput>
  46. <button class="verify-btn" @click="generateCaptcha">{{ captcha }}</button>
  47. </div>
  48. </div>
  49. <wButton
  50. text="立即注册"
  51. :rotate="isRotate"
  52. @click.native="startReg()"
  53. class="wbutton"
  54. ></wButton>
  55. </div>
  56. <!-- 底部链接 -->
  57. <div class="footer">
  58. <div style="color: #fff;font-size: 14px;cursor:pointer;" @click="goBack">找回密码</div>
  59. <span>|</span>
  60. <div style="color: #fff;font-size: 14px;cursor:pointer;" @click="goToLogin">登录账号</div>
  61. </div>
  62. </div>
  63. <!-- 网站底部信息 -->
  64. <div class="site-footer">
  65. <div class="copyright">版权所有:中国建设科技集团股份有限公司</div>
  66. <div class="address">地址:北京市西城区德胜门外大街36号A座</div>
  67. <div class="beian">
  68. 京ICP备 2022001408号-6号 京公网安备 11010202010460号
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import wInput from "@/components/watch-login/watch-input.vue";
  75. import wButton from "@/components/watch-login/watch-button.vue";
  76. import { register } from "@/api/login.js";
  77. import { Toast } from "vant";
  78. export default {
  79. data() {
  80. return {
  81. phoneData: "", // 账号
  82. name: "", // 姓名
  83. passData: "", // 密码
  84. inviteCode: "", // 邀请码
  85. msg: "", // 消息
  86. code: "", // 验证码
  87. showAgree: true, // 协议是否选择
  88. isRotate: false, // 是否加载旋转
  89. captcha: '', // 当前验证码内容
  90. captchaInput: '' // 用户输入的验证码
  91. };
  92. },
  93. mounted() {
  94. this.generateCaptcha();
  95. this.getInviteCodeFromUrl();
  96. },
  97. methods: {
  98. goBack() {
  99. this.$router.go(-1);
  100. },
  101. goToLogin() {
  102. this.$router.push('/');
  103. },
  104. getInviteCodeFromUrl() {
  105. // 从URL参数中获取邀请码
  106. const urlParams = new URLSearchParams(window.location.search);
  107. const inviteCodeFromUrl = urlParams.get('invitecode');
  108. // 如果URL中有邀请码,自动填入
  109. if (inviteCodeFromUrl) {
  110. this.inviteCode = inviteCodeFromUrl;
  111. }
  112. // 同时检查路由参数(Vue Router的方式)
  113. if (this.$route.query.invitecode) {
  114. this.inviteCode = this.$route.query.invitecode;
  115. }
  116. },
  117. generateCaptcha() {
  118. // 生成4个随机数字
  119. let code = '';
  120. for (let i = 0; i < 4; i++) {
  121. code += Math.floor(Math.random() * 10);
  122. }
  123. this.captcha = code;
  124. // 清空用户输入
  125. this.captchaInput = '';
  126. Toast('验证码已刷新');
  127. },
  128. checkCaptcha() {
  129. // 直接比较输入的数字和显示的验证码
  130. return this.captchaInput.trim() === this.captcha;
  131. },
  132. async startReg() {
  133. if (this.isRotate) {
  134. return false;
  135. }
  136. if (!this.phoneData) {
  137. Toast("手机号码不能为空");
  138. return false;
  139. }
  140. if (!this.name) {
  141. Toast("姓名不能为空");
  142. return false;
  143. }
  144. if (this.passData.length < 6) {
  145. Toast("密码不少于6位");
  146. return false;
  147. }
  148. if (!this.inviteCode) {
  149. Toast("邀请码不能为空");
  150. return false;
  151. }
  152. if (!this.checkCaptcha()) {
  153. Toast("验证码错误");
  154. this.generateCaptcha();
  155. return false;
  156. }
  157. this.isRotate = true;
  158. try {
  159. const data = {
  160. account: this.phoneData,
  161. name: this.name,
  162. password: this.passData,
  163. inviteCode: this.inviteCode,
  164. msg: this.msg,
  165. code: this.code
  166. };
  167. let res = await register(data);
  168. if(res.code == 1){
  169. Toast("注册成功");
  170. this.isRotate = false;
  171. setTimeout(() => {
  172. this.$router.push('/');
  173. }, 2000);
  174. }else{
  175. Toast(res.msg);
  176. this.isRotate = false;
  177. }
  178. } catch (error) {
  179. this.isRotate = false;
  180. }
  181. }
  182. },
  183. components: {
  184. wInput,
  185. wButton
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .register {
  191. height: 100vh;
  192. width: 100%;
  193. background: #b43a39;
  194. background-size: cover;
  195. background-position: center;
  196. overflow-y: auto;
  197. }
  198. .contents {
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. min-height: 100vh;
  203. padding-bottom: 20px;
  204. }
  205. .header {
  206. width: 165px;
  207. height: 73px;
  208. margin-top: 40px;
  209. display: flex;
  210. flex-direction: column;
  211. align-items: center;
  212. background-color: #fff;
  213. padding: 20px;
  214. border-radius: 50%;
  215. img {
  216. width: 150px;
  217. height: 150px;
  218. object-fit: cover;
  219. }
  220. }
  221. .welcome-title {
  222. color: #fff;
  223. font-size: 18px;
  224. font-weight: 500;
  225. margin: 15px 0;
  226. text-align: center;
  227. }
  228. .form-container {
  229. width: 76%;
  230. background: #fff;
  231. border-radius: 10px;
  232. padding: 30px 25px;
  233. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  234. margin-bottom: 20px;
  235. }
  236. .main {
  237. width: 100%;
  238. }
  239. .verify-code-container {
  240. display: flex;
  241. gap: 10px;
  242. align-items: center;
  243. margin-top: 15px;
  244. .verify-input {
  245. flex: none;
  246. width: 60%;
  247. }
  248. .verify-btn {
  249. background: #b43a39;
  250. color: #fff;
  251. border: none;
  252. padding: 12px 20px;
  253. border-radius: 5px;
  254. font-size: 14px;
  255. cursor: pointer;
  256. min-width: 80px;
  257. flex-shrink: 0;
  258. &:hover {
  259. background: #a03237;
  260. }
  261. }
  262. }
  263. .wbutton {
  264. margin-top: 30px;
  265. width: 100%;
  266. }
  267. .footer {
  268. margin-top: 20px;
  269. margin-bottom: 20px;
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. gap: 40px;
  274. div {
  275. opacity: 0.9;
  276. transition: opacity 0.3s;
  277. &:hover {
  278. opacity: 1;
  279. }
  280. }
  281. span {
  282. color: #fff;
  283. opacity: 0.5;
  284. }
  285. }
  286. .site-footer {
  287. width: 100%;
  288. padding: 15px 0;
  289. background: rgba(0, 0, 0, 0.5);
  290. text-align: center;
  291. margin-top: 20px;
  292. .copyright, .address, .beian {
  293. color: #fff;
  294. font-size: 12px;
  295. opacity: 0.8;
  296. margin-bottom: 3px;
  297. line-height: 1.2;
  298. }
  299. }
  300. </style>
  301. <style>
  302. @import url("../components/watch-login/css/icon.css");
  303. </style>