VideoPost.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <el-container class="video-post-container">
  3. <el-header height="auto" class="post-header">
  4. <div class="header-wrapper">
  5. <h3 class="page-title">
  6. <i class="el-icon-collection" /> 稿件管理
  7. </h3>
  8. <div class="filter-controls">
  9. <el-select
  10. v-model="queryInfo.scope"
  11. clearable
  12. placeholder="可见范围筛选"
  13. size="small"
  14. class="filter-select"
  15. @change="handleFilterChange"
  16. >
  17. <el-option label="全部范围" :value="null" />
  18. <el-option label="本人可见" :value="1" />
  19. <el-option label="所有人可见" :value="2" />
  20. <el-option label="VIP 可见" :value="3" />
  21. </el-select>
  22. <el-button
  23. type="primary"
  24. icon="el-icon-plus"
  25. size="small"
  26. class="publish-btn"
  27. @click="handlePost"
  28. >发布稿件</el-button>
  29. </div>
  30. </div>
  31. </el-header>
  32. <el-main class="post-main">
  33. <div class="table-card">
  34. <el-table
  35. v-loading="loading"
  36. :data="dataList"
  37. style="width: 100%"
  38. header-cell-class-name="table-header-cell"
  39. >
  40. <el-table-column label="No" type="index" width="60" align="center" />
  41. <el-table-column label="封面" width="120" align="center">
  42. <template slot-scope="scope">
  43. <el-image
  44. class="video-cover"
  45. :src="scope.row.coverUrl"
  46. fit="cover"
  47. :preview-src-list="[scope.row.coverUrl]"
  48. >
  49. <div slot="error" class="image-slot">
  50. <i class="el-icon-picture-outline" />
  51. </div>
  52. </el-image>
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="title" label="视频信息" min-width="200">
  56. <template slot-scope="scope">
  57. <div class="video-info-cell">
  58. <router-link :to="`/video/${scope.row.videoId}`" class="video-title-link">
  59. {{ scope.row.title }}
  60. </router-link>
  61. <div class="video-meta">
  62. <span class="vid-tag">ID: {{ scope.row.videoId }}</span>
  63. <span class="duration-tag"><i class="el-icon-time" /> {{ scope.row.duration }}</span>
  64. </div>
  65. </div>
  66. </template>
  67. </el-table-column>
  68. <el-table-column prop="pubDate" label="发布时间" width="160" align="center" />
  69. <el-table-column label="可见范围" width="130" align="center">
  70. <template slot-scope="scope">
  71. <el-tooltip content="点击修改可见范围" placement="top">
  72. <div class="scope-pointer" @click="handleScope(scope.$index, scope.row)">
  73. <el-tag v-if="scope.row.scope === 1" size="medium" type="info" effect="plain">本人可见</el-tag>
  74. <el-tag v-else-if="scope.row.scope === 2" size="medium" type="success" effect="plain">所有人可见</el-tag>
  75. <el-tag v-else-if="scope.row.scope === 3" size="medium" type="warning" effect="plain">VIP 可见</el-tag>
  76. </div>
  77. </el-tooltip>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="稿件状态" width="120" align="center">
  81. <template slot-scope="scope">
  82. <span :class="['status-dot', getStatusClass(scope.row.status)]">
  83. {{ getStatusText(scope.row.status) }}
  84. </span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" width="220" fixed="right" align="center">
  88. <template slot-scope="scope">
  89. <el-button type="text" size="small" icon="el-icon-view" @click="handlePreview(scope.$index, scope.row)">预览</el-button>
  90. <el-button type="text" size="small" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
  91. <el-button type="text" size="small" icon="el-icon-delete" class="danger-text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <div class="pagination-container">
  96. <el-pagination
  97. background
  98. :small="screenWidth <= 768"
  99. layout="total, prev, pager, next, jumper"
  100. :page-size="pageSize"
  101. :current-page="currentPage"
  102. :total="totalSize"
  103. @current-change="handlePageChange"
  104. />
  105. </div>
  106. </div>
  107. </el-main>
  108. <el-dialog
  109. :visible.sync="publishVideoDiaglog"
  110. width="70%"
  111. custom-class="custom-glass-dialog"
  112. append-to-body
  113. destroy-on-close
  114. @close="editingVideo = null"
  115. >
  116. <div slot="title" class="dialog-header-custom">
  117. <i :class="editingVideo ? 'el-icon-edit' : 'el-icon-circle-plus-outline'" />
  118. <span>{{ editingVideo ? '编辑视频稿件' : '发布新视频稿件' }}</span>
  119. </div>
  120. <video-post-publish
  121. :video-info="editingVideo"
  122. @video-publish="onVideoPublish"
  123. />
  124. </el-dialog>
  125. <el-dialog :visible.sync="showEditScopeDialog" width="400px" custom-class="custom-glass-dialog compact-dialog" append-to-body center>
  126. <div slot="title" class="dialog-header-custom">
  127. <i class="el-icon-lock" /><span>权限设置</span>
  128. </div>
  129. <div class="dialog-body-padding">
  130. <p class="input-label-tip">请选择该视频的可见范围:</p>
  131. <el-select v-model="form.scope" placeholder="选择可见范围" style="width: 100%">
  132. <el-option label="本人可见" value="1" />
  133. <el-option label="所有人可见" value="2" />
  134. <el-option label="VIP 可见" value="3" />
  135. </el-select>
  136. </div>
  137. <span slot="footer" class="dialog-footer">
  138. <el-button size="small" round @click="showEditScopeDialog = false">取 消</el-button>
  139. <el-button size="small" type="primary" round @click="onUpdateScope">确认更新</el-button>
  140. </span>
  141. </el-dialog>
  142. <el-dialog :visible.sync="showPreviewDialog" width="900px" top="8vh" custom-class="custom-glass-dialog preview-dialog" append-to-body @close="handleDialogClose(()=> { showPreviewDialog = false })">
  143. <div slot="title" class="dialog-header-custom">
  144. <i class="el-icon-video-play" /><span>内容预览</span>
  145. </div>
  146. <div class="preview-wrapper">
  147. <video-preview-player :video-prop.sync="videoProp" />
  148. </div>
  149. </el-dialog>
  150. </el-container>
  151. </template>
  152. <script>
  153. import VideoPreviewPlayer from 'components/VideoPreviewPlayer'
  154. import VideoPostPublish from '@/views/post/VideoPostPublish'
  155. import {updateVideoScope, videoInfo, deleteVideoPost, getVideoPosts, addVideoPost, updateVideoInfo} from '@/api/video'
  156. export default {
  157. name: 'VideoPost',
  158. components: { VideoPreviewPlayer, VideoPostPublish },
  159. data() {
  160. return {
  161. loading: false,
  162. queryInfo: {
  163. scope: null, // 从 URL 获取
  164. pn: 1 // 从 URL 获取
  165. },
  166. screenWidth: document.body.clientWidth,
  167. pageSize: 12,
  168. totalSize: 0,
  169. dataList: [],
  170. videoProp: { videoId: null, play: false },
  171. showEditScopeDialog: false,
  172. showPreviewDialog: false,
  173. form: { videoId: null, scope: 1 },
  174. publishVideoDiaglog: false,
  175. editingVideo: null
  176. }
  177. },
  178. computed: {
  179. // 映射当前页码给 el-pagination 使用
  180. currentPage() {
  181. return parseInt(this.queryInfo.pn) || 1
  182. }
  183. },
  184. watch: {
  185. // 核心优化:监听路由变化,一旦 URL 参数变了,就重新抓取数据
  186. '$route': {
  187. handler: 'syncParamsAndLoad',
  188. immediate: true
  189. }
  190. },
  191. methods: {
  192. // 1. 同步 URL 参数到 data,并执行请求
  193. syncParamsAndLoad() {
  194. const { pn, scope } = this.$route.query
  195. this.queryInfo.pn = pn ? parseInt(pn) : 1
  196. this.queryInfo.scope = scope ? (isNaN(scope) ? scope : parseInt(scope)) : null
  197. this.getData()
  198. },
  199. // 2. 更新 URL 的通用方法
  200. updateRouter() {
  201. this.$router.push({
  202. path: this.$route.path,
  203. query: {
  204. pn: this.queryInfo.pn,
  205. scope: this.queryInfo.scope || undefined // 为 null 时不显示在 URL 中
  206. }
  207. }).catch(err => {
  208. // 捕获冗余导航错误(点击同一页时)
  209. if (err.name !== 'NavigationDuplicated') throw err
  210. })
  211. },
  212. // 3. 交互触发:切换分页
  213. handlePageChange(pageNumber) {
  214. this.queryInfo.pn = pageNumber
  215. this.updateRouter()
  216. window.scrollTo({ top: 0, behavior: 'smooth' })
  217. },
  218. // 4. 交互触发:切换筛选
  219. handleFilterChange() {
  220. this.queryInfo.pn = 1 // 筛选条件变了,重置回第一页
  221. this.updateRouter()
  222. },
  223. getData() {
  224. this.loading = true
  225. // 注意:这里建议给后端接口也加上 scope 参数,此处假设你原有接口支持
  226. getVideoPosts(this.queryInfo.pn, this.queryInfo.scope).then(resp => {
  227. if (resp.code === 0) {
  228. this.dataList = resp.data.list
  229. this.totalSize = resp.data.totalSize
  230. }
  231. }).finally(() => {
  232. this.loading = false
  233. })
  234. },
  235. /* --- 其余 UI 逻辑保持不变 --- */
  236. getStatusClass(status) {
  237. const map = { 1: 'warning', 2: 'success', 3: 'danger', 4: 'info' }
  238. return map[status] || 'info'
  239. },
  240. getStatusText(status) {
  241. const map = { 1: '审核中', 2: '已发布', 3: '审核失败', 4: '已下架' }
  242. return map[status] || `未知(${status})`
  243. },
  244. handleScope(index, row) {
  245. this.form.videoId = row.videoId
  246. this.form.scope = '' + row.scope
  247. this.showEditScopeDialog = true
  248. },
  249. handleDialogClose(done) {
  250. this.videoProp = { videoId: null, play: false }
  251. if (typeof done === 'function') done()
  252. },
  253. handlePreview(index, row) {
  254. videoInfo(row.videoId).then(res => {
  255. if (res.code === 0) {
  256. this.showPreviewDialog = true
  257. this.videoProp = { videoId: res.data.videoId, play: true }
  258. }
  259. })
  260. },
  261. handleEdit(row) {
  262. this.editingVideo = row
  263. this.publishVideoDiaglog = true
  264. },
  265. handlePost() {
  266. this.editingVideo = null
  267. this.publishVideoDiaglog = true
  268. },
  269. handleDelete(index, row) {
  270. this.$confirm(`确定要删除《${row.title}》?`, '警告', {
  271. type: 'warning',
  272. confirmButtonClass: 'el-button--danger'
  273. }).then(() => {
  274. deleteVideoPost(row.videoId).then(res => {
  275. if (res.code === 0) {
  276. this.$message.info('稿件已删除')
  277. this.getData()
  278. }
  279. })
  280. }).catch(() => {})
  281. },
  282. onUpdateScope() {
  283. updateVideoScope(this.form).then(res => {
  284. if (res.code === 0) {
  285. this.showEditScopeDialog = false
  286. this.getData()
  287. this.$message.info('可见范围已更新')
  288. }
  289. })
  290. },
  291. onVideoPublish({ data, mode }) {
  292. const videoForm = data
  293. if (mode === 'edit') {
  294. updateVideoInfo(videoForm).then(res => {
  295. this.$message.info(res.msg)
  296. }).catch(error => {
  297. this.$message.error(error.message)
  298. })
  299. } else {
  300. addVideoPost(videoForm).then(res => {
  301. if (res.code === 0) {
  302. this.publishVideoDiaglog = false
  303. this.$message.info('投稿成功,请等待审核')
  304. this.getData()
  305. }
  306. })
  307. }
  308. this.finishPublish()
  309. },
  310. finishPublish() {
  311. this.publishVideoDiaglog = false
  312. this.editingVideo = null
  313. this.getData()
  314. }
  315. }
  316. }
  317. </script>
  318. <style scoped>
  319. /* 样式部分同上一版,保持“三层”视觉感 */
  320. .video-post-container { padding: 24px; background-color: #f5f7fa; min-height: 100%; }
  321. .post-header { background: white; padding: 20px 24px; border-radius: 12px 12px 0 0; box-shadow: 0 4px 12px 0 rgba(0,0,0,0.03); }
  322. .header-wrapper { display: flex; justify-content: space-between; align-items: center; }
  323. .page-title { margin: 0; font-size: 20px; color: #303133; display: flex; align-items: center; gap: 8px; }
  324. .filter-controls { display: flex; gap: 16px; }
  325. .publish-btn { box-shadow: 0 4px 10px rgba(64, 158, 255, 0.3); }
  326. .post-main { padding: 0; }
  327. .table-card { background: white; border-radius: 0 0 12px 12px; padding: 10px 24px 24px; box-shadow: 0 8px 24px 0 rgba(0,0,0,0.04); min-height: 400px; }
  328. .video-cover { width: 90px; height: 50px; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.12); transition: transform 0.3s; }
  329. .video-cover:hover { transform: scale(1.08); }
  330. .video-title-link { color: #303133; text-decoration: none; font-weight: 600; font-size: 14px; }
  331. .video-title-link:hover { color: #409EFF; }
  332. .video-meta { margin-top: 6px; font-size: 12px; color: #909399; }
  333. .vid-tag { background: #f0f2f5; padding: 2px 6px; border-radius: 4px; margin-right: 10px; }
  334. .status-dot { position: relative; padding-left: 16px; font-size: 13px; color: #606266; }
  335. .status-dot::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 7px; height: 7px; border-radius: 50%; }
  336. .status-dot.success::before { background-color: #67C23A; box-shadow: 0 0 6px #67C23A; }
  337. .status-dot.warning::before { background-color: #E6A23C; box-shadow: 0 0 6px #E6A23C; }
  338. .status-dot.danger::before { background-color: #F56C6C; box-shadow: 0 0 6px #F56C6C; }
  339. .danger-text { color: #F56C6C; }
  340. .pagination-container { margin-top: 30px; display: flex; justify-content: center; }
  341. ::v-deep .custom-glass-dialog { border-radius: 16px !important; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.15) !important; }
  342. ::v-deep .custom-glass-dialog .el-dialog__header { padding: 20px 24px; background: #fcfcfd; border-bottom: 1px solid #f0f0f0; }
  343. .dialog-header-custom { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; color: #303133; }
  344. .dialog-header-custom i { color: #409EFF; font-size: 20px; }
  345. ::v-deep .custom-glass-dialog .el-dialog__body { padding: 24px; }
  346. .input-label-tip { font-size: 13px; color: #909399; margin-bottom: 12px; }
  347. .preview-wrapper { background: #1a1a1a; border-radius: 12px; overflow: hidden; line-height: 0; }
  348. ::v-deep .table-header-cell { background-color: #f8f9fb !important; color: #303133; font-weight: 600; padding: 12px 0; }
  349. </style>