PostList.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <el-row>
  3. <el-col :md="2">
  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="22">
  16. <el-row>
  17. <el-tabs v-model="activeName" @tab-click='tabClick'>
  18. <el-tab-pane label="视频" name="video">
  19. <video-post :data-list="dataList"/>
  20. </el-tab-pane>
  21. <el-tab-pane label="音频" name="audio">
  22. <audio-post :data-list="dataList"/>
  23. </el-tab-pane>
  24. <el-tab-pane label="相册" name="image">
  25. <image-post :data-list="dataList"/>
  26. </el-tab-pane>
  27. <el-tab-pane label="文章" name="article">
  28. <article-post :data-list="dataList"/>
  29. </el-tab-pane>
  30. </el-tabs>
  31. </el-row>
  32. <el-row>
  33. <el-col :span="22" class="pagination">
  34. <el-pagination
  35. background
  36. :small="screenWidth <= 768"
  37. layout="prev, pager, next"
  38. :page-size="pageSize"
  39. :current-page="currentPage"
  40. :total="totalSize"
  41. @current-change="handleCurrentChange"
  42. @prev-click="handleCurrentChange"
  43. @next-click="handleCurrentChange"
  44. />
  45. </el-col>
  46. </el-row>
  47. </el-col>
  48. </el-row>
  49. </template>
  50. <script>
  51. import VideoPost from "@/views/post/VideoPost";
  52. import AudioPost from "@/views/post/AudioPost";
  53. import ImagePost from "@/views/post/ImagePost";
  54. import ArticlePost from "@/views/post/ArticlePost";
  55. import { userVideoPost } from "@/api/video";
  56. import { getUserAudio } from "@/api/audio";
  57. import { getUserAlbums } from "@/api/image";
  58. import { getArticles } from "@/api/article";
  59. export default {
  60. name: 'PostList',
  61. components: { VideoPost, ImagePost, AudioPost, ArticlePost },
  62. data() {
  63. return {
  64. // 屏幕宽度, 为了控制分页条的大小
  65. screenWidth: document.body.clientWidth,
  66. currentPage: 1,
  67. pageSize: 12,
  68. totalSize: 0,
  69. dataList: [],
  70. /*************************************************************************/
  71. navList: [
  72. { path: '/post/publish', name: '发布', icon: 'el-icon-upload' },
  73. { path: '/post/list', name: '稿件', icon: 'el-icon-files' },
  74. { path: '/post/analysis', name: '数据', icon: 'el-icon-data-analysis' }
  75. ],
  76. activeName: 'video',
  77. userId: 10001,
  78. showPreviewDialog: false,
  79. videoProp: null,
  80. showEditScopeDialog: false,
  81. }
  82. },
  83. created() {
  84. document.title = "稿件列表"
  85. const path = this.$route.path
  86. if (path.endsWith("video")) {
  87. this.activeName = 'video'
  88. document.title = '视频稿件'
  89. } else if (path.endsWith("image")) {
  90. this.activeName = 'image'
  91. document.title = '图片稿件'
  92. } else if (path.endsWith("audio")) {
  93. this.activeName = 'audio'
  94. document.title = '音频稿件'
  95. } else if (path.endsWith("article")) {
  96. this.activeName = 'article'
  97. document.title = '文章稿件'
  98. }
  99. this.getData()
  100. },
  101. watch: {
  102. $route(){
  103. this.$router.go()
  104. }
  105. },
  106. methods: {
  107. handleCurrentChange(pageNumber) {
  108. this.currentPage = pageNumber
  109. this.getData()
  110. // 回到顶部
  111. scrollTo(0, 0)
  112. },
  113. tabClick(tab) {
  114. this.activeName = tab.name
  115. this.goToTab(this.activeName)
  116. },
  117. goToTab(activeName) {
  118. const path = '/post/' + activeName
  119. if (this.$route.path === path) {
  120. this.$router.go(0)
  121. return
  122. }
  123. this.$router.push(path)
  124. },
  125. getData() {
  126. this.dataList = []
  127. if (this.activeName === 'video') {
  128. userVideoPost(this.currentPage).then(res => {
  129. if (res.code === 0) {
  130. const resData = res.data
  131. this.dataList = resData.list
  132. this.totalSize = resData.totalSize
  133. if (this.totalSize !== 0) {
  134. this.showEmpty = false
  135. } else {
  136. this.showEmpty = true
  137. }
  138. } else {
  139. this.$notify({
  140. title: '提示',
  141. message: res.msg,
  142. type: 'warning',
  143. duration: 3000
  144. })
  145. }
  146. }).catch(error => {
  147. this.$notify({
  148. title: '提示',
  149. message: error.message,
  150. type: 'error',
  151. duration: 3000
  152. })
  153. })
  154. } else if (this.activeName === 'image') {
  155. getUserAlbums(this.userId).then(res => {
  156. if (res.code === 0) {
  157. const resData = res.data
  158. if (resData.length !== 0) {
  159. this.showEmpty = false
  160. for (const item of resData) {
  161. this.dataList.push(item)
  162. }
  163. } else {
  164. this.showEmpty = true
  165. }
  166. }
  167. })
  168. } else if (this.activeName === 'audio') {
  169. this.currentPage = 1
  170. this.lastId = 0
  171. getUserAudio(this.userId).then(res => {
  172. if (res.code === 0) {
  173. const resData = res.data.list
  174. if (resData.length !== 0) {
  175. this.showEmpty = false
  176. for (const item of resData) {
  177. this.dataList.push(item)
  178. }
  179. } else {
  180. this.showEmpty = true
  181. }
  182. }
  183. })
  184. } else if (this.activeName === 'article') {
  185. this.currentPage = 1
  186. this.lastId = 0
  187. getArticles(1).then(res => {
  188. if (res.code === 0) {
  189. const resData = res.data.list
  190. if (resData.length !== 0) {
  191. this.showEmpty = false
  192. for (const item of resData) {
  193. this.dataList.push(item)
  194. }
  195. } else {
  196. this.showEmpty = true
  197. }
  198. }
  199. })
  200. }
  201. },
  202. }
  203. }
  204. </script>
  205. <style>
  206. .uploader-example {
  207. width: 500px;
  208. padding: 15px;
  209. margin: 40px auto 0;
  210. font-size: 12px;
  211. box-shadow: 0 0 10px rgba(0, 0, 0, .4);
  212. }
  213. .uploader-example .uploader-btn {
  214. margin-right: 4px;
  215. }
  216. .uploader-example .uploader-list {
  217. max-height: 440px;
  218. overflow: auto;
  219. overflow-x: hidden;
  220. overflow-y: auto;
  221. }
  222. .avatar-uploader .el-upload {
  223. border: 1px dashed #d9d9d9;
  224. border-radius: 6px;
  225. cursor: pointer;
  226. position: relative;
  227. overflow: hidden;
  228. }
  229. .avatar-uploader .el-upload:hover {
  230. border-color: #409EFF;
  231. }
  232. .avatar-uploader-icon {
  233. font-size: 28px;
  234. color: #8c939d;
  235. width: 320px;
  236. height: 240px;
  237. line-height: 178px;
  238. text-align: center;
  239. }
  240. .avatar {
  241. width: 320px;
  242. height: 240px;
  243. display: block;
  244. }
  245. </style>