diff --git a/backend/shop/__pycache__/views.cpython-312.pyc b/backend/shop/__pycache__/views.cpython-312.pyc
index 18caa05..41ab6f6 100644
Binary files a/backend/shop/__pycache__/views.cpython-312.pyc and b/backend/shop/__pycache__/views.cpython-312.pyc differ
diff --git a/backend/shop/views.py b/backend/shop/views.py
index a6b48a3..271b135 100644
--- a/backend/shop/views.py
+++ b/backend/shop/views.py
@@ -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(
diff --git a/miniprogram/src/pages/user/index.tsx b/miniprogram/src/pages/user/index.tsx
index 03fec4d..883f6b5 100644
--- a/miniprogram/src/pages/user/index.tsx
+++ b/miniprogram/src/pages/user/index.tsx
@@ -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() {
ID: {userInfo ? (userInfo.phone_number || userInfo.id || '----') : '----'}
{!userInfo && (
-
+ */}