Skip to content

Commit

Permalink
fix: 修复kv配置项导出问题 (#2972)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuikill authored Feb 23, 2024
1 parent 3d207b4 commit 9e33937
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<bk-button>{{ $t('导出至') }}</bk-button>
<template #content>
<div class="export-config-operations">
<div v-for="item in exportItem" :key="item.value" class="operation-item">
<div v-for="item in exportItem" :key="item.value" class="operation-item" @click="handleExport(item.value)">
<span :class="['bk-bscp-icon', `icon-${item.value}`]" />
<span class="text" @click="handleExport(item.value)"> {{ item.text }}</span>
<span class="text"> {{ item.text }}</span>
</div>
</div>
</template>
Expand All @@ -16,10 +16,16 @@
import { computed } from 'vue';
import jsyaml from 'js-yaml';
import { getExportKvFile } from '../../../../../../../api/config';
import { storeToRefs } from 'pinia';
import useServiceStore from '../../../../../../../store/service';
const serviceStore = useServiceStore();
const { appData } = storeToRefs(serviceStore);
const props = defineProps<{
bkBizId: string;
appId: number;
verisionId: number;
versionId: number;
versionName: string;
}>();
const exportItem = computed(() => [
Expand All @@ -34,20 +40,21 @@
]);
const handleExport = async (type: string) => {
const res = await getExportKvFile(props.bkBizId, props.appId, props.verisionId, type);
const res = await getExportKvFile(props.bkBizId, props.appId, props.versionId, type);
let content: string;
let mimeType: string;
let extension: string;
const prefix = props.versionId ? `${appData.value.spec.name}_${props.versionName}` : `${appData.value.spec.name}`;
if (type === 'json') {
content = JSON.stringify(res, null, 2);
mimeType = 'application/json';
extension = 'json';
} else {
content = jsyaml.dump(res);
content = jsyaml.dump(res).replace(/^\|(\s*\n)/, '');
mimeType = 'text/yaml';
extension = 'yaml';
}
downloadFile(content, mimeType, `data.${extension}`);
downloadFile(content, mimeType, `${prefix}.${extension}`);
};
const downloadFile = (content: string, mimeType: string, fileName: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
v-if="!isFileType"
:bk-biz-id="props.bkBizId"
:app-id="props.appId"
:verision-id="versionData.id" />
:version-id="versionData.id"
:version-name="versionData.spec.name"/>
</div>
<SearchInput
v-model="searchStr"
Expand Down

0 comments on commit 9e33937

Please sign in to comment.