RegisterAccount.vue 8.4 KB

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