menu-item.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <el-submenu :index="index" v-if="hasChildren">
  3. <template slot="title">
  4. <i :class="iconCls" v-if="hasIcon"></i>
  5. <span slot="title">{{ title }}</span>
  6. </template>
  7. <naf-menu-item
  8. v-for="(item, idx) in children"
  9. :key="idx"
  10. :index="index + '-' + idx"
  11. :title="item.title"
  12. :children="item.children"
  13. :options="item.options"
  14. :prefix="prefix"
  15. >
  16. </naf-menu-item>
  17. </el-submenu>
  18. <el-menu-item :index="index" @click="menuClick" v-else
  19. ><i :class="iconCls"></i>
  20. <span slot="title" v-if="title.length < 10 && !hasTooltip">{{ title }}</span>
  21. <el-tooltip slot="title" v-else :content="hasTooltip ? options.tooltip : title" placement="top" effect="light">
  22. <span>{{ title.length > 9 ? title.substr(0, 9) + '...' : title }}</span>
  23. </el-tooltip>
  24. </el-menu-item>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'naf-menu-item',
  29. props: {
  30. title: String,
  31. index: String,
  32. options: Object,
  33. children: Array,
  34. prefix: { type: String, default: '' },
  35. },
  36. methods: {
  37. menuClick() {
  38. console.log('click menu item....');
  39. if (this.options.url) {
  40. window.open(this.options.url, this.options.target);
  41. } else if (this.options.path) {
  42. this.$router.push(`${this.prefix}${this.options.path}`);
  43. }
  44. },
  45. },
  46. computed: {
  47. hasChildren() {
  48. return this.children && this.children.length > 0;
  49. },
  50. hasIcon() {
  51. return this.options.icon && this.options.icon.length > 0;
  52. },
  53. hasTooltip() {
  54. return this.options.tooltip && this.options.tooltip.length > 0;
  55. },
  56. iconCls() {
  57. if (this.options.icon && !(this.options.icon.indexOf('el-') === 0)) {
  58. return `naf-icons naf-icon-${this.options.icon}`;
  59. }
  60. return this.options.icon;
  61. },
  62. },
  63. };
  64. </script>