Collection.vue 9.0 KB

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