@yyp92-cli/template-react-mobile 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/template/src/components/layout/content/index.tsx +27 -8
- package/template/src/components/layout/navBar/index.tsx +4 -16
- package/template/src/components/login/index.tsx +11 -1
- package/template/src/pages/home/index.tsx +16 -0
- package/template/src/router/router.tsx +12 -3
- package/template/src/store/login.ts +4 -7
- package/template/src/store/token.ts +28 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ import { permissionStore } from '@/store/permission'
|
|
|
6
6
|
import { routerConfig, type RouterConfigItemProps } from '@/router/router'
|
|
7
7
|
|
|
8
8
|
import styles from './index.module.scss'
|
|
9
|
+
import { localCache } from '@/utils'
|
|
10
|
+
import { LOGIN_TOKEN } from '@/global/constants'
|
|
9
11
|
|
|
10
12
|
interface ContentProps {
|
|
11
13
|
[key: string]: any
|
|
@@ -35,21 +37,38 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
35
37
|
navigate('/403')
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
else {
|
|
41
|
+
const token = localCache.getCache(LOGIN_TOKEN)
|
|
42
|
+
|
|
43
|
+
if (!token) {
|
|
44
|
+
navigate('/login')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
38
47
|
}, [location])
|
|
39
48
|
|
|
40
49
|
|
|
41
50
|
// ********** 渲染 **********
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
const renderContent = () => {
|
|
52
|
+
const token = localCache.getCache(LOGIN_TOKEN)
|
|
53
|
+
|
|
54
|
+
if (!token || !currentRouter) {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className={styles.layoutContent}>
|
|
60
|
+
<NavBar title={currentRouter?.label} />
|
|
61
|
+
|
|
62
|
+
<div className={styles.wraper}>
|
|
63
|
+
<Outlet />
|
|
64
|
+
</div>
|
|
45
65
|
|
|
46
|
-
|
|
47
|
-
<Outlet />
|
|
66
|
+
{!currentRouter?.showFullScreen && <TabBar />}
|
|
48
67
|
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
49
70
|
|
|
50
|
-
|
|
51
|
-
</div>
|
|
52
|
-
)
|
|
71
|
+
return renderContent()
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
export default Content
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import {FC, ReactNode} from 'react'
|
|
2
|
+
import {useNavigate} from 'react-router-dom'
|
|
3
3
|
import {NavBar as AntNavBar} from 'antd-mobile'
|
|
4
|
-
import { menusStore } from '@/store/menus'
|
|
5
4
|
import styles from './index.module.scss'
|
|
6
5
|
|
|
7
6
|
interface NavBarProps {
|
|
8
|
-
title?:
|
|
7
|
+
title?: ReactNode
|
|
9
8
|
backUrl?: string
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -13,18 +12,7 @@ const NavBar: FC<NavBarProps> = ({
|
|
|
13
12
|
title = '首页',
|
|
14
13
|
backUrl
|
|
15
14
|
}) => {
|
|
16
|
-
const location = useLocation()
|
|
17
15
|
const navigate = useNavigate()
|
|
18
|
-
const {menus} = menusStore()
|
|
19
|
-
const [curTitle, setCurTitle] = useState(title)
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const {pathname} = location ?? {}
|
|
23
|
-
const newPathname = pathname.slice(1)
|
|
24
|
-
|
|
25
|
-
const newCurrentRouter: any = menus?.find((group: any) => group.key === newPathname) ?? {}
|
|
26
|
-
setCurTitle(newCurrentRouter?.label ?? title)
|
|
27
|
-
}, [location])
|
|
28
16
|
|
|
29
17
|
|
|
30
18
|
// ********* 操作 *********
|
|
@@ -40,7 +28,7 @@ const NavBar: FC<NavBarProps> = ({
|
|
|
40
28
|
<div className={styles.navWraper}>
|
|
41
29
|
<AntNavBar
|
|
42
30
|
onBack={goBack}
|
|
43
|
-
>{
|
|
31
|
+
>{title}</AntNavBar>
|
|
44
32
|
</div>
|
|
45
33
|
)
|
|
46
34
|
}
|
|
@@ -4,6 +4,8 @@ import { Button, Form, Input } from 'antd-mobile'
|
|
|
4
4
|
import { EyeInvisibleOutline, EyeOutline } from 'antd-mobile-icons'
|
|
5
5
|
import { permissionStore } from '@/store/permission'
|
|
6
6
|
import { menusStore } from '@/store/menus'
|
|
7
|
+
import { userInfoStore } from '@/store/login'
|
|
8
|
+
import { tokenStore } from '@/store/token'
|
|
7
9
|
import { filterMenu } from '@/utils'
|
|
8
10
|
import { routerConfig } from '@/router/router'
|
|
9
11
|
|
|
@@ -25,7 +27,8 @@ const defaultList = [
|
|
|
25
27
|
'todo',
|
|
26
28
|
'message',
|
|
27
29
|
'personalCenter',
|
|
28
|
-
'detail',
|
|
30
|
+
'home/detail',
|
|
31
|
+
'home/screen-detail',
|
|
29
32
|
]
|
|
30
33
|
|
|
31
34
|
const Login: React.FC<LoginProps> = ({ }) => {
|
|
@@ -36,6 +39,8 @@ const Login: React.FC<LoginProps> = ({ }) => {
|
|
|
36
39
|
setPermissions
|
|
37
40
|
} = permissionStore()
|
|
38
41
|
const { setMenus } = menusStore()
|
|
42
|
+
const { setToken } = tokenStore()
|
|
43
|
+
const { setUserInfo } = userInfoStore()
|
|
39
44
|
|
|
40
45
|
const [visiblePassword, setVisiblePassword] = useState<boolean>(false)
|
|
41
46
|
|
|
@@ -46,6 +51,11 @@ const Login: React.FC<LoginProps> = ({ }) => {
|
|
|
46
51
|
|
|
47
52
|
if (username === 'yang' && password === '123456') {
|
|
48
53
|
setPermissions(defaultList)
|
|
54
|
+
setUserInfo({
|
|
55
|
+
userName: username,
|
|
56
|
+
userId: '3333'
|
|
57
|
+
})
|
|
58
|
+
setToken('222')
|
|
49
59
|
|
|
50
60
|
// todo模拟接口
|
|
51
61
|
setTimeout(() => {
|
|
@@ -44,6 +44,22 @@ const Home = () => {
|
|
|
44
44
|
>设置姓名</Button>
|
|
45
45
|
</div>
|
|
46
46
|
|
|
47
|
+
<div style={{ marginTop: 20 }}>
|
|
48
|
+
<Button
|
|
49
|
+
color="primary"
|
|
50
|
+
onClick={() => {
|
|
51
|
+
navigate('/home/detail')
|
|
52
|
+
}}
|
|
53
|
+
>详情</Button>
|
|
54
|
+
|
|
55
|
+
<Button
|
|
56
|
+
color="primary"
|
|
57
|
+
onClick={() => {
|
|
58
|
+
navigate('/home/screen-detail')
|
|
59
|
+
}}
|
|
60
|
+
>全局屏详情</Button>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
47
63
|
{/* <DatePicker
|
|
48
64
|
title='时间选择'
|
|
49
65
|
visible={true}
|
|
@@ -83,12 +83,21 @@ export const routerConfig: RouterConfigItemProps[] = [
|
|
|
83
83
|
// 需要全屏显示的页面
|
|
84
84
|
{
|
|
85
85
|
label: '详情',
|
|
86
|
-
key: 'detail',
|
|
87
|
-
path: 'detail',
|
|
86
|
+
key: 'home/detail',
|
|
87
|
+
path: 'home/detail',
|
|
88
|
+
icon: null,
|
|
89
|
+
hideInMenu: true,
|
|
90
|
+
showFullScreen: false,
|
|
91
|
+
element: <>详情</>,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: '全屏详情',
|
|
95
|
+
key: 'home/screen-detail',
|
|
96
|
+
path: 'home/screen-detail',
|
|
88
97
|
icon: null,
|
|
89
98
|
hideInMenu: true,
|
|
90
99
|
showFullScreen: true,
|
|
91
|
-
element:
|
|
100
|
+
element: <>全屏详情</>,
|
|
92
101
|
},
|
|
93
102
|
]
|
|
94
103
|
},
|
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { create } from 'zustand'
|
|
5
5
|
import { persist } from 'zustand/middleware';
|
|
6
|
+
import { USER_INFO } from '@/global/constants';
|
|
6
7
|
|
|
7
8
|
type UserInfoStoreState = {
|
|
8
9
|
userInfo: {
|
|
9
10
|
userId: string,
|
|
10
11
|
userName: string
|
|
11
|
-
}
|
|
12
|
-
token: string
|
|
12
|
+
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
type UserInfoStoreActions = {
|
|
16
16
|
setUserInfo: (
|
|
17
17
|
nextUserInfo: UserInfoStoreState['userInfo']
|
|
18
|
-
) => void
|
|
19
|
-
setToken: (token: string) => void
|
|
18
|
+
) => void
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
type UserInfoStore = UserInfoStoreState & UserInfoStoreActions
|
|
@@ -28,12 +27,10 @@ export const userInfoStore = create<UserInfoStore>()(
|
|
|
28
27
|
userName: '小明',
|
|
29
28
|
userId: '111'
|
|
30
29
|
},
|
|
31
|
-
token: '',
|
|
32
30
|
setUserInfo: (userInfo) => set({userInfo}),
|
|
33
|
-
setToken: (token) => set({token})
|
|
34
31
|
}),
|
|
35
32
|
{
|
|
36
|
-
name:
|
|
33
|
+
name: USER_INFO
|
|
37
34
|
}
|
|
38
35
|
)
|
|
39
36
|
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * 用户信息
|
|
3
|
+
*/
|
|
4
|
+
import { create } from 'zustand'
|
|
5
|
+
import { persist } from 'zustand/middleware';
|
|
6
|
+
import { LOGIN_TOKEN } from '@/global/constants';
|
|
7
|
+
|
|
8
|
+
type UserInfoStoreState = {
|
|
9
|
+
token: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type UserInfoStoreActions = {
|
|
13
|
+
setToken: (token: string) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type UserInfoStore = UserInfoStoreState & UserInfoStoreActions
|
|
17
|
+
|
|
18
|
+
export const tokenStore = create<UserInfoStore>()(
|
|
19
|
+
persist(
|
|
20
|
+
(set) => ({
|
|
21
|
+
token: '',
|
|
22
|
+
setToken: (token) => set({token})
|
|
23
|
+
}),
|
|
24
|
+
{
|
|
25
|
+
name: LOGIN_TOKEN
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
)
|