RegisterAccount.vue 9.3 KB

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