register.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar />
  5. <view class="content">
  6. <view class="logo">
  7. <image
  8. class="logo_img"
  9. src="@/static/login/login_logo.png"
  10. mode="widthFix"
  11. ></image>
  12. </view>
  13. <view class="tab-bar">
  14. <view
  15. class="tab-item"
  16. :class="{ active: loginType === 'phone' }"
  17. @click="changeTab('phone')"
  18. >
  19. <trans _t="手机注册" />
  20. </view>
  21. <view
  22. class="tab-item"
  23. :class="{ active: loginType === 'email' }"
  24. @click="changeTab('email')"
  25. >
  26. <trans _t="邮箱注册" />
  27. </view>
  28. </view>
  29. <up-form
  30. labelPosition="left"
  31. :model="form"
  32. :rules="getRules()"
  33. ref="formRef"
  34. labelWidth="0"
  35. >
  36. <up-form-item prop="userphone">
  37. <up-input
  38. type="text"
  39. shape="circle"
  40. :placeholder="t(loginType === 'phone' ? '手机号' : '电子邮件')"
  41. v-model="form.userphone"
  42. >
  43. <template #prefix>
  44. <view
  45. @click="areaClick"
  46. v-if="useSystem.getCountryCodes.length > 0"
  47. >
  48. <Area
  49. codeNum
  50. v-model="areacode"
  51. ref="areaRef"
  52. @confirm="areaConfirm"
  53. v-show="loginType === 'phone'"
  54. />
  55. </view>
  56. <view class="prefix">
  57. <image
  58. src="@/static/login/email.png"
  59. class="img"
  60. mode="widthFix"
  61. v-show="loginType === 'email'"
  62. ></image>
  63. </view>
  64. </template>
  65. </up-input>
  66. </up-form-item>
  67. <up-form-item prop="code" v-if="loginType === 'email'">
  68. <up-input
  69. :placeholder="t('验证码')"
  70. shape="circle"
  71. v-model="form.code"
  72. type="number"
  73. maxlength="6"
  74. >
  75. <template #prefix>
  76. <view class="prefix">
  77. <image
  78. src="@/static/login/code.png"
  79. class="img"
  80. mode="widthFix"
  81. ></image>
  82. </view>
  83. </template>
  84. <template #suffix>
  85. <view
  86. class="code_btn"
  87. @click="getCode"
  88. v-if="countdown == 60 || countdown == 0"
  89. >
  90. <trans color="var(--light)" _t="发送" />
  91. <template> </template>
  92. </view>
  93. <view class="code_btn" v-else> {{ countdown }}&nbsp;S </view>
  94. </template>
  95. </up-input>
  96. </up-form-item>
  97. <up-form-item prop="userpass">
  98. <up-input
  99. type="userpass"
  100. shape="circle"
  101. :placeholder="t('密码')"
  102. v-model="form.userpass"
  103. >
  104. <template #prefix>
  105. <view class="prefix">
  106. <image
  107. src="@/static/login/password.png"
  108. class="img"
  109. mode="widthFix"
  110. ></image>
  111. </view>
  112. </template>
  113. </up-input>
  114. </up-form-item>
  115. <up-form-item prop="confirmpassword">
  116. <up-input
  117. type="userpass"
  118. shape="circle"
  119. :placeholder="t('确认密码')"
  120. v-model="form.confirmpassword"
  121. >
  122. <template #prefix>
  123. <view class="prefix">
  124. <image
  125. src="@/static/login/password.png"
  126. class="img"
  127. mode="widthFix"
  128. ></image>
  129. </view>
  130. </template>
  131. </up-input>
  132. </up-form-item>
  133. <up-form-item prop="fromid">
  134. <up-input
  135. type="text"
  136. shape="circle"
  137. :placeholder="t('邀请码')"
  138. v-model="form.fromid"
  139. >
  140. <template #prefix>
  141. <view class="prefix">
  142. <image
  143. src="@/static/login/formId.png"
  144. class="img"
  145. mode="widthFix"
  146. ></image>
  147. </view>
  148. </template>
  149. </up-input>
  150. </up-form-item>
  151. </up-form>
  152. <up-button
  153. :text="t('注册')"
  154. class="btn"
  155. color="var(--light)"
  156. @click="submit"
  157. ></up-button>
  158. <view class="labels">
  159. <view class="label_text" @click="login">
  160. <trans _t="已有账户" />
  161. <trans class="register" _t="登录" />
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. <PinCodeModal
  167. :visible="showPinModal"
  168. @close="showPinModal = false"
  169. @complete="handlePinComplete"
  170. isHome
  171. />
  172. </Theme>
  173. </template>
  174. <script setup>
  175. import {
  176. reactive,
  177. ref,
  178. onMounted,
  179. nextTick,
  180. computed,
  181. onBeforeUnmount,
  182. } from "vue";
  183. import { t } from "@/locale";
  184. import Navbar from "@/components/navbar";
  185. import plaCard from "@/components/placard";
  186. import Area from "@/components/area";
  187. import PinCodeModal from "@/components/PinCodeModal";
  188. import { useUserStore, useSystemStore, useTabbarStore } from "@/store";
  189. import { USERS_EMAIL_GET, USER_SMS, USER_EDIT_PAYPASS } from "@/api";
  190. import { Toast, throttle } from "@/utils";
  191. import { onLoad } from "@dcloudio/uni-app";
  192. const useUser = useUserStore();
  193. const formRef = ref(null);
  194. const countdown = ref(60);
  195. const timer = ref(null);
  196. const loginType = ref("phone");
  197. const useSystem = useSystemStore();
  198. const useTabbar = useTabbarStore();
  199. const areaRef = ref(null);
  200. const areacode = ref("");
  201. const showPinModal = ref(false);
  202. const areaClick = () => {
  203. areaRef.value && areaRef.value.open();
  204. };
  205. const areaConfirm = (item) => {
  206. // console.log(item, areacode.value, "areaConfirm");
  207. };
  208. const form = reactive({
  209. userphone: "",
  210. userpass: "",
  211. confirmpassword: "",
  212. fromid: "",
  213. code: "",
  214. });
  215. const getRules = () => ({
  216. userphone: {
  217. required: true,
  218. message: t(
  219. loginType.value === "phone" ? "手机号为必填项" : "电子邮件为必填项"
  220. ),
  221. trigger: ["change"],
  222. },
  223. code: {
  224. required: true,
  225. message: t("验证码为必填项"),
  226. trigger: ["change"],
  227. },
  228. userpass: {
  229. required: true,
  230. message: t("密码是必需的"),
  231. trigger: ["change"],
  232. },
  233. confirmpassword: [
  234. {
  235. required: true,
  236. message: t("密码是必需的"),
  237. trigger: ["change"],
  238. },
  239. {
  240. validator: (rule, value, callback) => {
  241. if (value != form.userpass) {
  242. callback(new Error(t("两次密码不一致")));
  243. } else {
  244. callback();
  245. }
  246. },
  247. },
  248. ],
  249. });
  250. const handlePinComplete = async (pass) => {
  251. const res = await USER_EDIT_PAYPASS({
  252. newpass: pass,
  253. });
  254. Toast(res.msg, 1000).then(() => {
  255. showPinModal.value = false;
  256. uni.switchTab({ url: "/pages/index/index" });
  257. useTabbar.getPageCur("index");
  258. });
  259. };
  260. const changeTab = (type) => {
  261. loginType.value = type;
  262. form.userphone = "";
  263. formRef.value.clearValidate();
  264. };
  265. const getCode = throttle(async () => {
  266. clear();
  267. countdown.value = 60;
  268. if (!form.userphone)
  269. return Toast(
  270. t(loginType.value == "phone" ? "请输入手机号" : "请输入电子邮件")
  271. );
  272. try {
  273. let para = {
  274. must: 1,
  275. };
  276. if (loginType.value == "phone") {
  277. para.userphone = areacode.value + form.userphone;
  278. }
  279. const res =
  280. loginType.value == "phone"
  281. ? await USER_SMS(para)
  282. : await USERS_EMAIL_GET({ email: form.userphone });
  283. Toast(res.msg);
  284. timer.value = setInterval(() => {
  285. if (countdown.value == 0) {
  286. clear();
  287. return;
  288. }
  289. nextTick(() => {
  290. countdown.value--;
  291. });
  292. }, 1000);
  293. } catch (error) {
  294. Toast(error.msg);
  295. }
  296. }, 6000);
  297. onLoad((options) => {
  298. form.fromid = options.fromid || "";
  299. });
  300. onMounted(() => {
  301. // useUser.loginOut(true);
  302. });
  303. const clear = () => {
  304. clearInterval(timer.value);
  305. countdown.value = 60;
  306. timer.value = null;
  307. };
  308. onBeforeUnmount(() => {
  309. if (timer.value) {
  310. clearInterval(timer.value);
  311. timer.value = null;
  312. }
  313. });
  314. const goTo = (url) => {
  315. if (!url) return;
  316. uni.navigateTo({ url });
  317. };
  318. const login = () => {
  319. uni.reLaunch({ url: "/pages/login/login" });
  320. };
  321. const submit = throttle(() => {
  322. formRef.value
  323. .validate()
  324. .then(async (valid) => {
  325. const { confirmpassword, ...params } = form;
  326. if (loginType.value == "phone") {
  327. params.userphone = areacode.value + params.userphone;
  328. params.code = "112233";
  329. }
  330. try {
  331. const result = await useUser.login(params, true);
  332. console.log("登录成功", result);
  333. showPinModal.value = true;
  334. } catch (error) {
  335. console.log("登录失败", error);
  336. }
  337. })
  338. .catch(() => {});
  339. }, 6000);
  340. </script>
  341. <style lang="less" scoped>
  342. @import url("@/style.less");
  343. .wrap {
  344. min-height: 100vh;
  345. background: var(--light);
  346. .content {
  347. padding: 40rpx 60rpx;
  348. .logo {
  349. .flex_center();
  350. padding-bottom: 48rpx;
  351. &_img {
  352. width: 284rpx;
  353. }
  354. }
  355. .login_title {
  356. color: var(--black);
  357. .size();
  358. position: relative;
  359. width: fit-content;
  360. line-height: 44rpx;
  361. padding-bottom: 10rpx;
  362. &::before {
  363. position: absolute;
  364. content: "";
  365. left: 0;
  366. bottom: 0;
  367. width: 75%;
  368. height: 2px;
  369. background-color: var(--black);
  370. }
  371. }
  372. .tab-bar {
  373. display: flex;
  374. margin-bottom: 48rpx;
  375. .tab-item {
  376. position: relative;
  377. width: 50%;
  378. height: 100rpx;
  379. line-height: 100rpx;
  380. text-align: center;
  381. font-size: 28rpx;
  382. color: var(--black);
  383. background: url("@/static/login/left.png");
  384. background-size: 100% 100%;
  385. &.active {
  386. background: url("@/static/login/left_active.png");
  387. background-size: 100% 100%;
  388. color: #fff;
  389. }
  390. &:not(:first-child) {
  391. background: url("@/static/login/right.png");
  392. background-size: 100% 100%;
  393. &.active {
  394. background: url("@/static/login/right_active.png");
  395. background-size: 100% 100%;
  396. color: #fff;
  397. }
  398. }
  399. }
  400. }
  401. /deep/ .u-form {
  402. margin-top: 16px;
  403. }
  404. /deep/ .u-form-item {
  405. padding-bottom: 10px;
  406. .u-form-item__body {
  407. padding: 0;
  408. }
  409. .u-form-item__body__right__message {
  410. margin-top: 10rpx;
  411. }
  412. .u-form-item__body__right__content {
  413. .u-input {
  414. .flex_center();
  415. padding: 16rpx 24rpx 16rpx !important;
  416. // border-radius: 16rpx !important;
  417. background-color: var(--bg);
  418. border-color: #d8d8d8 !important;
  419. // &:hover {
  420. // box-shadow: 0 0 0 1px var(--primary) inset;
  421. // }
  422. }
  423. .u-input__content__field-wrapper__field {
  424. height: 32px;
  425. line-height: 32px;
  426. .uni-input-input {
  427. font-size: 28rpx !important;
  428. }
  429. .input-placeholder {
  430. color: var(--text-01) !important;
  431. font-size: 24rpx;
  432. }
  433. }
  434. }
  435. }
  436. .phone_box {
  437. display: flex;
  438. align-items: center;
  439. margin-right: 18rpx;
  440. }
  441. .prefix {
  442. display: flex;
  443. align-items: center;
  444. width: 40rpx;
  445. margin-right: 18rpx;
  446. .img {
  447. width: inherit;
  448. display: block;
  449. }
  450. }
  451. .code_btn {
  452. background-color: var(--black);
  453. .size(28rpx);
  454. padding: 10rpx 36rpx;
  455. color: var(--light);
  456. border-radius: 10rpx;
  457. }
  458. .btn {
  459. color: var(--light);
  460. background-color: var(--black) !important;
  461. border: 1px solid var(--black) !important;
  462. padding: 16rpx 30rpx;
  463. height: 100rpx;
  464. margin-top: 60rpx;
  465. border-radius: 100px;
  466. margin-bottom: 24rpx;
  467. color: var(--light);
  468. /deep/ .u-button__text {
  469. font-size: 32rpx !important;
  470. font-weight: 700;
  471. }
  472. }
  473. .label_texts {
  474. text-align: right;
  475. padding: 4px 0 14px;
  476. font-size: 24rpx;
  477. line-height: 44rpx;
  478. color: var(--text-01);
  479. }
  480. .tips {
  481. display: flex;
  482. align-items: center;
  483. .line {
  484. flex: 1;
  485. border: 1px solid #d8d8d8;
  486. }
  487. .tips_text {
  488. .size(24rpx);
  489. font-weight: 500;
  490. color: #d8d8d8;
  491. margin: 0 10rpx;
  492. line-height: 44rpx;
  493. }
  494. }
  495. .tip_text {
  496. color: var(--text-01);
  497. .size(20rpx);
  498. line-height: 44rpx;
  499. text-align: center;
  500. }
  501. .btns {
  502. .ver();
  503. flex-direction: column;
  504. &_item {
  505. width: 400rpx;
  506. border: 1px solid var(--black);
  507. border-radius: 100px;
  508. padding: 14rpx 52rpx;
  509. margin-top: 18rpx;
  510. .ver();
  511. color: var(--text-02);
  512. .size(24rpx);
  513. .btn_icon {
  514. width: 48rpx;
  515. margin-right: 52rpx;
  516. .img {
  517. width: inherit;
  518. display: block;
  519. }
  520. }
  521. }
  522. }
  523. .labels {
  524. margin-top: 24rpx;
  525. padding-bottom: 40rpx;
  526. .flex_center();
  527. .label_text {
  528. cursor: pointer;
  529. color: var(--text-01);
  530. .size(24rpx);
  531. line-height: 44rpx;
  532. .register {
  533. .size(28rpx);
  534. color: var(--black);
  535. }
  536. }
  537. }
  538. }
  539. }
  540. </style>