diff --git a/env/.env b/env/.env index 4bc22a7..f58336e 100644 --- a/env/.env +++ b/env/.env @@ -8,7 +8,7 @@ VITE_WX_APPID = 'wxa2abb91f64032a2b' VITE_APP_PUBLIC_BASE = '/h5' # 登录页面 -VITE_LOGIN_URL = '/pages/login/mobile' +VITE_LOGIN_URL = '/pages/my/my' # 第一个请求地址 VITE_SERVER_BASEURL = 'https://cz.stnav.com' @@ -25,6 +25,6 @@ VITE_API_SECONDARY_URL = 'https://cz.stnav.com' VITE_WX_SERVICE_ACCOUNT_APPID = 'wx0224f558e3b3f499' # 默认地址 -VITE_DEFAULT_LONGITUDE = 113.665412 -VITE_DEFAULT_LATITUDE = 34.757975 +VITE_DEFAULT_LONGITUDE = 121.473629 +VITE_DEFAULT_LATITUDE = 31.230393 VITE_DEFAULT_ADDRESS = '上海市' \ No newline at end of file diff --git a/src/api/home.ts b/src/api/home.ts index 6302c74..ba4bd22 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -46,3 +46,34 @@ export function getTeaSpecialist(data: ITeaSpecialistParams) { } ) } + +/** + * 经纬度转换为城市 + */ +export interface ILocationToCityParams { + latitude: number + longitude: number +} + +export function getLocationToCity(data: ILocationToCityParams) { + return http.Post<{ + message: string + result: { + ad_info: { + province: string + city: string + district: string + adcode: string + }, + location: { + lat: number + lng: number + } + } + }>('/api/common/cityAddress', + data, + { + meta: { ignoreAuth: true } + } + ) +} diff --git a/src/api/types/user.ts b/src/api/types/user.ts index 1080b4f..b26124c 100644 --- a/src/api/types/user.ts +++ b/src/api/types/user.ts @@ -47,4 +47,26 @@ export interface IUserAddressDetailsResult extends IUserAddressListResult { export interface IUserCouponListResult { no_use: Array use: Array +} + +/** + * 用户信息接口返回 + */ +export interface IUserResult { + id: number + sn: number + sex: "未知" | "男" | "女" + account: string + nickname: string + real_name: string + avatar: string + collect_count: number + coupon_count: number + create_time: string + has_auth: boolean + has_password: boolean + member: number + mobile: string + user_money: string + version: string } \ No newline at end of file diff --git a/src/api/user.ts b/src/api/user.ts index 3e7c61d..54fdfa6 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,13 +1,13 @@ import { http } from '@/http/alova' import type { IUserAddressListResult, IUserAddressDetailsResult, IUserCouponListResult } from '@/api/types/user' import type { IOrderListResult } from '@/api/types/order' - +import type { IUserResult } from '@/api/types/user' /** * 获取用户个人信息 */ export function getUserInfo() { - return http.Post('/api/user/info') + return http.Post('/api/user/info') } /** @@ -130,4 +130,16 @@ export interface IGetUserMoneyLogParams { export function getUserMoneyLog(data: IGetUserMoneyLogParams) { return http.Post('/api/user/moneyLogList', data) -} \ No newline at end of file +} + +/** + * 修改用户信息 + */ +export interface IUpdateUserInfoParams { + field: string, + value: string | number +} + +export function updateUserInfo(data: IUpdateUserInfoParams) { + return http.Post('/api/user/setInfo', data) +} diff --git a/src/bundle/order/tea-specialist/order-detail.vue b/src/bundle/order/tea-specialist/order-detail.vue index 17f7e17..1ea23ba 100644 --- a/src/bundle/order/tea-specialist/order-detail.vue +++ b/src/bundle/order/tea-specialist/order-detail.vue @@ -441,6 +441,10 @@ // 获取订单详情 OrderDetail.handleInit() }) + + onUnload(() => { + uni.$off('refreshOrderDetail') + }) const OrderDetail = { // 获取订单详情 diff --git a/src/bundle/profile/profile.vue b/src/bundle/profile/profile.vue index 092e15a..a739e4a 100644 --- a/src/bundle/profile/profile.vue +++ b/src/bundle/profile/profile.vue @@ -21,11 +21,13 @@ - + :action="action" + @success="Profile.handleUploadSuccess"> + @@ -39,7 +41,7 @@ - 王小伟 + {{ user.nickname }} @@ -54,7 +56,7 @@ - +86 155****5456 + +86 {{ maskedMobile }} @@ -124,34 +126,92 @@ import {toast} from '@/utils/toast' import { useUserStore } from '@/store' import { router } from '@/utils/tools' + import { getUserInfo, updateUserInfo } from '@/api/user' + import type { IUserResult } from '@/api/types/user' const OSS = inject('OSS') const showLogoutPopup = ref(false) // 是否显示退出登录弹出框 // 上传文件 const fileList = ref([]) - const action = 'https://www.mocky.io/v2/5cc8019d300000980a055e76' // 仅做测试使用,实际请换成真实上传接口 + const action = 'https://cz.stnav.com/api/upload/image' // 仅做测试使用,实际请换成真实上传接口 // 修改昵称 const showEditNicknamePopup = ref(false) // 是否显示退款详情弹出框 const nickname = ref('') // 昵称 + // 用户信息相关 + const user = ref({ + id: 0, + sn: 0, + sex: "未知", + account: "", + nickname: "", + real_name: "", + avatar: "", + collect_count: 0, + coupon_count: 0, + create_time: "", + has_auth: false, + has_password: false, + member: 0, + mobile: "", + user_money: "0.00", + version: "" + }) + + const tk = ref('') // 用户token + + onLoad(() => { + const userStore = useUserStore() + const { token } = userStore.userInfo + tk.value = token + + Profile.handleInit() + }) + const Profile = { - // 图片选择/删除 - handleChange: (e: any) => { - console.log("🚀 ~ e:", e) + /** + * 初始化用户信息 + */ + handleInit: () => { + getUserInfo().then(res => { + user.value = res + }) }, - // 保存昵称 - handleSaveNickname: () => { + handleUploadSuccess: async (e: any) => { + try { + const response = JSON.parse(e.file.response) + if (response.code) { + const avatarUrl = response.data.uri + await updateUserInfo({ field: 'avatar', value: avatarUrl }) + user.value.avatar = avatarUrl + toast.info('头像上传成功') + } else { + throw new Error('上传失败') + } + } catch (error) { + toast.info('上传失败') + } + }, + + /** + * 保存昵称 + */ + handleSaveNickname: async () => { if (!nickname.value) { toast.info('请输入昵称') return } + await updateUserInfo({ field: 'nickname', value: nickname.value }) + showEditNicknamePopup.value = false + user.value.nickname = nickname.value toast.info('昵称修改成功') }, + // 修改手机号 handleToEditMobile: () => { uni.navigateTo({ @@ -169,6 +229,15 @@ } } } + + /** + * 掩码处理手机号 + */ + const maskedMobile = computed(() => { + if (!user.value.mobile) return '' + // 只处理11位手机号 + return user.value.mobile.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2') + })