index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="go-flex-items-center">
  3. <n-popover class="edit-history-popover" :show-arrow="false" size="small" trigger="click" placement="top-start">
  4. <template #trigger>
  5. <n-button class="mr-10" secondary size="small" :disabled="options.length === 0">
  6. <span class="btn-text">历史记录</span>
  7. </n-button>
  8. </template>
  9. <div class="history-list-box">
  10. <n-scrollbar style="max-height: 500px">
  11. <div
  12. class="list-item go-flex-items-center go-ellipsis-1"
  13. v-for="(item, index) in options"
  14. :key="index"
  15. :title="item.label"
  16. >
  17. <n-icon class="item-icon" size="16" :depth="2" :component="item.icon" />
  18. <n-text depth="2">{{ item.label }}</n-text>
  19. </div>
  20. </n-scrollbar>
  21. <div class="popover-modal"></div>
  22. </div>
  23. </n-popover>
  24. <n-tooltip trigger="hover">
  25. <template #trigger>
  26. <n-icon size="21" :depth="3">
  27. <help-outline-icon></help-outline-icon>
  28. </n-icon>
  29. </template>
  30. <span>最多只保留{{ editHistoryMax }}条记录</span>
  31. </n-tooltip>
  32. </div>
  33. </template>
  34. <script setup lang="ts">
  35. import { ref, computed } from 'vue'
  36. import { icon } from '@/plugins'
  37. import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
  38. import { historyActionTypeName } from '@/store/modules/chartHistoryStore/chartHistoryDefine'
  39. import { CreateComponentType } from '@/packages/index.d'
  40. import { editHistoryMax } from '@/settings/designSetting'
  41. import reverse from 'lodash/reverse'
  42. import {
  43. HistoryItemType,
  44. HistoryTargetTypeEnum,
  45. HistoryActionTypeEnum
  46. } from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
  47. const {
  48. DesktopOutlineIcon,
  49. PencilIcon,
  50. TrashIcon,
  51. CopyIcon,
  52. LayersIcon,
  53. DuplicateIcon,
  54. HelpOutlineIcon,
  55. LockClosedOutlineIcon,
  56. LockOpenOutlineIcon,
  57. EyeOffOutlineIcon,
  58. EyeOutlineIcon
  59. } = icon.ionicons5
  60. const { StackedMoveIcon, Carbon3DCursorIcon, Carbon3DSoftwareIcon } = icon.carbon
  61. const chartHistoryStoreStore = useChartHistoryStore()
  62. // 设置类型对应图标
  63. const iconHandle = (e: HistoryItemType) => {
  64. // 画布编辑
  65. if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
  66. return DesktopOutlineIcon
  67. }
  68. switch (e.actionType) {
  69. case HistoryActionTypeEnum.UPDATE:
  70. return PencilIcon
  71. case HistoryActionTypeEnum.DELETE:
  72. return TrashIcon
  73. case HistoryActionTypeEnum.PASTE:
  74. return CopyIcon
  75. case HistoryActionTypeEnum.TOP:
  76. return LayersIcon
  77. case HistoryActionTypeEnum.BOTTOM:
  78. return LayersIcon
  79. case HistoryActionTypeEnum.UP:
  80. return LayersIcon
  81. case HistoryActionTypeEnum.DOWN:
  82. return LayersIcon
  83. case HistoryActionTypeEnum.MOVE:
  84. return StackedMoveIcon
  85. case HistoryActionTypeEnum.ADD:
  86. return DuplicateIcon
  87. case HistoryActionTypeEnum.GROUP:
  88. return Carbon3DCursorIcon
  89. case HistoryActionTypeEnum.UN_GROUP:
  90. return Carbon3DSoftwareIcon
  91. case HistoryActionTypeEnum.LOCK:
  92. return LockClosedOutlineIcon
  93. case HistoryActionTypeEnum.UNLOCK:
  94. return LockOpenOutlineIcon
  95. case HistoryActionTypeEnum.HIDE:
  96. return EyeOffOutlineIcon
  97. case HistoryActionTypeEnum.SHOW:
  98. return EyeOutlineIcon
  99. default:
  100. return PencilIcon
  101. }
  102. }
  103. // 设置类型对应文本
  104. const labelHandle = (e: HistoryItemType) => {
  105. // 画布编辑
  106. if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
  107. return historyActionTypeName[HistoryTargetTypeEnum.CANVAS]
  108. } else if (e.actionType === HistoryActionTypeEnum.GROUP || e.actionType === HistoryActionTypeEnum.UN_GROUP) {
  109. return `${historyActionTypeName[e.actionType]}`
  110. } else if (e.historyData.length) {
  111. return `${historyActionTypeName[e.actionType]} - ${(e.historyData[0] as CreateComponentType).chartConfig.title}`
  112. }
  113. }
  114. const options = computed(() => {
  115. const backStack: HistoryItemType[] = chartHistoryStoreStore.getBackStack
  116. const options = backStack.map((e: HistoryItemType) => {
  117. return {
  118. label: labelHandle(e),
  119. icon: iconHandle(e)
  120. }
  121. })
  122. return reverse(options.filter(item => item.label))
  123. })
  124. </script>
  125. <style lang="scss" scoped>
  126. .mr-10 {
  127. margin-right: 10px;
  128. }
  129. .edit-history-popover {
  130. .btn-text {
  131. font-size: 12px;
  132. margin-right: 3px;
  133. }
  134. .history-list-box {
  135. width: 100%;
  136. .list-item {
  137. z-index: 2;
  138. position: relative;
  139. cursor: default;
  140. padding: 2px;
  141. .item-icon {
  142. margin-right: 10px;
  143. }
  144. }
  145. }
  146. }
  147. </style>