forum
This commit is contained in:
Binary file not shown.
@@ -1139,7 +1139,12 @@ def wechat_login(request):
|
||||
'openid': user.openid,
|
||||
'is_new': created,
|
||||
'nickname': user.nickname,
|
||||
'phone_number': user.phone_number
|
||||
'avatar_url': user.avatar_url,
|
||||
'phone_number': user.phone_number,
|
||||
'gender': user.gender,
|
||||
'province': user.province,
|
||||
'city': user.city,
|
||||
'country': user.country
|
||||
})
|
||||
|
||||
@extend_schema(
|
||||
|
||||
@@ -17,8 +17,50 @@ export default function UserIndex() {
|
||||
const goWithdraw = () => Taro.navigateTo({ url: '/subpackages/distributor/withdraw' })
|
||||
|
||||
const handleAddress = async () => {
|
||||
try { await Taro.chooseAddress() } catch(e) {}
|
||||
try {
|
||||
const res = await Taro.chooseAddress()
|
||||
// 同步地址信息到后端
|
||||
const token = Taro.getStorageSync('token')
|
||||
if (token) {
|
||||
await Taro.request({
|
||||
url: 'https://market.quant-speed.com/api/wechat/update_user_info/',
|
||||
method: 'POST',
|
||||
header: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
province: res.provinceName,
|
||||
city: res.cityName,
|
||||
country: '中国' // 默认中国,chooseAddress通常返回国内地址
|
||||
}
|
||||
})
|
||||
// 更新本地 userInfo
|
||||
const updatedInfo = { ...userInfo, province: res.provinceName, city: res.cityName, country: '中国' }
|
||||
setUserInfo(updatedInfo)
|
||||
Taro.setStorageSync('userInfo', updatedInfo)
|
||||
Taro.showToast({ title: '地址信息已同步', icon: 'success' })
|
||||
}
|
||||
} catch(e) {
|
||||
// 用户取消或其他错误,忽略
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
Taro.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出登录吗?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
Taro.removeStorageSync('token')
|
||||
Taro.removeStorageSync('userInfo')
|
||||
setUserInfo(null)
|
||||
Taro.showToast({ title: '已退出登录', icon: 'success' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const login = async () => {
|
||||
try {
|
||||
@@ -108,7 +150,8 @@ export default function UserIndex() {
|
||||
{
|
||||
title: '其他',
|
||||
items: [
|
||||
{ title: '联系客服', icon: '🎧', isContact: true }
|
||||
{ title: '联系客服', icon: '🎧', isContact: true },
|
||||
...(userInfo ? [{ title: '退出登录', icon: '🚪', action: handleLogout }] : [])
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -132,13 +175,13 @@ export default function UserIndex() {
|
||||
<Text className='uid'>ID: {userInfo ? (userInfo.phone_number || userInfo.id || '----') : '----'}</Text>
|
||||
{!userInfo && (
|
||||
<View className='login-btns'>
|
||||
<Button
|
||||
{/* <Button
|
||||
className='btn-login'
|
||||
onClick={login}
|
||||
style={{ marginRight: '10px' }}
|
||||
>
|
||||
游客登录
|
||||
</Button>
|
||||
</Button> */}
|
||||
<Button
|
||||
className='btn-login primary'
|
||||
openType="getPhoneNumber"
|
||||
|
||||
Reference in New Issue
Block a user