Browse Source

内容页面根据资源的权限展示不同的页面内容

reghao 2 years ago
parent
commit
32c99428c2
3 changed files with 122 additions and 48 deletions
  1. 17 0
      src/api/content.js
  2. 12 12
      src/views/home/ImagePage.vue
  3. 93 36
      src/views/home/VideoPage.vue

+ 17 - 0
src/api/content.js

@@ -0,0 +1,17 @@
+import { get, post } from '@/utils/request'
+
+const videoApi = {
+  userContentDataApi: '/api/content/userdata',
+  contentAccessCodeApi: '/api/content/userdata'
+}
+
+/** *******************************************************************************************************************/
+// 获取用户内容统计
+export function getUserContentData(userId) {
+  return get(videoApi.userContentDataApi + '?userId=' + userId)
+}
+
+// 提交内容访问码
+export function submitAccessCode(jsonData) {
+  return post(videoApi.contentAccessCodeApi, jsonData)
+}

+ 12 - 12
src/views/home/ImagePage.vue

@@ -7,7 +7,7 @@
             <el-row>
               <el-col :md="1">
                 <el-avatar>
-                  <el-image :src="user.avatarUrl"/>
+                  <el-image :src="user.avatarUrl" />
                 </el-avatar>
               </el-col>
               <el-col :md="23">
@@ -21,7 +21,7 @@
                   :icon="followButton.icon"
                   @click="followUser(user.userId)"
                 >
-                  <span>{{followButton.text}}</span>
+                  <span>{{ followButton.text }}</span>
                 </el-button>
                 <el-button
                   type="danger"
@@ -35,7 +35,7 @@
             </el-row>
             <el-row>
               <br>
-              <span>{{data.albumName}}</span>
+              <span>{{ data.albumName }}</span>
             </el-row>
           </div>
         </el-card>
@@ -52,13 +52,13 @@
                   fit="cover"
                   class="coverImg"
                   :src="image.thumbnailUrl"
-                  @click="showImages(index)">
-                </el-image>
+                  @click="showImages(index)"
+                />
               </div>
               <div style="padding: 14px;">
                 <span>
-                  <i v-if="image.collected" class='el-icon-star-on' @click="collectItem(image)"/>
-                  <i v-else class='el-icon-star-off' @click="collectItem(image)"/>
+                  <i v-if="image.collected" class="el-icon-star-on" @click="collectItem(image)" />
+                  <i v-else class="el-icon-star-off" @click="collectItem(image)" />
                 </span>
               </div>
             </el-card>
@@ -68,15 +68,15 @@
     </el-row>
   </div>
   <div v-else>
-    <permission-denied-card :text-object="textObject"/>
+    <permission-denied-card :text-object="textObject" />
   </div>
 </template>
 
 <script>
 import PermissionDeniedCard from '@/components/card/PermissionDeniedCard'
-import { followUser, getUserInfo, unfollowUser } from "@/api/user";
-import { getAlbum } from "@/api/image";
-import {collectItem} from "@/api/collect";
+import { followUser, getUserInfo, unfollowUser } from '@/api/user'
+import { getAlbum } from '@/api/image'
+import { collectItem } from '@/api/collect'
 
 export default {
   name: 'ImagePage',
@@ -97,7 +97,7 @@ export default {
       textObject: {
         content: '相册',
         route: '/image'
-      },
+      }
     }
   },
   created() {

+ 93 - 36
src/views/home/VideoPage.vue

@@ -1,5 +1,5 @@
 <template>
-  <el-row v-if="video !== null" class="movie-list">
+  <el-row v-if="!permissionDenied" class="movie-list">
     <el-col :md="15">
       <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
         <el-card class="box-card">
@@ -172,6 +172,28 @@
       </el-row>
     </el-col>
 
+    <!-- 视频访问码对话框 -->
+    <el-dialog
+      append-to-body
+      :visible.sync="showAccessCodeDialog"
+      width="30%"
+      center
+    >
+      <el-card class="box-card">
+        <div slot="header" class="clearfix">
+          <span>输入视频访问码</span>
+          <el-button style="float: right; padding: 3px 0" type="text" @click="submitAccessCodeWrapper">提交</el-button>
+        </div>
+        <div class="text item">
+          <el-form ref="form" :model="accessCodeForm" label-width="80px">
+            <el-form-item label="访问码">
+              <el-input v-model="accessCodeForm.accessCode" style="width: 70%; padding-right: 2px" />
+            </el-form-item>
+          </el-form>
+        </div>
+      </el-card>
+    </el-dialog>
+
     <!-- 视频报错对话框 -->
     <el-dialog
       append-to-body
@@ -200,9 +222,13 @@
       </el-card>
     </el-dialog>
   </el-row>
+  <el-row v-else>
+    <permission-denied-card :text-object="textObject" />
+  </el-row>
 </template>
 
 <script>
+import PermissionDeniedCard from '@/components/card/PermissionDeniedCard'
 import VideoPlayer from 'components/VideoPlayer'
 import Comment from 'components/comment/Comment'
 import VideoCard from 'components/card/VideoCard'
@@ -211,10 +237,11 @@ import UserAvatarCard from '@/components/card/UserAvatarCard'
 import { similarVideo, videoInfo, videoErrorReport, downloadVideo, cacheBiliVideo } from '@/api/video'
 import { collectItem } from '@/api/collect'
 import { getUserInfo } from '@/api/user'
+import { submitAccessCode } from '@/api/content'
 
 export default {
   name: 'VideoPage',
-  components: { Comment, VideoCard, VideoPlayer, UserAvatarCard },
+  components: { Comment, VideoCard, VideoPlayer, UserAvatarCard, PermissionDeniedCard },
   data() {
     return {
       video: null,
@@ -226,11 +253,22 @@ export default {
       user: null,
       similarVideos: [],
       isCollected: false,
+      showAccessCodeDialog: false,
+      accessCodeForm: {
+        contentId: null,
+        contentType: 1002,
+        accessCode: null
+      },
       showErrorReportDialog: false,
       errorReportForm: {
         videoId: null,
         errorCode: null
       },
+      permissionDenied: false,
+      textObject: {
+        content: '视频',
+        route: '/video'
+      },
       showPlaylist: false,
       autoPlay: false
     }
@@ -243,22 +281,24 @@ export default {
   },
   created() {
     const videoId = this.$route.params.id
+    this.accessCodeForm.contentId = videoId
     this.getVideoInfo(videoId)
     this.getSimilarVideos(videoId)
   },
   methods: {
     // 获取视频的详细信息
     getVideoInfo(videoId) {
-      videoInfo(videoId).then(res => {
-        if (res.code === 0) {
-          this.videoProp = res.data
+      videoInfo(videoId).then(resp => {
+        if (resp.code === 0) {
+          // this.showAccessCodeDialog = true
+          this.videoProp = resp.data
 
-          this.video = res.data
-          document.title = res.data.title
-          this.userId = res.data.userId
-          getUserInfo(this.userId).then(res => {
-            if (res.code === 0) {
-              this.user = res.data
+          this.video = resp.data
+          document.title = resp.data.title
+          this.userId = resp.data.userId
+          getUserInfo(this.userId).then(resp => {
+            if (resp.code === 0) {
+              this.user = resp.data
             } else {
               this.$notify.error({
                 message: '用户数据获取失败',
@@ -267,13 +307,10 @@ export default {
               })
             }
           })
-        } else {
-          this.$notify.error({
-            message: '视频数据获取失败',
-            type: 'warning',
-            duration: 3000
-          })
+        } else if (resp.code === 2) {
           this.$router.push('/404')
+        } else {
+          this.permissionDenied = true
         }
       }).catch(error => {
         this.$notify.error({
@@ -285,9 +322,9 @@ export default {
     },
     // 获取和当前视频类似的其他视频
     getSimilarVideos(videoId) {
-      similarVideo(videoId).then(res => {
-        if (res.code === 0) {
-          this.similarVideos = res.data
+      similarVideo(videoId).then(resp => {
+        if (resp.code === 0) {
+          this.similarVideos = resp.data
         } else {
           this.$notify.error({
             message: '推荐视频数据获取失败',
@@ -313,8 +350,8 @@ export default {
       jsonData.contentType = 1002
       jsonData.contentId = videoId
       jsonData.collected = true
-      collectItem(jsonData).then(res => {
-        if (res.code !== 0) {
+      collectItem(jsonData).then(resp => {
+        if (resp.code !== 0) {
           this.$notify.success({
             title: '视频收藏失败',
             type: 'warning',
@@ -325,9 +362,9 @@ export default {
     },
     getDownloadUrl(videoId) {
       // let filename
-      downloadVideo(videoId).then(res => {
-        if (res.code === 0) {
-          const downloadUrl = res.data.url
+      downloadVideo(videoId).then(resp => {
+        if (resp.code === 0) {
+          const downloadUrl = resp.data.url
           window.open(downloadUrl, '_blank')
           /* fetch(downloadUrl.url, {
             headers: {
@@ -335,17 +372,17 @@ export default {
             },
             method: 'GET',
             credentials: 'include'
-          }).then(res => {
+          }).then(resp => {
             /!*
             遍历 formdata
-            for (const key of res.headers.keys()) {
-              console.log(key + ' : ' + res.headers.get(key))
+            for (const key of resp.headers.keys()) {
+              console.log(key + ' : ' + resp.headers.get(key))
             }*!/
-            const header = res.headers.get('Content-Disposition')
+            const header = resp.headers.get('Content-Disposition')
             const parts = header.split(';')
             const encodeFilename = parts[1].split('=')[1]
             filename = decodeURI(encodeFilename)
-            return res.blob()
+            return resp.blob()
           }).then(data => {
             const blobUrl = window.URL.createObjectURL(data)
             const a = document.createElement('a')
@@ -363,7 +400,7 @@ export default {
         } else {
           this.$notify({
             title: '提示',
-            message: res.msg,
+            message: resp.msg,
             type: 'warning',
             duration: 3000
           })
@@ -378,9 +415,9 @@ export default {
       })
     },
     cacheBiliVideo(bvId) {
-      cacheBiliVideo(bvId).then(res => {
-        if (res.code === 0) {
-          const resData = res.data
+      cacheBiliVideo(bvId).then(resp => {
+        if (resp.code === 0) {
+          const resData = resp.data
           this.$notify({
             title: '提示',
             message: resData.msg,
@@ -390,14 +427,34 @@ export default {
         }
       })
     },
+    submitAccessCodeWrapper() {
+      submitAccessCode(this.accessCodeForm).then(resp => {
+        if (resp.code === 0) {
+          this.video = resp.data
+        } else {
+          this.$notify({
+            message: resp.msg,
+            type: 'warning',
+            duration: 3000
+          })
+        }
+      }).catch(error => {
+        this.$notify({
+          title: '提示',
+          message: error.message,
+          type: 'warning',
+          duration: 3000
+        })
+      })
+    },
     displayErrorReportDialog() {
       this.errorReportForm.videoId = this.video.videoId
       this.showErrorReportDialog = true
     },
     submitErrorReport() {
       this.showErrorReportDialog = false
-      videoErrorReport(this.errorReportForm).then(res => {
-        if (res.code === 0) {
+      videoErrorReport(this.errorReportForm).then(resp => {
+        if (resp.code === 0) {
           this.$notify({
             title: '提示',
             message: '视频错误已提交',