From 91de5f4986935a85a34fd715df18902ce9199971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B9=E6=B3=A1=E6=B3=A1=E7=9A=84=E5=9B=A2=E5=AD=90?= Date: Wed, 20 Sep 2023 01:35:51 +0800 Subject: [PATCH] feat:global-tenant --- threadpool/console-new/src/api/tenant.ts | 32 +++++++++++++ .../src/components/header/index.tsx | 47 +++++++++++++++++-- threadpool/console-new/src/context/index.tsx | 29 +++++++++++- 3 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 threadpool/console-new/src/api/tenant.ts diff --git a/threadpool/console-new/src/api/tenant.ts b/threadpool/console-new/src/api/tenant.ts new file mode 100644 index 00000000..f947040b --- /dev/null +++ b/threadpool/console-new/src/api/tenant.ts @@ -0,0 +1,32 @@ +import request from '@/utils'; +import { useContext, useEffect } from 'react'; +import { MyContext } from '@/context'; + +const getTenantList = async () => { + return await request('/tenant/query/page', { + method: 'POST', + }) + .then(response => { + console.log('租户列表返回', response); + const { setTenantInfo } = useContext(MyContext); + useEffect(() => { + setTenantInfo(response.data); + }); + }) + .catch(err => { + console.log('租户列表获取出错:', err); + }); +}; + +const updataTenant = async (formData: { size: number }) => { + return await request('/tenant/update', { + method: 'POST', + params: { + ...formData, + }, + }).catch(err => { + console.log('租户列表获取出错:', err); + }); +}; + +export { getTenantList, updataTenant }; diff --git a/threadpool/console-new/src/components/header/index.tsx b/threadpool/console-new/src/components/header/index.tsx index dddb3252..21e64e1f 100644 --- a/threadpool/console-new/src/components/header/index.tsx +++ b/threadpool/console-new/src/components/header/index.tsx @@ -1,14 +1,16 @@ import React, { useContext } from 'react'; import style from './index.module.less'; import { UserOutlined } from '@ant-design/icons'; -import { Avatar, Button, Col, Dropdown, Row, Switch } from 'antd'; -import { useThemeMode } from '@/hooks'; +import { Avatar, Button, Col, Dropdown, Row, Switch, Select, Space } from 'antd'; +import { getTenantList } from '../../api/tenant'; +import { useThemeMode } from '@/hooks/useThemeMode'; import { MyContext } from '@/context'; import IconFont from '@/components/icon'; const HeaderChild = () => { const { isDark, setIsDark } = useThemeMode(); const { lang, setLang } = useContext(MyContext); + const { setTenantInfo } = useContext(MyContext); const items = [ { @@ -37,6 +39,36 @@ const HeaderChild = () => { }, ]; + const tenantList = [ + { + value: 'option1', + key: 1, + id: undefined, + tenantId: '', + tenantName: '', + owner: '', + tenantDesc: '', + }, + { + value: 'option2', + key: 2, + id: undefined, + tenantId: '', + tenantName: '', + owner: '', + tenantDesc: '', + }, + ]; + + const handleTenantChange = (value: string) => { + setTenantInfo(tenantList[0]); + }; + + getTenantList().then((resolve: any) => { + console.log('tenantList', resolve); + // this.tenantList = resolve; + }); + return (
@@ -44,7 +76,16 @@ const HeaderChild = () => {
- + + +