index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view class="detail-page">
  3. <!-- 顶部蓝色背景 + 顶栏 -->
  4. <view class="top-bg">
  5. <view class="detail-header">
  6. <view class="back" @click="goBack">
  7. <image class="header-icon-img" src="/static/icons/back.svg" mode="aspectFit" />
  8. </view>
  9. <!-- 右上角不显示三个点,但保留占位,避免标题中心抖动 -->
  10. <view class="header-actions" />
  11. </view>
  12. <view class="hero">
  13. <view class="hero-avatar">
  14. <UserAvatar
  15. :name="contactName"
  16. :id="contactId"
  17. :src="''"
  18. :size="140"
  19. unit="rpx"
  20. />
  21. </view>
  22. <view class="hero-names">
  23. <text class="hero-main-name">{{ contactName || '联系人' }}</text>
  24. <text class="hero-sub-name">{{ contactEnglishName || '' }}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 三个按钮:消息 / 语言 / 视频 -->
  29. <view class="action-row">
  30. <view class="action-item" @click="goChat">
  31. <image class="action-icon" src="/static/icons/message.svg" mode="aspectFit" />
  32. <text class="action-label">消息</text>
  33. </view>
  34. <view class="action-item" :class="{ 'is-hidden': !showVoiceVideo }" @click="onVoice">
  35. <image class="action-icon" src="/static/icons/file.svg" mode="aspectFit" />
  36. <text class="action-label">语音</text>
  37. </view>
  38. <view class="action-item" :class="{ 'is-hidden': !showVoiceVideo }" @click="onVideo">
  39. <image class="action-icon" src="/static/icons/video.svg" mode="aspectFit" />
  40. <text class="action-label">视频</text>
  41. </view>
  42. </view>
  43. <!-- 备注名行 -->
  44. <view class="remark-row">
  45. <text class="remark-label">备注名</text>
  46. <view class="remark-right">
  47. <text class="remark-value">{{ contactName || '' }}</text>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import UserAvatar from '../../components/UserAvatar.vue'
  54. export default {
  55. components: { UserAvatar },
  56. data() {
  57. return {
  58. contactId: '',
  59. contactName: '',
  60. contactEnglishName: '',
  61. contactStatus: '',
  62. // 需求:先隐藏“语音/视频”,但要保持“消息”位置和样式不变
  63. showVoiceVideo: false,
  64. loading: false
  65. }
  66. },
  67. computed: {},
  68. onLoad(options) {
  69. const rawContactId = options?.contactId ?? options?.otherUserId ?? ''
  70. const rawContactName = options?.contactName ?? ''
  71. const rawContactEnglishName = options?.contactEnglishName ?? ''
  72. const rawContactStatus = options?.contactStatus ?? ''
  73. // uni-app 在某些端上不会自动对 query 参数解码,避免直接显示 %E5... URL 编码结果
  74. const maybeDecode = (v) => {
  75. const s = String(v ?? '')
  76. // 仅当包含 %xx 形式时才尝试解码,避免重复解码造成破坏
  77. if (!/%[0-9A-Fa-f]{2}/.test(s)) return s
  78. try {
  79. return decodeURIComponent(s)
  80. } catch (e) {
  81. return s
  82. }
  83. }
  84. this.contactId = String(rawContactId)
  85. this.contactName = maybeDecode(rawContactName)
  86. this.contactEnglishName = maybeDecode(rawContactEnglishName)
  87. this.contactStatus = maybeDecode(rawContactStatus)
  88. this.loading = false
  89. },
  90. methods: {
  91. goBack() {
  92. uni.navigateBack()
  93. },
  94. onMore() {
  95. uni.showToast({ title: '更多', icon: 'none' })
  96. },
  97. goChat() {
  98. const id = String(this.contactId || '').trim()
  99. if (!id) {
  100. uni.showToast({ title: '无法进入聊天', icon: 'none' })
  101. return
  102. }
  103. uni.navigateTo({
  104. url:
  105. '/pages/chat/index?otherUserId=' +
  106. encodeURIComponent(id) +
  107. '&contactName=' +
  108. encodeURIComponent(this.contactName || '')
  109. })
  110. }
  111. ,
  112. onVoice() {
  113. uni.showToast({ title: '语音', icon: 'none' })
  114. },
  115. onVideo() {
  116. uni.showToast({ title: '视频', icon: 'none' })
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. .detail-page {
  123. height: 100vh;
  124. display: flex;
  125. flex-direction: column;
  126. background: #f5f5f7;
  127. }
  128. .top-bg {
  129. position: relative;
  130. background: linear-gradient(180deg, #2b7de9 0%, #5aa9ff 100%);
  131. padding-bottom: 48rpx;
  132. }
  133. .top-bg::after {
  134. content: '';
  135. position: absolute;
  136. left: 0;
  137. right: 0;
  138. /* 让蓝->白分界线与按钮卡片顶部重叠,同时避免中间空白露出蓝色 */
  139. bottom: -20rpx;
  140. /* 拉长白色覆盖层:向下延长但保持顶部边界不变 */
  141. height: 300rpx;
  142. background: #f5f5f7;
  143. border-top-left-radius: 40rpx;
  144. border-top-right-radius: 40rpx;
  145. transform: skewY(0deg);
  146. }
  147. .detail-header {
  148. position: relative;
  149. z-index: 2;
  150. display: flex;
  151. align-items: center;
  152. justify-content: space-between;
  153. padding: 24rpx 24rpx 24rpx 24rpx;
  154. padding-top: max(88rpx, calc(24rpx + constant(safe-area-inset-top)));
  155. padding-top: max(88rpx, calc(24rpx + env(safe-area-inset-top)));
  156. }
  157. .back {
  158. width: 64rpx;
  159. height: 64rpx;
  160. display: flex;
  161. align-items: center;
  162. justify-content: center;
  163. }
  164. .header-icon-img {
  165. width: 44rpx;
  166. height: 44rpx;
  167. opacity: 0.95;
  168. }
  169. .header-actions {
  170. width: 64rpx;
  171. height: 64rpx;
  172. display: flex;
  173. align-items: center;
  174. justify-content: flex-end;
  175. }
  176. .header-icon {
  177. width: 56rpx;
  178. height: 56rpx;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. }
  183. .hero {
  184. position: relative;
  185. z-index: 2;
  186. padding-top: 16rpx;
  187. padding-bottom: 28rpx;
  188. }
  189. .hero-avatar {
  190. margin-left: 46rpx;
  191. margin-bottom: 18rpx;
  192. }
  193. .hero-avatar :deep(.user-avatar) {
  194. box-shadow: 0 12rpx 40rpx rgba(0, 0, 0, 0.18);
  195. }
  196. .hero-names {
  197. margin-left: 40rpx;
  198. text-align: left;
  199. }
  200. .hero-main-name {
  201. display: block;
  202. font-size: 44rpx;
  203. font-weight: 700;
  204. color: #111827;
  205. }
  206. .hero-sub-name {
  207. display: block;
  208. margin-top: 10rpx;
  209. font-size: 28rpx;
  210. font-weight: 600;
  211. color: #111827;
  212. }
  213. .action-row {
  214. position: relative;
  215. z-index: 1;
  216. margin-top: -40rpx;
  217. padding: 0 40rpx;
  218. display: flex;
  219. gap: 28rpx;
  220. justify-content: space-between;
  221. }
  222. .action-item {
  223. flex: 1;
  224. background: #ffffff;
  225. border-radius: 18rpx;
  226. padding: 26rpx 0;
  227. display: flex;
  228. flex-direction: column;
  229. /* 图标和文字居中 */
  230. align-items: center;
  231. justify-content: center;
  232. box-shadow: 0 2rpx 10rpx rgba(17, 24, 39, 0.06);
  233. }
  234. /* 隐藏语音/视频但不改变布局:只隐藏内容,保留三个格子的宽度 */
  235. .action-item.is-hidden {
  236. visibility: hidden;
  237. pointer-events: none;
  238. }
  239. .action-icon {
  240. width: 54rpx;
  241. height: 54rpx;
  242. opacity: 0.95;
  243. }
  244. .action-label {
  245. margin-top: 12rpx;
  246. font-size: 28rpx;
  247. color: #111827;
  248. text-align: center;
  249. }
  250. .remark-row {
  251. position: relative;
  252. z-index: 1;
  253. margin: 28rpx 28rpx 0;
  254. background: #ffffff;
  255. border-radius: 18rpx;
  256. padding: 26rpx 28rpx;
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. }
  261. .remark-label {
  262. font-size: 28rpx;
  263. color: #111827;
  264. }
  265. .remark-right {
  266. display: flex;
  267. align-items: center;
  268. gap: 16rpx;
  269. }
  270. .remark-value {
  271. font-size: 28rpx;
  272. color: #6b7280;
  273. }
  274. </style>