RegisterAccount.vue 9.4 KB

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