Skip to content

Commit

Permalink
Merge pull request #32 from HXTIA/feat-auth
Browse files Browse the repository at this point in the history
WIP:feat: 初始化授权认证页面结构
  • Loading branch information
HardenSG authored May 16, 2024
2 parents db0acb1 + 507f3c0 commit bc9ce52
Show file tree
Hide file tree
Showing 28 changed files with 484 additions and 113 deletions.
36 changes: 23 additions & 13 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { Provider } from 'react-redux'
import Taro, { useError, useLaunch } from '@tarojs/taro'
import Error from 'src/components/baseBuiltComp/Error'
import { TBizStudentGetInfo } from 'src/utils'
import { IStudentStruct, TBizStudentGetInfo, omit, setStorage } from 'src/utils'
import { store } from './store'
import './app.scss'
import { Get, getStorage, preloadResource, requestUrlCreator, trackJsError } from './utils'
import { JSON_MAP } from './static/SVG/lottie-map'

const filterRules = /node/
function App(props) {
useError((err) => {
console.log('错了', err)
trackJsError({
token: getStorage('userInfo')?.token ?? 'no_login',
errMsg: err.toString(),
location: '全局错误捕捉 ===> ' + err.toString(),
errName: 'global_err_catch',
})
if (!filterRules.test(err)) {
trackJsError({
token: getStorage('userInfo')?.token ?? 'no_login',
errMsg: err.toString(),
location: '全局错误捕捉 ===> ' + err.toString(),
errName: 'global_err_catch',
})
}
return <Error />
})

Expand All @@ -25,17 +28,22 @@ function App(props) {

/** 2. 校验获取用户信息 */
/** TODO: 需和后端确定响应体 */
let userinfo: TBizStudentGetInfo | null = null
let userinfo: IStudentStruct | null = null
if (token) {
try {
const wrap = await Get<TBizStudentGetInfo>({
url: requestUrlCreator({ absolutePath: '/userInfo' }),
const res = await Get<TBizStudentGetInfo>({
url: requestUrlCreator({ rootPath: 'WX_STU', absolutePath: '/getStudent' }),
silent: true,
})
if (wrap.isSuccess && wrap.data) {
userinfo = wrap.data
if (res.isSuccess) {
const {
data: { studentVo },
} = res
userinfo = {
...studentVo,
}
store.dispatch.common.update_UserInfo({
...(userinfo as any) /** TODO: 更新响应体结构 */,
...userinfo /** TODO: 更新响应体结构 */,
})
}
} catch (err) {
Expand All @@ -49,6 +57,8 @@ function App(props) {
Taro.loadFontFace({
family: 'AlibabaPuHuiTi',
source: 'url("https://hx.404fwf.cn/notifyBoard/AlibabaPuHuiTi.ttf")',
success: console.log,
fail: console.log,
})

store.dispatch.common.update_SystemInfo({
Expand Down
4 changes: 4 additions & 0 deletions src/components/baseBuiltComp/Forb/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
margin-top: 10%;
color: $base-element-color;
}

.back-btn {
margin-top: 120rpx;
}
}
}
4 changes: 3 additions & 1 deletion src/components/baseBuiltComp/Forb/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const Index = (props) => {
{props.children ? (
<props.children />
) : (
<Button onClick={goToIndex}>返回主页(退一步海阔天空)</Button>
<Button className='back-btn' onClick={goToIndex}>
返回主页 退一步海阔天空
</Button>
)}
</View>
</View>
Expand Down
1 change: 1 addition & 0 deletions src/components/baseBuiltComp/HocWrap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Authorize = (Component) => {
export const Forbidden = (Component, props?: any) => {
return React.memo(() => {
const state = useSelector((root: RootState) => root.common)
/** TODO: 更新字段取值口径 */
if (!state.system.coldStartSuccess) {
return <Loading isShow />
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Config } from '@tarojs/taro'
export const config: Config = {
pages: [
'pages/main/Index/index',
'pages/main/Calendar/index',
// 'pages/main/Calendar/index',
'pages/main/Manage/index',
'pages/main/My/index',
// 'pages/Detail/index',
Expand Down Expand Up @@ -46,12 +46,12 @@ export const config: Config = {
iconPath: './static/tabbarIcon/home.png',
selectedIconPath: './static/tabbarIcon/home_active.png',
},
{
pagePath: 'pages/main/Calendar/index',
text: '',
iconPath: './static/tabbarIcon/group.png',
selectedIconPath: './static/tabbarIcon/group_active.png',
},
// {
// pagePath: 'pages/main/Calendar/index',
// text: '',
// iconPath: './static/tabbarIcon/group.png',
// selectedIconPath: './static/tabbarIcon/group_active.png',
// },
{
pagePath: 'pages/main/Manage/index',
text: '',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Initial/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const organizationInterUrl = requestUrlCreator({

/** 登录路径 */
export const loginInterUrl = requestUrlCreator({
absolutePath: '/login',
absolutePath: '/getToken',
})
4 changes: 2 additions & 2 deletions src/pages/Initial/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Index = () => {
...state.system,
sessionStatus: 'ok',
})
console.log('token =', getStorage<IUserInfo>('userInfo').token)
console.log('token =', getStorage('userInfo').token)
console.log('state', store.getState().common.userInfo.token)
}
} else {
Expand All @@ -69,7 +69,7 @@ const Index = () => {
let hasGrade = useCallback(() => !!(gradeId && gradeName), [gradeId, gradeName])

// 检查本地存储有无token
if (!!getStorage<IUserInfo>('userInfo').token) {
if (!!getStorage('userInfo').token) {
// 有token,判断微信登录态是否过期
Taro.checkSession({
success: function () {
Expand Down
15 changes: 0 additions & 15 deletions src/pages/main/Manage/components/apply-manage.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.apply {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-color: rgb(110, 220, 220);
border: 1px solid black;
box-sizing: border-box;

.title {
font-size: 35rpx;
font-family: AlibabaPuHuiTi;
margin-bottom: 30rpx;
}

.ipt {
width: 80%;
height: 80rpx;
background-color: greenyellow;
margin-bottom: 120rpx;
padding: 20rpx;
font-size: 35rpx;
font-family: AlibabaPuHuiTi;
box-sizing: border-box;
border-radius: 15rpx;
}

.btn_groups {
width: 100%;
height: 120rpx;
display: flex;
justify-content: center;
align-items: center;

.btn {
display: flex;
align-items: center;
justify-content: center;
}

.apply-btn {
width: 30%;
height: 70%;
}

.history-btn {
width: 30%;
height: 70%;
}
}
}
54 changes: 54 additions & 0 deletions src/pages/main/Manage/components/apply-manage/components/apply.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Button, Input, View, Text } from '@tarojs/components'
import React, { FC, useCallback, useState } from 'react'
import { Post, requestUrlCreator, showToast } from 'src/utils'
import './apply.modules.scss'
import { TComponents } from '..'
import Frame from './frame'

const url = requestUrlCreator({
rootPath: 'WX_STU',
absolutePath: '/apply',
}) /** TODO: 替换真实接口 */
const Index: FC<{ setView: React.Dispatch<React.SetStateAction<TComponents>> }> = ({ setView }) => {
const [ipt, setIpt] = useState('')
const apply = useCallback(async () => {
if (!ipt.length) return
/** 替换真实接口 */
const result = await Post({
url,
data: {
code: ipt,
},
silent: true,
})

if (result.isSuccess) {
showToast({ icon: 'success', title: '申请成功' })
setTimeout(() => {
setView('feedback')
}, 1500)
} else {
result.handleException()
}
}, [ipt])

return (
<View className='apply'>
<Frame targetView='feedback' setView={setView}>
<Text>你可以申请权限获得管理员能力,请输入</Text>
<Text className='title'>请输入授权码</Text>
<Input className='ipt' value={ipt} onInput={({ detail: { value } }) => setIpt(value)} />
<View className='btn_groups'>
<Button className='apply-btn btn' onClick={apply}>
点击申请
</Button>
<Button className='history-btn btn' key='button'>
申请历史
</Button>
</View>
</Frame>
</View>
)
}

export default React.memo(Index)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.feedback_wrapper {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
height: 100%;
border: 1px solid black;
box-sizing: border-box;

.back-btn {
width: 100%;
height: 5%;
}

.list_wrapper {
width: 100%;
max-height: 95%;
overflow-y: scroll;
}

.list {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 100rpx;
padding: 0 30rpx 0 20rpx;
box-sizing: border-box;
background-color: aqua;

&_left {
display: flex;
flex-direction: column;
justify-content: center;

.name {
font-family: AlibabaPuHuiTi;
font-size: 35rpx;
}

.time {
font-size: 25rpx;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { FC, memo, useEffect, useState } from 'react'
import { Button, View } from '@tarojs/components'
import { timeFormat } from 'src/utils'
import './feedback.modules.scss'
import { TComponents } from '..'
import Frame from './frame'

const enumO = {
0: '申请中',
1: '已完成',
}

const List = memo(({ children }: any) => {
const [data, setData] = useState<any[]>()
useEffect(() => {
/** TODO: 模拟请求 */
new Promise((resolve) => {
setTimeout(() => {
resolve([
{
id: 1,
name: 'xbhsjabxhjasbhjxa',
time: Date.now(),
status: 0,
},
{
id: 2,
name: 'xsjabxhjasbxhjasbxhj',
time: Date.now(),
status: 1,
},
])
}, 0)
}).then((res: any[]) => {
setData(res)
})
}, [])
return data && data.map((d) => children(d))
})

const Index: FC<{ setView: React.Dispatch<React.SetStateAction<TComponents>> }> = ({ setView }) => {
return (
<Frame targetView='apply' setView={setView}>
<View className='feedback_wrapper'>
<View key='button' className='back-btn'>
返回申请
</View>
<View className='list_wrapper'>
<List>
{({ name, time, status }) => (
<View className='list'>
<View className='list_left'>
<View className='name'>{name}</View>
<View className='time'>{timeFormat(time)}</View>
</View>
<View className='list_right'>
<View className='status'>{enumO[status]}</View>
</View>
</View>
)}
</List>
</View>
</View>
</Frame>
)
}

export default React.memo(Index)
Loading

0 comments on commit bc9ce52

Please sign in to comment.