1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- const app = getApp();
- export const login = () => {
- return new Promise((resolve) => {
- app.login(() => {
- const data = app.globalData.single;
- resolve(data);
- });
- });
- }
- export const getImageInfo = (src) => {
- return new Promise((resolve) => {
- const success = resolve;
- const config = { src, success };
- wx.getImageInfo(config);
- })
- }
- export const uploadImageFiles = (token, filePath) => {
- const key = Math.random().toString(36).substr(2); //生成一个随机字符串的文件名
- return new Promise((resolve) => {
- wx.uploadFile({
- url: 'https://upload.qiniup.com',
- filePath: filePath,
- name: 'file',
- formData: {
- token,
- key,
- },
- success: (data) => {
- let res;
- try {
- res = JSON.parse(data.data);
- } catch (e) {
- res = data.data;
- }
- // const key = res.key;
- resolve(res.key);
- },
- fail:(res)=>{
- console.error("******uploadFile***",res)
- reject(res);
- }
- });
- });
- };
- export const getSetting = () => {
- return new Promise((resolve) => {
- //获取相册授权
- wx.getSetting({
- success(res) {
- resolve(res.authSetting);
- },
- fail(res){
- reject();
- },
- });
- });
- }
- export const savePhoneAuth = () => {
- return new Promise((resolve) => {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- resolve(true);
- return true;
- },
- fail() {
- resolve(false);
- return false;
- },
- });
- })
- }
|