u
This commit is contained in:
1 parent
8a3dea8545
commit
1903861354
21 files changed
+335
-236
No files matched your search
@@ -21,15 +21,31 @@ export default function Index() {
|
||||
</Text>
|
||||
|
||||
<Text className="text-base text-gray-500 text-center mb-10">
|
||||
记录生活,记录情绪,也记录每一笔重要的支出
|
||||
记录生活,记录情绪
|
||||
</Text>
|
||||
|
||||
<AButton
|
||||
{/* <AButton
|
||||
className="w-full"
|
||||
onPress={() => router.replace('/money')}
|
||||
>
|
||||
开始使用
|
||||
</AButton>
|
||||
</AButton> */}
|
||||
<View className="flex flex-row gap-3 mt-4">
|
||||
<AButton
|
||||
className="flex-1"
|
||||
onPress={() => router.replace('/money')}
|
||||
>
|
||||
创建空间
|
||||
</AButton>
|
||||
<AButton
|
||||
className="flex-1"
|
||||
variant="outline"
|
||||
onPress={() => router.replace('/money')}
|
||||
>
|
||||
加入空间
|
||||
</AButton>
|
||||
</View>
|
||||
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ import ListItem from './components/ListItem'
|
||||
|
||||
export default function User() {
|
||||
const userStore = useUserStore()
|
||||
|
||||
console.log(userStore.userInfo)
|
||||
return (
|
||||
<SafeAreaView className="flex-1 p-4">
|
||||
<View className="flex flex-row items-center">
|
||||
@@ -20,7 +20,7 @@ export default function User() {
|
||||
source={{ uri: userStore.userInfo?.avatar }}
|
||||
/>
|
||||
</Avatar>
|
||||
<Text className="text-xl font-semibold ml-3">{userStore.userInfo?.username}</Text>
|
||||
<Text className="text-xl font-semibold ml-3">{userStore.userInfo?.nickname}</Text>
|
||||
<LucideIcon icon="ChevronRight" size={26} className="ml-auto" color="#aaa" strokeWidth={1.5} />
|
||||
</View>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEvent } from 'expo'
|
||||
// import ExpoQQ from 'expo-qq'
|
||||
import ExpoQQ from 'expo-qq'
|
||||
import { useRouter } from 'expo-router'
|
||||
// import ExpoWeChat from 'expo-wechat'
|
||||
import ExpoWeChat from 'expo-wechat'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Image, Text, View } from 'react-native'
|
||||
import { AButton, ACheckbox } from '@/components/common/ao'
|
||||
@@ -25,176 +25,174 @@ export default function Auth() {
|
||||
const userStore = useUserStore()
|
||||
const appStore = useAppStore()
|
||||
|
||||
// const onLoginFinished = useEvent(ExpoQQ, 'onLoginFinished')
|
||||
// const onGetUserInfo = useEvent(ExpoQQ, 'onGetUserInfo')
|
||||
// const authResult = useEvent(ExpoWeChat, 'onAuthResult')
|
||||
const onLoginFinished = useEvent(ExpoQQ, 'onLoginFinished')
|
||||
const onGetUserInfo = useEvent(ExpoQQ, 'onGetUserInfo')
|
||||
const authResult = useEvent(ExpoWeChat, 'onAuthResult')
|
||||
|
||||
// async function onQQLogin() {
|
||||
// setLoading(true)
|
||||
// setForm(val => ({
|
||||
// ...val,
|
||||
// type: 1,
|
||||
// }))
|
||||
// await ExpoQQ.login(['get_user_info'])
|
||||
// }
|
||||
|
||||
// async function onWeChatLogin() {
|
||||
// setLoading(true)
|
||||
|
||||
// // 检查微信是否安装
|
||||
// const isInstalled = await ExpoWeChat.isWXAppInstalled()
|
||||
// if (!isInstalled) {
|
||||
// toast.show({
|
||||
// title: onLoginFinished?.errorMessage || '请先安装微信',
|
||||
// })
|
||||
// setLoading(false)
|
||||
// return
|
||||
// }
|
||||
|
||||
// setForm(val => ({
|
||||
// ...val,
|
||||
// type: 0,
|
||||
// }))
|
||||
|
||||
// ExpoWeChat.sendAuthRequest('snsapi_userinfo', 'state123')
|
||||
// }
|
||||
|
||||
// useEffect(() => {
|
||||
// ExpoQQ.init('102826474', '')
|
||||
// ExpoWeChat.registerApp('wxdab3e21a1f7e392f', '')
|
||||
// }, [])
|
||||
|
||||
// useEffect(() => {
|
||||
// if (!onLoginFinished) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// if (!onLoginFinished.success) {
|
||||
// toast.show({
|
||||
// title: onLoginFinished?.errorMessage || '授权失败,请检查手机是否安装 QQ 或确认授权',
|
||||
// })
|
||||
// setLoading(false)
|
||||
// return
|
||||
// }
|
||||
|
||||
// const fetchUserInfo = async () => {
|
||||
// try {
|
||||
// const tokenInfo = await ExpoQQ.getLoginTokenInfo()
|
||||
// if (!tokenInfo.openId) {
|
||||
// toast.show({
|
||||
// title: tokenInfo?.errorMessage || '授权失败,请检查手机是否安装 QQ 或确认授权',
|
||||
// })
|
||||
// setLoading(false)
|
||||
// return
|
||||
// }
|
||||
|
||||
// setForm(val => ({
|
||||
// ...val,
|
||||
// openid: String(tokenInfo.openId),
|
||||
// }))
|
||||
|
||||
// await ExpoQQ.sendGetUserInfoReq()
|
||||
// }
|
||||
// catch (e) {
|
||||
// console.error('QQ 登录未完成', e)
|
||||
// setLoading(false)
|
||||
// }
|
||||
// }
|
||||
|
||||
// fetchUserInfo()
|
||||
// }, [onLoginFinished])
|
||||
|
||||
// // QQ登录
|
||||
// useEffect(() => {
|
||||
// const handleLogin = async () => {
|
||||
// if (!onGetUserInfo)
|
||||
// return
|
||||
|
||||
// try {
|
||||
// const loginRes = await loginQqApi({
|
||||
// openid: form.openid,
|
||||
// username: onGetUserInfo.nickname || '',
|
||||
// avatar: onGetUserInfo.figureurlQq_2 || onGetUserInfo.figureurl_2,
|
||||
// })
|
||||
|
||||
// if (loginRes.isSuccess) {
|
||||
// userStore.setUserInfo({
|
||||
// token: loginRes.data.token,
|
||||
// id: loginRes.data.userId,
|
||||
// username: loginRes.data.username,
|
||||
// avatar: loginRes.data.avatar,
|
||||
// })
|
||||
|
||||
// console.log(loginRes.data.token)
|
||||
|
||||
// router.push('/')
|
||||
// }
|
||||
// }
|
||||
// catch (err) {
|
||||
// console.error('登录接口出错', err)
|
||||
// }
|
||||
// finally {
|
||||
// setLoading(false)
|
||||
// }
|
||||
// }
|
||||
|
||||
// handleLogin()
|
||||
// }, [onGetUserInfo])
|
||||
|
||||
// // 微信登录
|
||||
// useEffect(() => {
|
||||
// if (!authResult)
|
||||
// return
|
||||
|
||||
// const handleLogin = async () => {
|
||||
// if (authResult.errorCode === 0) {
|
||||
// try {
|
||||
// const loginRes = await loginWxApi({
|
||||
// code: authResult.code,
|
||||
// })
|
||||
|
||||
// if (loginRes.isSuccess) {
|
||||
// userStore.setUserInfo({
|
||||
// token: loginRes.data.token,
|
||||
// id: loginRes.data.userId,
|
||||
// username: loginRes.data.username,
|
||||
// avatar: loginRes.data.avatar,
|
||||
// })
|
||||
|
||||
// router.push('/')
|
||||
// }
|
||||
// }
|
||||
// catch (err) {
|
||||
// console.error('登录接口出错', err)
|
||||
// }
|
||||
// finally {
|
||||
// setLoading(false)
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// console.log('授权失败:', authResult.errorMessage)
|
||||
// setLoading(false)
|
||||
// }
|
||||
// }
|
||||
|
||||
// handleLogin()
|
||||
// }, [authResult])
|
||||
|
||||
function testLogin() {
|
||||
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo3NjY3ODU5ODIxNjUwNjEsImlhdCI6MTc2OTM0ODI0Nn0.17ZNaHD3HSLM8dVn_JQK-gvsG9MKj47IRYV9D4xZkzs
|
||||
|
||||
userStore.setUserInfo({
|
||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo3Njc4NjM3NTU5MzE3MTcsImlhdCI6MTc2OTYwMzEzOX0.xfW-uyFBi799u4VJ-93A88c2CC8jwpYOPsALUuaIizg',
|
||||
id: 767863755931717,
|
||||
username: 'Zhang',
|
||||
avatar: 'http://thirdqq.qlogo.cn/ek_qqapp/AQHVialeUibE42oV8RvTTVZ4tyRlPYeJrUibWTwtCPfV68E4rSzn9cw00GkXQ3QDTiawwhjoqQb7/100',
|
||||
})
|
||||
|
||||
appStore.init()
|
||||
|
||||
router.push('/')
|
||||
async function onQQLogin() {
|
||||
setLoading(true)
|
||||
setForm(val => ({
|
||||
...val,
|
||||
type: 1,
|
||||
}))
|
||||
await ExpoQQ.login(['get_user_info'])
|
||||
}
|
||||
|
||||
async function onWeChatLogin() {
|
||||
setLoading(true)
|
||||
|
||||
// 检查微信是否安装
|
||||
const isInstalled = await ExpoWeChat.isWXAppInstalled()
|
||||
if (!isInstalled) {
|
||||
toast.show({
|
||||
title: onLoginFinished?.errorMessage || '请先安装微信',
|
||||
})
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
setForm(val => ({
|
||||
...val,
|
||||
type: 0,
|
||||
}))
|
||||
|
||||
ExpoWeChat.sendAuthRequest('snsapi_userinfo', 'state123')
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
ExpoQQ.init('102826474', '')
|
||||
ExpoWeChat.registerApp('wxdab3e21a1f7e392f', '')
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!onLoginFinished) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!onLoginFinished.success) {
|
||||
toast.show({
|
||||
title: onLoginFinished?.errorMessage || '授权失败,请检查手机是否安装 QQ 或确认授权',
|
||||
})
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const tokenInfo = await ExpoQQ.getLoginTokenInfo()
|
||||
if (!tokenInfo.openId) {
|
||||
toast.show({
|
||||
title: tokenInfo?.errorMessage || '授权失败,请检查手机是否安装 QQ 或确认授权',
|
||||
})
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
setForm(val => ({
|
||||
...val,
|
||||
openid: String(tokenInfo.openId),
|
||||
}))
|
||||
|
||||
await ExpoQQ.sendGetUserInfoReq()
|
||||
}
|
||||
catch (e) {
|
||||
console.error('QQ 登录未完成', e)
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
fetchUserInfo()
|
||||
}, [onLoginFinished])
|
||||
|
||||
// QQ登录
|
||||
useEffect(() => {
|
||||
const handleLogin = async () => {
|
||||
if (!onGetUserInfo)
|
||||
return
|
||||
|
||||
try {
|
||||
const loginRes = await loginQqApi({
|
||||
openid: form.openid,
|
||||
nickname: onGetUserInfo.nickname || '',
|
||||
avatar: onGetUserInfo.figureurlQq_2 || onGetUserInfo.figureurl_2,
|
||||
})
|
||||
|
||||
if (loginRes.isSuccess) {
|
||||
userStore.setUserInfo({
|
||||
token: loginRes.data.token,
|
||||
id: loginRes.data.userId,
|
||||
nickname: loginRes.data.nickname,
|
||||
avatar: loginRes.data.avatar,
|
||||
})
|
||||
|
||||
router.push('/auth/space')
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error('登录接口出错', err)
|
||||
}
|
||||
finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
handleLogin()
|
||||
}, [onGetUserInfo])
|
||||
|
||||
// 微信登录
|
||||
useEffect(() => {
|
||||
if (!authResult)
|
||||
return
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (authResult.errorCode === 0) {
|
||||
try {
|
||||
const loginRes = await loginWxApi({
|
||||
code: authResult.code,
|
||||
})
|
||||
|
||||
if (loginRes.isSuccess) {
|
||||
userStore.setUserInfo({
|
||||
token: loginRes.data.token,
|
||||
id: loginRes.data.userId,
|
||||
nickname: loginRes.data.nickname,
|
||||
avatar: loginRes.data.avatar,
|
||||
})
|
||||
|
||||
router.push('/')
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error('登录接口出错', err)
|
||||
}
|
||||
finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('授权失败:', authResult.errorMessage)
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
handleLogin()
|
||||
}, [authResult])
|
||||
|
||||
// function testLogin() {
|
||||
// // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo3NjY3ODU5ODIxNjUwNjEsImlhdCI6MTc2OTM0ODI0Nn0.17ZNaHD3HSLM8dVn_JQK-gvsG9MKj47IRYV9D4xZkzs
|
||||
|
||||
// userStore.setUserInfo({
|
||||
// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo3NzgxMTUwMzIxMDA5MzMsImlhdCI6MTc3MjExMDQ5N30.Ab7_YNwftJigktnPt8f-FwwcLeS45CkrH0jT2jLjRtA',
|
||||
// id: 778115032100933,
|
||||
// nickname: 'Zhang',
|
||||
// avatar: 'http://thirdqq.qlogo.cn/ek_qqapp/AQHVialeUibE42oV8RvTTVZ4tyRlPYeJrUibWTwtCPfV68E4rSzn9cw00GkXQ3QDTiawwhjoqQb7/100',
|
||||
// })
|
||||
|
||||
// appStore.init()
|
||||
|
||||
// router.push('/')
|
||||
// }
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-white px-6 justify-center">
|
||||
<CustomHeader
|
||||
@@ -212,7 +210,7 @@ export default function Auth() {
|
||||
</View>
|
||||
|
||||
<View className="flex flex-col gap-4">
|
||||
{/* <AButton
|
||||
<AButton
|
||||
leftIcon={
|
||||
<IconWeixin color="#fff" />
|
||||
}
|
||||
@@ -231,7 +229,7 @@ export default function Auth() {
|
||||
onPress={onQQLogin}
|
||||
>
|
||||
QQ
|
||||
</AButton> */}
|
||||
</AButton>
|
||||
|
||||
<AButton
|
||||
variant="outline"
|
||||
@@ -239,7 +237,7 @@ export default function Auth() {
|
||||
<IconQq />
|
||||
}
|
||||
loading={loading}
|
||||
onPress={testLogin}
|
||||
// onPress={testLogin}
|
||||
>
|
||||
模拟登录
|
||||
</AButton>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Text, View } from 'react-native'
|
||||
import { AButton, LucideIcon } from '@/components/common/ao'
|
||||
import EmptyState from '@/components/common/EmptyStatus'
|
||||
import CustomHeader from '@/components/custom/Header'
|
||||
|
||||
// name renshu
|
||||
|
||||
export default function AuthSpace() {
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<CustomHeader title="空间列表" />
|
||||
<View className="flex-1 px-4 pt-2 pb-8">
|
||||
<View>
|
||||
<Text className="text-lg font-semibold">你的空间</Text>
|
||||
<Text className="text-sm text-gray-600">选择要进入的空间</Text>
|
||||
</View>
|
||||
|
||||
<View className="flex-1 my-4">
|
||||
{/* <View className="items-center justify-center">
|
||||
<EmptyState title="暂无空间" description="请选择 创建 或 加入 空间" />
|
||||
</View> */}
|
||||
|
||||
<View>
|
||||
<View className="rounded-lg p-3 flex flex-row items-center justify-between bg-gray-100">
|
||||
<View className="flex-row items-center">
|
||||
<View className="mr-4">
|
||||
<LucideIcon
|
||||
icon="Grip"
|
||||
size={20}
|
||||
color="#666"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View className="">
|
||||
<View>
|
||||
<Text className="font-semibold">A 的空间</Text>
|
||||
</View>
|
||||
<Text className="text-sm text-gray-500 mt-1">张三 · 8 名成员</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View>
|
||||
<LucideIcon
|
||||
icon="Bolt"
|
||||
size={20}
|
||||
color="#aaa"
|
||||
style={{ padding: 6 }}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="flex gap-3">
|
||||
<AButton>创建新空间</AButton>
|
||||
<AButton variant="outline">加入其他空间</AButton>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export default function EmptyState({
|
||||
{image ?? defaultImages[type]}
|
||||
|
||||
{title && (
|
||||
<Text className="text-2xl font-semibold text-gray-900 mb-2">{title}</Text>
|
||||
<Text className="text-2xl font-semibold text-gray-900 mb-2 text-center ">{title}</Text>
|
||||
)}
|
||||
|
||||
{description && (
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface LucideIconProps {
|
||||
style?: ViewStyle
|
||||
clickable?: boolean
|
||||
className?: string
|
||||
fill?: string
|
||||
}
|
||||
|
||||
export default function LucideIcon({
|
||||
@@ -22,6 +23,7 @@ export default function LucideIcon({
|
||||
onPress,
|
||||
style,
|
||||
clickable = true,
|
||||
fill = 'none',
|
||||
className,
|
||||
}: LucideIconProps) {
|
||||
const IconComponent = icons[icon]
|
||||
@@ -30,12 +32,12 @@ export default function LucideIcon({
|
||||
return null
|
||||
|
||||
if (!clickable) {
|
||||
return <IconComponent size={size} color={color} strokeWidth={strokeWidth} style={style} className={className} />
|
||||
return <IconComponent size={size} color={color} strokeWidth={strokeWidth} style={style} className={className} fill={fill} />
|
||||
}
|
||||
|
||||
return (
|
||||
<Pressable onPress={onPress} style={style} className={className}>
|
||||
<IconComponent size={size} color={color} strokeWidth={strokeWidth} />
|
||||
<IconComponent size={size} color={color} strokeWidth={strokeWidth} fill={fill} />
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
@@ -8,5 +8,5 @@ export function loginQqApi(params: LoginQqParams) {
|
||||
}
|
||||
|
||||
export function loginWxApi(params: LoginWxParams) {
|
||||
return alovaInstance.Post<ResponseData<LoginResult>>(`${API_PREFIX}/login/wx`, params)
|
||||
return alovaInstance.Post<ResponseData<LoginResult>>(`${API_PREFIX}/login/wechat`, params)
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { useUserStore } from '@/store/user'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
enum HttpCode {
|
||||
Success = 200,
|
||||
Success = 1000,
|
||||
Unauthorized = 401,
|
||||
Fail = 500,
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ const DEFAULT_NAV_MENUS: NavItem[] = [
|
||||
{ label: '恋爱记', path: '/love', icon: 'Heart' },
|
||||
{ label: '聊天', path: '/chat', icon: 'MessageCircle' },
|
||||
{ label: '个人中心', path: '/user', icon: 'CircleUserRound' },
|
||||
{ label: '我的空间', path: '/auth/space', icon: 'Earth' },
|
||||
]
|
||||
|
||||
export const useNavStore = create<NavState>()(
|
||||
@@ -43,7 +44,7 @@ export const useNavStore = create<NavState>()(
|
||||
}),
|
||||
{
|
||||
name: 'nav-storage',
|
||||
storage: createJSONStorage(() => AsyncStorage),
|
||||
// storage: createJSONStorage(() => AsyncStorage),
|
||||
},
|
||||
),
|
||||
)
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface LoginQqParams {
|
||||
openid: string
|
||||
username: string
|
||||
nickname: string
|
||||
avatar: string
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ export interface LoginWxParams {
|
||||
export interface LoginResult {
|
||||
token: string
|
||||
userId: number
|
||||
username: string
|
||||
nickname: string
|
||||
avatar: string
|
||||
}
|
||||
+2
-3
@@ -2,7 +2,7 @@ export {}
|
||||
|
||||
declare global {
|
||||
interface ResponseData<T> {
|
||||
trackId: string
|
||||
track_id: string
|
||||
code: number
|
||||
message: string
|
||||
data: T
|
||||
@@ -12,14 +12,13 @@ declare global {
|
||||
interface UserInfo {
|
||||
id: number
|
||||
token: string
|
||||
username?: string
|
||||
nickname?: string
|
||||
avatar?: string
|
||||
}
|
||||
|
||||
interface UserSpace {
|
||||
id: number
|
||||
name: string
|
||||
invite_code: string
|
||||
role: number
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user