Skip to content

Commit

Permalink
fix: 变量恢复默认值失效--bug=119941897 (#2931)
Browse files Browse the repository at this point in the history
* fix: 变量恢复默认值失效--bug=119941897

* fix: 处理编译失败
  • Loading branch information
Yuikill authored Jan 26, 2024
1 parent 2abd4d5 commit 4024452
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/ui/src/i18n/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default {
设置变量: 'Set Variables',
设置变量成功: 'Set variable successfully',
恢复默认值: 'Restore Defaults',
服务变量值默认继承上个版本: 'Service variable values inherit from the previous version by default.',
'如果以下变量存在于全局变量中,其值将被重置为全局变量的默认值': 'If the following variable exists in a global variable, its value will be reset to the default value of the global variable',
暂无数据: 'No data',
变量名称: 'Variable name',
类型: 'Type',
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/ui/src/i18n/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default {
设置变量: '设置变量',
设置变量成功: '设置变量成功',
恢复默认值: '恢复默认值',
服务变量值默认继承上个版本: '服务变量值默认继承上个版本',
'如果以下变量存在于全局变量中,其值将被重置为全局变量的默认值': '如果以下变量存在于全局变量中,其值将被重置为全局变量的默认值',
暂无数据: '暂无数据',
变量名称: '变量名称',
类型: '类型',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<div class="variable-form" v-if="isFileType">
<div v-bkloading="{ loading }" class="section-title">{{ t('服务变量赋值') }}</div>
<ResetDefaultValue class="reset-default-btn" :list="initialVariables" @reset="handleResetDefault" />
<ResetDefaultValue class="reset-default-btn" :bk-biz-id="bkBizId" :list="initialVariables" @reset="handleResetDefault" />
<VariablesTable ref="tableRef" :list="variableList" :editable="true" @change="handleVariablesChange" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</bk-button>
<bk-sideslider width="960" :title="t('设置变量')" :is-show="isSliderShow" :before-close="handleBeforeClose" @closed="close">
<bk-loading :loading="loading" class="variables-table-content">
<ResetDefaultValue class="reset-default" :list="initialVariables" @reset="handleResetDefault" />
<ResetDefaultValue class="reset-default" :bk-biz-id="bkBizId" :list="initialVariables" @reset="handleResetDefault" />
<VariablesTable
ref="tableRef"
:list="variableList"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<template>
<bk-button class="reset-default-value-btn" text theme="primary" @click="triggerReset">
{{ t('恢复默认值') }}
<Help class="help-icon" v-bk-tooltips="{ content: t('服务变量值默认继承上个版本'), placement: 'top' }" />
<Help class="help-icon" v-bk-tooltips="{ content: t('如果以下变量存在于全局变量中,其值将被重置为全局变量的默认值'), placement: 'top' }" />
</bk-button>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue';
import { ref, watch, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { Help } from 'bkui-vue/lib/icon';
import { cloneDeep } from 'lodash';
import { IVariableEditParams } from '../../../../../../../../../types/variable';
import { IVariableEditParams, IVariableItem } from '../../../../../../../../../types/variable';
import { getVariableList } from '../../../../../../../../api/variable';
import { ICommonQuery } from '../../../../../../../../../types/index';
const { t } = useI18n();
const props = defineProps<{
list: IVariableEditParams[];
bkBizId: string
}>();
const emits = defineEmits(['reset']);
const initialList = ref(cloneDeep(props.list));
const variableList = ref<IVariableItem[]>();
watch(
() => props.list,
Expand All @@ -27,7 +31,24 @@ watch(
},
);
onMounted(() => {
getVariable();
});
const getVariable = async () => {
const params: ICommonQuery = {
start: 0,
all: true,
};
const res = await getVariableList(props.bkBizId, params);
variableList.value = res.details;
};
const triggerReset = () => {
initialList.value.forEach((item) => {
const variable = variableList.value?.find(variable => variable.spec.name === item.name);
if (variable) item.default_val = variable.spec.default_val;
});
emits('reset', cloneDeep(initialList.value));
};
</script>
Expand Down

0 comments on commit 4024452

Please sign in to comment.