Blame view

src/components/menu/menu-item.vue 2.95 KB
8778b343   梁灏   init Menu components
1
  <template>
2a7765f9   梁灏   update Menu
2
3
4
5
6
7
8
9
10
      <a
          v-if="to"
          :href="linkUrl"
          :target="target"
          :class="classes"
          @click.exact="handleClickItem($event, false)"
          @click.ctrl="handleClickItem($event, true)"
          @click.meta="handleClickItem($event, true)"
          :style="itemStyle"><slot></slot></a>
7d0b7384   梁灏   fixed #3484
11
      <li v-else :class="classes" @click.stop="handleClickItem" :style="itemStyle"><slot></slot></li>
8778b343   梁灏   init Menu components
12
13
  </template>
  <script>
fd1582c5   梁灏   support Menu & La...
14
      import Emitter from '../../mixins/emitter';
9932b935   梁灏   update
15
      import { findComponentUpward } from '../../utils/assist';
acba45fe   zhigang.li   move computed val...
16
      import mixin from './mixin';
7d0b7384   梁灏   fixed #3484
17
      import mixinsLink from '../../mixins/link';
e05d7289   梁灏   update Menu
18
  
8cb84923   梁灏   update
19
20
      const prefixCls = 'ivu-menu';
  
8778b343   梁灏   init Menu components
21
      export default {
e05d7289   梁灏   update Menu
22
          name: 'MenuItem',
7d0b7384   梁灏   fixed #3484
23
          mixins: [ Emitter, mixin, mixinsLink ],
e05d7289   梁灏   update Menu
24
          props: {
fd1582c5   梁灏   support Menu & La...
25
              name: {
e05d7289   梁灏   update Menu
26
27
28
29
30
31
                  type: [String, Number],
                  required: true
              },
              disabled: {
                  type: Boolean,
                  default: false
7d0b7384   梁灏   fixed #3484
32
              },
e05d7289   梁灏   update Menu
33
          },
8778b343   梁灏   init Menu components
34
          data () {
e05d7289   梁灏   update Menu
35
36
              return {
                  active: false
b0893113   jingsam   :art: add eslint
37
              };
e05d7289   梁灏   update Menu
38
39
40
41
42
43
44
45
46
47
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}-item`,
                      {
                          [`${prefixCls}-item-active`]: this.active,
                          [`${prefixCls}-item-selected`]: this.active,
                          [`${prefixCls}-item-disabled`]: this.disabled
                      }
b0893113   jingsam   :art: add eslint
48
                  ];
4bce7645   zhigang.li   make menu support...
49
              },
4bce7645   zhigang.li   make menu support...
50
              itemStyle () {
b2d676bd   zhigang.li   fixed the bug abo...
51
                  return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
4bce7645   zhigang.li   make menu support...
52
53
                      paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
                  } : {};
e05d7289   梁灏   update Menu
54
              }
8778b343   梁灏   init Menu components
55
          },
e05d7289   梁灏   update Menu
56
          methods: {
2a7765f9   梁灏   update Menu
57
              handleClickItem (event, new_window = false) {
0acdae19   梁灏   update Menu
58
                  if (this.disabled) return;
fd1582c5   梁灏   support Menu & La...
59
  
164f7bcb   梁灏   update Menu
60
                  if (new_window || this.target === '_blank') {
2a7765f9   梁灏   update Menu
61
62
                      // 如果是 new_window,直接新开窗口就行,无需发送状态
                      this.handleCheckClick(event, new_window);
164f7bcb   梁灏   update Menu
63
64
                      let parentMenu = findComponentUpward(this, 'Menu');
                      if (parentMenu) parentMenu.handleEmitSelectEvent(this.name);
fd1582c5   梁灏   support Menu & La...
65
                  } else {
2a7765f9   梁灏   update Menu
66
                      let parent = findComponentUpward(this, 'Submenu');
7d0b7384   梁灏   fixed #3484
67
  
2a7765f9   梁灏   update Menu
68
69
70
71
72
73
74
75
                      if (parent) {
                          this.dispatch('Submenu', 'on-menu-item-select', this.name);
                      } else {
                          this.dispatch('Menu', 'on-menu-item-select', this.name);
                      }
  
                      this.handleCheckClick(event, new_window);
                  }
e05d7289   梁灏   update Menu
76
              }
fd1582c5   梁灏   support Menu & La...
77
78
79
80
81
          },
          mounted () {
              this.$on('on-update-active-name', (name) => {
                  if (this.name === name) {
                      this.active = true;
4bce7645   zhigang.li   make menu support...
82
                      this.dispatch('Submenu', 'on-update-active-name', name);
fd1582c5   梁灏   support Menu & La...
83
84
85
86
                  } else {
                      this.active = false;
                  }
              });
e05d7289   梁灏   update Menu
87
          }
b0893113   jingsam   :art: add eslint
88
89
      };
  </script>