123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { WX_GET_PHONE, WX_GET_USER, WX_UPDATE_USER, WX_UPLOAD_URL } from '../utils/apiList'
- import { request, Response } from '../utils/http'
- const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
- // import { UPLOAD, transformUploadResponseOkData } from 'miniprogram-uploader';
- interface PhoneParams {
- code: string
- encryptedData: string
- iv: string
- }
- interface PhoneResType {
- countryCode: string
- phoneNumber: string
- purePhoneNumber: string
- }
- interface UserResType {
- }
- type UserRes = Response & {
- data: GlobalUserInfo
- }
- type PhoneRes = Response & {
- data: PhoneResType
- }
- export const getUserInfo = async (): Promise<UserResType> => {
- const res = await request.get<UserRes>(WX_GET_USER)
- const app = getApp<IAppOption>();
- app.globalData.userInfo = Object.assign({}, app.globalData.userInfo, res.data)
- wx.setStorageSync('wxUserId', res.data?.wxUserId || '')
- return res.data
- }
- export const updateUserInfo = async (params: Partial<GlobalUserInfo>): Promise<Response> => {
- const res = await request.post<Response>(WX_UPDATE_USER, params)
- return res
- }
- export const decrptPhone = async (params: PhoneParams): Promise<PhoneResType> => {
- const res = await request.get<PhoneRes>(WX_GET_PHONE, params)
- return res.data
- }
- export const updateAvatar = async (avatarUrl: string): Promise<string> => {
- let url = ''
- wx.uploadFile({
- filePath: avatarUrl,
- name: 'file',
- url: WX_UPLOAD_URL,
- success: async (res) => {
- const data = JSON.parse(res.data)
- url = data.data
- }
- })
- await sleep(500)
- return Promise.resolve(url)
- }
|