video.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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.list = []
  129. this.listQuery.videoTitle = keyword
  130. this.listQuery.pageNum = 1
  131. this.fetchList()
  132. },
  133. // 页码变化
  134. onPagiantionChange(index) {
  135. this.listQuery.pageNum = index
  136. this.fetchList()
  137. },
  138. // 加载更多
  139. onLoadMore() {
  140. this.fetchList()
  141. },
  142. },
  143. }
  144. </script>
  145. <style scoped lang="scss">
  146. /* scss中可以用mixin来扩展 */
  147. @mixin ellipsis($line: 1) {
  148. overflow: hidden;
  149. text-overflow: ellipsis;
  150. display: -webkit-box;
  151. -webkit-line-clamp: $line;
  152. -webkit-box-orient: vertical;
  153. }
  154. // pc 端
  155. @media screen and (min-width: 768px) {
  156. .page-top {
  157. height: 360px;
  158. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  159. background-size: auto 360px;
  160. .logo {
  161. display: block;
  162. width: 120px;
  163. height: 120px;
  164. border-radius: 50%;
  165. background: #fff;
  166. }
  167. .name {
  168. font-size: 30px;
  169. color: #fff;
  170. }
  171. }
  172. .page-content {
  173. width: 1200px;
  174. margin: 0 auto;
  175. background-color: #fff;
  176. .divider {
  177. height: 16px;
  178. background: #f7f7f7;
  179. }
  180. .search {
  181. display: none;
  182. }
  183. }
  184. .list {
  185. border-top: 16px solid #f7f7f7;
  186. border-bottom: 16px solid #f7f7f7;
  187. .section {
  188. padding: 32px 0;
  189. margin: 0 24px;
  190. background: #fff;
  191. border-bottom: 1px solid #d8d8d8;
  192. transition: all 0.4s;
  193. &:last-child {
  194. border-bottom: 0;
  195. }
  196. .info {
  197. width: 880px;
  198. height: 100%;
  199. .name {
  200. height: 56px;
  201. font-size: 18px;
  202. color: #404040;
  203. line-height: 1.6;
  204. margin-bottom: 18px;
  205. @include ellipsis(2);
  206. text-align: justify;
  207. }
  208. .date {
  209. font-size: 18px;
  210. color: #b2b2b2;
  211. line-height: 1.4;
  212. }
  213. .download {
  214. font-size: 16px;
  215. @include themify($themes) {
  216. color: themed('color');
  217. }
  218. cursor: pointer;
  219. margin-top: 8px;
  220. }
  221. }
  222. .cover {
  223. position: relative;
  224. width: 216px;
  225. height: 132px;
  226. background: #333;
  227. span {
  228. position: absolute;
  229. width: 36px;
  230. height: 36px;
  231. top: 50%;
  232. left: 50%;
  233. transform: translate(-50%, -50%);
  234. background: url(https://static.caimei365.com/www/authentic/h5/icon-play.png)
  235. no-repeat center;
  236. background-size: 36px;
  237. border-radius: 50%;
  238. cursor: pointer;
  239. box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  240. }
  241. }
  242. }
  243. }
  244. }
  245. // 移动 端
  246. @media screen and (max-width: 768px) {
  247. .page-top {
  248. height: 46vw;
  249. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  250. background-size: auto 46vw;
  251. .logo {
  252. display: block;
  253. width: 14.8vw;
  254. height: 14.8vw;
  255. border-radius: 50%;
  256. background: #fff;
  257. }
  258. .name {
  259. font-size: 4vw;
  260. color: #fff;
  261. }
  262. }
  263. .page-content {
  264. position: relative;
  265. .divider {
  266. border-bottom: 3.2vw solid #f7f7f7;
  267. height: 12.4vw;
  268. }
  269. }
  270. .search {
  271. position: absolute;
  272. left: 50%;
  273. top: 0;
  274. transform: translate(-50%, -50%);
  275. }
  276. .list {
  277. .section {
  278. position: relative;
  279. padding: 2.4vw 0;
  280. margin: 0 4vw;
  281. padding-bottom: 9.8vw;
  282. background: #fff;
  283. border-bottom: 0.1vw solid #d8d8d8;
  284. &:first-child {
  285. border-top: 0.1vw solid #d8d8d8;
  286. }
  287. .info {
  288. .name {
  289. font-size: 3.6vw;
  290. color: #404040;
  291. line-height: 1.5;
  292. margin-bottom: 2.4vw;
  293. @include ellipsis(2);
  294. text-align: justify;
  295. }
  296. .date {
  297. position: absolute;
  298. left: 0;
  299. bottom: 2.4vw;
  300. font-size: 3.2vw;
  301. color: #b2b2b2;
  302. line-height: 1.4;
  303. }
  304. .download {
  305. position: absolute;
  306. right: 0;
  307. bottom: 2.4vw;
  308. font-size: 3.2vw;
  309. @include themify($themes) {
  310. color: themed('color');
  311. }
  312. cursor: pointer;
  313. margin-top: 1.2vw;
  314. }
  315. }
  316. .cover {
  317. position: relative;
  318. width: 92vw;
  319. height: 56vw;
  320. border-bottom: 0.1vw solid #d8d8d8;
  321. background: #333;
  322. span {
  323. position: absolute;
  324. width: 12vw;
  325. height: 12vw;
  326. top: 50%;
  327. left: 50%;
  328. transform: translate(-50%, -50%);
  329. background: url(https://static.caimei365.com/www/authentic/h5/icon-play.png)
  330. no-repeat center;
  331. background-size: 12vw;
  332. border-radius: 50%;
  333. cursor: pointer;
  334. box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  335. }
  336. }
  337. }
  338. }
  339. }
  340. </style>