RegisterAccount.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="center">
  3. <div class="item">
  4. <span
  5. style="color: #bbb; font-size: 21px;"
  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;"
  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;" 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. line-height: 46px;
  267. height: 46px;
  268. background: #f8f8f8;
  269. img {
  270. width: 20px;
  271. }
  272. }
  273. .input {
  274. border: 1px solid #e8e8e8;
  275. height: 48px;
  276. padding: 0 44px 0 60px;
  277. width: 431px;
  278. }
  279. &.code {
  280. .input {
  281. padding-right: 10px;
  282. width: 150px;
  283. }
  284. }
  285. }
  286. .cancel {
  287. position: absolute;
  288. right: 0;
  289. top: 1px;
  290. width: 44px;
  291. height: 46px;
  292. text-align: center;
  293. line-height: 46px;
  294. cursor: pointer;
  295. }
  296. .error {
  297. margin-top: 10px;
  298. position: relative;
  299. color: #e2231a;
  300. height: 16px;
  301. line-height: 16px;
  302. }
  303. .submit {
  304. margin-top: 100px;
  305. background: $colorMain;
  306. color: #fff;
  307. text-align: center;
  308. border-radius: 2px;
  309. width: 100%;
  310. height: 45px;
  311. font-size: 18px;
  312. letter-spacing: 0px;
  313. &:hover {
  314. opacity: 0.9;
  315. }
  316. &.disabled {
  317. background-color: #909399;
  318. }
  319. }
  320. .agree_wrap {
  321. margin-top: 11px;
  322. height: 14px;
  323. line-height: 14px;
  324. color: #999;
  325. padding-left: 2px;
  326. position: relative;
  327. cursor: pointer;
  328. .agree_selected {
  329. color: #fff;
  330. position: absolute;
  331. top: 1px;
  332. left: 3px;
  333. z-index: 2;
  334. font-size: 13px;
  335. }
  336. .checkbox {
  337. width: 14px;
  338. height: 14px;
  339. display: inline-block;
  340. vertical-align: top;
  341. position: relative;
  342. outline: none;
  343. -webkit-appearance: none;
  344. background: none;
  345. border: none;
  346. box-sizing: border-box;
  347. cursor: pointer;
  348. box-shadow: none;
  349. &.checked {
  350. &:before {
  351. background: $colorMain;
  352. border-color: $colorMain;
  353. }
  354. }
  355. &:before {
  356. border: 1px solid #ddd;
  357. background: #fff;
  358. z-index: 1;
  359. position: absolute;
  360. top: 0;
  361. left: 0;
  362. content: " ";
  363. display: block;
  364. width: 100%;
  365. height: 100%;
  366. box-sizing: border-box;
  367. }
  368. }
  369. .text {
  370. margin-left: 5px;
  371. display: inline-block;
  372. vertical-align: top;
  373. .agreement {
  374. color: #000;
  375. &:hover {
  376. text-decoration: underline;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. </style>