index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="container">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header">
  5. <view class="header-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
  7. </view>
  8. <text class="header-title">修改手机号</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <view class="header-placeholder"></view>
  12. <view class="form-card">
  13. <view class="form-item">
  14. <text class="form-label">新手机号</text>
  15. <input
  16. class="form-input"
  17. type="number"
  18. v-model="phone"
  19. placeholder="请输入新手机号"
  20. placeholder-class="placeholder"
  21. maxlength="11"
  22. />
  23. </view>
  24. <view class="form-item no-border">
  25. <text class="form-label">验证码</text>
  26. <input
  27. class="form-input"
  28. type="number"
  29. v-model="code"
  30. placeholder="请输入验证码"
  31. placeholder-class="placeholder"
  32. maxlength="6"
  33. />
  34. <button
  35. class="code-btn"
  36. :disabled="countdown > 0"
  37. @click="sendCode">
  38. {{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
  39. </button>
  40. </view>
  41. </view>
  42. <view class="btn-area">
  43. <button class="submit-btn" @click="submitChange">确认修改</button>
  44. </view>
  45. <view class="tips">
  46. <text class="tips-text">• 修改手机号后,新手机号将作为登录账号</text>
  47. <text class="tips-text">• 请确保新手机号可以正常接收短信</text>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. // 引入 API @author steelwei
  53. import { updatePhone } from '@/api/fulfiller/fulfiller'
  54. export default {
  55. data() {
  56. return {
  57. phone: '',
  58. code: '',
  59. countdown: 0,
  60. timer: null
  61. }
  62. },
  63. onUnload() {
  64. if (this.timer) {
  65. clearInterval(this.timer);
  66. }
  67. },
  68. methods: {
  69. navBack() {
  70. uni.navigateBack({ delta: 1 });
  71. },
  72. // 发送验证码 @author steelwei
  73. sendCode() {
  74. // 验证手机号
  75. if (!this.phone) {
  76. uni.showToast({ title: '请输入手机号', icon: 'none' });
  77. return;
  78. }
  79. if (!/^1[3-9]\d{9}$/.test(this.phone)) {
  80. uni.showToast({ title: '手机号格式不正确', icon: 'none' });
  81. return;
  82. }
  83. // TODO: 调用发送验证码接口
  84. uni.showToast({ title: '验证码已发送', icon: 'success' });
  85. // 开始倒计时
  86. this.countdown = 60;
  87. this.timer = setInterval(() => {
  88. this.countdown--;
  89. if (this.countdown <= 0) {
  90. clearInterval(this.timer);
  91. }
  92. }, 1000);
  93. },
  94. // 提交修改 @author steelwei
  95. async submitChange() {
  96. // 验证输入
  97. if (!this.phone) {
  98. uni.showToast({ title: '请输入手机号', icon: 'none' });
  99. return;
  100. }
  101. if (!/^1[3-9]\d{9}$/.test(this.phone)) {
  102. uni.showToast({ title: '手机号格式不正确', icon: 'none' });
  103. return;
  104. }
  105. if (!this.code) {
  106. uni.showToast({ title: '请输入验证码', icon: 'none' });
  107. return;
  108. }
  109. uni.showLoading({ title: '提交中...' });
  110. try {
  111. const res = await updatePhone(this.phone, this.code);
  112. if (res.code === 200) {
  113. uni.showToast({
  114. title: '修改成功',
  115. icon: 'success',
  116. duration: 2000
  117. });
  118. setTimeout(() => {
  119. uni.navigateBack({ delta: 1 });
  120. }, 2000);
  121. } else {
  122. uni.showToast({
  123. title: res.msg || '修改失败',
  124. icon: 'none'
  125. });
  126. }
  127. } catch (error) {
  128. console.error('修改手机号失败:', error);
  129. uni.showToast({ title: error.message || error.msg || '请求失败', icon: 'none' });
  130. } finally {
  131. uni.hideLoading();
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137. <style>
  138. page {
  139. background-color: #F8F8F8;
  140. }
  141. .custom-header {
  142. position: fixed;
  143. top: 0;
  144. left: 0;
  145. width: 100%;
  146. height: 88rpx;
  147. padding-top: var(--status-bar-height);
  148. background-color: #fff;
  149. display: flex;
  150. align-items: center;
  151. justify-content: space-between;
  152. padding-left: 30rpx;
  153. padding-right: 30rpx;
  154. box-sizing: content-box;
  155. z-index: 100;
  156. }
  157. .header-placeholder {
  158. height: calc(88rpx + var(--status-bar-height));
  159. }
  160. .back-icon {
  161. width: 40rpx;
  162. height: 40rpx;
  163. }
  164. .header-title {
  165. font-size: 28rpx;
  166. font-weight: bold;
  167. color: #333;
  168. }
  169. .header-right {
  170. width: 40rpx;
  171. }
  172. .container {
  173. padding: 20rpx 30rpx;
  174. }
  175. .form-card {
  176. background-color: #fff;
  177. border-radius: 20rpx;
  178. padding: 0 30rpx;
  179. margin-bottom: 30rpx;
  180. }
  181. .form-item {
  182. display: flex;
  183. align-items: center;
  184. padding: 30rpx 0;
  185. border-bottom: 1px solid #F5F5F5;
  186. }
  187. .form-item.no-border {
  188. border-bottom: none;
  189. }
  190. .form-label {
  191. width: 160rpx;
  192. font-size: 28rpx;
  193. color: #333;
  194. }
  195. .form-input {
  196. flex: 1;
  197. font-size: 28rpx;
  198. color: #333;
  199. }
  200. .placeholder {
  201. color: #999;
  202. }
  203. .code-btn {
  204. width: 180rpx;
  205. height: 60rpx;
  206. line-height: 60rpx;
  207. background-color: #FF5722;
  208. color: #fff;
  209. font-size: 24rpx;
  210. border-radius: 30rpx;
  211. padding: 0;
  212. margin-left: 20rpx;
  213. }
  214. .code-btn[disabled] {
  215. background-color: #ccc;
  216. }
  217. .btn-area {
  218. padding: 40rpx 0;
  219. }
  220. .submit-btn {
  221. background-color: #FF5722;
  222. color: #fff;
  223. font-size: 32rpx;
  224. border-radius: 44rpx;
  225. height: 88rpx;
  226. line-height: 88rpx;
  227. border: none;
  228. }
  229. .tips {
  230. padding: 20rpx 30rpx;
  231. }
  232. .tips-text {
  233. display: block;
  234. font-size: 24rpx;
  235. color: #999;
  236. line-height: 40rpx;
  237. }
  238. </style>