|
|
|
|
|
// import {
|
|
|
|
|
|
// uploadGetQiniuToken,
|
|
|
|
|
|
// } from '@/common/api.js'
|
|
|
|
|
|
|
|
|
|
|
|
// import {
|
|
|
|
|
|
// user_wxRegister,
|
|
|
|
|
|
// user_commonLogin,
|
|
|
|
|
|
// tenantUser_becomeTenantUser,
|
|
|
|
|
|
// common_getQiniuToken, page_init, apiWeappLogin
|
|
|
|
|
|
// } from "./project-api";
|
|
|
|
|
|
|
|
|
|
|
|
// let Base64 = require('js-base64').Base64;
|
|
|
|
|
|
|
|
|
|
|
|
// import fly from './api-manager'
|
|
|
|
|
|
|
|
|
|
|
|
// import store from '../store/index'
|
|
|
|
|
|
import qiniuUploader from '@/utils/qiniuUploader'
|
|
|
|
|
|
// import {isEmpty} from "./project-self";
|
|
|
|
|
|
// import {commonImageCensor, pageInit, userRegister} from "./uni-app-api";
|
|
|
|
|
|
|
|
|
|
|
|
//获取七牛上传token 并 初始化七牛相关参数
|
|
|
|
|
|
export async function getQiniuToken() {
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
uni.$u.api.uploadGetQiniuToken({
|
|
|
|
|
|
"bucketName": "fxcyy",
|
|
|
|
|
|
"dir": "2022/9"
|
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
|
// console.log("token-->" + JSON.stringify(res));
|
|
|
|
|
|
let options = {
|
|
|
|
|
|
region: 'NCN', // 华北区
|
|
|
|
|
|
uptoken: res.token
|
|
|
|
|
|
};
|
|
|
|
|
|
qiniuUploader.init(options);
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
|
// console.log('err is:'+JSON.stringify(err)) ;
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 微信拍照并获取本地 路径
|
|
|
|
|
|
export function getLocalityImage() {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
uni.chooseImage({
|
|
|
|
|
|
sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
|
|
|
sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
|
|
|
count: 1,
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
let tempFilePaths = res.tempFilePaths[0];
|
|
|
|
|
|
resolve(tempFilePaths);
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
|
reject(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 微信拍照并七牛上传图片
|
|
|
|
|
|
export function chooseImage() {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
uni.chooseImage({
|
|
|
|
|
|
sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
|
|
|
sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
|
|
|
count: 1,
|
|
|
|
|
|
success: function(ret) {
|
|
|
|
|
|
let tempFilePaths = ret.tempFilePaths[0];
|
|
|
|
|
|
console.log(ret);
|
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
|
title: '正在上传图片',
|
|
|
|
|
|
})
|
|
|
|
|
|
qiniuUploader.upload(
|
|
|
|
|
|
tempFilePaths,
|
|
|
|
|
|
async res => {
|
|
|
|
|
|
console.log(res)
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
|
|
|
|
|
|
let image = getImgRealUrl(res.key);
|
|
|
|
|
|
// var msgObj = await commonImageCensor({
|
|
|
|
|
|
// url: image
|
|
|
|
|
|
// });
|
|
|
|
|
|
// if (!msgObj.data.result) {
|
|
|
|
|
|
// showToast(msgObj.data.message);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
resolve(image)
|
|
|
|
|
|
},
|
|
|
|
|
|
error => {
|
|
|
|
|
|
// console.error("七牛上传图片err: " + JSON.stringify(error));
|
|
|
|
|
|
reject(error)
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
|
// console.error("微信上传图片err: " + JSON.stringify(error));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function uploadImg(img) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
qiniuUploader.upload(
|
|
|
|
|
|
img,
|
|
|
|
|
|
res => {
|
|
|
|
|
|
let image = getImgRealUrl(res.key);
|
|
|
|
|
|
resolve(image)
|
|
|
|
|
|
},
|
|
|
|
|
|
error => {
|
|
|
|
|
|
// console.error("七牛上传图片err: " + JSON.stringify(error));
|
|
|
|
|
|
reject(error)
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//图片下载到本地
|
|
|
|
|
|
export function saveImage(image) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
// console.log("图片下载到本地:" + JSON.stringify(image));
|
|
|
|
|
|
//下载到本地
|
|
|
|
|
|
wx.downloadFile({
|
|
|
|
|
|
url: image,
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
|
|
wx.saveImageToPhotosAlbum({
|
|
|
|
|
|
filePath: res.tempFilePath,
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
// console.log("保存成功");
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
},
|
|
|
|
|
|
fail(e) {
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
// if (e.errMsg == "saveImageToPhotosAlbum:fail auth deny") {}
|
|
|
|
|
|
if (e.errMsg != "saveImageToPhotosAlbum:fail cancel") {
|
|
|
|
|
|
// vm.showDialog()
|
|
|
|
|
|
}
|
|
|
|
|
|
// console.log("saveImageToPhotosAlbum错误:" + JSON.stringify(e));
|
|
|
|
|
|
resolve(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function(e) {
|
|
|
|
|
|
resolve(false);
|
|
|
|
|
|
// console.log("downloadFile错误:::" + JSON.stringify(e));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 七牛上传图片
|
|
|
|
|
|
export function ctxQiniuUpload() {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
showLoading("上传中")
|
|
|
|
|
|
const ctx = wx.createCameraContext();
|
|
|
|
|
|
ctx.takePhoto({
|
|
|
|
|
|
quality: "high",
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
qiniuUploader.upload(res.tempImagePath, res => {
|
|
|
|
|
|
let image = getImgRealUrl(res.key);
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
resolve(image)
|
|
|
|
|
|
}, error => {
|
|
|
|
|
|
// console.error("七牛上传图片err: " + JSON.stringify(error));
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
reject(error)
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: err => {
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
// console.log("拍照错误::" + JSON.stringify(err));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//七牛上传视频
|
|
|
|
|
|
export function chooseVideo() {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
uni.chooseVideo({
|
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
|
maxDuration: 60,
|
|
|
|
|
|
camera: 'back',
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
JSON.stringify(JSON.stringify(res))
|
|
|
|
|
|
var tempFilePath = res.tempFilePath
|
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
|
title: '正在上传视频',
|
|
|
|
|
|
})
|
|
|
|
|
|
qiniuUploader.upload(tempFilePath, (res) => {
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
var video = getImgRealUrl(res.key)
|
|
|
|
|
|
resolve(video)
|
|
|
|
|
|
}, (error) => {
|
|
|
|
|
|
reject(error)
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function(error) {
|
|
|
|
|
|
reject(error)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 转换真实地址
|
|
|
|
|
|
export function getImgRealUrl(key) {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 后端修改目前不需要测试七牛域名全部更换为正式七牛域名
|
|
|
|
|
|
*
|
|
|
|
|
|
* 测试七牛域名:http://saas.baoguoer.com/
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author: 抠鼻屎的大熊i
|
|
|
|
|
|
* @author: 2020年11月6日16:21:57
|
|
|
|
|
|
*
|
|
|
|
|
|
* */
|
|
|
|
|
|
return 'http://fxcyy.isart.me/' + key;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 正式测试目前还需要区分 等待后端进行修改
|
|
|
|
|
|
* */
|
|
|
|
|
|
// return 'http://saas.baoguoer.com/' + key;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//微信支付
|
|
|
|
|
|
export function wxPay(payParam) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
wx.requestPayment({
|
|
|
|
|
|
timeStamp: payParam.timeStamp,
|
|
|
|
|
|
nonceStr: payParam.nonceStr,
|
|
|
|
|
|
package: payParam.package,
|
|
|
|
|
|
signType: payParam.signType,
|
|
|
|
|
|
paySign: payParam.paySign,
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
resolve(res)
|
|
|
|
|
|
showToast("支付成功")
|
|
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
showToast("您取消了支付")
|
|
|
|
|
|
// console.log("微信支付错误:" + JSON.stringify(err));
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取窗口可用高度
|
|
|
|
|
|
export function getWindowHeight() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = wx.getSystemInfoSync()
|
|
|
|
|
|
return res.windowHeight; //可用窗口高度
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// console.log("获取可用窗口高度错误:" + JSON.stringify(e));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 微信登陆拿code
|
|
|
|
|
|
export function wxLogin() {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
//登录
|
|
|
|
|
|
uni.login({
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
// console.log("wxlogin成功:" + JSON.stringify(res.code));
|
|
|
|
|
|
resolve(res.code)
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: err => {
|
|
|
|
|
|
// console.log("wxlogin错误:" + JSON.stringify(err));
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//根据code查询用户信息
|
|
|
|
|
|
/*
|
|
|
|
|
|
* type:是否是渠道分享进入
|
|
|
|
|
|
* */
|
|
|
|
|
|
export async function auth_login(type) {
|
|
|
|
|
|
// console.error('auth_login is start');
|
|
|
|
|
|
let code = await wxLogin();
|
|
|
|
|
|
// console.error('auth_login wxLogin code is:' + JSON.stringify(code));
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
|
|
|
|
uni.$u.post('/dp/v1/admin-user-login', {
|
|
|
|
|
|
accountType: "WECHAT_XCX",
|
|
|
|
|
|
jsCode: code
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
uni.setStorageSync('userInfo', res);
|
|
|
|
|
|
resolve(res);
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
|
uni.$u.toast(err.message);
|
|
|
|
|
|
//回到首页
|
|
|
|
|
|
// uni.reLaunch({
|
|
|
|
|
|
// url: `/mainPackage/pages/index`
|
|
|
|
|
|
// });
|
|
|
|
|
|
// return;
|
|
|
|
|
|
resolve(false);
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// user_commonLogin({
|
|
|
|
|
|
// account_type: 2,
|
|
|
|
|
|
// code: code
|
|
|
|
|
|
// }).then((res) => {
|
|
|
|
|
|
// // console.error('user_commonLogin res is:' + JSON.stringify(res))
|
|
|
|
|
|
// if (res.data.result) {
|
|
|
|
|
|
// let wechat_login_res = res.data.ret
|
|
|
|
|
|
// //登录成功之后判断当前用户是否已经创建过租户 , 并且判断该用户是否是渠道 , 并且判断当前界面是否是有分享模板进入
|
|
|
|
|
|
// uni.setStorageSync('user_info', wechat_login_res);
|
|
|
|
|
|
// if (type == 'template' && wechat_login_res.tenant != null && wechat_login_res.channel_id == null) {
|
|
|
|
|
|
// //清空当前小程序中所有缓存
|
|
|
|
|
|
// uni.clearStorageSync();
|
|
|
|
|
|
// //回到首页
|
|
|
|
|
|
// uni.reLaunch({
|
|
|
|
|
|
// url: `/mainPackage/pages/index`
|
|
|
|
|
|
// });
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// resolve(true);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// getApp().globalData.session_key = res.data.ret.session_key;
|
|
|
|
|
|
// wx.removeStorageSync('user_info');
|
|
|
|
|
|
// resolve(false);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*根据等级校验用户信息
|
|
|
|
|
|
* 1 校验本地缓存中有无用户信息
|
|
|
|
|
|
* 2 校验本地缓存中有无用户信息 并 校验用户信息中有无名字头像等信息
|
|
|
|
|
|
* 3 校验用户信息中是否有电话号码
|
|
|
|
|
|
* 4 不校验直接使用code登录 并 校验用户信息中有无名字头像等信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function byLevelGetUserInfo(level) {
|
|
|
|
|
|
switch (level) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
return await verifyUserInfoStorage();
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
var userInfo = await verifyUserInfoStorage();
|
|
|
|
|
|
await verifyUserInfo();
|
|
|
|
|
|
return userInfo
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
return await verifyPhonenum();
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
var userInfo = await auth_login();
|
|
|
|
|
|
await verifyUserInfo();
|
|
|
|
|
|
return userInfo
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
var userInfo = await auth_login();
|
|
|
|
|
|
return userInfo
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 判断是否存在用户缓存
|
|
|
|
|
|
*
|
|
|
|
|
|
* 2021年4月8日15:22:20
|
|
|
|
|
|
*
|
|
|
|
|
|
* @By 抠鼻屎的大熊!
|
|
|
|
|
|
*
|
|
|
|
|
|
* 修改登录逻辑 后端调整接口 用户登录、注册接口合并
|
|
|
|
|
|
*
|
|
|
|
|
|
* */
|
|
|
|
|
|
export async function handleGetUserByInfo() {
|
|
|
|
|
|
const userToken = uni.getStorageSync('user_info'); // 获取用户token缓存
|
|
|
|
|
|
// 效验是否存在用户token缓存
|
|
|
|
|
|
if (!isEmpty(userToken)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return await handleNewUserLogin();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 封装新版登录
|
|
|
|
|
|
* @date 2021年4月8日15:46:17
|
|
|
|
|
|
*
|
|
|
|
|
|
* 根据微信官方更新登录流程 修改登录业务
|
|
|
|
|
|
* */
|
|
|
|
|
|
export async function handleNewUserLogin() {
|
|
|
|
|
|
// eslint-disable-next-line no-async-promise-executor
|
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
|
const code = await wxLogin();
|
|
|
|
|
|
const userLogin = await handleUserLogin({
|
|
|
|
|
|
code
|
|
|
|
|
|
});
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 二次封装后端登录接口
|
|
|
|
|
|
* @param{Object} params
|
|
|
|
|
|
* */
|
|
|
|
|
|
export async function handleUserLogin(params = {}) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
apiWeappLogin(params).then(res => {
|
|
|
|
|
|
if (!res.data.result) {
|
|
|
|
|
|
showToast('登录失败~');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const wechat_login_res = res.data.ret
|
|
|
|
|
|
//登录成功之后判断当前用户是否已经创建过租户 , 并且判断该用户是否是渠道 , 并且判断当前界面是否是有分享模板进入
|
|
|
|
|
|
uni.setStorageSync('user_info', wechat_login_res);
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 封装创建用户相关信息缓存
|
|
|
|
|
|
* @param{Object} userInfo
|
|
|
|
|
|
* */
|
|
|
|
|
|
export async function handleCreatUserStorage(userInfo) {
|
|
|
|
|
|
uni.setStorageSync('user_info', userInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//校验是否本地是否有用户缓存
|
|
|
|
|
|
export async function verifyUserInfoStorage() {
|
|
|
|
|
|
let userInfo = wx.getStorageSync("user_info");
|
|
|
|
|
|
if (userInfo) {
|
|
|
|
|
|
return userInfo
|
|
|
|
|
|
}
|
|
|
|
|
|
let userInfo_login = await auth_login();
|
|
|
|
|
|
return userInfo_login
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//校验是否获取过用户信息
|
|
|
|
|
|
export function verifyUserInfo() {
|
|
|
|
|
|
let userInfo = wx.getStorageSync("user_info");
|
|
|
|
|
|
// console.log("-----" + JSON.stringify(userInfo));
|
|
|
|
|
|
if (!userInfo.nick_name) {
|
|
|
|
|
|
// console.log("没有nick_name:::" + JSON.stringify(userInfo));
|
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
|
url: "/pages/authorization"
|
|
|
|
|
|
});
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//调用微信的getUserInfo获取用户信息
|
|
|
|
|
|
async function wxGetUserInfo() {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
wx.getUserInfo({
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
var userInfo = res.userInfo
|
|
|
|
|
|
resolve(userInfo)
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
|
// console.log("微信的getUserInfo错误:" + JSON.stringify(err))
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//根据编号更新用户信息
|
|
|
|
|
|
export async function updateUserinfo() {
|
|
|
|
|
|
let userInfo_new = await wxGetUserInfo()
|
|
|
|
|
|
let param = {
|
|
|
|
|
|
gender: userInfo_new.gender, //性别 0:未知、1:男、2:女
|
|
|
|
|
|
nick_name: userInfo_new.nickName,
|
|
|
|
|
|
avatar: userInfo_new.avatarUrl,
|
|
|
|
|
|
country: userInfo_new.country,
|
|
|
|
|
|
province: userInfo_new.province,
|
|
|
|
|
|
city: userInfo_new.city,
|
|
|
|
|
|
language: userInfo_new.language,
|
|
|
|
|
|
}
|
|
|
|
|
|
let userInfo = await post(config.auth_updateById, param)
|
|
|
|
|
|
wx.setStorageSync('userInfo', userInfo)
|
|
|
|
|
|
// console.log("根据编号更新用户信息:" + JSON.stringify(userInfo))
|
|
|
|
|
|
return userInfo
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//消息解密
|
|
|
|
|
|
export async function decryptData(encrypted_data, iv, code) {
|
|
|
|
|
|
let ret = await fly.request({
|
|
|
|
|
|
method: api.wechat_decryptData.method,
|
|
|
|
|
|
url: api.wechat_decryptData.url,
|
|
|
|
|
|
body: {
|
|
|
|
|
|
code,
|
|
|
|
|
|
encryptedData: base64encode(encrypted_data),
|
|
|
|
|
|
iv: base64encode(iv)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
let userInfo = ret.ret
|
|
|
|
|
|
// console.log("消息解密" + JSON.stringify(userInfo));
|
|
|
|
|
|
if (userInfo) {
|
|
|
|
|
|
wx.setStorageSync('userInfo', userInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
return userInfo
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//更新小程序
|
|
|
|
|
|
export function updataXcx() {
|
|
|
|
|
|
// 获取小程序更新机制兼容
|
|
|
|
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
|
|
|
|
const updateManager = wx.getUpdateManager()
|
|
|
|
|
|
updateManager.onCheckForUpdate(function(res) {
|
|
|
|
|
|
console.log("是否有更新:" + JSON.stringify(res.hasUpdate));
|
|
|
|
|
|
// 请求完新版本信息的回调
|
|
|
|
|
|
if (res.hasUpdate) {
|
|
|
|
|
|
updateManager.onUpdateReady(function() {
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '更新提示',
|
|
|
|
|
|
content: '新版本已经准备好,是否重启应用?',
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
|
|
|
updateManager.applyUpdate()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
updateManager.onUpdateFailed(function() {
|
|
|
|
|
|
// 新的版本下载失败
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '已经有新版本了哟~',
|
|
|
|
|
|
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否授权过
|
|
|
|
|
|
export function getSetting(authType) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
wx.getSetting({
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
// 是否授权过
|
|
|
|
|
|
if (!res.authSetting[authType]) {
|
|
|
|
|
|
wx.authorize({
|
|
|
|
|
|
scope: authType,
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
},
|
|
|
|
|
|
fail() {
|
|
|
|
|
|
// console.log("授权失败:" + authType)
|
|
|
|
|
|
reject(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
|
// console.log("getSetting错误:" + JSON.stringify(err))
|
|
|
|
|
|
reject(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function showToast(title) {
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
title,
|
|
|
|
|
|
icon: 'none',
|
|
|
|
|
|
duration: 2000
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//搜索历史相关操作
|
|
|
|
|
|
// 将搜索历史存入本地缓存,在获取搜索历史时从本地缓存中获取
|
|
|
|
|
|
//本地缓存名称为seach_word_storage_arr,数组形式
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 获取缓存数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* By TerryQi
|
|
|
|
|
|
* 2019-09-15
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param max_history_words_num:需要获取的最多的历史纪录数目
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return [];
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getSearchHistoryWords(max_history_words_num) {
|
|
|
|
|
|
var search_history_word_arr = wx.getStorageSync("search_history_word_arr");
|
|
|
|
|
|
//首次搜索,没有搜索历史,返回空数组
|
|
|
|
|
|
if (!search_history_word_arr) {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (search_history_word_arr.length > max_history_words_num) {
|
|
|
|
|
|
search_history_word_arr = search_history_word_arr.slice(0, max_history_words_num - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
return search_history_word_arr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 将搜索历史存入数组
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param search_word
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return [],存入后的最新历史搜索数组
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function storeSearchHistoryWord(search_word, max_history_words_num = 10) {
|
|
|
|
|
|
let search_history_word_arr = wx.getStorageSync("search_history_word_arr");
|
|
|
|
|
|
//首次搜索,没有搜索历史,返回空数组
|
|
|
|
|
|
if (!search_history_word_arr) {
|
|
|
|
|
|
search_history_word_arr = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
search_history_word_arr.unshift(search_word); //插入到首位
|
|
|
|
|
|
wx.setStorageSync("search_history_word_arr", search_history_word_arr);
|
|
|
|
|
|
getSearchHistoryWords(max_history_words_num);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//展示Modal
|
|
|
|
|
|
export function showModal(title, content, showCancel = false, call) {
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title,
|
|
|
|
|
|
content,
|
|
|
|
|
|
showCancel,
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
call(true)
|
|
|
|
|
|
} else if (res.cancel) {
|
|
|
|
|
|
call(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//设置分享参数
|
|
|
|
|
|
var setQueryConfig = function(obj) {
|
|
|
|
|
|
var _str = "";
|
|
|
|
|
|
for (var o in obj) {
|
|
|
|
|
|
// if (obj[o] != -1) {
|
|
|
|
|
|
_str += o + "=" + obj[o] + "&";
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
var _str = _str.substring(0, _str.length - 1); //末尾是&
|
|
|
|
|
|
return _str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置分享参数
|
|
|
|
|
|
export function setShareInfo(shareJson) {
|
|
|
|
|
|
//获取用户信息
|
|
|
|
|
|
let user_info = uni.getStorageSync("user_info");
|
|
|
|
|
|
//获取租户信息
|
|
|
|
|
|
let tenant = uni.getStorageSync("tenant");
|
|
|
|
|
|
//获取租户用户id
|
|
|
|
|
|
let a_tenant_user_id = uni.getStorageSync("a_tenant_user_id");
|
|
|
|
|
|
let param = {};
|
|
|
|
|
|
//带租户id
|
|
|
|
|
|
if (tenant) {
|
|
|
|
|
|
param.tenant_id = tenant.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
//带用户id
|
|
|
|
|
|
if (user_info) {
|
|
|
|
|
|
param.user_id = user_info.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
//带分享租户用户id
|
|
|
|
|
|
if (a_tenant_user_id) {
|
|
|
|
|
|
param.a_tenant_user_id = a_tenant_user_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
//转换成常规字符串参数
|
|
|
|
|
|
param = setQueryConfig(param);
|
|
|
|
|
|
//进行分享
|
|
|
|
|
|
return {
|
|
|
|
|
|
title: shareJson.title ? shareJson.title : tenant.name,
|
|
|
|
|
|
imageUrl: shareJson.imageUrl,
|
|
|
|
|
|
path: `${shareJson.path}${param}`
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取分享参数
|
|
|
|
|
|
export function getShareInfo(appParam) {
|
|
|
|
|
|
let scene = appParam.scene;
|
|
|
|
|
|
|
|
|
|
|
|
scene = decodeURIComponent(scene);
|
|
|
|
|
|
|
|
|
|
|
|
let shareInfo = {};
|
|
|
|
|
|
if (!judgeIsAnyNullStr(scene)) {
|
|
|
|
|
|
let code = getQueryString("code", scene);
|
|
|
|
|
|
shareInfo.code = code
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!judgeIsAnyNullStr(appParam.a_user_id)) {
|
|
|
|
|
|
shareInfo.a_user_id = appParam.a_user_id;
|
|
|
|
|
|
fly
|
|
|
|
|
|
.request({
|
|
|
|
|
|
method: api.userInvite_record.method,
|
|
|
|
|
|
url: api.userInvite_record.url,
|
|
|
|
|
|
body: {
|
|
|
|
|
|
a_user_id: appParam.a_user_id
|
|
|
|
|
|
}
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
console.log("被邀请记录分享信息:" + JSON.stringify(res))
|
|
|
|
|
|
if (res) {
|
|
|
|
|
|
if (res.is_popup_flag) {
|
|
|
|
|
|
showModal('邀请成功', '您通过好友的邀请进入小程序,成功为好友助力~', false, ret => {})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!judgeIsAnyNullStr(appParam.shop_store_id)) {
|
|
|
|
|
|
shareInfo.shop_store_id = appParam.shop_store_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
return shareInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取参数
|
|
|
|
|
|
export function getQueryString(name, url) {
|
|
|
|
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(reg)
|
|
|
|
|
|
var r = url.substr(1).match(reg);
|
|
|
|
|
|
|
|
|
|
|
|
if (r != null) return unescape(r[2]);
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//展示loadding
|
|
|
|
|
|
export function showLoading(title) {
|
|
|
|
|
|
if (!wx.canIUse('showLoading')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (judgeIsAnyNullStr(title)) {
|
|
|
|
|
|
title = "加载中";
|
|
|
|
|
|
}
|
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
|
title
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取微信地址
|
|
|
|
|
|
export function getWxAddress(call) {
|
|
|
|
|
|
uni.chooseAddress({
|
|
|
|
|
|
complete(res) {
|
|
|
|
|
|
call(res);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//设置tenant_user
|
|
|
|
|
|
export function setTenantUser(new_tenant_user) {
|
|
|
|
|
|
let tenant_user = uni.getStorageSync("tenant_user");
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("id")) {
|
|
|
|
|
|
tenant_user.id = new_tenant_user.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("tenant_id")) {
|
|
|
|
|
|
tenant_user.tenant_id = new_tenant_user.tenant_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_name")) {
|
|
|
|
|
|
tenant_user.card_name = new_tenant_user.card_name;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_avatar")) {
|
|
|
|
|
|
tenant_user.card_avatar = new_tenant_user.card_avatar;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_phonenum")) {
|
|
|
|
|
|
tenant_user.card_phonenum = new_tenant_user.card_phonenum;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_mail")) {
|
|
|
|
|
|
tenant_user.card_mail = new_tenant_user.card_mail;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_address")) {
|
|
|
|
|
|
tenant_user.card_address = new_tenant_user.card_address;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_organization")) {
|
|
|
|
|
|
tenant_user.card_organization = new_tenant_user.card_organization;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_intro")) {
|
|
|
|
|
|
tenant_user.card_intro = new_tenant_user.card_intro;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (new_tenant_user.hasOwnProperty("card_position")) {
|
|
|
|
|
|
tenant_user.card_position = new_tenant_user.card_position;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uni.setStorageSync("tenant_user", tenant_user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//微信登录信息接口
|
|
|
|
|
|
export function userWxRegister(param) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
user_wxRegister({
|
|
|
|
|
|
// code: param.code,
|
|
|
|
|
|
session_key: getApp().globalData.session_key,
|
|
|
|
|
|
encryptedData: Base64.encode(param.encryptedData),
|
|
|
|
|
|
iv: Base64.encode(param.iv),
|
|
|
|
|
|
account_type: 2
|
|
|
|
|
|
}).then(async (res) => {
|
|
|
|
|
|
if (res.data.result) {
|
|
|
|
|
|
//获取接口返回数据
|
|
|
|
|
|
var msgObj = res.data.ret;
|
|
|
|
|
|
//创建用户缓存
|
|
|
|
|
|
uni.setStorageSync('user_info', msgObj);
|
|
|
|
|
|
//小程序初始化接口
|
|
|
|
|
|
page_init({
|
|
|
|
|
|
user_id: msgObj.id,
|
|
|
|
|
|
tenant_id: uni.getStorageSync('tenant_id'),
|
|
|
|
|
|
a_tenant_user_id: uni.getStorageSync('a_tenant_user_id')
|
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
|
if (res.data.result) {
|
|
|
|
|
|
//获取接口返回数据
|
|
|
|
|
|
var msgObj = res.data.ret;
|
|
|
|
|
|
//创建用户是否可以创建小程序按钮状态缓存
|
|
|
|
|
|
uni.setStorageSync("is_create_tenant_icon", msgObj
|
|
|
|
|
|
.is_create_tenant_icon);
|
|
|
|
|
|
//创建租户信息缓存
|
|
|
|
|
|
uni.setStorageSync('tenant', msgObj.tenant);
|
|
|
|
|
|
//创建租户id缓存
|
|
|
|
|
|
uni.setStorageSync('tenant_id', msgObj.tenant.id);
|
|
|
|
|
|
//创建租户用户缓存
|
|
|
|
|
|
uni.setStorageSync('tenant_user', msgObj.tenant_user);
|
|
|
|
|
|
//创建租户用户id缓存
|
|
|
|
|
|
uni.setStorageSync('a_tenant_user_id', msgObj.tenant_user.id);
|
|
|
|
|
|
//创建我的界面底部展示后台地址缓存
|
|
|
|
|
|
uni.setStorageSync('tenant_admin_domain', msgObj
|
|
|
|
|
|
.tenant_admin_domain);
|
|
|
|
|
|
//创建小程序模板消息id缓存
|
|
|
|
|
|
if (JSON.stringify(msgObj.xcx_templates) != "{}") {
|
|
|
|
|
|
uni.setStorageSync('xcx_templates', msgObj.xcx_templates);
|
|
|
|
|
|
}
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resolve(res.data.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
|
reject(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showToast(res.data.message);
|
|
|
|
|
|
reject(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(async (error) => {
|
|
|
|
|
|
reject(false);
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//微信登录信息接口
|
|
|
|
|
|
export function statusBarHeight(call) {
|
|
|
|
|
|
uni.getSystemInfo({
|
|
|
|
|
|
success: (e) => {
|
|
|
|
|
|
call(e.statusBarHeight);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//放大图片
|
|
|
|
|
|
export function previewImage(img) {
|
|
|
|
|
|
wx.previewImage({
|
|
|
|
|
|
current: img, // 当前显示图片的http链接
|
|
|
|
|
|
urls: [img] // 需要预览的图片http链接列表
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
//当前缓存信息
|
|
|
|
|
|
export function isUserHasLogin() {
|
|
|
|
|
|
let userInfo = uni.getStorageSync("userInfo");
|
|
|
|
|
|
if (!userInfo) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
wxLogin,
|
|
|
|
|
|
getQiniuToken,
|
|
|
|
|
|
chooseImage,
|
|
|
|
|
|
userWxRegister,
|
|
|
|
|
|
setShareInfo,
|
|
|
|
|
|
previewImage
|
|
|
|
|
|
}
|