video.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="page">
  3. <van-list
  4. v-model="isLoadingMore"
  5. :finished="finished"
  6. :immediate-check="false"
  7. :finished-text="total ? '没有更多了' : ''"
  8. @load="onLoadMore"
  9. >
  10. <div class="page-top flex flex-col justify-center items-center">
  11. <img class="logo" :src="supplierInfo.logo" />
  12. <span
  13. class="name mt-2"
  14. v-text="supplierInfo.shopName + '资料库'"
  15. ></span>
  16. </div>
  17. <div class="page-content">
  18. <!-- 搜索区域 -->
  19. <div class="search">
  20. <simple-search
  21. v-model="listQuery.videoTitle"
  22. @search="onSearch"
  23. placeholder="搜索视频"
  24. />
  25. </div>
  26. <div class="divider"></div>
  27. <!-- tabbar -->
  28. <simple-tabs
  29. :tabs="tabs"
  30. :current="current"
  31. @change="onTabChange"
  32. @search="onSearch"
  33. ></simple-tabs>
  34. <div class="list">
  35. <div
  36. class="section md:flex md:justify-between md:items-center"
  37. v-for="item in list"
  38. :key="item.videoId"
  39. >
  40. <div class="info">
  41. <div class="name" v-text="item.videoTitle"></div>
  42. <div class="date">{{ item.createTime | dateFormat }}</div>
  43. <div class="download" @click="downloadLink(item, $event)">
  44. 保存视频
  45. </div>
  46. </div>
  47. <div class="cover">
  48. <video class="cover" :src="item.videoPreviewUrl"></video>
  49. <span @click="onPlayer(item)"></span>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- 列表为空 -->
  54. <SimpleEmpty
  55. v-if="!total && !isRequest"
  56. description="敬请期待~"
  57. ></SimpleEmpty>
  58. </div>
  59. </van-list>
  60. <SimpleVideoPlayer ref="player" :videoSrc="videoUrl"></SimpleVideoPlayer>
  61. </div>
  62. </template>
  63. <script>
  64. import { mapGetters } from 'vuex'
  65. import { tabs } from '@/configs/tabs'
  66. import downloadLink from '@/utils/download-link'
  67. import { debounce } from '~/utils'
  68. export default {
  69. layout: 'app',
  70. data() {
  71. return {
  72. isLoadingMore: true,
  73. finished: false,
  74. isRequest: true,
  75. tabs: tabs(),
  76. current: 2,
  77. listQuery: {
  78. videoTitle: '',
  79. authUserId: '102',
  80. pageNum: 1,
  81. pageSize: 10,
  82. },
  83. list: [],
  84. total: 0,
  85. videoUrl: '',
  86. }
  87. },
  88. computed: {
  89. ...mapGetters(['routePrefix', 'supplierInfo', 'authUserId']),
  90. },
  91. mounted() {
  92. this.fetchList()
  93. },
  94. methods: {
  95. // 视频在线播放
  96. onPlayer(item) {
  97. this.videoUrl = item.videoPreviewUrl
  98. this.$refs.player.open()
  99. },
  100. // 下载方法
  101. downloadLink(item, $event) {
  102. const url = `${process.env.BASE_URL}/download/file?ossName=${item.videoDownloadUrl}&fileName=${item.videoName}`
  103. downloadLink(url, $event)
  104. },
  105. // 获取列表
  106. fetchList: debounce(async function () {
  107. try {
  108. this.isLoadingMore = true
  109. this.listQuery.authUserId = this.authUserId
  110. const res = await this.$http.api.getVideoList(this.listQuery)
  111. this.list = [...this.list, ...res.data.list]
  112. this.finished = !res.data.hasNextPage
  113. this.listQuery.pageNum += 1
  114. this.isLoadingMore = false
  115. this.total = res.data.total
  116. } catch (error) {
  117. console.log(error)
  118. } finally {
  119. this.isRequest = false
  120. }
  121. }, 400),
  122. // tab切换
  123. onTabChange(item) {
  124. this.$router.push(`${this.routePrefix}${item.path}`)
  125. },
  126. // 搜索
  127. onSearch(keyword) {
  128. this.listQuery.videoTitle = keyword
  129. this.listQuery.pageNum = 1
  130. this.fetchList()
  131. },
  132. // 页码变化
  133. onPagiantionChange(index) {
  134. this.listQuery.pageNum = index
  135. this.fetchList()
  136. },
  137. // 加载更多
  138. onLoadMore() {
  139. this.fetchList()
  140. },
  141. },
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. /* scss中可以用mixin来扩展 */
  146. @mixin ellipsis($line: 1) {
  147. overflow: hidden;
  148. text-overflow: ellipsis;
  149. display: -webkit-box;
  150. -webkit-line-clamp: $line;
  151. -webkit-box-orient: vertical;
  152. }
  153. // pc 端
  154. @media screen and (min-width: 768px) {
  155. .page-top {
  156. height: 360px;
  157. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  158. background-size: auto 360px;
  159. .logo {
  160. display: block;
  161. width: 120px;
  162. height: 120px;
  163. border-radius: 50%;
  164. background: #fff;
  165. }
  166. .name {
  167. font-size: 30px;
  168. color: #fff;
  169. }
  170. }
  171. .page-content {
  172. width: 1200px;
  173. margin: 0 auto;
  174. background-color: #fff;
  175. .divider {
  176. height: 16px;
  177. background: #f7f7f7;
  178. }
  179. .search {
  180. display: none;
  181. }
  182. }
  183. .list {
  184. border-top: 16px solid #f7f7f7;
  185. border-bottom: 16px solid #f7f7f7;
  186. .section {
  187. padding: 32px 0;
  188. margin: 0 24px;
  189. background: #fff;
  190. border-bottom: 1px solid #d8d8d8;
  191. transition: all 0.4s;
  192. &:last-child {
  193. border-bottom: 0;
  194. }
  195. .info {
  196. width: 880px;
  197. height: 100%;
  198. .name {
  199. height: 56px;
  200. font-size: 18px;
  201. color: #404040;
  202. line-height: 1.6;
  203. margin-bottom: 18px;
  204. @include ellipsis(2);
  205. text-align: justify;
  206. }
  207. .date {
  208. font-size: 18px;
  209. color: #b2b2b2;
  210. line-height: 1.4;
  211. }
  212. .download {
  213. font-size: 16px;
  214. @include themify($themes) {
  215. color: themed('color');
  216. }
  217. cursor: pointer;
  218. margin-top: 8px;
  219. }
  220. }
  221. .cover {
  222. position: relative;
  223. width: 216px;
  224. height: 132px;
  225. background: #333;
  226. span {
  227. position: absolute;
  228. width: 36px;
  229. height: 36px;
  230. top: 50%;
  231. left: 50%;
  232. transform: translate(-50%, -50%);
  233. background: url(https://static.caimei365.com/www/authentic/h5/icon-play.png)
  234. no-repeat center;
  235. background-size: 36px;
  236. border-radius: 50%;
  237. cursor: pointer;
  238. box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  239. }
  240. }
  241. }
  242. }
  243. }
  244. // 移动 端
  245. @media screen and (max-width: 768px) {
  246. .page-top {
  247. height: 46vw;
  248. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  249. background-size: auto 46vw;
  250. .logo {
  251. display: block;
  252. width: 14.8vw;
  253. height: 14.8vw;
  254. border-radius: 50%;
  255. background: #fff;
  256. }
  257. .name {
  258. font-size: 4vw;
  259. color: #fff;
  260. }
  261. }
  262. .page-content {
  263. position: relative;
  264. .divider {
  265. border-bottom: 3.2vw solid #f7f7f7;
  266. height: 12.4vw;
  267. }
  268. }
  269. .search {
  270. position: absolute;
  271. left: 50%;
  272. top: 0;
  273. transform: translate(-50%, -50%);
  274. }
  275. .list {
  276. .section {
  277. position: relative;
  278. padding: 2.4vw 0;
  279. margin: 0 4vw;
  280. padding-bottom: 9.8vw;
  281. background: #fff;
  282. border-bottom: 0.1vw solid #d8d8d8;
  283. &:first-child {
  284. border-top: 0.1vw solid #d8d8d8;
  285. }
  286. .info {
  287. .name {
  288. font-size: 3.6vw;
  289. color: #404040;
  290. line-height: 1.5;
  291. margin-bottom: 2.4vw;
  292. @include ellipsis(2);
  293. text-align: justify;
  294. }
  295. .date {
  296. position: absolute;
  297. left: 0;
  298. bottom: 2.4vw;
  299. font-size: 3.2vw;
  300. color: #b2b2b2;
  301. line-height: 1.4;
  302. }
  303. .download {
  304. position: absolute;
  305. right: 0;
  306. bottom: 2.4vw;
  307. font-size: 3.2vw;
  308. @include themify($themes) {
  309. color: themed('color');
  310. }
  311. cursor: pointer;
  312. margin-top: 1.2vw;
  313. }
  314. }
  315. .cover {
  316. position: relative;
  317. width: 92vw;
  318. height: 56vw;
  319. border-bottom: 0.1vw solid #d8d8d8;
  320. background: #333;
  321. span {
  322. position: absolute;
  323. width: 12vw;
  324. height: 12vw;
  325. top: 50%;
  326. left: 50%;
  327. transform: translate(-50%, -50%);
  328. background: url(https://static.caimei365.com/www/authentic/h5/icon-play.png)
  329. no-repeat center;
  330. background-size: 12vw;
  331. border-radius: 50%;
  332. cursor: pointer;
  333. box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. </style>