RegisterAccount.vue 9.1 KB

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