cuilei
23 小时以前 b6b2c379bd92f076acd16801b1442604ea21fc5d
src/views/dnc/base/modules/ProductStructure/ProductStructureTreeContextMenu.vue
@@ -1,24 +1,12 @@
<template>
  <a-dropdown :trigger="['contextmenu']">
    <span v-if="treeParams.label.indexOf(treeParams.searchValue) > -1">{{
        treeParams.label.substr(0, treeParams.label.indexOf(treeParams.searchValue))
      }}<span
        class="replaceSearch">{{
          treeParams.searchValue
        }}</span>{{
        treeParams.label.substr(treeParams.label.indexOf(treeParams.searchValue) + treeParams.searchValue.length)
      }}</span>
    <span v-else>{{ treeParams.label }}</span>
    <template #overlay>
      <a-menu @click="({ key: menuKey }) => onContextMenuClick(treeParams.treeKey, menuKey)"
              @contextmenu="event=>event.preventDefault()">
        <a-menu-item v-for="item in defaultContextMenuList[getCurrentMenuLevel]" :key="item.code" v-has="item.code">
          <a-icon :type="item.icon"/>
          {{ item.label }}
  <a-menu :style="menuStyle" @click="menuItemClick" v-if="menuVisible" mode="vertical" @contextmenu="menuContextMenu">
    <template v-for="menuItem in defaultContextMenuList[getCurrentMenuLevel]">
      <a-menu-item :key="menuItem.code" v-has="menuItem.code">
        <a-icon :type="menuItem.icon"/>
        {{ menuItem.label }}
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
  </a-menu>
</template>
<script>
@@ -32,6 +20,15 @@
  },
  data() {
    return {
        menuVisible: false,
        menuStyle: {
          position: 'fixed',
          top: 0,
          left: 0,
          border: '1px solid #eee',
          boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
          zIndex: 999
        },
      defaultContextMenuList: {
        //产品
        product: [
@@ -95,7 +92,8 @@
          { label: '导入其他文档', code: 'process_other_import', icon: 'import', isCommonMethod: true },
          { label: '检索电子样板', code: 'process_search', icon: 'search', isCommonMethod: true },
          { label: '检索NC文件', code: 'process_search_nc', icon: 'search', isCommonMethod: true },
          { label: '权限配置', code: 'public_assign_permission', icon: 'idcard', isCommonMethod: true }
            { label: '权限配置', code: 'public_assign_permission', icon: 'idcard', isCommonMethod: true },
            { label: '发送nc程序至三维工艺', code: 'process_send_nc_to_plm', icon: 'import', isCommonMethod: true }
        ],
        //工步
        processStep: [
@@ -108,7 +106,8 @@
          { label: '导入其他文档', code: 'processStep_other_import', icon: 'import', isCommonMethod: true },
          { label: '检索电子样板', code: 'processStep_search', icon: 'search', isCommonMethod: true },
          { label: '检索NC文件', code: 'processStep_search_nc', icon: 'search', isCommonMethod: true },
          { label: '权限配置', code: 'public_assign_permission', icon: 'idcard', isCommonMethod: true }
            { label: '权限配置', code: 'public_assign_permission', icon: 'idcard', isCommonMethod: true },
            { label: '发送nc程序至三维工艺', code: 'processStep_send_nc_to_plm', icon: 'import', isCommonMethod: true }
        ]
      }
    }
@@ -129,30 +128,14 @@
        case 6:
          return 'processStep'
      }
    },
    // getCurrentDocClassCode() {
    //   switch (+this.treeParams.type) {
    //     case 1:
    //       return 'OTHER'
    //     case 2:
    //       return 'OTHER'
    //     case 3:
    //       return 'OTHER'
    //     case 4:
    //       return 'OTHER'
    //     case 5:
    //       return 'NC'
    //     case 6:
    //       return 'NC'
    //   }
    // }
      }
  },
  methods: {
    onContextMenuClick(treeKey, menuKey) {
      menuItemClick({ key }) {
        const menuKey = key
      const level = this.getCurrentMenuLevel
      console.log('level---------------------', level)
      const treeNodeInfo = Object.assign({}, this.treeParams)
      console.log('treeNodeInfo******************', treeNodeInfo)
        const treeNodeInfo = Object.assign({ treeKey: this.treeParams.key }, this.treeParams)
        console.log('treeNodeInfo', treeNodeInfo)
      const menuKeyArray = menuKey.split('_')
      const isCommonMethod = this.defaultContextMenuList[level].find(item => item.code === menuKey).isCommonMethod
      // product_add => handleAdd 触发对应组件事件
@@ -163,19 +146,26 @@
      } else {
        methodName = 'handle' + menuKeyArray.map(item => item[0].toUpperCase() + item.slice(1)).join('')
      }
      console.log('methodName', methodName)
      const modalTitle = this.defaultContextMenuList[level].find(item => item.code === menuKey).label
      this.$bus.$emit('treeMenuItemMethodTrigger', { methodName, modalTitle, treeNodeInfo })
      },
      /**
       * 避免单次重复右键后关闭菜单或打开window菜单
       * @param event 事件对象
       */
      menuContextMenu(event) {
        event.preventDefault()
        event.stopPropagation()
    }
  }
}
</script>
<style scoped>
.replaceSearch {
  color: #40a9ff;
  font-weight: bold;
  background-color: rgb(204, 204, 204);
  /deep/ .ant-menu-item {
    height: 32px;
    line-height: 32px;
}
</style>