index.vue 3.5 KB

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