lyh
8 小时以前 b6247699693bdc200539f20851b3d2105fe8b674
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<template>
    <el-row>
      <div id="comMenu" style="height: 100%">
        <!--工序-->
        <ul id="processContextMenu" class="contextMenu" v-show="processMenuVisible">
          <li v-if="contextMenuList.process_add.show"  class="menu_item" @click="showProcessAddDialog"><i class="el-icon-plus"></i> 创建工序</li>
          <li v-if="contextMenuList.process_edit.show" @click="showProcessEditDialog"><i class="el-icon-edit"></i> 编辑工序信息</li>
          <li v-if="contextMenuList.process_delete.show" @click="processDelete"><i class="el-icon-delete"></i> 删除</li>
          <li v-if="contextMenuList.process_import.show"  class="menu_item" @click="showUploadDialog"><i class="el-icon-upload2"></i> 导入NC程序</li>
          <!--<li v-if="contextMenuList.process_export.show"  class="menu_item" @click=""><i class="el-icon-download"></i> 导出NC程序</li>-->
        </ul>
        <!--工序空白区-->
        <!--<ul id="processBContextMenu" class="contextMenu" v-show="processBMenuVisible">
          <li v-if="contextMenuList.process_add.show"  class="menu_item" @click=""><i class="el-icon-plus"></i> 创建工序</li>
          <li v-if="contextMenuList.process_import.show"  class="menu_item" @click=""><i class="el-icon-upload2"></i> 导入NC程序</li>
          <li v-if="contextMenuList.process_export.show"  class="menu_item" @click=""><i class="el-icon-download"></i> 导出NC程序</li>
        </ul>-->
      </div>
    </el-row>
</template>
 
<script>
  import * as SystemApi from '../../../base/api/system'
    export default {
        name: "processContextMenu",
      data(){
        return{
          processMenuVisible:false,
          treeContextNode:[],
          contextMenuList: {},
          defaultContextMenuList: {
            process_add : {show:false, code : 'process_add'},//工序-添加工序
            process_edit : {show:false, code : 'process_edit'},//编辑工序信息
            process_delete : {show:false, code : 'process_delete'},//删除
            process_export : {show:false, code : 'process_export'},//工序-导出NC程序
            process_import : {show:false, code : 'process_import'},//工序-导入NC程序
          }
        }
      },
      methods:{
        //新增工序
        showProcessAddDialog(){
          this.$emit('showProcessAddDialog');
        },
        //编辑工序信息
        showProcessEditDialog(){
          this.$emit('showProcessEditDialog');
        },
        showUploadDialog(){
          this.$emit('showUploadDialog');
        },
        processDelete(){
          this.$emit('processDelete');
        },
        processRightClick(row, column, event,params){
          this.contextMenuList = JSON.parse(JSON.stringify(this.defaultContextMenuList));
          SystemApi.button_list(params).then((res) =>{
            let flag = false;
            if (res.success && res.list && res.list.length>0) {
              res.list.forEach((v,k) =>{
                if(this.contextMenuList[v] && this.contextMenuList[v].code == v) {
                  this.contextMenuList[v].show = true;
                  flag = true;
                }
              });
              this.closeMenu();
              // 阻止右键默认行为
              // event.preventDefault();
              if(event.preventDefault){
                event.preventDefault();
              }
              if (flag) {
                this.processMenuVisible = true;
              }
              let menu = document.querySelector('#processContextMenu');
              document.addEventListener('click', this.foo);// 给整个document添加监听鼠标事件,点击任何位置执行foo方法
              menu.style.display = "block";
              this.$nextTick(function () {
                let w =document.body.offsetWidth;
                let w1 =  document.getElementById('treeDiv').offsetWidth;
                if (event.clientX - 105 > w ) {
                  menu.style.left = event.clientX - w1-105 + 'px';
                }else {
                  menu.style.left = event.clientX - w1 + 'px';
                }
                menu.style.top = event.clientY -125 + 'px';
                //this.secondMenu();
              })
            }else if(res.success){
              this.$message.error('没有权限');
            }else {
              this.$message.error('校验错误');
            }
          });
        },
        /*blankRightClick(event,params){
          this.contextMenuList = JSON.parse(JSON.stringify(this.defaultContextMenuList));
          SystemApi.button_list(params).then((res) =>{
            if (res.success) {
              res.list.forEach((v,k) =>{
                if(this.contextMenuList[v].code == v) {
                  this.contextMenuList[v].show = true;
                }
              });
              this.closeMenu();
              //this.proBMenuVisible = true; // 显示产品模态窗口,跳出自定义菜单栏
              let menu = document.querySelector('#processBContextMenu');
              document.addEventListener('click', this.foo);// 给整个document添加监听鼠标事件,点击任何位置执行foo方法
              menu.style.display = "block";
              this.$nextTick(function () {
                let w =document.body.offsetWidth;
                if (event.clientX - 105 > w ) {
                  menu.style.left = event.clientX - 375 + 'px';
                }else {
                  menu.style.left = event.clientX - 240 + 'px';
                }
                menu.style.top = event.clientY -135 + 'px';
                //this.secondMenu();
              })
            }else if(res.message){
              this.$message.error(res.message);
            }
          });
 
        },*/
        foo() { // 取消鼠标监听事件 菜单栏
          this.processMenuVisible = false; // 先把模态框关死,目的是 第二次或者第n次右键鼠标的时候 它默认的是true
          document.removeEventListener('click', this.foo) // 要及时关掉监听,不关掉的是一个坑,不信你试试,虽然前台显示的时候没有啥毛病,加一个alert你就知道了
        },
        closeMenu(){
          this.processMenuVisible = false; // 先把模态框关死,目的是 第二次或者第n次右键鼠标的时候 它默认的是true
        },
        getContextMenuList(params){
 
        }
      },
      //初始化  模板渲染前调用
      created(){
        //this.contextMenuList = this.defaultContextMenuList;
        this.contextMenuList = JSON.parse(JSON.stringify(this.defaultContextMenuList));
      },
      //监听
      watch: {
        //右键菜单
        processMenuVisible(value) {
          if (value) {
            document.body.addEventListener('click', this.closeMenu)
          } else {
            document.body.removeEventListener('click', this.closeMenu)
          }
        },
        processBMenuVisible(value) {
          if (value) {
            document.body.addEventListener('click', this.closeMenu)
          } else {
            document.body.removeEventListener('click', this.closeMenu)
          }
        },
      },
    }
</script>
 
<style scoped  lang="scss">
  .el-row{
    height: 100%;
  }
  #comMenu{
    height: 100%;
  }
  .contextMenu {
    margin: 0;
    background: #fff;
    width: 145px;
    z-index: 3000;
    position: absolute;
    list-style-type: none;
    padding: 5px 0;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 400;
    color: #333;
    box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);
  li {
    margin: 0;
    padding: 7px 16px;
    cursor: pointer;
    list-style-type:none;
    position: relative;
    font-size:15px
  }
  li:hover {
    background-color: #1790ff;
    color: white;
  }
  li ul {
    position: absolute;
    width: 100%;
    left: 146px;
    /* Set 1px less than menu width */
    top: -5px;
    display: none;
  }
  li:hover ul,
  li.over ul {
    display: block;
  }
  }
</style>