Ver Fonte

fix: abnormal display of programs and schedules

Casper Dai há 3 anos atrás
pai
commit
bd1913bc67

+ 1 - 4
src/components/Schedule/ScheduleSwiper/index.vue

@@ -234,10 +234,7 @@ export default {
       })
     },
     onView ({ id }) {
-      window.open(this.$router.resolve({
-        name: 'program',
-        params: { id }
-      }).href, '_blank')
+      this.$viewProgram(id)
     },
     onDel (event, index) {
       this.events.splice(index, 1)

+ 20 - 1
src/components/Schedule/index.vue

@@ -1,4 +1,5 @@
 <script>
+import { mapGetters } from 'vuex'
 import { getSchedule } from '@/api/calendar'
 import ScheduleCalendar from './ScheduleCalendar'
 import ScheduleSwiper from './ScheduleSwiper'
@@ -12,7 +13,11 @@ export default {
   props: {
     schedule: {
       type: String,
-      default: null
+      required: true
+    },
+    editable: {
+      type: [Boolean, String],
+      default: false
     }
   },
   data () {
@@ -20,6 +25,9 @@ export default {
       options: null
     }
   },
+  computed: {
+    ...mapGetters(['tenant', 'userId'])
+  },
   watch: {
     schedule: {
       handler () {
@@ -72,9 +80,20 @@ export default {
     }
 
     const { detail } = this.options
+
+    if (detail.tenant !== this.tenant) {
+      return h('el-result', {
+        props: {
+          icon: 'warning',
+          subTitle: '无权限'
+        }
+      })
+    }
+
     return h([null, 'ScheduleSwiper', 'ScheduleCalendar'][detail.type - 1], {
       props: {
         detail,
+        editable: this.editable && detail.createBy === this.userId,
         ...this.$attrs
       },
       on: this.$listeners

+ 1 - 4
src/components/Schedule/mixins/event.js

@@ -62,10 +62,7 @@ export default {
             this.$refs.scheduleDialog.show(event.target.id)
             break
           default:
-            window.open(this.$router.resolve({
-              name: 'program',
-              params: { id: event.target.id }
-            }).href, '_blank')
+            this.$viewProgram(event.target.id)
             break
         }
       }

+ 4 - 2
src/components/Schedule/mixins/schedule.js

@@ -2,7 +2,6 @@ import {
   saveScheduleEvents,
   submitSchedule
 } from '@/api/calendar'
-import { State } from '@/constant'
 
 export default {
   props: {
@@ -13,6 +12,10 @@ export default {
     hideHeader: {
       type: [Boolean, String],
       default: false
+    },
+    editable: {
+      type: [Boolean, String],
+      default: false
     }
   },
   data () {
@@ -36,7 +39,6 @@ export default {
     }
   },
   created () {
-    this.editable = this.detail.status === State.READY
     this.scheduleOptions = {
       ...this.detail,
       events: this.transformEvents(this.detail.events)

+ 1 - 4
src/components/dialog/EventTargetDialog/index.vue

@@ -74,10 +74,7 @@ export default {
     onView ({ id }) {
       switch (this.$refs.tableDialog.getTable().getCondition().type) {
         case EventTarget.PROGRAM:
-          window.open(this.$router.resolve({
-            name: 'program',
-            params: { id }
-          }).href, '_blank')
+          this.$viewProgram(id)
           break
         case EventTarget.RECUR:
           this.$refs.scheduleDialog.show(id)

+ 28 - 0
src/global-api.js

@@ -0,0 +1,28 @@
+import {
+  showLoading,
+  closeLoading
+} from './utils/pop'
+
+export function injectGlobalApi (Vue, store) {
+  Vue.config.productionTip = false
+  Vue.config.errorHandler = err => {
+    closeLoading()
+    throw err
+  }
+
+  Vue.prototype.__STAGING__ = __STAGING__
+  Vue.prototype.__PLACEHOLDER__ = __PLACEHOLDER__
+
+  Vue.prototype.roleSet = store.getters.roles
+  Vue.prototype.accessSet = store.getters.accesses
+
+  Vue.prototype.$showLoading = showLoading
+  Vue.prototype.$closeLoading = closeLoading
+
+  Vue.prototype.$viewProgram = function (id, type = 'view') {
+    window.open(this.$router.resolve({
+      name: 'program',
+      params: { type, id }
+    }).href, '_blank')
+  }
+}

+ 2 - 17
src/main.js

@@ -14,10 +14,7 @@ import './icons'
 import './components'
 import './permission'
 
-import {
-  showLoading,
-  closeLoading
-} from './utils/pop'
+import { injectGlobalApi } from './global-api'
 
 const initOptions = {
   url: process.env.VUE_APP_KEYCLOAK_OPTIONS_URL,
@@ -58,17 +55,6 @@ async function startApp () {
 
   Vue.use(Element)
   Vue.prototype.$keycloak = keycloak
-  Vue.prototype.$showLoading = showLoading
-  Vue.prototype.$closeLoading = closeLoading
-
-  Vue.prototype.__STAGING__ = __STAGING__
-  Vue.prototype.__PLACEHOLDER__ = __PLACEHOLDER__
-
-  Vue.config.productionTip = false
-  Vue.config.errorHandler = err => {
-    closeLoading()
-    throw err
-  }
 
   await store.dispatch('user/login', keycloak)
   store.dispatch('permission/generateRoutes', {
@@ -77,8 +63,7 @@ async function startApp () {
   })
   router.addRoutes(store.getters.permissionRoutes)
 
-  Vue.prototype.roleSet = store.getters.roles
-  Vue.prototype.accessSet = store.getters.accesses
+  injectGlobalApi(Vue, store, router)
 
   new Vue({
     router,

+ 1 - 1
src/router/index.js

@@ -318,7 +318,7 @@ export const asyncRoutes = [
   {
     hidden: true,
     name: 'program',
-    path: '/cm/program/:id',
+    path: '/cm/program/:type/:id',
     component: () => import('@/views/bigscreen/ast/index'),
     props: true
   },

+ 2 - 4
src/views/bigscreen/Program.vue

@@ -59,10 +59,8 @@ export default {
   },
   methods: {
     onClick () {
-      window.open(this.$router.resolve({
-        name: 'program',
-        params: { id: this.program.id }
-      }).href, '_blank')
+      const { id, status } = this.program
+      this.$viewProgram(id, status !== State.SUBMITTED && status !== State.RESOLVED ? 'design' : 'view')
     },
     onEdit () {
       const name = this.name

+ 1 - 4
src/views/bigscreen/ProgramDesigner.vue

@@ -180,10 +180,7 @@ export default {
         this.active = `${State.READY}`
         this.$refs.table.resetCondition({ status: State.READY, name: this.program.name })
         setTimeout(() => {
-          window.open(this.$router.resolve({
-            name: 'program',
-            params: { id }
-          }).href, '_blank')
+          this.$viewProgram(id)
         }, 500)
       })
     },

+ 15 - 3
src/views/bigscreen/ast/index.vue

@@ -1,6 +1,7 @@
 <script>
 import '@/scss/iconfont/iconfont.css'
 
+import { mapGetters } from 'vuex'
 import { getProgram } from '@/api/program'
 import {
   State,
@@ -19,6 +20,10 @@ export default {
     next(false)
   },
   props: {
+    type: {
+      type: String,
+      default: 'view'
+    },
     id: {
       type: String,
       default: null
@@ -32,6 +37,9 @@ export default {
       activeComponent: null
     }
   },
+  computed: {
+    ...mapGetters(['tenant', 'userId'])
+  },
   watch: {
     id: {
       handler () {
@@ -47,16 +55,20 @@ export default {
       getProgram(this.id, { custom: true }).then(
         ({ data }) => {
           try {
-            const { id, status, name, resolutionRatio, itemJsonStr } = data
+            const { tenant, createBy, id, status, name, resolutionRatio, itemJsonStr } = data
+            if (tenant !== this.tenant) {
+              this.showMessage('warning', '无权限')
+              return
+            }
             const [width, height] = resolutionRatio.split('x')
             if (!width || !height) {
               this.showMessage('error', '布局分辨率异常,请联系管理员')
               return
             }
 
-            if (status === State.SUBMITTED || status === State.RESOLVED) {
+            if (this.type !== 'design' || status === State.SUBMITTED || status === State.RESOLVED) {
               this.activeComponent = 'Viewer'
-            } else if (this.accessSet.has(Access.MANAGE_CALENDAR)) {
+            } else if (this.accessSet.has(Access.MANAGE_CALENDAR) && createBy === this.userId) {
               this.activeComponent = 'Designer'
             } else {
               this.showMessage('warning', '暂无编辑权限,请联系管理员')

+ 1 - 4
src/views/device/timeline/index.vue

@@ -473,10 +473,7 @@ export default {
       if (this.programProxy) {
         switch (this.programProxy.event.target.type) {
           case EventTarget.PROGRAM:
-            window.open(this.$router.resolve({
-              name: 'program',
-              params: { id: this.programProxy.event.target.id }
-            }).href, '_blank')
+            this.$viewProgram(this.programProxy.event.target.id)
             break
           case EventTarget.RECUR:
             this.$refs.scheduleDialog.show(this.programProxy.event.target.id)

+ 1 - 4
src/views/review/components/ReviewProgram.vue

@@ -43,10 +43,7 @@ export default {
       return program
     },
     onView ({ id }) {
-      window.open(this.$router.resolve({
-        name: 'program',
-        params: { id }
-      }).href, '_blank')
+      this.$viewProgram(id)
     }
   }
 }

+ 1 - 4
src/views/review/components/ReviewPublish.vue

@@ -119,10 +119,7 @@ export default {
       this.$refs.scheduleDialog.show(id)
     },
     viewProgram (id) {
-      window.open(this.$router.resolve({
-        name: 'program',
-        params: { id }
-      }).href, '_blank')
+      this.$viewProgram(id)
     }
   }
 }

+ 1 - 4
src/views/schedule/deploy/index.vue

@@ -254,10 +254,7 @@ export default {
       this.eventOptions.schedule = { id, name }
     },
     onViewProgram () {
-      window.open(this.$router.resolve({
-        name: 'program',
-        params: { id: this.programId }
-      }).href, '_blank')
+      this.$viewProgram(this.programId)
     },
     getPublishTarget () {
       if (this.eventOptions.type === PublishType.CALENDAR) {

+ 1 - 0
src/views/schedule/designer/index.vue

@@ -8,6 +8,7 @@
     <schedule
       class="l-flex__auto"
       :schedule="scheduleId"
+      editable
       @submit="onSubmit"
     />
   </wrapper>

+ 1 - 4
src/views/schedule/history/index.vue

@@ -115,10 +115,7 @@ export default {
       this.$refs.scheduleDialog.show(id)
     },
     viewProgram (id) {
-      window.open(this.$router.resolve({
-        name: 'program',
-        params: { id }
-      }).href, '_blank')
+      this.$viewProgram(id)
     }
   }
 }