RegisterAccount.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <div class="center">
  3. <div class="item">
  4. <span class="icon">
  5. <img src="/login/User.png" alt="">
  6. </span>
  7. <input
  8. type="text"
  9. v-model="name"
  10. :placeholder="L['请输入用户名']"
  11. class="input"
  12. />
  13. <div data-type="userName" class="cancel" @click="clearInputVal">
  14. <span class="iconfont icon-cuowu"></span>
  15. </div>
  16. <div class="error">
  17. <span
  18. v-if="nameErrorMsg"
  19. class="iconfont icon-jubao"
  20. ></span>
  21. {{ nameErrorMsg }}
  22. </div>
  23. </div>
  24. <div class="item password">
  25. <span class="icon">
  26. <img src="/login/Password.png" alt="">
  27. </span>
  28. <input
  29. :type="showPwdFlag ? 'text' : 'password'"
  30. v-model="password"
  31. :placeholder="L['请输入密码']"
  32. class="input"
  33. @focus="checkPwdValidate"
  34. @blur="checkPwdValidate"
  35. />
  36. <div class="cancel" @click="isShowPwd">
  37. <span
  38. :class="{
  39. iconfont: true,
  40. 'icon-bukejian11': !showPwdFlag,
  41. 'icon-kejian': showPwdFlag,
  42. show_pwd: showPwdFlag,
  43. }"
  44. ></span>
  45. </div>
  46. </div>
  47. <div class="error" >
  48. <span
  49. v-if="checkPwdErrorMsg"
  50. style="color: #e1251b; font-size: 14px"
  51. class="iconfont icon-jubao"
  52. ></span>
  53. {{ checkPwdErrorMsg }}
  54. </div>
  55. <div class="item confirm">
  56. <span class="icon">
  57. <img src="/login/Password.png" alt="">
  58. </span>
  59. <input
  60. class="input"
  61. v-model="confirmPassword"
  62. :type="showConfirmPwdFlag ? 'text' : 'password'"
  63. :placeholder="L['register']['请确认密码']"
  64. @blur="checkPwdMatched"
  65. />
  66. <div class="cancel" @click="isShowConfirmPwd">
  67. <span
  68. :class="{
  69. iconfont: true,
  70. 'icon-bukejian11': !showConfirmPwdFlag,
  71. 'icon-kejian': showConfirmPwdFlag,
  72. show_pwd: showConfirmPwdFlag,
  73. }"
  74. ></span>
  75. </div>
  76. </div>
  77. <div class="error">
  78. <span
  79. v-if="checkErrorMsg"
  80. style="color: #e1251b; font-size: 14px"
  81. class="iconfont icon-jubao"
  82. ></span>
  83. {{ checkErrorMsg }}
  84. </div>
  85. <el-button
  86. @click="joinForFree"
  87. :class="{ submit: true, disabled: joinForFreeDisabled }"
  88. :disabled="joinForFreeDisabled"
  89. :loading="joinForFreeLoading"
  90. >{{ L["去注册"] }}</el-button
  91. >
  92. <div class="agree_wrap">
  93. <input
  94. type="checkbox"
  95. :class="{ checkbox: true, default: true, checked: agreeFlag }"
  96. />
  97. <span class="agree_selected iconfont icon-finish" @click="agree" />
  98. <span class="text">
  99. {{ L["我同意"]
  100. }}<nuxt-link
  101. target="_blank"
  102. class="agreement"
  103. :to="`/member/login/agreement?type=1`"
  104. >
  105. {{ L["《用户注册协议》"] }}</nuxt-link
  106. >
  107. <nuxt-link
  108. target="_blank"
  109. class="agreement"
  110. :to="`/member/login/agreement?type=2`"
  111. >{{ L["《隐私政策》"] }}
  112. </nuxt-link>
  113. </span>
  114. </div>
  115. <div class="error">
  116. <span
  117. v-if="agreeErrorMsg"
  118. style="color: #e1251b; font-size: 14px"
  119. class="iconfont icon-jubao"
  120. ></span>
  121. {{ agreeErrorMsg }}
  122. </div>
  123. </div>
  124. </template>
  125. <script setup>
  126. import { getCurLanguage } from "@/composables/common.js";
  127. import { showMessage } from "@/utils/common";
  128. const L = getCurLanguage();
  129. const emits = defineEmits(["success"]);
  130. const props = defineProps({
  131. email: {
  132. type: String,
  133. default: "",
  134. },
  135. mobile: {
  136. type: String,
  137. default: "",
  138. }
  139. });
  140. const agreeFlag = ref(false); //同意注册协议标识,默认不同意
  141. const agreeErrorMsg = ref(); // 协议错误提示
  142. const name = ref(""); //用户名
  143. const nameErrorMsg = ref(""); //用户名错误提示
  144. const checkErrorMsg = ref(""); // 密码一致性错误提示
  145. const password = ref(""); //密码
  146. const confirmPassword = ref(""); //二次确认密码
  147. const showPwdFlag = ref(false); //密码是否明文显示,默认密文
  148. const showConfirmPwdFlag = ref(false); // 二次密码是否明文显示,默认密文
  149. const joinForFreeLoading = ref(false);
  150. const checkPwdErrorMsg = ref("");
  151. const joinForFreeDisabled = computed(
  152. () => !name.value || !password.value || !confirmPassword.value
  153. );
  154. const clearInputVal = () => {
  155. name.value = "";
  156. };
  157. //密码是否显示
  158. const isShowPwd = () => {
  159. showPwdFlag.value = !showPwdFlag.value;
  160. };
  161. // 二次确认密码是否显示
  162. const isShowConfirmPwd = () => {
  163. showConfirmPwdFlag.value = !showConfirmPwdFlag.value;
  164. };
  165. //是否同意用户注册协议
  166. const agree = () => {
  167. agreeFlag.value = !agreeFlag.value;
  168. if (agreeFlag.value) {
  169. agreeErrorMsg.value = "";
  170. }
  171. };
  172. const joinForFree = () => {
  173. if (!checkPwdValidate()) return;
  174. if (!checkPwdMatched()) return;
  175. if (!agreeFlag.value) {
  176. agreeErrorMsg.value = L["请同意用户注册协议及隐私政策"];
  177. return false;
  178. }
  179. agreeErrorMsg.value = "";
  180. // 注册账号
  181. joinForFreeLoading.value = true;
  182. const baseParams = {
  183. confirmPassword: confirmPassword.value,
  184. email: props.email,
  185. nickName: name.value,
  186. password: password.value,
  187. mobile: props.mobile
  188. }
  189. const params = {}
  190. Object.keys(baseParams).forEach(key => {
  191. if (baseParams[key]) {
  192. params[key] = baseParams[key]
  193. }
  194. })
  195. post("/v3/member/front/active/register", params)
  196. .then((res) => {
  197. if (res.state === 200) {
  198. showMessage({
  199. message: L["register"]["注册成功"],
  200. type: "success",
  201. });
  202. emits("success");
  203. } else {
  204. showMessage({
  205. message: res.msg,
  206. type: "warning",
  207. });
  208. }
  209. })
  210. .finally(() => {
  211. joinForFreeLoading.value = false;
  212. });
  213. };
  214. const checkPwdMatched = () => {
  215. if (password.value === confirmPassword.value) {
  216. checkErrorMsg.value = "";
  217. return true;
  218. }
  219. checkErrorMsg.value = L["register"]["两次输入的密码不一致"];
  220. return false;
  221. };
  222. const checkPwdValidate = () => {
  223. const regex = /^[A-Za-z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{6,20}$/;
  224. if (regex.test(password.value)) {
  225. checkPwdErrorMsg.value = "";
  226. return true;
  227. }
  228. checkPwdErrorMsg.value = L['请输入6~20位英文、数字、符号'];
  229. return false;
  230. };
  231. watch(name, (val) => {
  232. nameErrorMsg.value = val ? "" : L["请输入用户名"];
  233. });
  234. </script>
  235. <style lang="scss" scoped>
  236. .center {
  237. flex: 1;
  238. height: 100%;
  239. position: relative;
  240. padding: 0 28px;
  241. margin-top: 60px;
  242. .item {
  243. position: relative;
  244. margin-top: 15px;
  245. border-radius: 2px;
  246. &:first-child {
  247. margin-top: 0;
  248. }
  249. .icon {
  250. display: flex;
  251. align-items: center;
  252. justify-content: flex-end;
  253. position: absolute;
  254. left: 1px;
  255. top: 1px;
  256. width: 50px;
  257. height: 46px;
  258. img {
  259. width: 22px;
  260. height: 22px;
  261. position: relative;
  262. right: 5px;
  263. }
  264. }
  265. .input {
  266. border: 1px solid #e8e8e8;
  267. height: 48px;
  268. padding: 0 44px 0 60px;
  269. width: 431px;
  270. font-size: 14px;
  271. }
  272. &.code {
  273. .input {
  274. padding-right: 10px;
  275. width: 150px;
  276. }
  277. }
  278. }
  279. .cancel {
  280. position: absolute;
  281. right: 0;
  282. top: 1px;
  283. width: 44px;
  284. height: 46px;
  285. text-align: center;
  286. line-height: 46px;
  287. cursor: pointer;
  288. .iconfont {
  289. font-size: 16px;
  290. color: '#bbb' !important;
  291. &.show_pwd {
  292. font-size: 20px;
  293. }
  294. }
  295. }
  296. .error {
  297. margin-top: 10px;
  298. position: relative;
  299. color: #e2231a;
  300. height: 16px;
  301. line-height: 16px;
  302. .iconfont {
  303. font-size: 14px;
  304. }
  305. }
  306. .submit {
  307. margin-top: 100px;
  308. background: $colorMain;
  309. color: #fff;
  310. text-align: center;
  311. border-radius: 2px;
  312. width: 100%;
  313. height: 45px;
  314. font-size: 18px;
  315. letter-spacing: 0px;
  316. &:hover {
  317. opacity: 0.9;
  318. }
  319. &.disabled {
  320. background-color: #909399;
  321. }
  322. }
  323. .agree_wrap {
  324. margin-top: 11px;
  325. height: 14px;
  326. line-height: 14px;
  327. color: #999;
  328. padding-left: 2px;
  329. position: relative;
  330. cursor: pointer;
  331. .agree_selected {
  332. color: #fff;
  333. position: absolute;
  334. top: 1px;
  335. left: 3px;
  336. z-index: 2;
  337. font-size: 13px;
  338. }
  339. .checkbox {
  340. width: 14px;
  341. height: 14px;
  342. display: inline-block;
  343. vertical-align: top;
  344. position: relative;
  345. outline: none;
  346. -webkit-appearance: none;
  347. background: none;
  348. border: none;
  349. box-sizing: border-box;
  350. cursor: pointer;
  351. box-shadow: none;
  352. &.checked {
  353. &:before {
  354. background: $colorMain;
  355. border-color: $colorMain;
  356. }
  357. }
  358. &:before {
  359. border: 1px solid #ddd;
  360. background: #fff;
  361. z-index: 1;
  362. position: absolute;
  363. top: 0;
  364. left: 0;
  365. content: " ";
  366. display: block;
  367. width: 100%;
  368. height: 100%;
  369. box-sizing: border-box;
  370. }
  371. }
  372. .text {
  373. margin-left: 5px;
  374. display: inline-block;
  375. vertical-align: top;
  376. .agreement {
  377. color: #000;
  378. &:hover {
  379. text-decoration: underline;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. </style>