Skip to content

Commit

Permalink
Merge pull request #34 from HXTIA/feat-my
Browse files Browse the repository at this point in the history
feat:新增我的页面
  • Loading branch information
HardenSG authored May 18, 2024
2 parents bc9ce52 + 30b074d commit a7a223a
Show file tree
Hide file tree
Showing 57 changed files with 1,276 additions and 556 deletions.
29 changes: 12 additions & 17 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Provider } from 'react-redux'
import Taro, { useError, useLaunch } from '@tarojs/taro'
import Error from 'src/components/baseBuiltComp/Error'
import { IStudentStruct, TBizStudentGetInfo, omit, setStorage } from 'src/utils'
import { IStudentStruct, TBizStudentGetInfo } 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/
const filterRules = /evaluating 'n\[0\]\.node'|Cannot read property 'node' of null/
function App(props) {
useError((err) => {
console.log('错了', err)
if (!filterRules.test(err)) {
console.log('错了', err)

trackJsError({
token: getStorage('userInfo')?.token ?? 'no_login',
errMsg: err.toString(),
location: '全局错误捕捉 ===> ' + err.toString(),
errName: 'global_err_catch',
err_name: 'global_err_catch',
})
}
return <Error />
Expand All @@ -31,20 +32,13 @@ function App(props) {
let userinfo: IStudentStruct | null = null
if (token) {
try {
const res = await Get<TBizStudentGetInfo>({
const { isSuccess, data } = await Get<TBizStudentGetInfo>({
url: requestUrlCreator({ rootPath: 'WX_STU', absolutePath: '/getStudent' }),
silent: true,
})
if (res.isSuccess) {
const {
data: { studentVo },
} = res
userinfo = {
...studentVo,
}
store.dispatch.common.update_UserInfo({
...userinfo /** TODO: 更新响应体结构 */,
})
if (isSuccess) {
userinfo = data.studentVo
store.dispatch.userinfoModel.update_UserInfo(userinfo)
}
} catch (err) {
console.log(' === 获取用户信息请求错误 === ', err)
Expand All @@ -61,10 +55,11 @@ function App(props) {
fail: console.log,
})

store.dispatch.common.update_SystemInfo({
const { classId = 0, collegeId = 0, gradeId = 0 } = userinfo || {}
store.dispatch.systemModel.update_SystemInfo({
sessionStatus: !token ? 'fail' : 'ok',
coldStartSuccess: true,
hasAccountCompleted: !!(userinfo || false) /** TODO: 是否具备完整信息需要再确认下 */,
hasAccountCompleted: collegeId > 0 && gradeId > 0 && classId > 0,
})
console.log('==== 应用冷启动初始化成功! ====')
})
Expand Down
27 changes: 26 additions & 1 deletion src/common-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,39 @@ import { getStorage, setStorage } from './utils/storage'
export interface IUserInfo {
token?: string
username?: string
userActor?: string
avatarUrl?: string
wechatId?: string
/** 是否绑定授权码 */
isBindManage?: boolean
/** 所属组织 */
orgId?: number
orgName?: string
gradeId?: number
gradeName?: string
classId?: number
className?: string
organization?: {
collegeId: string
gradeId: string
classId: string
}
organizationVo?: {
classVo?: {
gradeId: string
id: number
name: string
}
college?: {
id: number
logoUrl: string
name: string
}
grade?: {
collegeId: string
id: number
name: string
}
}
}

/** 系统运行所需全局缓存 */
Expand Down
10 changes: 6 additions & 4 deletions src/components/baseBuiltComp/HocWrap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Guide from './components/guideInit'
/** @HOC 校验登陆态 */
export const Authorize = (Component) => {
return React.memo(() => {
const state = useSelector((root: RootState) => root.common.system)
const state = useSelector((root: RootState) => root.systemModel)
console.log('=== sysState ===', state)
if (!state.coldStartSuccess) {
return <Loading isShow />
} else {
Expand All @@ -23,12 +24,13 @@ export const Authorize = (Component) => {
/** @HOC 禁止页面要求必须是已授权的 */
export const Forbidden = (Component, props?: any) => {
return React.memo(() => {
const state = useSelector((root: RootState) => root.common)
const sysState = useSelector((root: RootState) => root.systemModel)
const userState = useSelector((root: RootState) => root.userinfoModel)
/** TODO: 更新字段取值口径 */
if (!state.system.coldStartSuccess) {
if (!sysState.coldStartSuccess) {
return <Loading isShow />
} else {
if (state.userInfo.isBindManage) return <Component />
if (userState.isBindManage) return <Component />
return <ForbiddenComp>{props}</ForbiddenComp>
}
})
Expand Down
33 changes: 17 additions & 16 deletions src/components/common/InputMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { View } from '@tarojs/components'
import Mask from '../Mask'
import './index.module.scss'
import VirtialList from '../VirtualList'
import { TInputMenuItem } from './types'

interface IInputMenuProps {
/** 下拉列表 */
Expand All @@ -26,6 +27,8 @@ interface IInputMenuProps {
onPageScrollToLower?: () => void
/** 输入值改变回调 */
handleInputChange?: (value) => void
/** 输入值改变回调 */
clickMark?: () => void
}

const Index = ({
Expand All @@ -37,6 +40,7 @@ const Index = ({
inputPlace = '请输入...',
onPageScrollToLower,
handleInputChange,
clickMark = () => {},
inputStyle,
listStyle,
}: IInputMenuProps) => {
Expand All @@ -51,15 +55,18 @@ const Index = ({

console.log('menuLists', menuLists)
/** 下拉框数据是否存在 */
const isCanShowMenu = useMemo(() => menuLists && menuLists.length, [menuLists])
const isCanShowMenu = useMemo(() => menuLists && menuLists.length != 0, [menuLists])

/** 下拉框显示状态 */
const clickShowMenu = () => {
if (status === true) {
clickMark()
}
setStatus(!status)
}
/** 点击item选项 */
const clickItem = (item) => {
setValue(item)
setValue(item.name)
setStatus(false)
handleInputChange?.(item)
}
Expand All @@ -74,11 +81,14 @@ const Index = ({
// const total = 15

/** 渲染列表Item */
const renderFunc = (item, index, pageIndex) => {
const renderFunc = (item: TInputMenuItem, index, pageIndex) => {
return (
<View className='InputMenu__Container__item' onClick={() => clickItem(item.Value)}>
<View
className='InputMenu__Container__item'
onClick={() => clickItem({ name: item.name, id: item.id })}
>
<View className='InputMenu__Container__leftIcon'></View>
<View className='InputMenu__Container__text'>{`${item.Value}`}</View>
<View className='InputMenu__Container__text'>{`${item.name}`}</View>
</View>
)
}
Expand All @@ -97,7 +107,7 @@ const Index = ({
alignItems: 'center',
}}
>
没有更多了
没啦没啦,真的没有了~
</View>
)
}
Expand Down Expand Up @@ -186,16 +196,7 @@ const Index = ({
</>
) : (
/** 下拉框数据不存在 */
<Divider
style={{
color: '#ffffff',
borderColor: '##ffffff',
padding: '0 30rpx',
margin: '0',
}}
>
暂无数据
</Divider>
<Divider>暂无数据</Divider>
)
}
</View>
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/InputMenu/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** 输入下拉菜单列表的类型 */
export type TInputMenuItem = {
Id: number
Value: string
id: number
name: string
}

/** 任务列表的类型 */
Expand Down
14 changes: 7 additions & 7 deletions src/components/common/VirtualList/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CSSProperties, ComponentClass } from 'react'

/** 输入下拉菜单列表的类型 */
export type TInputMenuItem = {
Id: number
Value: string
}
// /** 输入下拉菜单列表的类型 */
// export type TInputMenuItem = {
// id: number
// name: string
// }

/** 任务列表的类型 */
export type TInputMenuList = TInputMenuItem[]
// /** 任务列表的类型 */
// export type TInputMenuList = TInputMenuItem[]

export interface BaseComponent {
className?: string
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export const config: Config = {
{
pagePath: 'pages/main/Manage/index',
text: '',
iconPath: './static/tabbarIcon/my.png',
selectedIconPath: './static/tabbarIcon/my_active.png',
iconPath: './static/tabbarIcon/manage.png',
selectedIconPath: './static/tabbarIcon/manage_active.png',
},
{
pagePath: 'pages/main/My/index',
text: '',
iconPath: './static/tabbarIcon/manage.png',
selectedIconPath: './static/tabbarIcon/manage_active.png',
iconPath: './static/tabbarIcon/my.png',
selectedIconPath: './static/tabbarIcon/my_active.png',
},
],
},
Expand Down
3 changes: 3 additions & 0 deletions src/model/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './runtime-model'
export * from './system-model'
export * from './userinfo-model'
41 changes: 41 additions & 0 deletions src/model/runtime-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createModel } from '@rematch/core'
import { RootModel } from 'src/models'
import { getStorage, setStorage } from '../utils/storage'

type TOrganizationCache = {
/** 所属组织 */
orgId?: number
orgName?: string
gradeId?: number
gradeName?: string
classId?: number
className?: string
courseIds?: number[]
}
/** 系统运行所需全局缓存 */
export interface IRuntimeCache {
organizationCache: TOrganizationCache
}

/** 默认store值 从storage中激活 */
export const defaultRuntimeValue: IRuntimeCache = {
organizationCache: getStorage('runtimeCache').organizationCache || {},
}

export const runtimeModel = createModel<RootModel>()({
state: defaultRuntimeValue,
reducers: {
writeOrgCache(
state: IRuntimeCache,
newCache: Partial<TOrganizationCache>,
needLasting?: boolean,
) {
state.organizationCache = newCache
state.organizationCache = Object.assign({}, state.organizationCache, newCache)
if (needLasting) {
setStorage('runtimeCache', state)
}
return state
},
},
})
31 changes: 31 additions & 0 deletions src/model/system-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createModel } from '@rematch/core'
import { RootModel } from 'src/models'

/** 系统运行所需全局缓存 */
export interface ISystemInfo {
/** session状态 */
sessionStatus?: string
/** 冷启动初始化是否完成 */
coldStartSuccess?: boolean
/** 是否完善用户信息 */
hasAccountCompleted?: boolean
/** 是否弹过授权弹窗 */
isAuthorizeSubscribePop?: boolean
}

/** 默认store值 从storage中激活 */
export const defaultSystemValue: ISystemInfo = {
coldStartSuccess: false,
hasAccountCompleted: false,
isAuthorizeSubscribePop: false,
}

export const systemModel = createModel<RootModel>()({
state: defaultSystemValue,
reducers: {
update_SystemInfo: (state: ISystemInfo, newSystemInfo: Partial<ISystemInfo>) => {
state = Object.assign({}, state, newSystemInfo)
return state
},
},
})
26 changes: 26 additions & 0 deletions src/model/userinfo-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createModel } from '@rematch/core'
import { RootModel } from 'src/models'
import { IStudentStruct } from 'src/types'
import { getStorage, setStorage } from '../utils/storage'

/** TODO: 用户信息需要确定好内容 */
export interface IUserInfo extends IStudentStruct {
/** 鉴权 */
token?: string
}

/** 默认store值 从storage中激活 */
export const defaultUserinfoValue: Partial<IUserInfo> = {
...(getStorage('userInfo') || {}),
}

export const userinfoModel = createModel<RootModel>()({
state: defaultUserinfoValue,
reducers: {
update_UserInfo: (state: IUserInfo, newUserinfo: Partial<IUserInfo>) => {
state = Object.assign({}, state, newUserinfo)
setStorage('userInfo', state)
return state
},
},
})
10 changes: 7 additions & 3 deletions src/models.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Models } from '@rematch/core'
import { common } from './common-model'
import { userinfoModel, systemModel, runtimeModel } from './model'

export interface RootModel extends Models<RootModel> {
common: typeof common
userinfoModel: typeof userinfoModel
systemModel: typeof systemModel
runtimeModel: typeof runtimeModel
}

export const models: RootModel = {
common,
userinfoModel,
systemModel,
runtimeModel,
}
Loading

0 comments on commit a7a223a

Please sign in to comment.