Skip to content

Commit

Permalink
feat: 跨租户协同接口联调 TencentBlueKing#1684
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 7385
  • Loading branch information
yuri0528 committed May 9, 2024
1 parent ca0bb3e commit fcf2dbe
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 148 deletions.
19 changes: 16 additions & 3 deletions src/pages/src/components/field-mapping/FieldMapping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div>
<div class="field-mapping">
<div class="field-title">
<bk-form-item class="w-[240px]" :label="$t('用户管理字段')" required />
<bk-form-item class="w-[240px]" :label="sourceField" required />
<bk-form-item class="w-[100px]" :label="$t('映射关系')" />
<bk-form-item class="w-[240px]" :label="$t('API返回字段')" required />
<bk-form-item class="w-[240px]" :label="targetField" required />
</div>
<div class="field-content" v-for="(item, index) in fieldSettingData?.field_mapping?.builtin_fields" :key="index">
<div class="field-name">
Expand All @@ -29,6 +29,7 @@
<bk-select
class="w-[240px]"
v-model="item.source_field"
:disabled="disabledBuiltinField"
@change="(val, oldVal) => emit('changeApiFields', val, oldVal)">
<bk-option
v-for="option in apiFields"
Expand Down Expand Up @@ -96,7 +97,7 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { defineEmits, defineProps, ref } from 'vue';
import { t } from '@/language/index';
Expand All @@ -113,6 +114,18 @@ defineProps({
type: Object,
default: () => ({}),
},
sourceField: {
type: String,
default: '',
},
targetField: {
type: String,
default: '',
},
disabledBuiltinField: {
type: Boolean,
default: false,
},
});
const emit = defineEmits(['changeApiFields', 'handleAddField', 'handleDeleteField', 'changeCustomField']);
Expand Down
52 changes: 52 additions & 0 deletions src/pages/src/http/settingFiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import http from './fetch';
import type {
FromStrategiesConfirmParams,
NewCustomFieldsParams,
NewToStrategiesParams,
PatchBuiltinManagerParams,
PutCustomFieldsParams,
PutPasswordParams,
Expand Down Expand Up @@ -84,3 +86,53 @@ export const getTenantInfo = () => http.get('/api/v1/web/tenant-info/');
* 基础设置-更新租户
*/
export const PutTenantInfo = (params: PutTenantInfoParams) => http.put('/api/v1/web/tenant-info/', params);

/**
* 跨租户协同-我分享的协同策略
*/
export const getToStrategies = () => http.get('/api/v1/web/collaboration/to-strategies/');

/**
* 跨租户协同-我分享的协同策略切换状态
*/
export const putToStrategiesStatus = (id: number) => http.put(`/api/v1/web/collaboration/to-strategies/${id}/source-status/`);

/**
* 跨租户协同-新建协同策略
*/
export const postToStrategies = (params: NewToStrategiesParams) => http.post('/api/v1/web/collaboration/to-strategies/', params);

/**
* 跨租户协同-更新协同策略
*/
export const putToStrategies = (id: number, params: NewToStrategiesParams) => http.put(`/api/v1/web/collaboration/to-strategies/${id}/`, params);

/**
* 跨租户协同-删除协同策略
*/
export const deleteToStrategies = (id: number) => http.delete(`/api/v1/web/collaboration/to-strategies/${id}/`);

/**
* 跨租户协同-我接受的协同策略
*/
export const getFromStrategies = () => http.get('/api/v1/web/collaboration/from-strategies/');

/**
* 跨租户协同-我接受的协同策略切换状态
*/
export const putFromStrategiesStatus = (id: number) => http.put(`/api/v1/web/collaboration/from-strategies/${id}/target-status/`);

/**
* 跨租户协同-源租户自定义字段
*/
export const getSourceTenantCustomFields = (id: number) => http.get(`/api/v1/web/collaboration/from-strategies/${id}/source-tenant-custom-fields/`);

/**
* 跨租户协同-确认协同策略
*/
export const putFromStrategiesConfirm = (params: FromStrategiesConfirmParams) => http.put(`/api/v1/web/collaboration/from-strategies/${params.id}/operations/confirm/`, params);

/**
* 跨租户协同-编辑协同策略
*/
export const putFromStrategies = (params: FromStrategiesConfirmParams) => http.put(`/api/v1/web/collaboration/from-strategies/${params.id}/`, params);
30 changes: 30 additions & 0 deletions src/pages/src/http/types/settingFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,33 @@ export interface PutTenantInfoParams {
visible: boolean,
user_number_visible: boolean,
}

/**
* 跨租户协同-新建协同策略
*/
export interface NewToStrategiesParams {
name: string,
target_tenant_id: string,
source_config: {
organization_scope_type: string,
organization_scope_config: object,
field_scope_type: string,
field_scope_config: object,
},
}

/**
* 跨租户协同-确认协同策略
*/
export interface FromStrategiesConfirmParams {
id: number,
target_config: {
organization_scope_type: string,
organization_scope_config: object,
field_mapping: {
source_field: string,
mapping_operation: string,
target_field: string,
}[],
},
}
11 changes: 9 additions & 2 deletions src/pages/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@
"租户logo": "Tenant Logo",
"我分享的": "Shared by Me",
"其他租户分享的": "Shared by Other Tenants",
"目标公司": "Target company",
"确认": "Confirm",
"数据变更记录": "Data Change Logs",
"重置": "Reset",
Expand Down Expand Up @@ -463,5 +462,13 @@
"是否启用管理员账号?": "Enable Administrator Account?",
"停用后,将不可使用管理员账号进行登录": "After deactivation, the administrator account cannot be used for logging in",
"停用后,可使用管理员账号进行登录": "After deactivation, the administrator account can still be used for logging in",
"当前还没有数据源,需要先选择数据源类型并进行配置": "There is currently no data source; you need to select a data source type and configure it first"
"当前还没有数据源,需要先选择数据源类型并进行配置": "There is currently no data source; you need to select a data source type and configure it first",
"搜索策略名称": "Search Strategy Name",
"协同策略创建成功": "Collaboration Strategy Created Successfully",
"协同策略更新成功": "Collaboration Strategy Updated Successfully",
"所有部门 + 用户": "All departments + Users",
"协同数据选择": "Select Collaboration Data",
"已协同": "Already collaborated",
"源租户用户字段": "Source tenant user fields",
"本租户用户字段": "This tenant's user fields"
}
11 changes: 9 additions & 2 deletions src/pages/src/language/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@
"租户logo": "租户logo",
"我分享的": "我分享的",
"其他租户分享的": "其他租户分享的",
"目标公司": "目标公司",
"确认": "确认",
"数据变更记录": "数据变更记录",
"重置": "重置",
Expand Down Expand Up @@ -463,5 +462,13 @@
"是否启用管理员账号?": "是否启用管理员账号?",
"停用后,将不可使用管理员账号进行登录": "停用后,将不可使用管理员账号进行登录",
"停用后,可使用管理员账号进行登录": "停用后,可使用管理员账号进行登录",
"当前还没有数据源,需要先选择数据源类型并进行配置": "当前还没有数据源,需要先选择数据源类型并进行配置"
"当前还没有数据源,需要先选择数据源类型并进行配置": "当前还没有数据源,需要先选择数据源类型并进行配置",
"搜索策略名称": "搜索策略名称",
"协同策略创建成功": "协同策略创建成功",
"协同策略更新成功": "协同策略更新成功",
"所有部门 + 用户": "所有部门 + 用户",
"协同数据选择": "协同数据选择",
"已协同": "已协同",
"源租户用户字段": "源租户用户字段",
"本租户用户字段": "本租户用户字段"
}
4 changes: 4 additions & 0 deletions src/pages/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export const dataSourceStatus = {
icon: warningImg,
text: t('待确认'),
},
unconfirmed: {
icon: warningImg,
text: t('待确认'),
},
};

export const validTime = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
<bk-form-item class="w-[590px]" :label="$t('策略名称')" property="name" required>
<bk-input v-model="formData.name" :placeholder="validate.name.message" @focus="handleChange" />
</bk-form-item>
<bk-form-item class="w-[590px]" :label="$t('目标公司')" property="name" required>
<bk-input v-model="formData.name" :placeholder="validate.name.message" @focus="handleChange" />
<bk-form-item class="w-[590px]" :label="$t('目标租户')" property="target_tenant_id" required>
<bk-input
v-model="formData.target_tenant_id"
:placeholder="validate.name.message"
:disabled="config.type === 'edit'"
@focus="handleChange" />
</bk-form-item>
</div>
</div>
Expand All @@ -35,11 +39,11 @@
<div class="operation-content-info flex">
<bk-form-item class="w-[350px]" :label="$t('同步范围')" required>
<bk-radio-group
v-model="formData.sync_type"
v-model="formData.source_config.field_scope_type"
>
<bk-radio label="all">{{ $t('所有字段') }}</bk-radio>
<!-- <bk-radio label="appoint">{{ $t('指定字段') }}</bk-radio>
<bk-radio label="basics">{{ $t('仅基础字段') }}</bk-radio> -->
<bk-radio label="appoint" disabled>{{ $t('指定字段') }}</bk-radio>
<bk-radio label="basics" disabled>{{ $t('仅基础字段') }}</bk-radio>
</bk-radio-group>
</bk-form-item>
<bk-form-item
Expand All @@ -63,7 +67,8 @@
</bk-select>
</bk-form-item>
</div>
<div class="operation-content-info mt-[24px]">
<!-- 一期不做 -->
<!-- <div class="operation-content-info mt-[24px]">
<bk-form-item class="w-[800px]" :label="$t('字段预览')">
<bk-table
:data="tableData"
Expand All @@ -83,11 +88,11 @@
<bk-table-column prop="organization" :label="$t('组织')" />
</bk-table>
</bk-form-item>
</div>
</div> -->
</div>
</bk-form>
<div class="footer fixed">
<bk-button theme="primary" @click="handleSave">
<bk-button theme="primary" @click="handleSave" :loading="btnLoading">
{{ $t('保存并启用') }}
</bk-button>
<bk-button @click="() => $emit('handleCancelEdit')">
Expand All @@ -98,12 +103,15 @@
</template>

<script setup lang="ts">
import { Message } from 'bkui-vue';
import { defineEmits, defineProps, onMounted, reactive, ref } from 'vue';
import Empty from '@/components/Empty.vue';
// import Empty from '@/components/Empty.vue';
import { useValidate } from '@/hooks';
import { postToStrategies, putToStrategies } from '@/http';
import { t } from '@/language';
defineEmits(['handleCancelEdit']);
const emit = defineEmits(['handleCancelEdit', 'updateList']);
const props = defineProps({
config: {
Expand Down Expand Up @@ -144,8 +152,29 @@ const handleChange = () => {
window.changeInput = true;
};
const btnLoading = ref(false);
// 表单校验
const handleSave = async () => {
await basicRef.value.validate();
try {
await basicRef.value.validate();
btnLoading.value = true;
if (props.config.type === 'add') {
await postToStrategies(formData);
Message({ theme: 'success', message: t('协同策略创建成功') });
emit('updateList');
} else {
const params = {
name: formData.name,
target_tenant_id: formData.target_tenant_id,
source_config: formData.source_config,
};
await putToStrategies(formData.id, params);
Message({ theme: 'success', message: t('协同策略更新成功') });
emit('updateList');
}
} finally {
btnLoading.value = false;
}
};
</script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template>
<div class="view-details-wrapper">
<div class="view-details-content">
<LabelContent :label="$t('策略名称')"></LabelContent>
<LabelContent :label="$t('目标公司')"></LabelContent>
<LabelContent :label="$t('策略名称')">{{ data.name }}</LabelContent>
<LabelContent :label="$t('目标租户')">{{ data.target_tenant_id }}</LabelContent>
<LabelContent :label="$t('协同范围')">{{ $t('所有部门 + 用户') }}</LabelContent>
<!-- 一期不做 -->
<!-- <div class="content-item">
<span class="item-key">{{ $t('协同范围') }}:</span>
Expand All @@ -16,8 +17,9 @@
</div>
</div>
</div> -->
<LabelContent :label="$t('同步范围')"></LabelContent>
<LabelContent :label="$t('字段预览')">
<LabelContent :label="$t('同步范围')">{{ $t('所有字段') }}</LabelContent>
<!-- 一期不做 -->
<!-- <LabelContent :label="$t('字段预览')">
<bk-table
class="mt-[8px]"
:data="tableData"
Expand All @@ -36,15 +38,15 @@
<bk-table-column prop="phone" :label="$t('手机号')" />
<bk-table-column prop="organization" :label="$t('组织')" />
</bk-table>
</LabelContent>
</LabelContent> -->
</div>
</div>
</template>

<script setup lang="ts">
import { defineProps, onMounted, ref } from 'vue';
import { defineProps } from 'vue';
import Empty from '@/components/Empty.vue';
// import Empty from '@/components/Empty.vue';
import LabelContent from '@/components/layouts/LabelContent.vue';
defineProps({
Expand Down Expand Up @@ -72,19 +74,9 @@ defineProps({
// }
// };
const tableData = ref([]);
const isDataEmpty = ref(false);
const isDataError = ref(false);
onMounted(() => {
isDataEmpty.value = false;
isDataError.value = false;
setTimeout(() => {
if (tableData.value.length === 0) {
isDataEmpty.value = true;
}
}, 1000);
});
// const tableData = ref([]);
// const isDataEmpty = ref(false);
// const isDataError = ref(false);
</script>

<style lang="less" scoped>
Expand Down
Loading

0 comments on commit fcf2dbe

Please sign in to comment.