name.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="container" :style="{paddingTop: navbarHeight + 'rpx'}">
  3. <!-- 顶部渐变背景 -->
  4. <view class="top-gradient"></view>
  5. <!-- 自定义导航栏 -->
  6. <view class="custom-navbar" :style="{paddingTop: statusBarHeight + 'px'}">
  7. <view class="navbar-content">
  8. <view class="navbar-back" @click="handleBack">
  9. <view class="iconfont icon-right back-icon"></view>
  10. </view>
  11. <text class="navbar-title">姓名</text>
  12. <view class="navbar-right" @click="handleConfirm">
  13. <text class="confirm-text" :class="{ disabled: !canConfirm }">确定</text>
  14. </view>
  15. </view>
  16. </view>
  17. <!-- 输入区域 -->
  18. <view class="input-container">
  19. <view class="input-wrapper">
  20. <input
  21. class="name-input"
  22. v-model="nameValue"
  23. placeholder="请输入姓名"
  24. maxlength="30"
  25. @input="handleInput"
  26. />
  27. <view class="char-count">{{ nameValue.length }}/30</view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { editLawyerUser } from "@/api/api"
  34. export default {
  35. data() {
  36. return {
  37. nameValue: '',
  38. originalName: '',
  39. statusBarHeight: 0,
  40. userId: null
  41. }
  42. },
  43. onLoad(options) {
  44. // 获取状态栏高度
  45. const systemInfo = uni.getSystemInfoSync()
  46. this.statusBarHeight = systemInfo.statusBarHeight || 0
  47. // 获取传入的姓名和用户ID
  48. if (options.name) {
  49. this.nameValue = decodeURIComponent(options.name)
  50. this.originalName = this.nameValue
  51. }
  52. if (options.userId) {
  53. this.userId = options.userId
  54. }
  55. },
  56. computed: {
  57. navbarHeight() {
  58. // 状态栏高度(px转rpx) + 导航栏高度(88rpx) + 间距(20rpx)
  59. return (this.statusBarHeight * 2) + 88 + 20
  60. },
  61. canConfirm() {
  62. // 有输入且与原始值不同时可以确认
  63. return this.nameValue.trim().length > 0 && this.nameValue !== this.originalName
  64. }
  65. },
  66. methods: {
  67. handleInput(e) {
  68. this.nameValue = e.detail.value
  69. },
  70. handleBack() {
  71. uni.navigateBack()
  72. },
  73. handleConfirm() {
  74. if (!this.canConfirm) {
  75. return
  76. }
  77. const trimmedName = this.nameValue.trim()
  78. if (trimmedName.length === 0) {
  79. uni.showToast({
  80. title: '请输入姓名',
  81. icon: 'none'
  82. })
  83. return
  84. }
  85. // 显示加载提示
  86. uni.showLoading({
  87. title: '保存中...',
  88. mask: true
  89. })
  90. // 调用API更新姓名
  91. const params = {
  92. id: 1, // 如果没有传入userId,使用默认值1
  93. name: trimmedName
  94. }
  95. editLawyerUser(params).then(response => {
  96. uni.hideLoading()
  97. uni.showToast({
  98. title: '保存成功',
  99. icon: 'success'
  100. })
  101. // 延迟返回,让用户看到成功提示
  102. setTimeout(() => {
  103. uni.navigateBack()
  104. }, 1500)
  105. }).catch(error => {
  106. uni.hideLoading()
  107. console.error('更新姓名失败:', error)
  108. uni.showToast({
  109. title: error.message || '保存失败,请重试',
  110. icon: 'none'
  111. })
  112. })
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. page {
  119. background-color: #f5f5f5;
  120. }
  121. .container {
  122. min-height: 100vh;
  123. padding: 0 30rpx 20rpx 30rpx;
  124. background-color: #f5f5f5;
  125. position: relative;
  126. // 顶部渐变背景
  127. .top-gradient {
  128. position: fixed;
  129. top: 0;
  130. left: 0;
  131. right: 0;
  132. height: 800rpx;
  133. background: linear-gradient(180deg, rgba(59, 130, 246, 0.1) 0%, rgba(147, 197, 253, 0.05) 50%, transparent 100%);
  134. z-index: 0;
  135. pointer-events: none;
  136. }
  137. // 自定义导航栏
  138. .custom-navbar {
  139. position: fixed;
  140. top: 0;
  141. left: 0;
  142. right: 0;
  143. z-index: 999;
  144. background-color: transparent;
  145. pointer-events: none;
  146. .navbar-content {
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. height: 88rpx;
  151. pointer-events: auto;
  152. position: relative;
  153. .navbar-back {
  154. position: absolute;
  155. left: 30rpx;
  156. width: 60rpx;
  157. height: 60rpx;
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. .back-icon {
  162. font-size: 36rpx;
  163. color: #000000;
  164. transform: rotate(180deg);
  165. }
  166. }
  167. .navbar-title {
  168. font-size: 36rpx;
  169. font-weight: 500;
  170. color: #000000;
  171. }
  172. .navbar-right {
  173. position: absolute;
  174. right: 30rpx;
  175. height: 60rpx;
  176. display: flex;
  177. align-items: center;
  178. justify-content: center;
  179. .confirm-text {
  180. font-size: 32rpx;
  181. color: #007AFF;
  182. font-weight: 400;
  183. &.disabled {
  184. color: #cccccc;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. // 输入区域
  192. .input-container {
  193. padding: 40rpx 0;
  194. margin-top: 20rpx;
  195. }
  196. .input-wrapper {
  197. position: relative;
  198. background-color: #ffffff;
  199. border-radius: 16rpx;
  200. padding: 32rpx 30rpx;
  201. min-height: 100rpx;
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. }
  206. .name-input {
  207. flex: 1;
  208. font-size: 32rpx;
  209. color: #000000;
  210. background-color: transparent;
  211. border: none;
  212. outline: none;
  213. padding: 0;
  214. margin: 0;
  215. }
  216. .char-count {
  217. font-size: 28rpx;
  218. color: #999999;
  219. margin-left: 20rpx;
  220. white-space: nowrap;
  221. }
  222. </style>