EditorToolbar.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="editor-toolbar">
  3. <a-space>
  4. <span class="toolbar-label">环境:</span>
  5. <a-select
  6. :value="isDevValue"
  7. style="width: 100px"
  8. :options="envOptions"
  9. @update:value="emit('update:isDev', $event == 'true' ? true : false)"
  10. />
  11. <a-dropdown>
  12. <a-button>
  13. 加载
  14. <DownOutlined />
  15. </a-button>
  16. <template #overlay>
  17. <a-menu v-if="historyList.length">
  18. <a-menu-item @click="emit('select-default')">
  19. 默认版本
  20. <a-badge v-if="currentConfig?.activeHistoryId === 0" count="激活" />
  21. </a-menu-item>
  22. <a-menu-item
  23. v-for="(item, index) in historyList"
  24. :key="index"
  25. @click="emit('select-history', item.id!)"
  26. >
  27. {{ item.name }}
  28. <a-badge v-if="item.id === currentConfig?.activeHistoryId" count="激活" />
  29. </a-menu-item>
  30. </a-menu>
  31. <a-menu v-else>
  32. <a-menu-item disabled>暂无历史版本</a-menu-item>
  33. </a-menu>
  34. </template>
  35. </a-dropdown>
  36. <a-dropdown-button type="primary" :icon="h(DownOutlined)" @click="emit('save')">
  37. 保存
  38. <template #overlay>
  39. <a-menu>
  40. <a-menu-item @click="emit('open-save-as')">另存为历史版本</a-menu-item>
  41. <a-menu-item v-if="isDev" @click="emit('sync-to-production')">同步至正式版</a-menu-item>
  42. </a-menu>
  43. </template>
  44. </a-dropdown-button>
  45. <div>
  46. <InfoCircleFilled />
  47. 当前激活版本:
  48. <span>{{ currentShowConfigName }}</span>
  49. </div>
  50. <a-button v-if="currentConfig" @click="emit('set-active')">
  51. {{ currentConfig.activeHistoryId === currentHistoryId ? '已经是激活版本' : '设置为激活版本' }}
  52. </a-button>
  53. <a-button v-if="currentConfig && currentHistoryId !== 0" danger @click="emit('delete-history')">
  54. <DeleteOutlined />
  55. 删除历史版本
  56. </a-button>
  57. </a-space>
  58. <a-space>
  59. <a-button type="primary" @click="emit('help')">
  60. 帮助
  61. <QuestionCircleOutlined />
  62. </a-button>
  63. <a-button @click="emit('export')">
  64. 导出为JSON文件
  65. <DownloadOutlined />
  66. </a-button>
  67. </a-space>
  68. <a-modal
  69. :open="saveAsModalVisible"
  70. title="另存为历史版本"
  71. ok-text="保存"
  72. cancel-text="取消"
  73. :confirm-loading="saveAsLoading"
  74. @update:open="emit('update:saveAsModalVisible', $event)"
  75. @ok="emit('confirm-save-as')"
  76. >
  77. <a-form layout="vertical" class="save-as-form">
  78. <a-form-item label="版本名称">
  79. <a-input
  80. :value="saveAsVersionName"
  81. placeholder="请输入版本名称"
  82. allow-clear
  83. @update:value="emit('update:saveAsVersionName', $event)"
  84. />
  85. </a-form-item>
  86. </a-form>
  87. </a-modal>
  88. </div>
  89. </template>
  90. <script setup lang="ts">
  91. import { computed, h } from 'vue';
  92. import { DownOutlined, DownloadOutlined, InfoCircleFilled, DeleteOutlined, QuestionCircleOutlined } from '@ant-design/icons-vue';
  93. import type { IHistoryListItem } from '../composables/useEditorConfig';
  94. import type { ICommonCategoryConfigItem } from '../../api/CommonCategoryApi';
  95. const props = defineProps<{
  96. historyList: IHistoryListItem[];
  97. currentConfig?: ICommonCategoryConfigItem;
  98. currentHistoryId: number;
  99. currentShowConfigName: string;
  100. isDev: boolean;
  101. saveAsModalVisible: boolean;
  102. saveAsVersionName: string;
  103. saveAsLoading: boolean;
  104. }>();
  105. const emit = defineEmits<{
  106. (e: 'select-default'): void;
  107. (e: 'select-history', id: number): void;
  108. (e: 'save'): void;
  109. (e: 'open-save-as'): void;
  110. (e: 'confirm-save-as'): void;
  111. (e: 'sync-to-production'): void;
  112. (e: 'set-active'): void;
  113. (e: 'delete-history'): void;
  114. (e: 'export'): void;
  115. (e: 'help'): void;
  116. (e: 'update:isDev', v: boolean): void;
  117. (e: 'update:saveAsModalVisible', v: boolean): void;
  118. (e: 'update:saveAsVersionName', v: string): void;
  119. }>();
  120. const isDevValue = computed({
  121. get: () => props.isDev ? 'true' : 'false',
  122. set: (v: boolean) => emit('update:isDev', Boolean(v)),
  123. });
  124. const envOptions = [
  125. { value: 'true', label: '开发版' },
  126. { value: 'false', label: '正式版' },
  127. ];
  128. </script>
  129. <style scoped>
  130. .editor-toolbar {
  131. padding: 8px 16px;
  132. background: #fff;
  133. border-bottom: 1px solid #eee;
  134. display: flex;
  135. justify-content: space-between;
  136. align-items: center;
  137. }
  138. .toolbar-label {
  139. color: rgba(0, 0, 0, 0.65);
  140. font-size: 14px;
  141. }
  142. </style>