You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
5.0 KiB

4 weeks ago
  1. <template>
  2. <view class="main">
  3. <view :style="{height:iSMT+'px'}"></view>
  4. <view class="tab">
  5. <view class="tab-item" :class="{active: activeTab === 'email'}" @click="activeTab = 'email'">邮箱</view>
  6. <!-- <view class="tab-item" :class="{active: activeTab === 'phone'}" @click="activeTab = 'phone'">手机号</view> -->
  7. </view>
  8. <view class="switch-tab">
  9. <view class="input-list" v-if="activeTab === 'email'">
  10. <image src="/static/my/changeEmail.png" mode="aspectFit"></image>
  11. <input type="text" placeholder="请输入邮箱" class="input" v-model="userEmail" />
  12. <button class="code-btn" :class="{disabled: gettingCode}" @click="getCode" :disabled="gettingCode">
  13. {{ gettingCode ? `重新发送 ${time}s` : '获取验证码' }}
  14. </button>
  15. </view>
  16. <view class="input-list" v-else>
  17. <image src="/static/my/changeBindPhone.png" mode="aspectFit"></image>
  18. <input type="number" placeholder="请输入手机号" class="input" v-model="userPhone" />
  19. <button class="code-btn" :class="{disabled: gettingCode}" @click="getCode" :disabled="gettingCode">
  20. {{ gettingCode ? `重新发送 ${time}s` : '获取验证码' }}
  21. </button>
  22. </view>
  23. <view class="input-list">
  24. <image src="/static/my/verification.png" mode="aspectFit"></image>
  25. <input type="text" placeholder="请输入验证码" class="input" v-model="verifyCode" />
  26. </view>
  27. </view>
  28. <view class="btn-area">
  29. <button class="next-btn" @click="goToPwdNext">下一步</button>
  30. </view>
  31. </view>
  32. </template>
  33. <script setup>
  34. import {
  35. ref,
  36. onMounted
  37. } from 'vue'
  38. import {
  39. sendEmail,
  40. validateCode,
  41. sendPhone
  42. } from "@/api/setting/password";
  43. const iSMT = ref(0)
  44. const activeTab = ref('email')
  45. const gettingCode = ref(false)
  46. const time = ref(60)
  47. const userEmail = ref('')
  48. const userPhone = ref('')
  49. const verifyCode = ref('')
  50. const getCode = () => {
  51. if (gettingCode.value) return
  52. gettingCode.value = true
  53. time.value = 2
  54. const timer = setInterval(() => {
  55. time.value--
  56. if (time.value <= 0) {
  57. clearInterval(timer)
  58. gettingCode.value = false
  59. time.value = 2
  60. }
  61. }, 1000)
  62. if (activeTab.value === 'email') {
  63. sendEmail({
  64. email: userEmail.value
  65. })
  66. } else {
  67. sendPhone({
  68. phone: userPhone.value
  69. })
  70. }
  71. }
  72. const goToPwdNext = async () => {
  73. if (activeTab.value === 'email') {
  74. if (!userEmail.value) {
  75. uni.showToast({
  76. title: '请输入邮箱',
  77. icon: 'none'
  78. })
  79. return
  80. }
  81. }else{
  82. if (!userPhone.value) {
  83. uni.showToast({
  84. title: '请输入手机号',
  85. icon: 'none'
  86. })
  87. return
  88. }
  89. }
  90. if (!verifyCode.value) {
  91. uni.showToast({
  92. title: '请输入验证码',
  93. icon: 'none'
  94. })
  95. return
  96. }
  97. try {
  98. let param;
  99. if (activeTab.value === 'email') {
  100. param = {
  101. loginType: 'EMAIL',
  102. account: userEmail.value,
  103. verifyCode: verifyCode.value
  104. }
  105. } else {
  106. param = {
  107. loginType: 'PHONE',
  108. account: userPhone.value,
  109. verifyCode: verifyCode.value
  110. }
  111. }
  112. const res = await validateCode(param)
  113. console.log('看看参数', param)
  114. console.log('看看结果', res)
  115. // 如果返回成功
  116. if (res.code === 200) {
  117. uni.showToast({
  118. title: '验证成功',
  119. icon: 'success'
  120. })
  121. uni.navigateTo({
  122. url: '../setting/nextPwd'
  123. })
  124. } else {
  125. uni.showToast({
  126. title: res.message || '验证失败',
  127. icon: 'none'
  128. })
  129. }
  130. } catch (err) {
  131. console.error(err)
  132. uni.showToast({
  133. title: '请求出错',
  134. icon: 'none'
  135. })
  136. }
  137. }
  138. onMounted(() => {
  139. // 获取状态栏高度
  140. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  141. })
  142. </script>
  143. <style>
  144. .tab {
  145. display: flex;
  146. height: 8vh;
  147. background-color: #fff;
  148. border-bottom: 1rpx solid #eee;
  149. }
  150. .tab-item {
  151. flex: 1;
  152. display: flex;
  153. justify-content: center;
  154. align-items: center;
  155. font-size: 32rpx;
  156. position: relative;
  157. }
  158. .tab-item.active {
  159. color: #000;
  160. font-weight: bold;
  161. }
  162. .tab-item.active::after {
  163. content: '';
  164. position: absolute;
  165. bottom: 0;
  166. left: 50%;
  167. transform: translateX(-50%);
  168. width: 40rpx;
  169. height: 6rpx;
  170. background-color: #000;
  171. /* ????? */
  172. }
  173. .switch-tab {
  174. background-color: #fff;
  175. padding: 0 60rpx;
  176. }
  177. .input-list {
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. height: 7vh;
  182. border-bottom: 1rpx solid #eee;
  183. }
  184. .input-list image {
  185. width: 40rpx;
  186. height: 40rpx;
  187. margin-right: 20rpx;
  188. }
  189. .input {
  190. flex: 1;
  191. height: 14vh;
  192. font-size: 28rpx;
  193. }
  194. .code-btn {
  195. width: 200rpx;
  196. height: 60rpx;
  197. font-size: 24rpx;
  198. border-radius: 10rpx;
  199. background-color: #eee;
  200. color: #666;
  201. display: flex;
  202. align-items: center;
  203. justify-content: center;
  204. }
  205. .code-btn.disabled {
  206. background-color: #ccc;
  207. color: #999;
  208. }
  209. .btn-area {
  210. height: 8vh;
  211. background-color: white;
  212. padding-top: 120rpx;
  213. }
  214. .next-btn {
  215. width: 610rpx;
  216. height: 85rpx;
  217. background-color: #000;
  218. color: #fff;
  219. font-size: 30rpx;
  220. border-radius: 40rpx;
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. }
  225. </style>