intro.vue 5.6 KB

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