Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 资源导入表格可批量修改资源文档 #1164

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@
</template>
</bk-table-column>
<bk-table-column
:label="t('资源文档')"
prop="doc"
width="85"
:label="() => action === 'add' ? renderDocColLabel() : t('资源文档')"
>
<template #default="{ row }: { row: ILocalImportedResource }">
<bk-button
v-if="showDoc"
v-if="docConfig.showDoc"
text
theme="primary"
@click="handleShowResourceDoc(row)"
Expand Down Expand Up @@ -186,6 +184,7 @@ import { useI18n } from 'vue-i18n';
import { MethodsEnum } from '@/types';
import useTextGetter from '@/views/resource/setting/hooks/useTextGetter';
import TableEmpty from '@/components/table-empty.vue';
import { type IDocConfig } from '@/views/resource/setting/import.vue';

const {
getAuthConfigText,
Expand All @@ -199,16 +198,19 @@ const methodsEnum = Object.freeze(MethodsEnum);

interface IProps {
tableData: ILocalImportedResource[];
showDoc: boolean;
action: ActionType;
keyword: string;
docConfig: IDocConfig;
}

const props = withDefaults(defineProps<IProps>(), {
tableData: () => [],
showDoc: true,
action: 'add',
keyword: '',
docConfig: () => ({
showDoc: true,
language: 'zh',
}),
});

const emit = defineEmits<{
Expand All @@ -218,6 +220,7 @@ const emit = defineEmits<{
'toggle-row-unchecked': [row: ILocalImportedResource]
'confirm-auth-config': [action: ActionType]
'confirm-pub-config': [action: ActionType]
'confirm-doc-config': [docConfig: IDocConfig]
'clear-filter': [action: ActionType]
}>();

Expand All @@ -231,16 +234,18 @@ const tempPublicConfig = defineModel<IPublicConfig>('tempPublicConfig', {

const {
tableData,
showDoc,
action,
keyword,
docConfig,
} = toRefs(props);

const pagination = ref({
count: tableData.value.length,
limit: 10,
});

const localDocConfig = ref({ ...docConfig.value });

const handleShowResourceDoc = (row: ILocalImportedResource) => {
emit('show-row-doc', row);
};
Expand Down Expand Up @@ -289,6 +294,10 @@ const handleCancelPublicConfig = () => {
}
};

const handleConfirmDocConfig = () => {
emit('confirm-doc-config', localDocConfig.value);
};

const renderAuthConfigColLabel = () => {
return (
<div>
Expand Down Expand Up @@ -407,6 +416,61 @@ const renderIsPublicColLabel = () => {
</div>
);
};

// 是否生成文档列 TSX
const renderDocColLabel = () => {
return (
<div>
<div class="public-config-col-label">
<span>{t('资源文档')}</span>
<bk-pop-confirm
width="360"
trigger="click"
title={<span class="f16" style="color: #313238;">{t('批量修改资源文档')}</span>}
content={
<div class="multi-edit-popconfirm-wrap public-config" style="margin-bottom: -12px;">
<bk-form model={localDocConfig.value} labelWidth="100" labelPosition="right">
<bk-form-item
label={t('生成文档')}
style="margin-bottom: 12px;"
>
<bk-switcher
v-model={localDocConfig.value.showDoc}
theme="primary"
size="small"
/>
</bk-form-item>
{localDocConfig.value.showDoc ?
<bk-form-item
label={t('文档语言')}
style="margin-bottom: 12px;"
>
<bk-radio-group v-model={localDocConfig.value.language} size="small">
<bk-radio label="zh">{t('中文文档')}</bk-radio>
<bk-radio label="en">{t('英文文档')}</bk-radio>
</bk-radio-group>
</bk-form-item> : ''
}
</bk-form>
</div>
}
onConfirm={() => handleConfirmDocConfig()}
>
<i
class="apigateway-icon icon-ag-bulk-edit edit-action ml5 f14 default-c"
v-bk-tooltips={{
content: (
<div>
{t('批量修改资源文档')}
</div>
),
}}
/>
</bk-pop-confirm>
</div>
</div>
);
};
</script>

<style lang="scss" scoped>
Expand Down
34 changes: 23 additions & 11 deletions src/dashboard-front/src/views/resource/setting/import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@
class="mb0"
:label-width="20"
>
<bk-checkbox v-model="showDoc" size="small">
<bk-checkbox v-model="docConfig.showDoc" size="small">
{{ t('生成资源文档') }}
</bk-checkbox>
</bk-form-item>
<bk-form-item
v-if="showDoc"
v-if="docConfig.showDoc"
class="mb0"
:label="t('文档语言')"
:required="true"
:label-width="120"
>
<bk-radio-group v-model="language" size="small">
<bk-radio-group v-model="docConfig.language" size="small">
<bk-radio label="zh">{{ t('中文文档') }}</bk-radio>
<bk-radio label="en">{{ t('英文文档') }}</bk-radio>
</bk-radio-group>
Expand Down Expand Up @@ -263,8 +263,8 @@
<TableResToAction
action="add"
:table-data="tableDataToAdd"
:show-doc="showDoc"
:keyword="filterInputAddClone"
:doc-config="docConfig"
v-model:tempAuthConfig="tempAuthConfig"
v-model:tempPublicConfig="tempPublicConfig"
@show-row-doc="handleShowResourceDoc"
Expand All @@ -273,6 +273,7 @@
@toggle-row-unchecked="toggleRowUnchecked"
@confirm-auth-config="handleConfirmAuthConfigPopConfirm"
@confirm-pub-config="handleConfirmPublicConfigPopConfirm"
@confirm-doc-config="handleConfirmDocConfigPopConfirm"
@clear-filter="clearFilterInput"
></TableResToAction>
</div>
Expand Down Expand Up @@ -434,7 +435,7 @@
:show-footer="false"
:show-create-btn="false"
:is-preview="!editingResource.id"
:preview-lang="language"
:preview-lang="docConfig.language"
></ResourceDocSideSlider>
<!-- 查看插件侧边栏 -->
<PluginPreviewSideSlider
Expand Down Expand Up @@ -606,15 +607,22 @@ type CodeErrorResponse = {
message: string,
};

export interface IDocConfig {
showDoc: boolean;
language: 'zh' | 'en',
}

const { useRouter, onBeforeRouteLeave } = useTsxRouter();
const router = useRouter();
const { t } = useI18n();
const common = useCommon();
const editorText = ref<string>(exampleData.content);
const { apigwId } = common; // 网关id
const resourceEditorRef = ref<InstanceType<typeof editorMonaco>>(); // 实例化
const showDoc = ref(true);
const language = ref<'zh' | 'en'>('zh');
const docConfig = ref<IDocConfig>({
showDoc: true,
language: 'zh',
});
const isDataLoading = ref(false);
// 代码校验是否通过
const isCodeValid = ref(false);
Expand Down Expand Up @@ -856,8 +864,8 @@ const handleCheckData = async ({ changeView }: { changeView: boolean }) => {
allow_overwrite: true,
};
// 如果勾选了资源文档
if (showDoc.value) {
params.doc_language = language.value;
if (docConfig.value.showDoc) {
params.doc_language = docConfig.value.language;
}
// 配置是否显示错误 Message,只校验代码时不显示,改为展示在编辑器的错误消息栏中
const interceptorConfig = _changeView ? {} : { globalError: false };
Expand Down Expand Up @@ -996,8 +1004,8 @@ const handleImportResource = async () => {
});
const params = { import_resources };
// 如果勾选了资源文档,传入 doc_language
if (showDoc.value) {
Object.assign(params, { doc_language: language.value });
if (docConfig.value.showDoc) {
Object.assign(params, { doc_language: docConfig.value.language });
}
await importResource(apigwId, params);
isImportSucceeded.value = true;
Expand Down Expand Up @@ -1247,6 +1255,10 @@ const handleConfirmPublicConfigPopConfirm = (action: ActionType) => {
});
};

const handleConfirmDocConfigPopConfirm = (config: IDocConfig) => {
docConfig.value = { ...config };
};

const filterData = (action: ActionType) => {
if (action === 'add') {
filterInputAdd.value = filterInputAddClone.value;
Expand Down