change_password.vue 6.3 KB

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