change_password.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="login-wrapper">
  3. <view class="whiteBg">
  4. <view class="list">
  5. <form @submit.prevent="submit">
  6. <view class="item">
  7. <view class="acea-row row-middle">
  8. <input
  9. type="text"
  10. class="texts"
  11. placeholder="填写手机号"
  12. v-model="phone"
  13. required
  14. />
  15. </view>
  16. </view>
  17. <view class="item">
  18. <view class="acea-row row-middle">
  19. <image
  20. src="https://sb-admin.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2025/08/28/1cfaad5f37a64884b3eef985d254606eqzlswf1m9g.png"
  21. style="width: 28rpx; height: 32rpx"
  22. ></image>
  23. <input
  24. type="text"
  25. placeholder="填写验证码"
  26. class="codeIput"
  27. v-model="captcha"
  28. style="width: 80%"
  29. />
  30. <view
  31. class="code"
  32. :disabled="disabled"
  33. :class="disabled === true ? 'on' : ''"
  34. @click="code"
  35. >
  36. {{ text }}
  37. </view>
  38. </view>
  39. </view>
  40. <view class="item">
  41. <view class="acea-row row-middle">
  42. <image
  43. src="https://sb-admin.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2025/08/28/1cfaad5f37a64884b3eef985d254606eqzlswf1m9g.png"
  44. style="width: 28rpx; height: 32rpx"
  45. ></image>
  46. <input
  47. type="password"
  48. class="texts"
  49. placeholder="填写新密码"
  50. v-model="password"
  51. required
  52. />
  53. </view>
  54. </view>
  55. <view class="item">
  56. <view class="acea-row row-middle">
  57. <image
  58. src="https://sb-admin.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2025/08/28/1cfaad5f37a64884b3eef985d254606eqzlswf1m9g.png"
  59. style="width: 28rpx; height: 32rpx"
  60. ></image>
  61. <input
  62. type="password"
  63. class="texts"
  64. placeholder="重复新密码"
  65. v-model="passwordRP"
  66. required
  67. />
  68. </view>
  69. </view>
  70. </form>
  71. </view>
  72. <view class="logon" @click="submit">确认修改</view>
  73. </view>
  74. </view>
  75. </template>
  76. <script setup>
  77. import { ref } from "vue";
  78. import { onLoad } from "@dcloudio/uni-app";
  79. import { useAppStore } from "@/stores/app";
  80. import { registerVerify, registerReset } from "@/api/user";
  81. import { useSendCode } from "@/hooks/useSendCode";
  82. import { useToast } from "@/hooks/useToast.js";
  83. import { telEncrypt } from "@/utils/util.js";
  84. const appStore = useAppStore();
  85. const { Toast } = useToast();
  86. // Reactive state
  87. const phone = ref("");
  88. const password = ref("");
  89. const passwordRP = ref("");
  90. const captcha = ref("");
  91. const { disabled, text, sendCode } = useSendCode();
  92. onLoad(() => {
  93. phone.value = appStore.$userInfo?.phone || "";
  94. });
  95. // Send verification code
  96. const code = async () => {
  97. if (!phone.value) return Toast({ title: "请填写手机号", icon: "none" });
  98. try {
  99. const res = await registerVerify(phone.value);
  100. Toast({ title: res.message, icon: "none" });
  101. sendCode();
  102. } catch (err) {
  103. Toast({ title: err.message, icon: "none" });
  104. }
  105. };
  106. // h5 login
  107. const submit = async () => {
  108. if (!phone.value) return Toast({ title: "请填写手机号", icon: "none" });
  109. if (!captcha.value) return Toast({ title: "请填写验证码", icon: "none" });
  110. if (!password.value)
  111. return uni.showToast({ title: "请填写密码", icon: "none" });
  112. // if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(password.value))
  113. // return uni.showToast({ title: "您输入的密码过于简单", icon: "none" });
  114. if (password.value !== passwordRP.value)
  115. return Toast({ title: "两次密码不一致" });
  116. try {
  117. const { data } = await registerReset({
  118. password: password.value,
  119. captcha: captcha.value,
  120. account: phone.value,
  121. });
  122. Toast({ title: "修改成功", icon: "none" });
  123. setTimeout(() => {
  124. uni.switchTab({
  125. url: "/pages/index/index",
  126. });
  127. }, 1000);
  128. } catch (err) {
  129. console.log("submit error", err);
  130. Toast({ title: err, icon: "none" });
  131. }
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. page {
  136. background: #fff;
  137. }
  138. .appLogin {
  139. margin-top: 60rpx;
  140. }
  141. .code img {
  142. width: 100%;
  143. height: 100%;
  144. }
  145. .acea-row.row-middle {
  146. input {
  147. margin-left: 20rpx;
  148. display: block;
  149. }
  150. }
  151. .login-wrapper {
  152. padding: 30rpx;
  153. .whiteBg {
  154. margin-top: 100rpx;
  155. .list {
  156. border-radius: 16rpx;
  157. overflow: hidden;
  158. .item {
  159. border-bottom: 1px solid #f0f0f0;
  160. background: #fff;
  161. .row-middle {
  162. position: relative;
  163. padding: 16rpx 45rpx;
  164. .texts {
  165. flex: 1;
  166. font-size: 28rpx;
  167. height: 80rpx;
  168. line-height: 80rpx;
  169. display: flex;
  170. justify-content: center;
  171. align-items: center;
  172. }
  173. input {
  174. flex: 1;
  175. font-size: 28rpx;
  176. height: 80rpx;
  177. line-height: 80rpx;
  178. display: flex;
  179. justify-content: center;
  180. align-items: center;
  181. }
  182. .code {
  183. position: absolute;
  184. right: 30rpx;
  185. top: 50%;
  186. color: $theme-color;
  187. font-size: 26rpx;
  188. transform: translateY(-50%);
  189. border: 1px solid $theme-color;
  190. padding: 6rpx 20rpx;
  191. border-radius: 12rpx;
  192. z-index: 99;
  193. }
  194. }
  195. }
  196. }
  197. .logon {
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. width: 100%;
  202. height: 86rpx;
  203. margin-top: 80rpx;
  204. background-color: $theme-color;
  205. border-radius: 120rpx;
  206. color: #ffffff;
  207. font-size: 30rpx;
  208. }
  209. }
  210. }
  211. </style>