Explorar o código

feat: automatically remove rejected data

Casper Dai %!s(int64=3) %!d(string=hai) anos
pai
achega
cba67e9f8a

+ 3 - 4
src/api/asset.js

@@ -105,11 +105,10 @@ export function resolveAsset ({ keyName, originalName }) {
   }, originalName)
 }
 
-export function rejectAsset ({ keyName, originalName }, reason) {
+export function rejectAsset ({ keyName, originalName }, remark) {
   return reject({
     url: '/minio-data/reject',
-    method: 'GET',
-    params: { keyName },
-    data: { reason }
+    method: 'POST',
+    data: { keyName, remark }
   }, originalName)
 }

+ 55 - 2
src/components/Schedule/index.vue

@@ -46,14 +46,67 @@ export default {
       this.options = options
       getSchedule(this.schedule).then(
         schedule => {
-          options.detail = schedule
+          if (schedule) {
+            const { rejectIds } = schedule
+            if (this.editable && rejectIds?.length) {
+              this.ask(schedule, options)
+            } else {
+              options.detail = schedule
+              options.loading = false
+            }
+          } else {
+            options.loading = false
+          }
         },
         () => {
           options.error = true
+          options.loading = false
+        }
+      )
+    },
+    ask (schedule, options) {
+      this.$confirm(
+        '节目若已完成修改可选择保留',
+        '存在被驳回的节目',
+        {
+          type: 'info',
+          showClose: false,
+          confirmButtonText: '保留',
+          cancelButtonText: '移除',
+          closeOnClickModal: false,
+          closeOnPressEscape: false
         }
-      ).finally(() => {
+      ).catch(action => {
+        if (action === 'cancel') {
+          const { type } = schedule
+          ;[val => val, this.removeRejectedFromSwiper, this.removeRejectedFromCalendar][type - 1](schedule)
+        }
+      }).finally(() => {
+        options.detail = schedule
         options.loading = false
       })
+    },
+    removeRejectedFromCalendar (schedule) {
+      const { events, rejectIds } = schedule
+      let length = events.length
+      for (let i = 0; i < length; i++) {
+        if (rejectIds.includes(events[i].target.id)) {
+          events.splice(i, 1)
+          i -= 1
+          length -= 1
+        }
+      }
+    },
+    removeRejectedFromSwiper (schedule) {
+      const { events, rejectIds } = schedule
+      let length = events.length
+      for (let i = 0; i < length; i++) {
+        if (rejectIds.includes(events[i].programId)) {
+          events.splice(i, 1)
+          i -= 1
+          length -= 1
+        }
+      }
     }
   },
   render (h) {

+ 23 - 0
src/views/bigscreen/ast/core/utils.js

@@ -299,3 +299,26 @@ export function switchToNext (toggleType, arr, curr) {
 
   return index
 }
+
+export function removeRejectedAssets (nodeJson, rejectIds) {
+  removeAssets(nodeJson.bgm, rejectIds)
+  removeAssets(nodeJson.backgroundImage, rejectIds)
+  nodeJson.widgets?.forEach(({ sources }) => {
+    removeAssets(sources, rejectIds)
+  })
+}
+
+function removeAssets (arr, rejectIds) {
+  if (!arr) {
+    return
+  }
+  let length = arr.length
+  for (let i = 0; i < length; i++) {
+    const keyName = arr[i].keyName
+    if (keyName && rejectIds.includes(keyName)) {
+      arr.splice(i, 1)
+      i -= 1
+      length -= 1
+    }
+  }
+}

+ 18 - 13
src/views/bigscreen/ast/index.vue

@@ -2,14 +2,13 @@
 import { mapGetters } from 'vuex'
 import { getProgram } from '@/api/program'
 import { Access } from '@/constant'
+import { removeRejectedAssets } from './core/utils'
 import Designer from './Designer'
-import Viewer from './Viewer'
 
 export default {
   name: 'ProgramAst',
   components: {
-    Designer,
-    Viewer
+    Designer
   },
   beforeRouteLeave (to, from, next) {
     next(false)
@@ -17,15 +16,14 @@ export default {
   props: {
     id: {
       type: String,
-      default: null
+      required: true
     }
   },
   data () {
     return {
       loading: true,
       error: null,
-      program: null,
-      activeComponent: null
+      program: null
     }
   },
   computed: {
@@ -46,16 +44,14 @@ export default {
       getProgram(this.id, { custom: true }).then(
         ({ data }) => {
           try {
-            const { tenant, createBy, id, status, name, resolutionRatio, itemJsonStr } = data
+            const { tenant, createBy, id, status, name, resolutionRatio, itemJsonStr, rejectIds } = data
             if (!this.isSuperAdmin && tenant !== this.tenant) {
               this.showMessage('warning', '无权限')
               return
             }
 
-            if (this.accessSet.has(Access.MANAGE_CALENDAR) && (this.isSuperAdmin || createBy === this.userId)) {
-              this.activeComponent = 'Designer'
-            } else {
-              this.showMessage('warning', '暂无编辑权限,请联系管理员')
+            if (!(this.accessSet.has(Access.MANAGE_CALENDAR) && (this.isSuperAdmin || createBy === this.userId))) {
+              this.showMessage('warning', '无编辑权限,请联系管理员')
               return
             }
 
@@ -65,12 +61,21 @@ export default {
               return
             }
 
+            const widget = JSON.parse(itemJsonStr)
+            if (widget && rejectIds?.length) {
+              removeRejectedAssets(widget, rejectIds)
+              this.$message({
+                type: 'info',
+                message: '被驳回的媒资已移除'
+              })
+            }
+
             this.program = {
               id, status, name, resolutionRatio,
               detail: {
                 width: Number(width),
                 height: Number(height),
-                ...JSON.parse(itemJsonStr)
+                ...widget
               }
             }
           } catch (e) {
@@ -125,7 +130,7 @@ export default {
       ])
     }
 
-    return h(this.activeComponent, {
+    return h('Designer', {
       props: {
         program: this.program
       }