index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 no-border">
  14. <text class="form-label">真实姓名</text>
  15. <input
  16. class="form-input"
  17. type="text"
  18. v-model="name"
  19. placeholder="请输入真实姓名"
  20. placeholder-class="placeholder"
  21. maxlength="20"
  22. />
  23. </view>
  24. </view>
  25. <view class="btn-area">
  26. <button class="submit-btn" @click="submitChange">确认修改</button>
  27. </view>
  28. <view class="tips">
  29. <text class="tips-text">• 请输入您的真实姓名</text>
  30. <text class="tips-text">• 姓名将用于实名认证和订单服务</text>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. // 引入 API @author steelwei
  36. import { updateName } from '@/api/fulfiller/fulfiller'
  37. export default {
  38. data() {
  39. return {
  40. name: ''
  41. }
  42. },
  43. onLoad(options) {
  44. if (options.name) {
  45. this.name = decodeURIComponent(options.name);
  46. }
  47. },
  48. methods: {
  49. navBack() {
  50. uni.navigateBack({ delta: 1 });
  51. },
  52. // 提交修改 @author steelwei
  53. async submitChange() {
  54. // 验证输入
  55. if (!this.name || !this.name.trim()) {
  56. uni.showToast({ title: '请输入姓名', icon: 'none' });
  57. return;
  58. }
  59. if (this.name.trim().length < 2) {
  60. uni.showToast({ title: '姓名至少2个字符', icon: 'none' });
  61. return;
  62. }
  63. uni.showLoading({ title: '提交中...' });
  64. try {
  65. const res = await updateName(this.name.trim());
  66. if (res.code === 200) {
  67. uni.showToast({
  68. title: '修改成功',
  69. icon: 'success',
  70. duration: 2000
  71. });
  72. // 通知上一页更新姓名
  73. uni.$emit('updateName', this.name.trim());
  74. setTimeout(() => {
  75. uni.navigateBack({ delta: 1 });
  76. }, 2000);
  77. } else {
  78. uni.showToast({
  79. title: res.msg || '修改失败',
  80. icon: 'none'
  81. });
  82. }
  83. } catch (error) {
  84. console.error('修改姓名失败:', error);
  85. uni.showToast({ title: error.message || error.msg || '请求失败', icon: 'none' });
  86. } finally {
  87. uni.hideLoading();
  88. }
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. page {
  95. background-color: #F8F8F8;
  96. }
  97. .custom-header {
  98. position: fixed;
  99. top: 0;
  100. left: 0;
  101. width: 100%;
  102. height: 88rpx;
  103. padding-top: var(--status-bar-height);
  104. background-color: #fff;
  105. display: flex;
  106. align-items: center;
  107. justify-content: space-between;
  108. padding-left: 30rpx;
  109. padding-right: 30rpx;
  110. box-sizing: content-box;
  111. z-index: 100;
  112. }
  113. .header-placeholder {
  114. height: calc(88rpx + var(--status-bar-height));
  115. }
  116. .back-icon {
  117. width: 40rpx;
  118. height: 40rpx;
  119. }
  120. .header-title {
  121. font-size: 28rpx;
  122. font-weight: bold;
  123. color: #333;
  124. }
  125. .header-right {
  126. width: 40rpx;
  127. }
  128. .container {
  129. padding: 20rpx 30rpx;
  130. }
  131. .form-card {
  132. background-color: #fff;
  133. border-radius: 20rpx;
  134. padding: 0 30rpx;
  135. margin-bottom: 30rpx;
  136. }
  137. .form-item {
  138. display: flex;
  139. align-items: center;
  140. padding: 30rpx 0;
  141. border-bottom: 1px solid #F5F5F5;
  142. }
  143. .form-item.no-border {
  144. border-bottom: none;
  145. }
  146. .form-label {
  147. width: 160rpx;
  148. font-size: 28rpx;
  149. color: #333;
  150. }
  151. .form-input {
  152. flex: 1;
  153. font-size: 28rpx;
  154. color: #333;
  155. }
  156. .placeholder {
  157. color: #999;
  158. }
  159. .btn-area {
  160. padding: 40rpx 0;
  161. }
  162. .submit-btn {
  163. background-color: #FF5722;
  164. color: #fff;
  165. font-size: 32rpx;
  166. border-radius: 44rpx;
  167. height: 88rpx;
  168. line-height: 88rpx;
  169. border: none;
  170. }
  171. .tips {
  172. padding: 20rpx 30rpx;
  173. }
  174. .tips-text {
  175. display: block;
  176. font-size: 24rpx;
  177. color: #999;
  178. line-height: 40rpx;
  179. }
  180. </style>