video-list.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="vl-page">
  3. <view class="vl-nav" :style="{ paddingTop: statusBar + 'px' }">
  4. <view class="vl-nav-row">
  5. <view class="vl-back" @tap="goBack">
  6. <text class="vl-back-icon">←</text>
  7. </view>
  8. <text class="vl-nav-title">{{ pageTitle }}</text>
  9. <view class="vl-nav-placeholder" />
  10. </view>
  11. </view>
  12. <scroll-view scroll-y class="vl-scroll" :style="{ height: scrollHeight + 'px' }" :lower-threshold="120"
  13. :refresher-enabled="true" :refresher-triggered="refreshing" @refresherrefresh="onRefresh"
  14. @refresherrestore="onRefreshEnd" @refresherabort="onRefreshEnd" @scrolltolower="onLoadMore">
  15. <view class="vl-body" :style="{ paddingBottom: safeBottom + 'px' }">
  16. <view v-if="loading && !cards.length" class="vl-state">
  17. <text class="vl-state-txt">{{ copy.loading }}</text>
  18. </view>
  19. <empty v-else-if="loaded && !cards.length" src="find_default3x" :text="copy.emptyVideos" />
  20. <view v-else class="waterfall">
  21. <view class="waterfall-col">
  22. <view v-for="card in leftCol" :key="card.id" class="card" @tap="onCardTap(card)">
  23. <image v-if="card.cover" class="card-cover" :src="card.cover" mode="widthFix" />
  24. <view v-else class="card-cover-placeholder" :style="{ background: cardGradient(card.id) }" />
  25. <view class="card-body">
  26. <text class="card-title">{{ card.title }}</text>
  27. <view class="card-meta">
  28. <image v-if="card.avatar" class="card-avatar" :src="card.avatar" mode="aspectFill" />
  29. <view v-else class="card-avatar card-avatar-fallback" />
  30. <text class="card-user">{{ card.user }}</text>
  31. <text class="card-like">♡ {{ formatLikes(card.likes) }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="waterfall-col">
  37. <view v-for="card in rightCol" :key="card.id" class="card" @tap="onCardTap(card)">
  38. <image v-if="card.cover" class="card-cover" :src="card.cover" mode="widthFix" />
  39. <view v-else class="card-cover-placeholder" :style="{ background: cardGradient(card.id) }" />
  40. <view class="card-body">
  41. <text class="card-title">{{ card.title }}</text>
  42. <view class="card-meta">
  43. <image v-if="card.avatar" class="card-avatar" :src="card.avatar" mode="aspectFill" />
  44. <view v-else class="card-avatar card-avatar-fallback" />
  45. <text class="card-user">{{ card.user }}</text>
  46. <text class="card-like">♡ {{ formatLikes(card.likes) }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <uni-load-more v-if="cards.length" :status="loadStatus" :content-text="loadMoreText" />
  53. </view>
  54. </scroll-view>
  55. </view>
  56. </template>
  57. <script>
  58. import { pullLabelVideoPage, pullRecommendVideoPage } from '@/features/travel/gateway'
  59. import { videoDetailUrl } from '@/features/dynamics/post-media'
  60. const CARD_GRADIENTS = [
  61. 'linear-gradient(135deg, #f7d4b8 0%, #e8a87c 100%)',
  62. 'linear-gradient(135deg, #c1c8d6 0%, #8e96a6 100%)',
  63. 'linear-gradient(135deg, #f4c5d8 0%, #de8aae 100%)',
  64. 'linear-gradient(135deg, #c5dcc4 0%, #8eb592 100%)'
  65. ]
  66. export default {
  67. data() {
  68. return {
  69. statusBar: 0,
  70. scrollHeight: 600,
  71. safeBottom: 0,
  72. labelId: '',
  73. orderType: '',
  74. isHotDian: '',
  75. pageTitle: '',
  76. cards: [],
  77. page: 1,
  78. lastPage: 1,
  79. loading: false,
  80. loaded: false,
  81. refreshing: false,
  82. loadStatus: 'more'
  83. }
  84. },
  85. computed: {
  86. copy() {
  87. const t = this.$t.bind(this)
  88. return {
  89. video: t('home.video'),
  90. sectionHot: t('home.sectionHot'),
  91. loading: t('home.loading'),
  92. loadFailed: t('home.loadFailed'),
  93. emptyVideos: t('home.emptyVideos')
  94. }
  95. },
  96. loadMoreText() {
  97. const t = this.$t.bind(this)
  98. return {
  99. contentdown: t('home.loadMore'),
  100. contentrefresh: t('home.loading'),
  101. contentnomore: t('home.noMore')
  102. }
  103. },
  104. leftCol() {
  105. return this.cards.filter((_, i) => i % 2 === 0)
  106. },
  107. rightCol() {
  108. return this.cards.filter((_, i) => i % 2 === 1)
  109. }
  110. },
  111. onLoad(query) {
  112. this.labelId = (query && query.label_id) != null ? String(query.label_id) : ''
  113. this.orderType = (query && query.order_type) != null ? String(query.order_type) : ''
  114. this.isHotDian = (query && query.is_hot_dian) != null ? String(query.is_hot_dian) : ''
  115. const title = (query && query.title) ? decodeURIComponent(query.title) : ''
  116. this.pageTitle = title || (this.orderType ? this.copy.sectionHot : this.copy.video)
  117. this.initLayout()
  118. this.reload()
  119. },
  120. methods: {
  121. initLayout() {
  122. try {
  123. const info = uni.getSystemInfoSync()
  124. this.statusBar = info.statusBarHeight || 0
  125. this.safeBottom = (info.safeAreaInsets && info.safeAreaInsets.bottom) || 0
  126. const navH = this.statusBar + uni.upx2px(88)
  127. this.scrollHeight = (info.windowHeight || info.screenHeight || 600) - navH
  128. } catch (_) { }
  129. },
  130. goBack() {
  131. uni.navigateBack({
  132. fail: () => uni.switchTab({ url: '/pages/index/index' })
  133. })
  134. },
  135. cardGradient(seed) {
  136. const hash = String(seed).split('').reduce((a, c) => a + c.charCodeAt(0), 0)
  137. return CARD_GRADIENTS[hash % CARD_GRADIENTS.length]
  138. },
  139. formatLikes(n) {
  140. const v = Number(n) || 0
  141. if (v >= 10000) return (v / 10000).toFixed(1) + 'w'
  142. if (v >= 1000) return (v / 1000).toFixed(1) + 'k'
  143. return v
  144. },
  145. async reload() {
  146. this.page = 1
  147. this.lastPage = 1
  148. this.loadStatus = 'more'
  149. this.loaded = false
  150. this.cards = []
  151. await this.loadPage(true)
  152. },
  153. onRefresh() {
  154. this.refreshing = true
  155. this.reload().finally(() => this.onRefreshEnd())
  156. },
  157. onRefreshEnd() {
  158. this.refreshing = false
  159. },
  160. onLoadMore() {
  161. if (this.loadStatus === 'loading' || this.loadStatus === 'noMore') return
  162. this.loadPage(false)
  163. },
  164. async loadPage(reset) {
  165. if (this.loading) return
  166. if (!reset && this.page >= this.lastPage) {
  167. this.loadStatus = 'noMore'
  168. return
  169. }
  170. const nextPage = reset ? 1 : this.page + 1
  171. this.loading = true
  172. this.loadStatus = 'loading'
  173. try {
  174. const pack = this.orderType
  175. ? await pullRecommendVideoPage({
  176. page: nextPage,
  177. orderType: this.orderType,
  178. isHotDian: this.isHotDian !== '' ? this.isHotDian : undefined
  179. })
  180. : await pullLabelVideoPage({
  181. labelId: this.labelId,
  182. page: nextPage
  183. })
  184. this.page = pack.currentPage
  185. this.lastPage = pack.lastPage
  186. if (reset) {
  187. this.cards = pack.rows.map((row) =>
  188. Object.assign({}, row, { listPage: pack.currentPage })
  189. )
  190. } else {
  191. this.cards = this.cards.concat(
  192. pack.rows.map((row) =>
  193. Object.assign({}, row, { listPage: pack.currentPage })
  194. )
  195. )
  196. }
  197. this.loadStatus =
  198. pack.currentPage >= pack.lastPage || !pack.rows.length ? 'noMore' : 'more'
  199. this.loaded = true
  200. } catch (err) {
  201. this.loadStatus = 'more'
  202. if (reset) this.cards = []
  203. this.$appKit && this.$appKit.msg(err.message || this.copy.loadFailed)
  204. this.loaded = true
  205. } finally {
  206. this.loading = false
  207. }
  208. },
  209. onCardTap(card) {
  210. if (!card) return
  211. const id = (card.raw && card.raw.id) || card.id
  212. if (!id) return
  213. // 顶部菜单(label_id)入口才传 label_id;推荐更多(order_type)入口不传
  214. uni.navigateTo({
  215. url: videoDetailUrl(id, {
  216. labelId: this.labelId || undefined,
  217. page: card.listPage || (card.raw && card.raw.page) || 1,
  218. orderType: this.orderType || undefined,
  219. isHotDian: this.isHotDian !== '' ? this.isHotDian : undefined
  220. })
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style scoped>
  227. .vl-page {
  228. min-height: 100vh;
  229. background-color: #f7f8fc;
  230. }
  231. .vl-nav {
  232. background-color: #ffffff;
  233. border-bottom: 1rpx solid #eef1f6;
  234. }
  235. .vl-nav-row {
  236. display: flex;
  237. flex-direction: row;
  238. align-items: center;
  239. height: 88rpx;
  240. padding: 0 24rpx;
  241. box-sizing: border-box;
  242. }
  243. .vl-back {
  244. width: 64rpx;
  245. height: 64rpx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. }
  250. .vl-back-icon {
  251. font-size: 40rpx;
  252. color: #1a1d26;
  253. line-height: 1;
  254. }
  255. .vl-nav-title {
  256. flex: 1;
  257. text-align: center;
  258. font-size: 32rpx;
  259. font-weight: 600;
  260. color: #1a1d26;
  261. }
  262. .vl-nav-placeholder {
  263. width: 64rpx;
  264. }
  265. .vl-body {
  266. padding: 24rpx 0 0;
  267. box-sizing: border-box;
  268. }
  269. .vl-state {
  270. padding: 120rpx 0;
  271. text-align: center;
  272. }
  273. .vl-state-txt {
  274. font-size: 28rpx;
  275. color: #8a8d9e;
  276. }
  277. .waterfall {
  278. display: flex;
  279. flex-direction: row;
  280. padding: 0 24rpx;
  281. }
  282. .waterfall-col {
  283. flex: 1;
  284. display: flex;
  285. flex-direction: column;
  286. padding: 0 8rpx;
  287. }
  288. .card {
  289. background-color: #ffffff;
  290. border-radius: 18rpx;
  291. overflow: hidden;
  292. margin-bottom: 16rpx;
  293. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  294. }
  295. .card-cover {
  296. width: 100%;
  297. display: block;
  298. }
  299. .card-cover-placeholder {
  300. width: 100%;
  301. height: 320rpx;
  302. }
  303. .card-body {
  304. padding: 16rpx 18rpx 18rpx;
  305. }
  306. .card-title {
  307. font-size: 26rpx;
  308. color: #1a1d29;
  309. line-height: 36rpx;
  310. font-weight: 500;
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. display: -webkit-box;
  314. -webkit-line-clamp: 2;
  315. -webkit-box-orient: vertical;
  316. }
  317. .card-meta {
  318. display: flex;
  319. flex-direction: row;
  320. align-items: center;
  321. margin-top: 14rpx;
  322. }
  323. .card-avatar {
  324. width: 36rpx;
  325. height: 36rpx;
  326. border-radius: 18rpx;
  327. margin-right: 8rpx;
  328. background-color: #e6e8ef;
  329. }
  330. .card-avatar-fallback {
  331. background: linear-gradient(135deg, #4a8cff 0%, #6ba0ff 100%);
  332. }
  333. .card-user {
  334. font-size: 22rpx;
  335. color: #4a4d5e;
  336. flex: 1;
  337. overflow: hidden;
  338. text-overflow: ellipsis;
  339. white-space: nowrap;
  340. }
  341. .card-like {
  342. font-size: 22rpx;
  343. color: #8a8d9e;
  344. flex-shrink: 0;
  345. }
  346. </style>