RegisterAccount.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 joinForFreeDisabled = computed(
  155. () => !name.value || !password.value || !confirmPassword.value
  156. );
  157. const clearInputVal = () => {
  158. name.value = "";
  159. };
  160. //密码是否显示
  161. const isShowPwd = () => {
  162. showPwdFlag.value = !showPwdFlag.value;
  163. };
  164. // 二次确认密码是否显示
  165. const isShowConfirmPwd = () => {
  166. showConfirmPwdFlag.value = !showConfirmPwdFlag.value;
  167. };
  168. //是否同意用户注册协议
  169. const agree = () => {
  170. agreeFlag.value = !agreeFlag.value;
  171. if (agreeFlag.value) {
  172. agreeErrorMsg.value = "";
  173. }
  174. };
  175. const joinForFree = () => {
  176. if (!checkPwdValidate()) return;
  177. if (!checkPwdMatched()) return;
  178. if (!agreeFlag.value) {
  179. agreeErrorMsg.value = L["请同意用户注册协议及隐私政策"];
  180. return false;
  181. }
  182. agreeErrorMsg.value = "";
  183. // 注册账号
  184. joinForFreeLoading.value = true;
  185. post("/v3/member/front/active/register", {
  186. confirmPassword: confirmPassword.value,
  187. email: props.email,
  188. nickName: name.value,
  189. password: password.value,
  190. })
  191. .then((res) => {
  192. if (res.state === 200) {
  193. showMessage({
  194. message: L["register"]["注册成功"],
  195. type: "success",
  196. });
  197. emits("success");
  198. } else {
  199. showMessage({
  200. message: res.msg,
  201. type: "warning",
  202. });
  203. }
  204. })
  205. .finally(() => {
  206. joinForFreeLoading.value = false;
  207. });
  208. };
  209. const checkPwdMatched = () => {
  210. if (password.value === confirmPassword.value) {
  211. checkErrorMsg.value = "";
  212. return true;
  213. }
  214. checkErrorMsg.value = L["register"]["两次输入的密码不一致"];
  215. return false;
  216. };
  217. const checkPwdValidate = () => {
  218. const regex = /^[A-Za-z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{6,20}$/;
  219. if (regex.test(password.value)) {
  220. checkPwdErrorMsg.value = "";
  221. return true;
  222. }
  223. checkPwdErrorMsg.value = L['请输入6~20位英文、数字、符号'];
  224. return false;
  225. };
  226. watch(name, (val) => {
  227. nameErrorMsg.value = val ? "" : L["请输入用户名"];
  228. });
  229. </script>
  230. <style lang="scss" scoped>
  231. .center {
  232. padding: 30px 30px 40px;
  233. .item {
  234. position: relative;
  235. margin-top: 15px;
  236. border-radius: 2px;
  237. &:first-child {
  238. margin-top: 0;
  239. }
  240. .icon {
  241. position: absolute;
  242. left: 1px;
  243. top: 1px;
  244. width: 50px;
  245. text-align: center;
  246. height: 38px;
  247. background: #f8f8f8;
  248. img {
  249. width: 20px;
  250. }
  251. }
  252. .input {
  253. border: 1px solid #e8e8e8;
  254. height: 40px;
  255. padding: 0 44px 0 60px;
  256. width: 326px;
  257. }
  258. &.code {
  259. .input {
  260. padding-right: 10px;
  261. width: 150px;
  262. }
  263. }
  264. }
  265. .cancel {
  266. position: absolute;
  267. right: 0;
  268. top: 1px;
  269. width: 44px;
  270. height: 38px;
  271. cursor: pointer;
  272. :before {
  273. position: absolute;
  274. top: 9px;
  275. // left: 14px;
  276. }
  277. }
  278. .error {
  279. margin-top: 10px;
  280. position: relative;
  281. color: $colorMain;
  282. height: 16px;
  283. line-height: 16px;
  284. }
  285. .submit {
  286. margin-top: 35px;
  287. background: $colorMain;
  288. color: #fff;
  289. text-align: center;
  290. border-radius: 2px;
  291. width: 100%;
  292. height: 45px;
  293. font-size: 18px;
  294. letter-spacing: 0px;
  295. &:hover {
  296. opacity: 0.9;
  297. }
  298. &.disabled {
  299. background-color: #909399;
  300. }
  301. }
  302. .agree_wrap {
  303. margin-top: 11px;
  304. height: 14px;
  305. line-height: 14px;
  306. color: #999;
  307. padding-left: 2px;
  308. position: relative;
  309. cursor: pointer;
  310. .agree_selected {
  311. color: #fff;
  312. position: absolute;
  313. top: 1px;
  314. left: 3px;
  315. z-index: 2;
  316. font-size: 13px;
  317. }
  318. .checkbox {
  319. width: 14px;
  320. height: 14px;
  321. display: inline-block;
  322. vertical-align: top;
  323. position: relative;
  324. outline: none;
  325. -webkit-appearance: none;
  326. background: none;
  327. border: none;
  328. box-sizing: border-box;
  329. cursor: pointer;
  330. box-shadow: none;
  331. &.checked {
  332. &:before {
  333. background: $colorMain;
  334. border-color: $colorMain;
  335. }
  336. }
  337. &:before {
  338. border: 1px solid #ddd;
  339. background: #fff;
  340. z-index: 1;
  341. position: absolute;
  342. top: 0;
  343. left: 0;
  344. content: " ";
  345. display: block;
  346. width: 100%;
  347. height: 100%;
  348. box-sizing: border-box;
  349. }
  350. }
  351. .text {
  352. margin-left: 5px;
  353. display: inline-block;
  354. vertical-align: top;
  355. .agreement {
  356. color: #000;
  357. &:hover {
  358. text-decoration: underline;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. </style>