Skip to content

Commit

Permalink
feat: 模板管理:1.批量添加接口联调;2.新建配置文件、添加已有配置文件调用添加接口的改动--story118110616
Browse files Browse the repository at this point in the history
  • Loading branch information
q15971095971 committed Jul 17, 2024
1 parent d63ac40 commit 31275bb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
9 changes: 7 additions & 2 deletions bcs-services/bcs-bscp/ui/src/api/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,27 @@ export const getTemplatesDetailByIds = (biz_id: string, ids: number[]) =>
* @param template_space_id 空间ID
* @param template_id 模板ID
* @param template_set_ids 模板套餐列表
* @param exclusion_operation 是否跨页全选
* @param template_set_id 设置目标模板套餐
* @param no_set_specified 是否未指定套餐
* @returns
*/
export const addTemplateToPackage = (
biz_id: string,
template_space_id: number,
template_ids: number[],
template_set_ids: number[],
template_set_id: string | number,
exclusion_operation: boolean,
template_set_id: number | string,
no_set_specified: boolean,
) =>
http.post(
`/config/biz/${biz_id}/template_spaces/${template_space_id}/template_set/${template_set_id}/templates/add_to_template_sets`,
{
template_ids,
template_set_ids,
exclusion_operation,
template_ids,
no_set_specified,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@
try {
pending.value = true;
const configIds = selectedConfigs.value.map((item) => item.id);
await addTemplateToPackage(spaceId.value, currentTemplateSpace.value, configIds, [currentPkg.value as number]);
await addTemplateToPackage(
spaceId.value,
currentTemplateSpace.value,
configIds,
[currentPkg.value as number],
false,
currentPkg.value,
false,
);
emits('added');
close();
Message({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@confirm="handleCreateConfirm" />
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue';
import { ref, watch, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { storeToRefs } from 'pinia';
import Message from 'bkui-vue/lib/message';
Expand All @@ -46,7 +46,7 @@
const templateStore = useTemplateStore();
const { spaceId } = storeToRefs(useGlobalStore());
const { currentTemplateSpace } = storeToRefs(useTemplateStore());
const { currentTemplateSpace, currentPkg } = storeToRefs(useTemplateStore());
const { t } = useI18n();
const props = defineProps<{
Expand All @@ -63,6 +63,10 @@
const isSelectPkgDialogShow = ref(false);
const isFormChanged = ref(false);
const templateSetID = computed(() => {
return typeof currentPkg.value === 'string' ? 0 : currentPkg.value;
});
watch(
() => props.show,
(val) => {
Expand Down Expand Up @@ -104,8 +108,17 @@
const params = { ...configForm.value, ...{ sign, byte_size: size } };
const res = await createTemplate(spaceId.value, currentTemplateSpace.value, params);
// 选择未指定套餐时,不需要调用添加接口
// 新建配置不存在全选反选,未指定套餐不存在新建
if (pkgIds.length > 1 || pkgIds[0] !== 0) {
await addTemplateToPackage(spaceId.value, currentTemplateSpace.value, [res.data.id], pkgIds);
await addTemplateToPackage(
spaceId.value,
currentTemplateSpace.value,
[res.data.id],
pkgIds,
false,
templateSetID.value,
false,
);
}
templateStore.$patch((state) => {
state.topIds = [res.data.id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
const windowHeight = window.innerHeight;
return windowHeight * 0.6 - 200;
});
const templateSetID = computed(() => {
return typeof currentPkg.value === 'string' ? 0 : currentPkg.value;
});
const noSetSpecified = computed(() => {
return currentPkg.value === 'no_specified';
});
watch(
() => props.show,
Expand Down Expand Up @@ -141,7 +147,6 @@
const handleConfirm = async () => {
const isValid = await formRef.value.validate();
if (!isValid) return;
try {
pending.value = true;
const templateIds = props.value.map((item) => item.id);
Expand All @@ -150,8 +155,9 @@
currentTemplateSpace.value,
templateIds,
selectedPkgs.value,
currentPkg.value,
currentCheckType.value,
templateSetID.value,
noSetSpecified.value,
);
emits('added');
close();
Expand Down

0 comments on commit 31275bb

Please sign in to comment.