Invitation.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <!-- show="true" -->
  3. <u-popup :show="show" @close="handleClose" @open="handleOpen" round="32rpx" bgColor="#ffffff" zIndex="10077">
  4. <view class="viewer-list-popup">
  5. <view class="top">
  6. <image class="top_bg" src="/static/images/viewer_top.png"></image>
  7. <image class="title" src="/static/images/viewer_title.png"></image>
  8. </view>
  9. <scroll-view v-if="Array.isArray(viewers)" scroll-y class="scroll-content"
  10. :style="{ height: scrollHeight + 'px' }" @scrolltolower="handleScrollToLower">
  11. <view class="header">
  12. <text class="left">用户昵称</text>
  13. <view class="right">
  14. 邀请值
  15. <image class="ml8 img" src="/static/images/problem.png"></image>
  16. </view>
  17. </view>
  18. <view class="viewer-item x-f mb32 mt20" v-for="(item, index) in viewers"
  19. :key="getViewerKey(item, index)">
  20. <view class="item">
  21. <image class="rank-level" v-if="index<3" :src="`/static/images/ranking${index+1}.png`"></image>
  22. <view v-else class="rank-level number">
  23. {{ index + 1 }}.
  24. </view>
  25. <view class="avatar-container">
  26. <u-avatar v-if="item.avatar" :src="item.avatar" :size="36"></u-avatar>
  27. <view v-else class="default-avatar"
  28. :style="{ backgroundColor: getUserRandomColor(item.userId) }">
  29. <text class="avatar-text">{{ getNicknameInitial(item.nickName) }}</text>
  30. </view>
  31. </view>
  32. <text class="nickname ml20 f30">{{ item.nickName || '未命名' }}</text>
  33. </view>
  34. <view class="item">
  35. <text class="txt">邀请值</text>
  36. <text class="num">2555</text>
  37. </view>
  38. </view>
  39. <!-- 加载状态 -->
  40. <view v-if="loading" class="loading-text">
  41. <u-loading-icon size="16"></u-loading-icon>
  42. 加载中...
  43. </view>
  44. <!-- 无数据提示 -->
  45. <view v-if="!loading && viewers.length === 0" class="empty-text">
  46. 暂无在线观众
  47. </view>
  48. </scroll-view>
  49. </view>
  50. </u-popup>
  51. </template>
  52. <script>
  53. export default {
  54. // name: 'Viewer',
  55. props: {
  56. // 是否显示弹窗
  57. show: {
  58. type: Boolean,
  59. default: false
  60. },
  61. // 观众列表数据
  62. // viewers: {
  63. // type: Array,
  64. // default: () => []
  65. // },
  66. // 是否正在加载
  67. loading: {
  68. type: Boolean,
  69. default: false
  70. },
  71. // 滚动区域高度
  72. scrollHeight: {
  73. type: Number,
  74. default: 400
  75. }
  76. },
  77. data() {
  78. return {
  79. viewers: [{
  80. avatar: "/static/images/viewer_top.png",
  81. nickName: '大概有'
  82. }, {
  83. avatar: "/static/images/viewer_top.png",
  84. nickName: '大概有'
  85. }]
  86. // 本地状态可以根据需要添加
  87. };
  88. },
  89. methods: {
  90. /**
  91. * 处理关闭事件
  92. */
  93. handleClose() {
  94. this.$emit('close');
  95. },
  96. /**
  97. * 处理打开事件
  98. */
  99. handleOpen() {
  100. this.$emit('open');
  101. },
  102. /**
  103. * 处理滚动到底部事件
  104. */
  105. handleScrollToLower() {
  106. this.$emit('scrolltolower');
  107. },
  108. /**
  109. * 生成观众项的唯一key
  110. */
  111. getViewerKey(item, index) {
  112. return item.userId ? `viewer_${item.userId}` : `viewer_${index}`;
  113. },
  114. /**
  115. * 获取排名样式
  116. */
  117. getRankStyle(index) {
  118. const rankColors = {
  119. 0: '#FF3B30', // 第一名
  120. 1: '#FF9500', // 第二名
  121. 2: '#FFCC00' // 第三名
  122. };
  123. return {
  124. color: rankColors[index] || '#8E8E93',
  125. fontWeight: index < 3 ? 'bold' : 'normal',
  126. width: '50rpx'
  127. };
  128. },
  129. /**
  130. * 获取用户随机颜色(从父组件传入或本地实现)
  131. */
  132. getUserRandomColor(userId) {
  133. // 如果父组件传入了方法,可以使用父组件的方法
  134. // 否则这里实现一个简单的版本
  135. if (this.$parent && this.$parent.getUserRandomColor) {
  136. return this.$parent.getUserRandomColor(userId);
  137. }
  138. // 简单的本地实现
  139. if (!userId) return '#8978e2';
  140. const colorPool = [
  141. '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
  142. '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9'
  143. ];
  144. let seed = 0;
  145. for (let i = 0; i < userId.length; i++) {
  146. seed = (seed * 31 + userId.charCodeAt(i)) % 1000000;
  147. }
  148. return colorPool[seed % colorPool.length];
  149. },
  150. /**
  151. * 获取昵称首字母
  152. */
  153. getNicknameInitial(nickName) {
  154. if (!nickName || typeof nickName !== 'string') return '未';
  155. if (/^[\u4e00-\u9fa5]/.test(nickName[0])) {
  156. return nickName[0];
  157. }
  158. return nickName[0].toUpperCase();
  159. }
  160. },
  161. watch: {
  162. // 监听显示状态变化
  163. show(newVal) {
  164. if (newVal) {
  165. this.$emit('open');
  166. }
  167. }
  168. }
  169. };
  170. </script>
  171. <style scoped lang="scss">
  172. .viewer-list-popup {
  173. position: relative;
  174. height: 60vh;
  175. box-sizing: border-box;
  176. display: flex;
  177. flex-direction: column;
  178. .top {
  179. overflow: hidden;
  180. border-radius: 32rpx 32rpx 0rpx 0rpx;
  181. position: absolute;
  182. top: -126rpx;
  183. z-index: -1;
  184. width: 100%;
  185. height: 166rpx;
  186. .top_bg {
  187. width: 100%;
  188. height: 100%;
  189. }
  190. .title {
  191. position: absolute;
  192. left: 50%;
  193. top: 26rpx;
  194. transform: translateX(-50%);
  195. width: 262rpx;
  196. height: 72rpx;
  197. }
  198. }
  199. .scroll-content {
  200. padding: 36rpx 24rpx;
  201. box-sizing: border-box;
  202. flex: 1;
  203. overflow-y: auto;
  204. background: linear-gradient(180deg, #E7FEEE 0%, #FFFFFF 9%, #FFFFFF 100%);
  205. border-radius: 32rpx 32rpx 0rpx 0rpx;
  206. border: 4rpx solid #FFFFFF;
  207. }
  208. .header {
  209. margin-bottom: 42rpx;
  210. display: flex;
  211. justify-content: space-between;
  212. .left {
  213. font-size: 26rpx;
  214. color: #666666;
  215. }
  216. .right {
  217. font-size: 26rpx;
  218. color: #999999;
  219. display: flex;
  220. align-items: center;
  221. .img {
  222. width: 24rpx;
  223. height: 24rpx;
  224. }
  225. }
  226. }
  227. .viewer-item {
  228. margin-top: 32rpx;
  229. display: flex;
  230. justify-content: space-between;
  231. align-items: center;
  232. .item {
  233. display: flex;
  234. align-items: center;
  235. .rank-level {
  236. width: 40rpx;
  237. height: 40rpx;
  238. margin-right: 20rpx;
  239. }
  240. .number {
  241. font-size: 32rpx;
  242. color: #666666;
  243. text-align: center;
  244. font-family: Roboto Flex, Roboto Flex;
  245. }
  246. .avatar-container {
  247. .default-avatar {
  248. width: 72rpx;
  249. height: 72rpx;
  250. border-radius: 50%;
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. .avatar-text {
  255. color: #ffffff;
  256. font-size: 24rpx;
  257. font-weight: 500;
  258. }
  259. }
  260. }
  261. .nickname {
  262. flex: 1;
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. white-space: nowrap;
  266. font-weight: 500;
  267. font-size: 32rpx;
  268. color: #333333;
  269. }
  270. .txt {
  271. font-size: 24rpx;
  272. color: #999999;
  273. margin-right: 16rpx;
  274. }
  275. .num {
  276. font-weight: 500;
  277. font-size: 32rpx;
  278. color: #02B176;
  279. }
  280. }
  281. }
  282. .loading-text {
  283. text-align: center;
  284. color: #999;
  285. font-size: 28rpx;
  286. padding: 40rpx;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. gap: 16rpx;
  291. }
  292. .empty-text {
  293. text-align: center;
  294. color: #999;
  295. font-size: 28rpx;
  296. padding: 80rpx 40rpx;
  297. }
  298. }
  299. </style>