TopologicalDynamicCommands.js 4.05 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import DeleteTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/DeleteTopologicalDialog.vue'
import ImportTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/ImportTopologicalDialog.vue'
import EnableTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/EnableTopologicalDialog.vue'
import DisableTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/DisableTopologicalDialog.vue'


Vue.component('DeleteTopologicalDialog', DeleteTopologicalDialog)
Vue.component('ImportTopologicalDialog', ImportTopologicalDialog)
Vue.component('EnableTopologicalDialog', EnableTopologicalDialog)
Vue.component('DisableTopologicalDialog', DisableTopologicalDialog)

let CommandTypes = {
  UPLOAD_TOPOLOGICAL__CMD: {
    type: 'UploadTopological',
    executeComponent: 'ImportTopologicalDialog',
    registerComponent: ImportTopologicalDialog // 对应的对话框组件
  },
  DElETE_TOPOLOGICAL__CMD: {
    type: 'DeleteToplological',
    executeComponent: 'DeleteTopologicalDialog',
    registerComponent: DeleteTopologicalDialog // 对应的对话框组件
  },
  ENABLE_TOPOLOGICAL__CMD: {
    type: 'EnableToplological',
    executeComponent: 'EnableTopologicalDialog',
    registerComponent: EnableTopologicalDialog // 对应的对话框组件
  },
  DISABLE_TOPOLOGICAL__CMD: {
    type: 'DisableToplological',
    executeComponent: 'DisableTopologicalDialog',
    registerComponent: DisableTopologicalDialog // 对应的对话框组件
  },
}

class TopologicalDynamicCommands {
  static uploadTopologicalCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPLOAD_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: null,
      executeComponent: CommandTypes.UPLOAD_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }

  static deleteTopologicalCommand (topoKeyList, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DElETE_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: topoKeyList,
      executeComponent: CommandTypes.DElETE_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }

  static enableTopologicalCommand (enableString, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.ENABLE_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: enableString,
      executeComponent: CommandTypes.ENABLE_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }

  static disableTopologicalCommand (disableString, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DISABLE_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: disableString,
      executeComponent: CommandTypes.DISABLE_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }
}

TopologicalDynamicCommands.CommandTypes = CommandTypes;

export default TopologicalDynamicCommands