forget.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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">
  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>
  134. <up-button
  135. :text="t('重置')"
  136. class="btn"
  137. color="var(--light)"
  138. @click="submit"
  139. ></up-button>
  140. </view>
  141. </view>
  142. </Theme>
  143. </template>
  144. <script setup>
  145. import {
  146. reactive,
  147. ref,
  148. onMounted,
  149. nextTick,
  150. computed,
  151. onBeforeUnmount,
  152. } from "vue";
  153. import { t } from "@/locale";
  154. import Navbar from "@/components/navbar";
  155. import Area from "@/components/area";
  156. import { useUserStore, useSystemStore } from "@/store";
  157. import { USERS_EMAIL_GET, USER_FORGET, USER_SMS } from "@/api";
  158. import { Toast, throttle, TimeOut } from "@/utils";
  159. const useUser = useUserStore();
  160. const formRef = ref(null);
  161. const countdown = ref(60);
  162. const timer = ref(null);
  163. const loginType = ref("phone");
  164. const useSystem = useSystemStore();
  165. const areaRef = ref(null);
  166. const areacode = ref("");
  167. const areaClick = () => {
  168. areaRef.value && areaRef.value.open();
  169. };
  170. const areaConfirm = (item) => {
  171. // console.log(item, areacode.value, "areaConfirm");
  172. };
  173. const form = reactive({
  174. email: "",
  175. code: "",
  176. userpass: "",
  177. confirmpassword: "",
  178. });
  179. const getRules = () => ({
  180. userphone: {
  181. required: true,
  182. message: t(
  183. loginType.value === "phone" ? "手机号为必填项" : "电子邮件为必填项"
  184. ),
  185. trigger: ["change"],
  186. },
  187. code: {
  188. required: true,
  189. message: t("验证码为必填项"),
  190. trigger: ["change"],
  191. },
  192. userpass: {
  193. required: true,
  194. message: t("密码是必需的"),
  195. trigger: ["change"],
  196. },
  197. confirmpassword: [
  198. {
  199. required: true,
  200. message: t("密码是必需的"),
  201. trigger: ["change"],
  202. },
  203. {
  204. validator: (rule, value, callback) => {
  205. if (value != form.userpass) {
  206. callback(new Error(t("两次密码不一致")));
  207. } else {
  208. callback();
  209. }
  210. },
  211. },
  212. ],
  213. });
  214. const selectItem = (item) => {
  215. country.value = [item.value[0].code];
  216. iconPosition.value = item.value[0].position;
  217. form.userphone = "";
  218. showCountry.value = false;
  219. };
  220. const changeTab = (type) => {
  221. loginType.value = type;
  222. form.userphone = "";
  223. formRef.value.clearValidate();
  224. };
  225. const getCode = throttle(async () => {
  226. clear();
  227. countdown.value = 60;
  228. if (!form.userphone)
  229. return Toast(
  230. t(loginType.value == "phone" ? "请输入手机号" : "请输入电子邮件")
  231. );
  232. try {
  233. let para = {
  234. must: 1,
  235. };
  236. if (loginType.value == "phone") {
  237. para.userphone = areacode.value + form.userphone;
  238. }
  239. const res =
  240. loginType.value == "phone"
  241. ? await USER_SMS(para)
  242. : await USERS_EMAIL_GET({ email: form.userphone });
  243. Toast(res.msg);
  244. timer.value = setInterval(() => {
  245. if (countdown.value == 0) {
  246. clear();
  247. return;
  248. }
  249. nextTick(() => {
  250. countdown.value--;
  251. });
  252. }, 1000);
  253. } catch (error) {
  254. Toast(error.msg);
  255. }
  256. }, 6000);
  257. onMounted(() => {
  258. // useUser.loginOut(true);
  259. });
  260. const clear = () => {
  261. clearInterval(timer.value);
  262. countdown.value = 60;
  263. timer.value = null;
  264. };
  265. onBeforeUnmount(() => {
  266. if (timer.value) {
  267. clearInterval(timer.value);
  268. timer.value = null;
  269. }
  270. });
  271. const goTo = (url) => {
  272. if (!url) return;
  273. uni.navigateTo({ url });
  274. };
  275. const login = () => {
  276. uni.reLaunch({ url: "/pages/login/login" });
  277. };
  278. const submit = throttle(() => {
  279. formRef.value
  280. .validate()
  281. .then((valid) => {
  282. const { confirmpassword, ...params } = form;
  283. if (loginType.value == "phone") {
  284. params.userphone = areacode.value + params.userphone;
  285. }
  286. forget(params);
  287. })
  288. .catch(() => {});
  289. }, 6000);
  290. const forget = async (params) => {
  291. try {
  292. const res = await USER_FORGET(params);
  293. res.data && login();
  294. } catch (error) {
  295. Toast(error.msg);
  296. }
  297. };
  298. </script>
  299. <style lang="less" scoped>
  300. @import url("@/style.less");
  301. .wrap {
  302. min-height: 100vh;
  303. background: var(--light);
  304. .content {
  305. padding: 40rpx 60rpx;
  306. .logo {
  307. .flex_center();
  308. padding-bottom: 48rpx;
  309. &_img {
  310. width: 284rpx;
  311. }
  312. }
  313. .tab-bar {
  314. display: flex;
  315. margin-bottom: 48rpx;
  316. .tab-item {
  317. position: relative;
  318. width: 50%;
  319. height: 100rpx;
  320. line-height: 100rpx;
  321. text-align: center;
  322. font-size: 28rpx;
  323. color: var(--black);
  324. background: url("@/static/login/left.png");
  325. background-size: 100% 100%;
  326. &.active {
  327. background: url("@/static/login/left_active.png");
  328. background-size: 100% 100%;
  329. color: #fff;
  330. }
  331. &:not(:first-child) {
  332. background: url("@/static/login/right.png");
  333. background-size: 100% 100%;
  334. &.active {
  335. background: url("@/static/login/right_active.png");
  336. background-size: 100% 100%;
  337. color: #fff;
  338. }
  339. }
  340. }
  341. }
  342. /deep/ .u-form {
  343. margin-top: 16px;
  344. }
  345. /deep/ .u-form-item {
  346. padding-bottom: 10px;
  347. .u-form-item__body {
  348. padding: 0;
  349. }
  350. .u-form-item__body__right__message {
  351. margin-top: 10rpx;
  352. }
  353. .u-form-item__body__right__content {
  354. .u-input {
  355. .flex_center();
  356. padding: 16rpx 24rpx 16rpx !important;
  357. // border-radius: 16rpx !important;
  358. background-color: var(--bg);
  359. border-color: #d8d8d8 !important;
  360. // &:hover {
  361. // box-shadow: 0 0 0 1px var(--primary) inset;
  362. // }
  363. }
  364. .u-input__content__field-wrapper__field {
  365. height: 32px;
  366. line-height: 32px;
  367. .uni-input-input {
  368. font-size: 28rpx !important;
  369. }
  370. .input-placeholder {
  371. color: var(--text-01) !important;
  372. font-size: 24rpx;
  373. }
  374. }
  375. }
  376. }
  377. .phone_box {
  378. display: flex;
  379. align-items: center;
  380. margin-right: 18rpx;
  381. }
  382. .prefix {
  383. width: 40rpx;
  384. margin-right: 18rpx;
  385. .img {
  386. width: inherit;
  387. display: block;
  388. }
  389. }
  390. .code_btn {
  391. background-color: var(--black);
  392. .size(28rpx);
  393. padding: 10rpx 36rpx;
  394. color: var(--light);
  395. border-radius: 10rpx;
  396. }
  397. .btn {
  398. color: var(--light);
  399. background-color: var(--black) !important;
  400. border: 1px solid var(--black) !important;
  401. padding: 16rpx 30rpx;
  402. height: 100rpx;
  403. margin-top: 60rpx;
  404. border-radius: 100rpx;
  405. margin-bottom: 24rpx;
  406. color: var(--light);
  407. /deep/ .u-button__text {
  408. font-size: 32rpx !important;
  409. font-weight: 700;
  410. }
  411. }
  412. .label_texts {
  413. text-align: right;
  414. padding: 4px 0 14px;
  415. font-size: 24rpx;
  416. line-height: 44rpx;
  417. color: var(--text-01);
  418. }
  419. .tips {
  420. display: flex;
  421. align-items: center;
  422. .line {
  423. flex: 1;
  424. border: 1px solid #d8d8d8;
  425. }
  426. .tips_text {
  427. .size(24rpx);
  428. font-weight: 500;
  429. color: #d8d8d8;
  430. margin: 0 10rpx;
  431. line-height: 44rpx;
  432. }
  433. }
  434. .tip_text {
  435. color: var(--text-01);
  436. .size(20rpx);
  437. line-height: 44rpx;
  438. text-align: center;
  439. }
  440. .btns {
  441. .ver();
  442. flex-direction: column;
  443. &_item {
  444. width: 400rpx;
  445. border: 1px solid var(--black);
  446. border-radius: 100px;
  447. padding: 14rpx 52rpx;
  448. margin-top: 18rpx;
  449. .ver();
  450. color: var(--text-02);
  451. .size(24rpx);
  452. .btn_icon {
  453. width: 48rpx;
  454. margin-right: 52rpx;
  455. .img {
  456. width: inherit;
  457. display: block;
  458. }
  459. }
  460. }
  461. }
  462. .labels {
  463. margin-top: 24rpx;
  464. padding-bottom: 40rpx;
  465. .flex_center();
  466. .label_text {
  467. cursor: pointer;
  468. color: var(--text-01);
  469. .size(24rpx);
  470. line-height: 44rpx;
  471. .register {
  472. .size(28rpx);
  473. color: var(--black);
  474. }
  475. }
  476. }
  477. }
  478. }
  479. </style>