index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="go-edit-history go-flex-items-center">
  3. <n-dropdown
  4. @select="handleSelect"
  5. :show="showDropdownRef"
  6. :options="options"
  7. scrollable
  8. size="small"
  9. placement="top-start"
  10. style="max-height: 100vh; overflow-y: auto;"
  11. >
  12. <n-button
  13. class="mr-10"
  14. secondary
  15. size="small"
  16. :disabled="options.length === 0"
  17. @click="handleClick"
  18. >
  19. <span class="btn-text">历史记录</span>
  20. </n-button>
  21. </n-dropdown>
  22. <n-tooltip trigger="hover">
  23. <template #trigger>
  24. <n-icon size="21" :depth="3">
  25. <HelpOutlineIcon />
  26. </n-icon>
  27. </template>
  28. <span>最多只保留 20 条记录</span>
  29. </n-tooltip>
  30. </div>
  31. </template>
  32. <script setup lang="ts">
  33. import { ref, computed } from 'vue'
  34. import { icon } from '@/plugins'
  35. import { renderIcon } from '@/utils'
  36. import { useChartHistoryStoreStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
  37. import { historyActionTypeName } from '@/store/modules/chartHistoryStore/chartHistoryDefine'
  38. import { CreateComponentType } from '@/packages/index.d'
  39. import {
  40. HistoryItemType,
  41. HistoryTargetTypeEnum,
  42. HistoryActionTypeEnum
  43. } from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
  44. const {
  45. DesktopOutlineIcon,
  46. PencilIcon,
  47. TrashIcon,
  48. CopyIcon,
  49. LayersIcon,
  50. DuplicateIcon,
  51. HelpOutlineIcon
  52. } = icon.ionicons5
  53. const { StackedMoveIcon } = icon.carbon
  54. const showDropdownRef = ref(false)
  55. const chartHistoryStoreStore = useChartHistoryStoreStore()
  56. // 设置类型对应图标
  57. const iconHandle = (e: HistoryItemType) => {
  58. // 画布编辑
  59. if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
  60. return renderIcon(DesktopOutlineIcon)
  61. }
  62. switch (e.actionType) {
  63. case HistoryActionTypeEnum.UPDATE:
  64. return renderIcon(PencilIcon)
  65. case HistoryActionTypeEnum.DELETE:
  66. return renderIcon(TrashIcon)
  67. case HistoryActionTypeEnum.PASTE:
  68. return renderIcon(CopyIcon)
  69. case HistoryActionTypeEnum.TOP:
  70. return renderIcon(LayersIcon)
  71. case HistoryActionTypeEnum.BOTTOM:
  72. return renderIcon(LayersIcon)
  73. case HistoryActionTypeEnum.UP:
  74. return renderIcon(LayersIcon)
  75. case HistoryActionTypeEnum.DOWN:
  76. return renderIcon(LayersIcon)
  77. case HistoryActionTypeEnum.MOVE:
  78. return renderIcon(StackedMoveIcon)
  79. case HistoryActionTypeEnum.ADD:
  80. return renderIcon(DuplicateIcon)
  81. default:
  82. return renderIcon(PencilIcon)
  83. }
  84. }
  85. // 设置类型对应文本
  86. const labelHandle = (e: HistoryItemType) => {
  87. // 画布编辑
  88. if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
  89. return historyActionTypeName[HistoryTargetTypeEnum.CANVAS]
  90. }
  91. return `${historyActionTypeName[e.actionType]} - ${
  92. (e.historyData as CreateComponentType).chartData.title
  93. }`
  94. }
  95. const options = computed(() => {
  96. const backStack: HistoryItemType[] = chartHistoryStoreStore.getBackStack
  97. const options = backStack.map((e: HistoryItemType) => {
  98. return {
  99. label: labelHandle(e),
  100. key: e.id,
  101. icon: iconHandle(e)
  102. }
  103. })
  104. return options
  105. })
  106. const handleClick = () => {
  107. showDropdownRef.value = !showDropdownRef.value
  108. }
  109. const handleSelect = (key: string) => {}
  110. </script>
  111. <style lang="scss" scoped>
  112. @include go(edit-history) {
  113. max-height: 50vh;
  114. .mr-10 {
  115. margin-right: 10px;
  116. }
  117. .btn-text {
  118. font-size: 12px;
  119. margin-right: 3px;
  120. }
  121. }
  122. </style>