DimensionMemberTabs.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <!--
  3. 五维页 · 成员标签条(DimensionMemberTabs)
  4. 用途:已登录家庭用户在身/心/智/富页通过点击标签切换成员,查看该成员各维度数值。
  5. 视觉:chip 形态(比大卡更轻,适合作为 PageBanner 下的筛选器);选中态用所属维度色渐变。
  6. 交互:点击切换(emit select);长按唤出管理菜单(emit longpress);右侧管理入口(emit manage)。
  7. 规范:触摸目标 >= 88rpx;维度色取 uni.scss 令牌(编译期内联,规避 mp-weixin CSS var 不稳)。
  8. -->
  9. <view class="member-tabs" :class="'dim-' + (dimensionCode || 'body')">
  10. <scroll-view
  11. class="tabs-scroll"
  12. scroll-x
  13. :enhanced="true"
  14. :scroll-with-animation="true"
  15. show-scrollbar="false"
  16. v-if="members && members.length > 0"
  17. >
  18. <view class="tabs-inner">
  19. <view
  20. v-for="m in members"
  21. :key="m.id"
  22. class="member-tab"
  23. :class="{ 'is-selected': String(m.id) === String(selectedMemberId), 'is-self': m.isSelf }"
  24. @click="onTap(m)"
  25. @longpress="onLongPress(m)"
  26. >
  27. <view class="tab-avatar-wrap">
  28. <image class="tab-avatar" :src="m.avatar || defaultAvatar" mode="aspectFill" />
  29. <view class="tab-self-mark" v-if="m.isSelf">我</view>
  30. </view>
  31. <view class="tab-body">
  32. <text class="tab-name">{{ m.nickname || '成员' }}</text>
  33. <view class="tab-meta">
  34. <text class="tab-relation">{{ relationText(m) }}</text>
  35. <text class="tab-score" v-if="scoreOf(m) !== null">{{ scoreOf(m) }}<text class="tab-score-unit">分</text></text>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 管理入口 -->
  40. <view class="tab-manage" @click="onManage" v-if="members.length > 1">
  41. <text class="tab-manage-icon">管理</text>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. <!-- 空态:未创建家庭 / 无可见成员 -->
  46. <view class="tabs-empty" v-else>
  47. <text class="tabs-empty-text">创建家庭后,可在这里切换查看每位家人的维度数值</text>
  48. <view class="tabs-empty-btn" @click="onManage">+ 管理家庭成员</view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. name: 'DimensionMemberTabs',
  55. props: {
  56. members: { type: Array, default: function() { return [] } },
  57. selectedMemberId: { type: [Number, String], default: null },
  58. // 所属维度码:body / mind / wisdom / wealth / action,决定选中态配色
  59. dimensionCode: { type: String, default: 'body' },
  60. // { memberId: score },用于在标签上直接显示该成员的维度分数
  61. scoreMap: { type: Object, default: function() { return {} } }
  62. },
  63. data: function() {
  64. return { defaultAvatar: '/static/default-avatar.png' }
  65. },
  66. computed: {
  67. dimensionList: function() {
  68. return this.members || []
  69. }
  70. },
  71. methods: {
  72. relationText: function(m) {
  73. if (!m) return '成员'
  74. return m.relationship || m.relativeLabel || m.roleLabel || (m.isSelf ? '本人' : '成员')
  75. },
  76. scoreOf: function(m) {
  77. if (!m || !this.scoreMap) return null
  78. var v = this.scoreMap[m.id]
  79. if (v === undefined || v === null || v === '') return null
  80. var n = Number(v)
  81. return isNaN(n) ? null : Math.round(n)
  82. },
  83. onTap: function(m) {
  84. if (m && String(m.id) === String(this.selectedMemberId)) return
  85. this.$emit('select', m)
  86. },
  87. onLongPress: function(m) {
  88. this.$emit('longpress', m)
  89. },
  90. onManage: function() {
  91. this.$emit('manage')
  92. }
  93. }
  94. }
  95. </script>
  96. <style scoped lang="scss">
  97. // 维度色映射:选中态渐变用主色 -> 深阶,五维统一从 uni.scss 取令牌
  98. $tab-dims: (
  99. body: $dim-body,
  100. mind: $dim-mind,
  101. wisdom: $dim-wisdom,
  102. wealth: $dim-wealth,
  103. action: $dim-action
  104. );
  105. .member-tabs {
  106. padding: 8rpx 30rpx 4rpx;
  107. }
  108. .tabs-scroll {
  109. width: 100%;
  110. white-space: nowrap;
  111. }
  112. .tabs-inner {
  113. display: inline-flex;
  114. flex-direction: row;
  115. align-items: center;
  116. gap: 16rpx;
  117. padding: 4rpx 0;
  118. }
  119. /* ---- 成员标签(chip) ---- */
  120. .member-tab {
  121. display: inline-flex;
  122. flex-direction: row;
  123. align-items: center;
  124. min-height: 88rpx;
  125. padding: 10rpx 22rpx 10rpx 12rpx;
  126. background: $app-surface;
  127. border: 2rpx solid $app-border-subtle;
  128. border-radius: 44rpx;
  129. transition: border-color $dur-state $ease-standard, background $dur-state $ease-standard, transform $dur-press $ease-standard;
  130. flex-shrink: 0;
  131. &:active {
  132. transform: scale(0.97);
  133. opacity: $press-opacity;
  134. }
  135. }
  136. .tab-avatar-wrap {
  137. position: relative;
  138. flex-shrink: 0;
  139. }
  140. .tab-avatar {
  141. width: 64rpx;
  142. height: 64rpx;
  143. border-radius: 50%;
  144. background: $app-surface-subtle;
  145. }
  146. .tab-self-mark {
  147. position: absolute;
  148. right: -6rpx;
  149. bottom: -6rpx;
  150. min-width: 36rpx;
  151. height: 36rpx;
  152. padding: 0 8rpx;
  153. border-radius: 18rpx;
  154. background: $brand-primary;
  155. color: $app-surface;
  156. font-size: 20rpx;
  157. font-weight: 600;
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. }
  162. .tab-body {
  163. display: flex;
  164. flex-direction: column;
  165. margin-left: 14rpx;
  166. max-width: 200rpx;
  167. }
  168. .tab-name {
  169. font-size: 26rpx;
  170. font-weight: 600;
  171. color: $app-text;
  172. line-height: 1.3;
  173. overflow: hidden;
  174. text-overflow: ellipsis;
  175. white-space: nowrap;
  176. }
  177. .tab-meta {
  178. display: flex;
  179. flex-direction: row;
  180. align-items: center;
  181. margin-top: 2rpx;
  182. gap: 10rpx;
  183. }
  184. .tab-relation {
  185. font-size: 20rpx;
  186. color: $app-text-muted;
  187. line-height: 1.2;
  188. }
  189. .tab-score {
  190. font-size: 22rpx;
  191. font-weight: 700;
  192. color: $app-text-secondary;
  193. line-height: 1.2;
  194. }
  195. .tab-score-unit {
  196. font-size: 18rpx;
  197. font-weight: 400;
  198. margin-left: 1rpx;
  199. }
  200. /* ---- 管理入口 ---- */
  201. .tab-manage {
  202. display: inline-flex;
  203. align-items: center;
  204. justify-content: center;
  205. min-height: 88rpx;
  206. min-width: 88rpx;
  207. padding: 0 20rpx;
  208. border-radius: 44rpx;
  209. background: $app-surface-subtle;
  210. flex-shrink: 0;
  211. &:active {
  212. opacity: $press-opacity;
  213. }
  214. }
  215. .tab-manage-icon {
  216. font-size: 24rpx;
  217. color: $app-text-secondary;
  218. font-weight: 500;
  219. }
  220. /* ---- 空态 ---- */
  221. .tabs-empty {
  222. display: flex;
  223. flex-direction: column;
  224. align-items: flex-start;
  225. padding: 24rpx 28rpx;
  226. background: $app-surface;
  227. border-radius: 16rpx;
  228. border: 2rpx dashed $app-border;
  229. }
  230. .tabs-empty-text {
  231. font-size: 24rpx;
  232. color: $app-text-secondary;
  233. line-height: 1.5;
  234. }
  235. .tabs-empty-btn {
  236. margin-top: 16rpx;
  237. padding: 12rpx 32rpx;
  238. border-radius: 40rpx;
  239. background: $brand-primary;
  240. color: $app-surface;
  241. font-size: 26rpx;
  242. font-weight: 500;
  243. &:active {
  244. opacity: $press-opacity;
  245. }
  246. }
  247. /* ---- 选中态:按维度着色 ---- */
  248. @each $code, $color in $tab-dims {
  249. .dim-#{$code} .member-tab.is-selected {
  250. background: linear-gradient(135deg, $color, rgba(red($color), green($color), blue($color), 0.82));
  251. border-color: $color;
  252. .tab-name,
  253. .tab-relation,
  254. .tab-score {
  255. color: $app-surface;
  256. }
  257. .tab-avatar {
  258. border: 2rpx solid $app-surface;
  259. }
  260. }
  261. }
  262. </style>