Collection.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <el-row>
  3. <el-col :md="4">
  4. <el-menu
  5. :default-active="this.$route.path"
  6. router
  7. class="el-menu-vertical-demo"
  8. >
  9. <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.path">
  10. <i :class="item.icon" />
  11. <span slot="title">{{ item.name }}</span>
  12. </el-menu-item>
  13. </el-menu>
  14. </el-col>
  15. <el-col :md="20">
  16. <div id="collection-list">
  17. <!--搜索结果面包屑-->
  18. <el-breadcrumb
  19. class="bread"
  20. separator-class="el-icon-arrow-right"
  21. >
  22. <el-breadcrumb-item>我的收藏:共 <span class="reslut">{{ totalSize }}</span> 条</el-breadcrumb-item>
  23. </el-breadcrumb>
  24. <el-row v-if="totalSize !== 0" class="movie-list">
  25. <el-col style="text-align: right">
  26. <el-button
  27. type="danger"
  28. size="mini"
  29. icon="el-icon-delete"
  30. @click="removeFavlist"
  31. >删除收藏夹</el-button>
  32. </el-col>
  33. <el-col v-for="(item,index) in dataList" :key="index" :md="6" :sm="8" :xs="12">
  34. <div v-if="contentType === 1001">
  35. <el-card :body-style="{ padding: '0px' }" class="card">
  36. <div class="imgs">
  37. <el-image
  38. lazy
  39. fit="cover"
  40. class="coverImg"
  41. :src="item.thumbnailUrl"
  42. @click="showImages(index)"
  43. />
  44. </div>
  45. </el-card>
  46. </div>
  47. <div v-else-if="contentType === 1002">
  48. <video-card :video="item" />
  49. </div>
  50. <div v-else-if="contentType === 1003" />
  51. <div v-else-if="contentType === 1004" />
  52. <div v-else>
  53. <span>未知 {{ contentType }}</span>
  54. </div>
  55. <el-button
  56. type="danger"
  57. size="mini"
  58. icon="el-icon-delete"
  59. title="删除本收藏"
  60. @click.stop="removeCollection(item)"
  61. />
  62. </el-col>
  63. <el-col class="pagination">
  64. <el-pagination
  65. background
  66. :small="screenWidth <= 768"
  67. hide-on-single-page
  68. layout="prev, pager, next"
  69. :page-size="pageSize"
  70. :current-page="currentPage"
  71. :total="totalSize"
  72. @current-change="handleCurrentChange"
  73. @prev-click="handleCurrentChange"
  74. @next-click="handleCurrentChange"
  75. />
  76. </el-col>
  77. </el-row>
  78. <el-row v-else class="not-result">
  79. <el-col :span="12" :offset="6">
  80. <img src="@/assets/img/icon/not-collection.png">
  81. <div>你还没有收藏任何东西呢</div>
  82. </el-col>
  83. </el-row>
  84. </div>
  85. </el-col>
  86. </el-row>
  87. </template>
  88. <script>
  89. import VideoCard from '@/components/card/VideoCard'
  90. import {
  91. deleteFavlist,
  92. getUserFavlist,
  93. getFavlist,
  94. collectItem
  95. } from '@/api/collect'
  96. export default {
  97. name: 'Collection',
  98. components: { VideoCard },
  99. data() {
  100. return {
  101. navList: [],
  102. // 屏幕宽度, 为了控制分页条的大小
  103. screenWidth: document.body.clientWidth,
  104. currentPage: 1,
  105. pageSize: 12,
  106. totalSize: 0,
  107. dataList: [],
  108. favlist: null,
  109. contentType: 1001
  110. }
  111. },
  112. watch: {
  113. $route() {
  114. this.$router.go()
  115. }
  116. },
  117. created() {
  118. /* const myfavlist = localStorage.getItem('myfavlist')
  119. if (myfavlist !== undefined) {
  120. const myfavlist1 = JSON.parse(myfavlist)
  121. this.navList = []
  122. for (const item of myfavlist1) {
  123. this.navList.push(item)
  124. }
  125. } else {
  126. this.getUserFavlistWrapper()
  127. }*/
  128. const page = this.$route.query.page
  129. if (page !== undefined) {
  130. this.currentPage = parseInt(page)
  131. }
  132. const type = this.$route.query.contentType
  133. if (type !== undefined) {
  134. this.contentType = parseInt(type)
  135. }
  136. const favlistId1 = this.$route.query.favlistId
  137. if (favlistId1 === undefined) {
  138. // this.$router.push(this.navList[0].path)
  139. this.getUserFavlistWrapper()
  140. } else {
  141. const myfavlist = localStorage.getItem('myfavlist')
  142. const myfavlist1 = JSON.parse(myfavlist)
  143. this.navList = []
  144. for (const item of myfavlist1) {
  145. this.navList.push(item)
  146. }
  147. this.favlistId = favlistId1
  148. this.getFavlistWrapper(this.favlistId, this.contentType, this.currentPage)
  149. }
  150. document.title = '我的收藏夹'
  151. },
  152. methods: {
  153. handleCurrentChange(pageNumber) {
  154. this.currentPage = pageNumber
  155. this.dataList = []
  156. // 回到顶部
  157. scrollTo(0, 0)
  158. },
  159. getFavlistWrapper(favlistId, conentType, page) {
  160. getFavlist(favlistId, conentType, page).then(resp => {
  161. if (resp.code === 0) {
  162. const respData = resp.data
  163. this.dataList = respData.list
  164. this.totalSize = respData.totalSize
  165. }
  166. })
  167. },
  168. getUserFavlistWrapper() {
  169. getUserFavlist().then(resp => {
  170. if (resp.code === 0) {
  171. const respData = resp.data
  172. this.navList = []
  173. for (const item of respData) {
  174. const contentType = item.contentType
  175. if (contentType === 1001) {
  176. this.navList.push({
  177. path: '/u/favlist?favlistId=' + item.favlistId + '&contentType=' + contentType + '&page=1',
  178. name: item.favlistName,
  179. icon: 'el-icon-picture' })
  180. } else if (contentType === 1002) {
  181. this.navList.push({
  182. path: '/u/favlist?favlistId=' + item.favlistId + '&contentType=' + contentType + '&page=1',
  183. name: item.favlistName,
  184. icon: 'el-icon-film' })
  185. } else if (contentType === 1003) {
  186. this.navList.push({
  187. path: '/u/favlist?favlistId=' + item.favlistId + '&contentType=' + contentType + '&page=1',
  188. name: item.favlistName,
  189. icon: 'el-icon-headset' })
  190. } else if (contentType === 1004) {
  191. this.navList.push({
  192. path: '/u/favlist?favlistId=' + item.favlistId + '&contentType=' + contentType + '&page=1',
  193. name: item.favlistName,
  194. icon: 'el-icon-document' })
  195. }
  196. }
  197. localStorage.setItem('myfavlist', JSON.stringify(this.navList))
  198. }
  199. })
  200. },
  201. showImages(index) {
  202. const imageUrls = []
  203. for (const i of this.dataList) {
  204. imageUrls.push(i.originalUrl)
  205. }
  206. this.$viewerApi({
  207. images: imageUrls,
  208. options: {
  209. initialViewIndex: index,
  210. movable: true,
  211. fullscreen: false,
  212. keyboard: true
  213. }
  214. })
  215. },
  216. // 移除收藏
  217. removeCollection(item) {
  218. this.$confirm('确认删除本收藏?', '提示', {
  219. confirmButtonText: '确定',
  220. cancelButtonText: '取消',
  221. type: 'warning'
  222. }).then(() => {
  223. const jsonData = {}
  224. jsonData.contentType = 1001
  225. jsonData.contentId = item.imageFileId
  226. jsonData.collected = false
  227. collectItem(jsonData).then(res => {
  228. if (res.code === 0) {
  229. this.$message({
  230. type: 'success',
  231. message: '移除成功!'
  232. })
  233. this.$router.go(0)
  234. }
  235. })
  236. }).catch(() => {
  237. this.$message({
  238. type: 'info',
  239. message: '已取消'
  240. })
  241. })
  242. },
  243. // 删除收藏夹
  244. removeFavlist() {
  245. // 移除所有收藏
  246. this.$confirm('确认要删除收藏夹?', '提示', {
  247. confirmButtonText: '确定',
  248. cancelButtonText: '取消',
  249. type: 'warning'
  250. }).then(() => {
  251. deleteFavlist(this.favlistId).then(res => {
  252. if (res.code === 0) {
  253. this.$message({
  254. type: 'success',
  255. message: '收藏夹已清空!'
  256. })
  257. this.$router.go(0)
  258. }
  259. })
  260. }).catch(() => {
  261. this.$message({
  262. type: 'info',
  263. message: '已取消'
  264. })
  265. })
  266. }
  267. }
  268. }
  269. </script>
  270. <style scoped>
  271. /*处于手机屏幕时*/
  272. @media screen and (max-width: 768px){
  273. .movie-list {
  274. padding-top: 8px;
  275. padding-left: 0.5%;
  276. padding-right: 0.5%;
  277. }
  278. .coverImg {
  279. height: 120px !important;
  280. }
  281. }
  282. .movie-list {
  283. padding-top: 15px;
  284. padding-left: 6%;
  285. padding-right: 6%;
  286. }
  287. .coverImg {
  288. width: 100%;
  289. height: 320px;
  290. display: block;
  291. }
  292. .card {
  293. margin-bottom: 20px;
  294. transition: all 0.6s; /*所有属性变化在0.6秒内执行动画*/
  295. }
  296. .imgs {
  297. position: relative;
  298. }
  299. #collection-list {
  300. padding-left: 6%;
  301. padding-right: 6%;
  302. padding-top: 30px;
  303. }
  304. .bread {
  305. font-size: 15px;
  306. }
  307. .movie-list {
  308. padding-top: 15px;
  309. }
  310. .reslut {
  311. color: red;
  312. }
  313. .not-result {
  314. padding-top: 100px;
  315. padding-bottom: 100px;
  316. text-align: center;
  317. }
  318. .remove-slot {
  319. position: absolute;
  320. right: 5px;
  321. bottom: 2px;
  322. }
  323. </style>