Merge remote-tracking branch 'origin/main' into dev/chat

dev/chat
Lei OT 1 year ago
commit acbd36a8b4

@ -0,0 +1,16 @@
import { useState } from 'react'
export function useFormInput(initialValue) {
const [value, setValue] = useState(initialValue);
function handleChange(e) {
setValue(e.target.value);
}
const inputProps = {
value: value,
onChange: handleChange
};
return inputProps;
}

@ -0,0 +1,36 @@
import { useEffect, useState } from 'react'
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response
} else {
const message =
'Fetch error: ' + response.url + ' ' + response.status + ' (' +
response.statusText + ')'
const error = new Error(message)
error.response = response
throw error
}
}
export function useJson(url) {
const [data, setData] = useState(null)
useEffect(() => {
if (url) {
let ignore = false
fetch(url)
.then(checkStatus)
.then(response => response.json())
.then(json => {
if (!ignore) {
setData(json)
}
})
return () => {
ignore = true
}
}
}, [url])
return data
}

@ -6,6 +6,7 @@ import {
RouterProvider, RouterProvider,
} from 'react-router-dom' } from 'react-router-dom'
import { AuthContext } from '@/stores/AuthContext' import { AuthContext } from '@/stores/AuthContext'
import { ThemeContext } from '@/stores/ThemeContext'
import Auth from '@/stores/Auth' import Auth from '@/stores/Auth'
import App from '@/views/App' import App from '@/views/App'
import Standlone from '@/views/Standlone' import Standlone from '@/views/Standlone'
@ -59,15 +60,16 @@ const router = createBrowserRouter([
} }
]) ])
const auth = new Auth();
ReactDOM.createRoot(document.getElementById('root')).render( ReactDOM.createRoot(document.getElementById('root')).render(
// <React.StrictMode> // <React.StrictMode>
<AuthContext.Provider value={auth}> <ThemeContext.Provider value={{colorPrimary: '#1ba784', borderRadius: 4}}>
<AuthContext.Provider value={{loginUser: {userId: 1, openId: '123456789'}, permissionList: []}}>
<RouterProvider <RouterProvider
router={router} router={router}
fallbackElement={() => <div>Loading...</div>} fallbackElement={() => <div>Loading...</div>}
/> />
</AuthContext.Provider> </AuthContext.Provider>
</ThemeContext.Provider>
// </React.StrictMode> // </React.StrictMode>
) )

@ -5,8 +5,14 @@ class Auth {
constructor() { constructor() {
} }
//
// loginUser:
// HT 账号 OP_SN // HT 账号 OP_SN
userId = 1 userId = 1
openId = '123456789'
} }
export default Auth export default Auth

@ -1,7 +1,7 @@
import { createContext, useContext } from 'react' import { createContext, useContext } from 'react'
export const AuthContext = createContext(null) export const AuthContext = createContext({})
export function useAuth() { export function useAuthContext() {
return useContext(AuthContext) return useContext(AuthContext)
} }

@ -0,0 +1,7 @@
import { createContext, useContext } from 'react'
export const ThemeContext = createContext({})
export function useThemeContext() {
return useContext(ThemeContext)
}

@ -4,11 +4,14 @@ import {
Row, Col, Space, Descriptions, Avatar Row, Col, Space, Descriptions, Avatar
} from 'antd' } from 'antd'
import { useAuth } from '@/stores/AuthContext.js' import { useAuthContext } from '@/stores/AuthContext.js'
function AccountProfile() { function AccountProfile() {
const auth = useAuth() const { loginUser, permissionList } = useAuthContext()
console.info('useAuth: ' + auth.userId) console.info('loginUser: ')
console.info(loginUser)
console.info('permissionList: ')
console.info(permissionList)
useEffect(() => { useEffect(() => {
// //

@ -4,7 +4,7 @@ import { Layout, Menu, ConfigProvider, theme, Empty, Row, Col, Dropdown, Space,
import { DownOutlined } from "@ant-design/icons"; import { DownOutlined } from "@ant-design/icons";
import ErrorBoundary from '@/components/ErrorBoundary'; import ErrorBoundary from '@/components/ErrorBoundary';
import zhLocale from 'antd/locale/zh_CN'; import zhLocale from 'antd/locale/zh_CN';
import dayjs from 'dayjs'; import { useThemeContext } from '@/stores/ThemeContext'
import 'dayjs/locale/zh-cn'; import 'dayjs/locale/zh-cn';
import 'react-chat-elements/dist/main.css' import 'react-chat-elements/dist/main.css'
@ -17,6 +17,7 @@ const { Title } = Typography
function App() { function App() {
const {colorPrimary, borderRadius} = useThemeContext()
const href = useHref() const href = useHref()
//const shouldBeLogin = (isEmpty(userId) || isEmpty(website)) && (href.indexOf('/authorise/') == -1) //const shouldBeLogin = (isEmpty(userId) || isEmpty(website)) && (href.indexOf('/authorise/') == -1)
let defaultPath = 'follow' let defaultPath = 'follow'
@ -120,8 +121,8 @@ function App() {
<ConfigProvider <ConfigProvider
theme={{ theme={{
token: { token: {
colorPrimary: '#1ba784', colorPrimary: colorPrimary,
borderRadius: 4 borderRadius: borderRadius
}, },
algorithm: theme.defaultAlgorithm, algorithm: theme.defaultAlgorithm,
}} }}

@ -6,7 +6,7 @@ import { useRequest } from 'ahooks'
const { Title } = Typography const { Title } = Typography
const { Meta } = Card const { Meta } = Card
import { useAuth } from '@/stores/AuthContext.js' import { useAuthContext } from '@/stores/AuthContext.js'
function DingdingCallbak() { function DingdingCallbak() {
@ -18,10 +18,12 @@ function DingdingCallbak() {
console.info('code: ' + code) console.info('code: ' + code)
console.info('state: ' + state) console.info('state: ' + state)
const auth = useAuth() const { loginUser, permissionList } = useAuthContext()
console.info('useAuth: ' + auth.userId) console.info('loginUser: ')
console.info(loginUser)
console.info('permissionList: ')
console.info(permissionList)
auth.userId = 3344343
// const { data, error, loading } = useRequest(() => { // const { data, error, loading } = useRequest(() => {
// return new Promise((resolve) => { // return new Promise((resolve) => {
@ -31,6 +33,8 @@ function DingdingCallbak() {
// }); // });
// }); // });
setTimeout(() => { setTimeout(() => {
loginUser.userId = 999
loginUser.openId = '987654321'
navigate('/s/account/profile') navigate('/s/account/profile')
}, 1000); }, 1000);

@ -8,6 +8,9 @@ import {
StarFilled, ZoomInOutlined, StarOutlined, SearchOutlined, ImportOutlined StarFilled, ZoomInOutlined, StarOutlined, SearchOutlined, ImportOutlined
} from '@ant-design/icons' } from '@ant-design/icons'
import {useFormInput} from '@/hooks/useFormInput'
import {useJson} from '@/hooks/userFetch'
const { Search } = Input; const { Search } = Input;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
@ -99,7 +102,11 @@ const columns = [
]; ];
function SalesManagement() { function SalesManagement() {
const keywordProps = useFormInput('')
const countryList = useJson(`https://p9axztuwd7x8a7.mycht.cn/service-InfoSys/InfoSys/GetCountryList`)
console.info(countryList)
useEffect(() => { useEffect(() => {
}, []) }, [])
@ -111,13 +118,10 @@ function SalesManagement() {
<RangePicker /> <RangePicker />
</Col> </Col>
<Col span={6}> <Col span={6}>
<Search <Input placeholder='关键词' {...keywordProps} />
placeholder="关键词"
allowClear
onSearch={()=>{}}
/>
</Col> </Col>
<Col span={6}> <Col span={6}>
<Button icon={<ImportOutlined />} onClick={() => {console.info(keywordProps.value)}}>OK</Button>
<Button icon={<ImportOutlined />}>导入联系人</Button> <Button icon={<ImportOutlined />}>导入联系人</Button>
</Col> </Col>
</Row> </Row>

@ -4,7 +4,7 @@ import { Layout, Menu, ConfigProvider, theme, Empty, Row, Col, Dropdown, Space,
import { DownOutlined } from "@ant-design/icons"; import { DownOutlined } from "@ant-design/icons";
import '@/assets/App.css' import '@/assets/App.css'
import AppLogo from '@/assets/logo-gh.png' import AppLogo from '@/assets/logo-gh.png'
import { useStore } from '@/stores/StoreContext.js' import { useThemeContext } from '@/stores/ThemeContext'
import { isEmpty } from '@/utils/commons' import { isEmpty } from '@/utils/commons'
const { Header, Footer, Content } = Layout const { Header, Footer, Content } = Layout
@ -28,6 +28,9 @@ const items = [
}, },
]; ];
function Standlone() { function Standlone() {
const {colorPrimary, borderRadius} = useThemeContext()
const { const {
token: { colorBgContainer }, token: { colorBgContainer },
} = theme.useToken() } = theme.useToken()
@ -83,8 +86,8 @@ function Standlone() {
<ConfigProvider <ConfigProvider
theme={{ theme={{
token: { token: {
colorPrimary: '#1ba784', colorPrimary: colorPrimary,
borderRadius: 4 borderRadius: borderRadius
}, },
algorithm: theme.defaultAlgorithm, algorithm: theme.defaultAlgorithm,
}} }}

Loading…
Cancel
Save