index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div
  3. :ref="convHeaderRef"
  4. class="tui-conversation-header"
  5. >
  6. <ul
  7. v-if="menuList.length > 0"
  8. class="list"
  9. >
  10. <li
  11. v-for="(item, index) in menuList"
  12. :key="index"
  13. class="list-item"
  14. >
  15. <main
  16. class="tui-conversation-header-item"
  17. @click.stop="handleMenu(item)"
  18. >
  19. <Icon
  20. v-if="item.icon && !item.data.children"
  21. class="tui-conversation-header-item-icon"
  22. :file="item.icon"
  23. />
  24. <i
  25. v-else
  26. class="plus"
  27. />
  28. <h1 class="tui-conversation-header-item-title">
  29. {{ item.text }}
  30. </h1>
  31. </main>
  32. </li>
  33. </ul>
  34. <ul
  35. v-if="showChildren.length > 0"
  36. class="tui-conversation-header-children list"
  37. >
  38. <li
  39. v-for="(childrenItem, childrenIndex) in showChildren"
  40. :key="childrenIndex"
  41. class="list-item"
  42. >
  43. <main
  44. class="tui-conversation-header-item"
  45. @click="handleMenu(childrenItem)"
  46. >
  47. <Icon
  48. v-if="childrenItem.icon"
  49. class="tui-conversation-header-item-icon"
  50. :file="childrenItem.icon"
  51. />
  52. <h1 class="tui-conversation-header-item-title">
  53. {{ childrenItem.text }}
  54. </h1>
  55. </main>
  56. </li>
  57. </ul>
  58. </div>
  59. </template>
  60. <script lang="ts" setup>
  61. import { computed, ref, onMounted } from '../../../adapter-vue';
  62. import Icon from '../../common/Icon.vue';
  63. import Server, { IMenuItem } from './server';
  64. const showChildren = ref<Array<IMenuItem>>([]);
  65. const convHeaderRef = ref<HTMLElement | undefined>();
  66. const menuList = computed(() => {
  67. return Server.getInstance().getMenu();
  68. });
  69. onMounted(() => {
  70. showChildren.value = [];
  71. });
  72. const handleMenu = (item: IMenuItem) => {
  73. const { data: { children }, listener = { onClicked: () => {} } } = item;
  74. if (children) {
  75. showChildren.value = showChildren.value.length > 0 ? [] : children;
  76. } else {
  77. listener.onClicked(item);
  78. closeChildren();
  79. }
  80. };
  81. const closeChildren = () => {
  82. showChildren.value = [];
  83. };
  84. defineExpose({
  85. closeChildren,
  86. });
  87. </script>
  88. <style lang="scss" scoped src="../style/index.scss"></style>