index.vue 3.3 KB

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