|
31 | 31 | <template #main>
|
32 | 32 | <PanelTab
|
33 | 33 | v-model="panelTabActive"
|
34 |
| - :tab-list="tabListMap[dbType]" /> |
| 34 | + :db-type="dbType" /> |
35 | 35 | <Component
|
36 |
| - :is="renderCom" |
| 36 | + :is="ClusterSelect" |
37 | 37 | :key="panelTabActive"
|
38 | 38 | :active-panel-id="panelTabActive"
|
39 | 39 | :last-values="lastValues"
|
|
68 | 68 | </template>
|
69 | 69 | </BkDialog>
|
70 | 70 | </template>
|
71 |
| - |
72 | 71 | <script lang="ts">
|
73 |
| - import type { queryAllTypeCluster } from '@services/source/dbbase'; |
74 |
| - |
75 |
| - export type ICluster = ServiceReturnType<typeof queryAllTypeCluster>['results'][number]; |
| 72 | + import type { ClusterInfo } from '@services/types'; |
76 | 73 |
|
77 |
| - interface Props { |
78 |
| - dbType: DBTypes; |
79 |
| - selected: Record<string, ICluster[]>; |
80 |
| - } |
| 74 | + import { ClusterTypes, DBTypes } from '@common/const'; |
81 | 75 |
|
82 |
| - interface Emits { |
83 |
| - (e: 'change', value: Props['selected']): void; |
| 76 | + interface SelectedMap { |
| 77 | + [DBTypes.MYSQL]: { |
| 78 | + [ClusterTypes.TENDBHA]: ClusterInfo[]; |
| 79 | + [ClusterTypes.TENDBSINGLE]: ClusterInfo[]; |
| 80 | + }; |
| 81 | + [DBTypes.TENDBCLUSTER]: { |
| 82 | + [ClusterTypes.TENDBCLUSTER]: ClusterInfo[]; |
| 83 | + }; |
84 | 84 | }
|
85 | 85 | </script>
|
86 |
| -<script setup lang="ts"> |
87 |
| - import { ClusterTypes, DBTypes } from '@common/const'; |
88 |
| - |
89 |
| - import { t } from '@locales/index'; |
| 86 | +<script setup lang="ts" generic="T extends keyof SelectedMap"> |
| 87 | + import { useI18n } from 'vue-i18n'; |
90 | 88 |
|
91 | 89 | import ClusterSelect from './components/cluster-select/Index.vue';
|
92 | 90 | import PanelTab from './components/common/PanelTab.vue';
|
93 |
| - import ManualInput from './components/manual-input/Index.vue'; |
| 91 | + // import ManualInput from './components/manual-input/Index.vue'; |
94 | 92 | import PreviewResult from './components/preview-result/Index.vue';
|
95 | 93 |
|
96 |
| - const props = withDefaults(defineProps<Props>(), { |
97 |
| - selected: () => ({}), |
98 |
| - }); |
| 94 | + interface Props { |
| 95 | + dbType: T; |
| 96 | + selected: SelectedMap[T]; |
| 97 | + } |
| 98 | + |
| 99 | + interface Emits { |
| 100 | + (e: 'change', value: ClusterInfo[]): void; |
| 101 | + } |
| 102 | + |
| 103 | + const props = defineProps<Props>(); |
99 | 104 |
|
100 | 105 | const emits = defineEmits<Emits>();
|
101 | 106 |
|
102 | 107 | const isShow = defineModel<boolean>('isShow', {
|
103 | 108 | default: false,
|
104 | 109 | });
|
105 | 110 |
|
106 |
| - const tabListMap = { |
107 |
| - [DBTypes.MYSQL]: [ |
108 |
| - { |
109 |
| - id: ClusterTypes.TENDBHA, |
110 |
| - name: t('MySQL主从'), |
111 |
| - }, |
112 |
| - { |
113 |
| - id: ClusterTypes.TENDBSINGLE, |
114 |
| - name: t('MySQL单节点'), |
115 |
| - }, |
116 |
| - ], |
117 |
| - } as Record<DBTypes, { id: string; name: string }[]>; |
118 |
| - |
119 |
| - const panelTabActive = ref(tabListMap[props.dbType][0].id); |
120 |
| - const lastValues = reactive<NonNullable<Props['selected']>>({}); |
121 |
| - |
122 |
| - const renderCom = computed(() => { |
123 |
| - if (panelTabActive.value === 'manual') { |
124 |
| - return ManualInput; |
125 |
| - } |
126 |
| - return ClusterSelect; |
127 |
| - }); |
| 111 | + const { t } = useI18n(); |
| 112 | + |
| 113 | + const panelTabActive = ref(); |
| 114 | + const lastValues = reactive<Record<string, ClusterInfo[]>>({}); |
| 115 | + |
| 116 | + // const renderCom = computed( |
| 117 | + // () => { |
| 118 | + // if (panelTabActive.value === 'manual') { |
| 119 | + // return ManualInput; |
| 120 | + // } |
| 121 | + // return ClusterSelect; |
| 122 | + // } |
| 123 | + // ); |
128 | 124 | const isEmpty = computed(() => Object.values(lastValues).every((values) => values.length < 1));
|
129 | 125 |
|
130 | 126 | watch(
|
|
152 | 148 | lastValues[oldValue] = [];
|
153 | 149 | });
|
154 | 150 |
|
155 |
| - const handleChange = (values: Props['selected']) => { |
| 151 | + const handleChange = (values: Record<string, ClusterInfo[]>) => { |
156 | 152 | Object.assign(lastValues, values);
|
157 | 153 | };
|
158 | 154 |
|
159 | 155 | const handleSubmit = () => {
|
160 |
| - emits('change', lastValues); |
| 156 | + emits('change', Object.values(lastValues).flat()); |
161 | 157 | handleClose();
|
162 | 158 | };
|
163 | 159 |
|
|
0 commit comments