header.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="hl88-lr-header">
  3. <view class="hl88-lr-hdRight round">
  4. <view class="hl88-lr-hdAvWrap justify-center bg-white round align-center">
  5. <image class="hl88-lr-hdAvImg round" :src="displayAvatar"/>
  6. </view>
  7. <view class="hl88-lr-hdShop">
  8. <text class="hl88-lr-hdShopNm"> {{ formatEllipsis(displayName, 16) }} </text>
  9. <view class="hl88-lr-hdShopMeta">
  10. <text class="hl88-lr-hdShopMetaTxt">{{ numFormat(online) }} {{ headerLangTexts.watching }}</text>
  11. </view>
  12. </view>
  13. <view
  14. v-if="showFollowButton"
  15. class="hl88-lr-hdFollowBtn"
  16. :class="{ 'hl88-lr-hdFollowOn': isFollowing }"
  17. @tap.stop="like"
  18. >
  19. <text class="hl88-lr-hdFollowTxt" :class="{ 'hl88-lr-hdFollowTxtOn': isFollowing }">{{ isFollowing ? headerLangTexts.followed : headerLangTexts.follow }}</text>
  20. </view>
  21. </view>
  22. <view class="hl88-lr-hdLeft">
  23. <view class="hl88-lr-btn-icon" @tap="back()">
  24. <image class="hl88-lr-btn-icon-img" src="/static/imgs/close.png" mode="aspectFit" />
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'LiveRoomHeader',
  32. props: {
  33. online: {
  34. type: Number,
  35. default: 0
  36. },
  37. state: {
  38. default: 0
  39. },
  40. // 与 user 页一致:0 未关注,1 已关注(接口也可能返回布尔)
  41. isFollow: {
  42. type: [Boolean, Number],
  43. default: 0
  44. },
  45. shopdata: {
  46. type: Object,
  47. default: function() {
  48. return {};
  49. }
  50. },
  51. // 为 true 时点击返回不直接后退,由父组件监听 @back 先弹框确认后再退出
  52. confirmBeforeBack: {
  53. type: Boolean,
  54. default: false
  55. },
  56. // 主播端等场景可不展示关注按钮(默认展示,与观众端直播间一致)
  57. showFollowButton: {
  58. type: Boolean,
  59. default: true
  60. },
  61. /** 当前直播间 id,与 getLiveStatus /wanlshop/live/getLiveStatus 的 data.id 一致;关注时回传给父页 */
  62. liveId: {
  63. type: [String, Number],
  64. default: ''
  65. }
  66. },
  67. computed: {
  68. hasShopAvatar() {
  69. return !!(this.shopdata && this.shopdata.avatar);
  70. },
  71. displayAvatar() {
  72. const avatar = this.hasShopAvatar
  73. ? this.shopdata.avatar
  74. : (this.$store.state.user && this.$store.state.user.avatar);
  75. return this.stcOss(avatar);
  76. },
  77. displayName() {
  78. if (this.hasShopAvatar) {
  79. return (this.shopdata && this.shopdata.shopname) || '';
  80. }
  81. const user = this.$store.state.user || {};
  82. return user.nickname || user.username || '';
  83. },
  84. /**
  85. * nvue 直播间内 $t 可能不可用;与 pages/apps/find/details/live-room.nvue 中 initLanguageStrings 一致:
  86. * uni.getStorageSync('language') || uni.getLocale(),再按 languageMap 取值。
  87. */
  88. headerLangTexts() {
  89. const locale = uni.getLocale() || 'zh-Hans';
  90. const savedLanguage = uni.getStorageSync('language');
  91. const currentLang = savedLanguage || locale;
  92. const languageMap = {
  93. 'zh-Hans': {
  94. follow: '关注',
  95. followed: '已关注',
  96. watching: '在看'
  97. },
  98. 'zh-Hant': {
  99. follow: '關注',
  100. followed: '已關注',
  101. watching: '在看'
  102. },
  103. 'en': {
  104. follow: 'Follow',
  105. followed: 'Followed',
  106. watching: 'watching'
  107. },
  108. 'en-SG': {
  109. follow: 'Follow',
  110. followed: 'Followed',
  111. watching: 'watching'
  112. },
  113. 'en-MY': {
  114. follow: 'Follow',
  115. followed: 'Followed',
  116. watching: 'watching'
  117. },
  118. 'ja': {
  119. follow: 'フォロー',
  120. followed: 'フォロー済み',
  121. watching: '視聴中'
  122. }
  123. };
  124. return languageMap[currentLang] || languageMap['zh-Hans'];
  125. },
  126. /** 与接口一致:0 未关注,大于 0(含多种枚举值)已关注 */
  127. isFollowing() {
  128. const f = this.isFollow;
  129. if (f === true) return true;
  130. const n = Number(f);
  131. return !Number.isNaN(n) && n > 0;
  132. }
  133. },
  134. methods: {
  135. like() {
  136. // 避免与原生 change 冲突,父页使用 @followTap;携带当前直播间 id(同 getLiveStatus 的 id)
  137. this.$emit('followTap', this.liveId);
  138. },
  139. back() {
  140. if (this.confirmBeforeBack) {
  141. this.$emit('back');
  142. } else {
  143. uni.navigateBack({
  144. delta: 1
  145. });
  146. }
  147. },
  148. stcOss(url) {
  149. let oss = (this.$store.state.shell && this.$store.state.shell.appUrl && this.$store.state.shell.appUrl.oss) || '';
  150. let image = '';
  151. if (url) {
  152. if ((/^(http|https):\/\/.+/.test(url))) {
  153. image = url;
  154. } else {
  155. image = oss + url;
  156. }
  157. } else {
  158. image = oss + '/assets/addons/wanlshop/img/common/img_default3x.png';
  159. }
  160. return image;
  161. },
  162. numFormat(num) {
  163. return num > 9999 ? ((num - num % 1000) / 10000 + 'W') : num
  164. },
  165. formatEllipsis(str = '', limitLen = 24) {
  166. let len = 0,
  167. reg = /[\x00-\xff]/, //半角字符的正则匹配
  168. strs = str.split(''),
  169. inx = strs.findIndex(s => {
  170. len += reg.test(s) ? 1 : 2
  171. if (len > limitLen) return true
  172. })
  173. return inx === -1 ? str : str.substr(0, inx) + '...'
  174. }
  175. }
  176. }
  177. </script>
  178. <style>
  179. @import '@/static/style/wanlnvue.css';
  180. .hl88-lr-header {
  181. background-color: transparent;
  182. justify-content: space-between;
  183. align-items: center;
  184. flex-direction: row;
  185. padding-top: 16rpx;
  186. padding-left: 24rpx;
  187. padding-right: 24rpx;
  188. /* #ifdef MP */
  189. padding-right: 200rpx;
  190. /* #endif */
  191. }
  192. .hl88-lr-hdRight{
  193. align-items: center;
  194. flex-direction: row;
  195. background-color: rgba(0,0,0,.2);
  196. padding-top: 8rpx;
  197. padding-right: 16rpx;
  198. padding-bottom: 8rpx;
  199. padding-left: 8rpx;
  200. }
  201. .hl88-lr-hdAvWrap{
  202. width: 68rpx;
  203. height: 68rpx;
  204. }
  205. .hl88-lr-hdAvImg{
  206. width: 68rpx;
  207. height: 68rpx;
  208. }
  209. .hl88-lr-hdShop{
  210. padding-left: 15rpx;
  211. }
  212. .hl88-lr-hdShopNm{
  213. color: rgba(255, 255, 255, .8);
  214. font-size: 28rpx;
  215. line-height: 36rpx;
  216. }
  217. .hl88-lr-hdShopMetaTxt{
  218. color: rgba(255, 255, 255, .7);
  219. font-size: 20rpx;
  220. }
  221. .hl88-lr-hdFollowBtn{
  222. background-color: #f40;
  223. min-width: 86rpx;
  224. padding-left: 12rpx;
  225. padding-right: 12rpx;
  226. height: 50rpx;
  227. justify-content: center;
  228. align-items: center;
  229. border-radius: 18rpx;
  230. margin-left: 30rpx;
  231. }
  232. .hl88-lr-hdFollowOn {
  233. background-color: rgba(0, 0, 0, 0);
  234. border-width: 2rpx;
  235. border-style: solid;
  236. border-color: rgba(255, 255, 255, 0.85);
  237. }
  238. .hl88-lr-hdFollowTxt{
  239. color: #fff;
  240. font-size: 24rpx;
  241. }
  242. .hl88-lr-hdFollowTxtOn {
  243. color: rgba(255, 255, 255, 0.95);
  244. }
  245. .hl88-lr-hdLeft{
  246. align-items: center;
  247. justify-content: center;
  248. }
  249. .hl88-lr-btn-icon{
  250. width: 76rpx;
  251. height: 76rpx;
  252. border-radius: 38rpx;
  253. background-color: rgba(0, 0, 0, 0.2);
  254. align-items: center;
  255. justify-content: center;
  256. }
  257. .hl88-lr-btn-icon-img{
  258. width: 40rpx;
  259. height: 40rpx;
  260. }
  261. </style>