Commit 72969146 authored by Bill's avatar Bill

Merge branch 'dev' into test

parents 89a7ece2 8a3511ae
import React from 'react' import React from 'react'
import { Layout, Menu } from 'antd' import { Layout, Menu, Avatar, Image } from 'antd'
import { AppstoreOutlined } from '@ant-design/icons' import { AppstoreOutlined } from '@ant-design/icons'
import { Link } from 'umi' import { Link } from 'umi'
import styles from '../styles/MenuSlider.less' import styles from '../styles/MenuSlider.less'
import { getRouters } from '@/utils/auth' import { getRouters } from '@/utils/auth'
import { isDev } from '@/constants' import { isDev } from '@/constants'
import {observer, inject} from 'mobx-react';
const { Sider } = Layout const { Sider } = Layout
export interface OuterSiderProps { export interface OuterSiderProps {
...@@ -14,7 +14,7 @@ export interface OuterSiderProps { ...@@ -14,7 +14,7 @@ export interface OuterSiderProps {
} }
const OuterSider: React.FC<OuterSiderProps> = (props) => { const OuterSider: React.FC<OuterSiderProps> = observer((props) => {
const { menuData, pathname = "/" } = props const { menuData, pathname = "/" } = props
const authRouters = getRouters() const authRouters = getRouters()
let defaultSelectedKeys: string = "" let defaultSelectedKeys: string = ""
...@@ -45,7 +45,13 @@ const OuterSider: React.FC<OuterSiderProps> = (props) => { ...@@ -45,7 +45,13 @@ const OuterSider: React.FC<OuterSiderProps> = (props) => {
const siderMenu = getSubMenu() const siderMenu = getSubMenu()
return <> return <>
<Sider collapsed={true} collapsedWidth={64} className={styles.wrapperSilder}> <Sider collapsed={true} collapsedWidth={64} className={styles.wrapperSilder}>
<div className={styles.userPic} /> {
props.UserStore.avatar
? <div className={styles.userPic}>
<img src={props.UserStore.avatar} className={styles.avatar} />
</div>
: <div className={styles.userPic} />
}
<ul className={styles.menuBox}> <ul className={styles.menuBox}>
{ {
siderMenu.map(item => ( siderMenu.map(item => (
...@@ -60,8 +66,9 @@ const OuterSider: React.FC<OuterSiderProps> = (props) => { ...@@ -60,8 +66,9 @@ const OuterSider: React.FC<OuterSiderProps> = (props) => {
</ul> </ul>
</Sider> </Sider>
</> </>
} })
OuterSider.defaultProps = {} OuterSider.defaultProps = {}
export default OuterSider // export default OuterSider
\ No newline at end of file export default inject('UserStore')(OuterSider)
...@@ -33,11 +33,8 @@ const GlobalHeaderRight: React.FC<{}> = (props) => { ...@@ -33,11 +33,8 @@ const GlobalHeaderRight: React.FC<{}> = (props) => {
if (SOCKET_URL && (!ws.current || ws.current.readyState === 3) && userInfo) { if (SOCKET_URL && (!ws.current || ws.current.readyState === 3) && userInfo) {
const url = `${SOCKET_URL}/report/websocket?memberId=${userInfo.memberId}&roleId=${userInfo.memberRoleId}&token=${userInfo.token}&source=${1}`; const url = `${SOCKET_URL}/report/websocket?memberId=${userInfo.memberId}&roleId=${userInfo.memberRoleId}&token=${userInfo.token}&source=${1}`;
ws.current = new WebSocket(url); ws.current = new WebSocket(url);
ws.current.onopen = (e) => { ws.current.onopen = (e) => {}
console.log(e)
}
ws.current.onmessage = (e) => { ws.current.onmessage = (e) => {
console.log(e)
const data = JSON.parse(e.data); const data = JSON.parse(e.data);
if(data.type === NOT_READ_MESSAGE) { if(data.type === NOT_READ_MESSAGE) {
setMessage(data.data); setMessage(data.data);
......
...@@ -48,6 +48,11 @@ ...@@ -48,6 +48,11 @@
background: rgba(255, 255, 255, 0.2); background: rgba(255, 255, 255, 0.2);
margin: 16px; margin: 16px;
border-radius: 50%; border-radius: 50%;
overflow: hidden;
.avatar {
width: 32px;
height: 32px;
}
} }
.wrapperSilder { .wrapperSilder {
...@@ -117,4 +122,4 @@ ...@@ -117,4 +122,4 @@
height: 48px !important; height: 48px !important;
line-height: 48px !important; line-height: 48px !important;
} }
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ import StatusTag from '@/components/StatusTag'; ...@@ -12,6 +12,7 @@ import StatusTag from '@/components/StatusTag';
import home_user from '@/assets/imgs/home_user.png'; import home_user from '@/assets/imgs/home_user.png';
import { UPLOAD_TYPE } from '@/constants' import { UPLOAD_TYPE } from '@/constants'
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
import {observer, inject} from 'mobx-react';
interface Iprops {} interface Iprops {}
const WEEKDAYS = ["天", "一","二", "三", "四", "五","六"]; const WEEKDAYS = ["天", "一","二", "三", "四", "五","六"];
...@@ -31,12 +32,11 @@ function reducer(state, action) { ...@@ -31,12 +32,11 @@ function reducer(state, action) {
} }
} }
const UserCenter: React.FC<Iprops> = () => { const UserCenter: React.FC<Iprops> = (props) => {
// const [uploadLoading, setUpload]
const today = moment(); const today = moment();
const userAuth = getAuth(); const userAuth = getAuth();
const hasChangeMemberAuth = userAuth?.urls.includes(EDIT_USER_URL); // const hasChangeMemberAuth = userAuth?.urls.includes(EDIT_USER_URL);
const hasCenterAuth = userAuth?.urls.includes(USER_CENTER_URL); // const hasCenterAuth = userAuth?.urls.includes(USER_CENTER_URL);
const currentRole = userAuth.roles.filter((item) => item.memberRoleId === userAuth.memberRoleId) const currentRole = userAuth.roles.filter((item) => item.memberRoleId === userAuth.memberRoleId)
const [state, dispatch] = useReducer(reducer, { loading: false, logo: userAuth.logo}) const [state, dispatch] = useReducer(reducer, { loading: false, logo: userAuth.logo})
if(!userAuth) { if(!userAuth) {
...@@ -65,6 +65,7 @@ const UserCenter: React.FC<Iprops> = () => { ...@@ -65,6 +65,7 @@ const UserCenter: React.FC<Iprops> = () => {
.then((res) => { .then((res) => {
if(res.code === 1000) { if(res.code === 1000) {
dispatch({type: 'done', payload: {url: data}}) dispatch({type: 'done', payload: {url: data}})
props.UserStore.setUserAvatar(data)
} }
}) })
} }
...@@ -146,4 +147,5 @@ const UserCenter: React.FC<Iprops> = () => { ...@@ -146,4 +147,5 @@ const UserCenter: React.FC<Iprops> = () => {
) )
} }
export default UserCenter // export default UserCenter
export default inject('UserStore')(observer(UserCenter))
import { action, computed, observable, runInAction } from 'mobx' import { action, computed, observable, runInAction } from 'mobx'
import { ILoginModule } from '@/module/userModule' import { ILoginModule } from '@/module/userModule'
import { getAuth } from '@/utils/auth' import { getAuth } from '@/utils/auth'
import { localStorage } from '@/utils/storage' import { localStorage } from '@/utils/storage'
// import { userDetailGet } from '@/services/user' // import { userDetailGet } from '@/services/user'
// const userInfo = localStorage.getItem('userInfo') // const userInfo = localStorage.getItem('userInfo')
class LoginStore implements ILoginModule { class LoginStore implements ILoginModule {
@observable public username: string = 'admin'; @observable public username: string = 'admin';
@observable public password: string = "123456"; @observable public password: string = "123456";
@observable public res: object = {}; @observable public res: object = {};
@observable public userInfo = getAuth() @observable public userInfo = getAuth();
@observable public avatar = this.userInfo.logo;
// 可以改变对应的状态值
// @todo 接入更新用户信息接口 // 可以改变对应的状态值
@action.bound // @todo 接入更新用户信息接口
public async updateUserInfo() { @action.bound
// try { public async updateUserInfo() {
// const res = await userDetailGet() // try {
// runInAction(() => { // const res = await userDetailGet()
// this.userInfo = res.data; // runInAction(() => {
// localStorage.setItem('userInfo', JSON.stringify(this.userInfo)) // this.userInfo = res.data;
// }) // localStorage.setItem('userInfo', JSON.stringify(this.userInfo))
// } catch (error) { // })
// return error // } catch (error) {
// } // return error
} // }
}
// 当有时需要拼接状态,但又不希望改变原有状态,可以采取如下, 类似vue中的computed
@computed // 当有时需要拼接状态,但又不希望改变原有状态,可以采取如下, 类似vue中的computed
public get printInfo(): string { @computed
return `hello, ${this.username}, your password is ${this.password}` public get printInfo(): string {
} return `hello, ${this.username}, your password is ${this.password}`
}
// 可以改变对应的状态值
@action.bound // 可以改变对应的状态值
public setUsername(username: string) { @action.bound
this.username = username; public setUsername(username: string) {
} this.username = username;
}
@action.bound
public setPassword(password: string) { @action.bound
this.password = password; public setPassword(password: string) {
} this.password = password;
}
// 异步修改数据, 需要使用bound,保持this指向当前store
@action.bound // 异步修改数据, 需要使用bound,保持this指向当前store
public async handleLogin() { @action.bound
try { public async handleLogin() {
let params = { try {
username: this.username, let params = {
password: this.password username: this.username,
} password: this.password
const result = {} }
runInAction(() => { const result = {}
this.res = result runInAction(() => {
}) this.res = result
})
return result
} catch (error) { return result
return error } catch (error) {
} return error
} }
} }
// 改变用户的头像
export default LoginStore @action.bound
public setUserAvatar(link: string) {
this.avatar = link;
}
}
export default LoginStore
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment