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: 组织树增加下钻功能 && 主入口增加语言切换&&重置数据源增加同时清除登录配置 #1885

Merged
merged 1 commit into from
Aug 12, 2024
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
73 changes: 72 additions & 1 deletion src/bk-login/pages/src/views/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@
{{ $t('忘记密码?') }}
</span>
</div>

<div class="language-switcher">
<div class="language-select" style="display: flex">
<p class="language-item" :class="{ active: activeTab === 'zh-cn' }" @click="handleSwitchLocale('zh-cn')">
<span id="ch" class="text-active ">中文</span>
</p>
<p class="language-item " :class="{ active: activeTab === 'en' }" @click="handleSwitchLocale('en')">
<span id="en" class="text-active">English</span>
</p>
</div>
</div>
</section>
<Protocol v-if="protocolVisible" @close="protocolVisible = false" />
</bk-form>
Expand All @@ -175,9 +184,13 @@ import Protocol from './components/protocol.vue';
import useAppStore from '@/store/app';
import CustomLogin from './components/custom-login.vue';
import { platformConfig } from '@/store/platformConfig';
import I18n, { t } from '@/language/index';
import Cookies from 'js-cookie';

const platformConfigData = platformConfig()
const appLogo = computed(() => platformConfigData.appLogo);
const activeTab = ref(I18n.global.locale.value)


interface Item {
id: string;
Expand Down Expand Up @@ -469,6 +482,31 @@ const showOptions = computed(() => {
inputTenant.value?.name && selectRef.value?.showPopover()
return options
})

// 语言切换
const handleSwitchLocale = (locale: string) => {
activeTab.value = locale
const api = `${window.BK_COMPONENT_API_URL}/api/c/compapi/v2/usermanage/fe_update_user_language/`;
const scriptId = 'jsonp-script';
const prevJsonpScript = document.getElementById(scriptId);
if (prevJsonpScript) {
document.body.removeChild(prevJsonpScript);
}
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = `${api}?language=${locale}`;
script.id = scriptId;
document.body.appendChild(script);

Cookies.set('blueking_language', locale, {
expires: 3600,
path: '/',
domain: window.BK_DOMAIN,
});
I18n.global.locale.value = locale as any;
document.querySelector('html')?.setAttribute('lang', locale);
// window.location.reload();
};
</script>

<style lang="postcss" scoped>
Expand Down Expand Up @@ -714,4 +752,37 @@ const showOptions = computed(() => {
align-items: center;
width: 100%;
}

.language-item {
width: 70px;
text-align: center;
background: #f5f7fa;
transform: skew(-15deg, 0deg);
display: inline-block;
height: 24px;
cursor: pointer;
.text-active {
display: block;
width: 70px;
height: 24px;
line-height: 24px;
font-size: 12px;
transform: skew(15deg, 0deg);
}
}
.language-switcher {
display: flex;
border-radius: 2px;
height: 24px;
line-height: 24px;
justify-content: end;
text-align: right;
margin-top: 23px;
}
.active {
background: #e1ecff;
.text-active {
color: #3a84ff;
}
}
</style>
17 changes: 15 additions & 2 deletions src/pages/src/hooks/useInfoBoxContent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { h } from 'vue';
import { Checkbox } from 'bkui-vue';
import { h, ref } from 'vue';

import { t } from '@/language/index';

// 重置数据源、删除租户前的确认信息
export const useInfoBoxContent = (data: any, type: string) => {
const resetIdpConfig = ref(false);

function updateMessage(data) {
resetIdpConfig.value = data;
}
const subContent = h('div', {
style: {
textAlign: 'left',
Expand Down Expand Up @@ -71,7 +77,14 @@ export const useInfoBoxContent = (data: any, type: string) => {
h('span', t('个用户。')),
]),
]),
type === 'tenant' ? null : h(Checkbox, {
style: {
marginTop: '14px',
},
value: resetIdpConfig.value,
onChange: updateMessage,
}, t('同时清除登录配置')),
]);

return { subContent };
return { subContent, resetIdpConfig };
};
2 changes: 1 addition & 1 deletion src/pages/src/http/dataSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const putUsersPassword = (params: ResetPasswordParams) => http.put(`/api/
/**
* 重置数据源
*/
export const deleteDataSources = (id: string) => http.delete(`/api/v1/web/data-sources/${id}/`);
export const deleteDataSources = (id: string, param: any) => http.delete(`/api/v1/web/data-sources/${id}/`, param);

/**
* 数据源关联资源信息
Expand Down
3 changes: 2 additions & 1 deletion src/pages/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,5 +538,6 @@
"关闭后用户将无法通过企业微信登录": "After deactivation, users will not be able to log in via WeChat Work",
"请将以下回调地址填写到企业微信配置内:": "Please enter the following callback address in the enterprise wechat configuration:",
"至": "to ",
"成功 ": " Success"
"成功 ": " Success",
"同时清除登录配置": "Clear the login configuration"
}
3 changes: 2 additions & 1 deletion src/pages/src/language/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,5 +538,6 @@
"关闭后用户将无法通过企业微信登录": "关闭后用户将无法通过企业微信登录",
"请将以下回调地址填写到企业微信配置内:": "请将以下回调地址填写到企业微信配置内:",
"至": "至",
"成功 ": "成功"
"成功 ": "成功",
"同时清除登录配置": "同时清除登录配置"
}
3 changes: 1 addition & 2 deletions src/pages/src/views/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@

<script setup lang="ts">
import { DownShape } from 'bkui-vue/lib/icon';
import Cookies from 'js-cookie';
import { computed, onMounted, reactive, ref } from 'vue';
import { useRoute } from 'vue-router';

Expand All @@ -144,7 +143,7 @@ import '@blueking/notice-component/dist/style.css';
import '@blueking/release-note/vue3/vue3.css';
import { logout } from '@/common/auth';
import { getTenantInfo, getVersionLogs } from '@/http';
import I18n, { t } from '@/language/index';
import { t } from '@/language/index';
import router from '@/router';
import { platformConfig, useUser } from '@/store';
import { handleSwitchLocale, logoConvert } from '@/utils';
Expand Down
26 changes: 23 additions & 3 deletions src/pages/src/views/organization/components/search-result-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@
</div>
<bk-tree
:data="treeData"
:expand-all="true"
label="name"
node-key="id"
children="children"
:prefix-icon="getPrefixIcon"
:async="{
callback: getRemoteData,
cache: true,
}"
>
</bk-tree>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { computed, ref, watch } from 'vue';

import { getDepartmentsList } from '@/http/organizationFiles';
import useAppStore from '@/store/app';

const appStore = useAppStore();

/**
* 根据organization_path转化为树结构
*/
const treeData = computed(() => {
const getData = (isChildren) => {
const orgs = appStore.currentOrg.organization_path || '';
let root = null;
let currentParent = null;
Expand All @@ -43,6 +47,8 @@ const treeData = computed(() => {
id: appStore.currentOrg.name === item ? appStore.currentOrg.id : item,
name: item,
children: [],
async: isChildren,
isOpen: appStore.currentOrg.name !== item,
};
if (!root) {
root = node;
Expand All @@ -52,8 +58,22 @@ const treeData = computed(() => {
currentParent = node;
});
return [root];
};

const treeData = ref([]);

watch(() => appStore.currentOrg.organization_path, async () => {
const { data = [] } = await getDepartmentsList(appStore.currentOrg.id, appStore.currentOrg.tenant_id);
treeData.value = getData(Boolean(data?.length));
});

const formatTreeData = (data = []) => data.map(item => ({ ...item, async: item.has_children }));

const getRemoteData = async (item: IOrg) => {
const res = await getDepartmentsList(item.id, appStore.currentTenant.id);
return formatTreeData(res?.data);
};

const getPrefixIcon = (item: { children?: any[] }, renderType: string) => {
if (renderType === 'node_action') {
return 'default';
Expand Down
1 change: 1 addition & 0 deletions src/pages/src/views/organization/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const tableListRef = ref()
const getList = async () => {
isLoading.value = true;
const tenantData = await getCurrentTenant();
appStore.currentTenant = tenantData?.data;
const collaborationData = await getCollaboration();
const deptData = await getDepartmentsList(0, tenantData?.data?.id);
isLoading.value = false;
Expand Down
15 changes: 9 additions & 6 deletions src/pages/src/views/setting/data-source/ConfigList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@
import { InfoBox, Message } from 'bkui-vue';
import { InfoLine, Upload } from 'bkui-vue/lib/icon';
import Cookies from 'js-cookie';
import { reactive, ref, onMounted, onBeforeUnmount} from 'vue';
import { onBeforeUnmount, onMounted, reactive, ref } from 'vue';
import { useRoute } from 'vue-router';

import HttpDetails from './HttpDetails.vue';

Expand All @@ -197,7 +198,6 @@ import { t } from '@/language/index';
import router from '@/router';
import { useUser } from '@/store';
import { dataRecordStatus } from '@/utils';
import { useRoute } from 'vue-router';
const route = useRoute();

const userStore = useUser();
Expand All @@ -212,14 +212,16 @@ const {
handleClick,
importDialog,
handleOperationsSync,
stopPolling
stopPolling,
} = useDataSource();

// 重置数据源
const handleReset = async () => {
try {
const res = await getRelatedResource(dataSource.value?.id);
const { subContent } = useInfoBoxContent(res.data, '');
const { subContent, resetIdpConfig } = useInfoBoxContent(res.data, '');


InfoBox({
width: 600,
infoType: 'warning',
Expand All @@ -228,8 +230,9 @@ const handleReset = async () => {
confirmText: t('重置'),
theme: 'danger',
onConfirm: () => {
const resetConfig = resetIdpConfig.value ? 'True' : 'False';
if (dataSource.value?.id) {
deleteDataSources(dataSource.value.id).then(() => {
deleteDataSources(dataSource.value.id, { reset_idp_config: resetConfig }).then(() => {
Message({ theme: 'success', message: t('数据源重置成功') });
initDataSourceList();
});
Expand Down Expand Up @@ -372,7 +375,7 @@ onMounted(() => {
if (route.query?.isLink) {
handleImport();
}
})
});

onBeforeUnmount(() => {
stopPolling();
Expand Down
Loading