【小程序】个人资料

This commit is contained in:
洪树泽
2022-09-09 14:27:52 +08:00
parent a54756e081
commit 145f85edf7
3 changed files with 413 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
import { getToken } from './auth'
/**
* @description 获取元素节点信息在组件中的元素必须要传ctx
* @param { String } selector 选择器 '.app' | '#app'
@@ -23,3 +25,44 @@ export const getRect = (selector: string, all = false, context?: any) => {
.exec()
})
}
/**
* @description 上传图片
* @param { String } path 选择的本地地址
*/
export function uploadFile(path: any) {
return new Promise((resolve, reject) => {
const token = getToken()
uni.uploadFile({
url: `${import.meta.env.VITE_APP_BASE_URL}/api/Upload/image`,
filePath: path,
name: 'file',
header: {
token,
},
fileType: 'image',
success: res => {
console.log('uploadFile res ==> ', res)
let data = JSON.parse(res.data);
if (data.code == 1) {
resolve(data.data);
} else {
reject()
}
},
fail: (err) => {
console.log(err)
reject()
}
});
});
}
export const getWxCode = (): Promise<void> => {
return new Promise((resolve, reject) => {
uni.login({
desc: '获取用户信息,完善用户资料',
success: (res: Event) => resolve(res.code)
})
})
}