var WxParse = require('components/wxParse/wxParse.js');
var util = require('utils/util.js');
App({
onLaunch: function () {
var userInfo;
if(userInfo = wx.getStorageSync('userInfo')){
this.globalData.userInfo = userInfo;
}
this.getSystemInfo();
},
getSystemInfo : function() {
var that = this;
wx.getSystemInfo({
success: function(res) {
that.systemInfo = res;
}
});
},
sendRequest: function(param, customSiteUrl){
var that = this,
data = param.data || {},
header = param.header,
requestUrl;
if(data.app_id){
data._app_id = data.app_id;
} else {
data._app_id = data.app_id = this.getAppId();
}
// data._app_id = this.getAppId();
// data.app_id = this.getAppId();
if(!this.globalData.notBindXcxAppId){
data.session_key = this.getSessionKey();
}
if(customSiteUrl) {
requestUrl = customSiteUrl + param.url;
} else {
requestUrl = this.globalData.siteBaseUrl + param.url;
}
if(param.method){
if(param.method.toLowerCase() == 'post'){
data = this.modifyPostParam(data);
header = header || {
'content-type': 'application/x-www-form-urlencoded;'
}
}
param.method = param.method.toUpperCase();
}
if(!param.hideLoading){
this.showToast({
title: '请求中...',
icon: 'loading'
});
}
wx.request({
url: requestUrl,
data: data,
method: param.method || 'GET',
header: header || {
'content-type': 'application/json'
},
success: function(res) {
if(res.statusCode && res.statusCode != 200){
that.hideToast();
that.showModal({
content: ''+res.errMsg
});
return;
}
if(res.data.status){
if(res.data.status == 401 || res.data.status == 2){
// 未登录
that.login();
return;
}
if(res.data.status != 0){
that.hideToast();
that.showModal({
content: ''+res.data.data
});
return;
}
}
typeof param.success == 'function' && param.success(res.data);
},
fail: function(res){
that.showModal({
content: '请求失败 '+res.errMsg
})
typeof param.fail == 'function' && param.fail(res.data);
},
complete: function(res){
// that.hideToast();
typeof param.complete == 'function' && param.complete(res.data);
}
});
},
turnToPage: function(url, isRedirect){
var tabBarPagePathArr = this.getTabPagePathArr();
// tabBar中的页面改用switchTab跳转
if(tabBarPagePathArr.indexOf(url) != -1) {
this.switchToTab(url);
return;
}
if(!isRedirect){
wx.navigateTo({
url: url
});
} else {
wx.redirectTo({
url: url
});
}
},
tapPrevewPictureHandler:function(e){
wx.previewImage({
urls: e.currentTarget.dataset.imgarr instanceof Array ? e.currentTarget.dataset.imgarr : [e.currentTarget.dataset.imgarr],
})
},
switchToTab: function(url){
wx.switchTab({
url: url
});
},
turnBack: function(){
wx.navigateBack();
},
setPageTitle: function(title){
wx.setNavigationBarTitle({
title: title
});
},
showToast: function(param){
wx.showToast({
title: param.title,
icon: param.icon,
duration: param.duration || 1500,
success: function(res){
typeof param.success == 'function' && param.success(res);
},
fail: function(res){
typeof param.fail == 'function' && param.fail(res);
},
complete: function(res){
typeof param.complete == 'function' && param.complete(res);
}
})
},
hideToast: function(){
wx.hideToast();
},
showModal: function(param){
wx.showModal({
title: param.title || '提示',
content: param.content,
showCancel: param.showCancel || false,
cancelText: param.cancelText || '取消',
cancelColor: param.cancelColor || '#000000',
confirmText: param.confirmText || '确定',
confirmColor: param.confirmColor || '#3CC51F',
success: function(res) {
if (res.confirm) {
typeof param.confirm == 'function' && param.confirm(res);
} else {
typeof param.cancel == 'function' && param.cancel(res);
}
},
fail: function(res){
typeof param.fail == 'function' && param.fail(res);
},
complete: function(res){
typeof param.complete == 'function' && param.complete(res);
}
})
},
chooseVideo: function(callback, maxDuration){
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: maxDuration || 60,
camera: ['front', 'back'],
success: function (res) {
typeof callback == 'function' && callback(res.tempFilePaths[0]);
}
})
},
chooseImage: function(callback, count){
var that = this;
wx.chooseImage({
count: count || 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFilePaths = res.tempFilePaths,
imageUrls = [];
that.showToast({
title: '提交中...',
icon: 'loading',
duration: 10000
});
for (var i = 0; i < tempFilePaths.length; i++) {
wx.uploadFile({
url : that.globalData.siteBaseUrl+ '/index.php?r=AppData/uploadImg',
filePath: tempFilePaths[i],
name: 'img_data',
success: function(res){
var data = JSON.parse(res.data);
if(data.status == 0){
imageUrls.push(data.data);
if(imageUrls.length == tempFilePaths.length){
that.hideToast();
typeof callback == 'function' && callback(imageUrls);
}
} else {
that.showModal({
content: data.data
})
}
},
fail: function(res){
console.log(res.errMsg);
}
})
}
}
})
},
previewImage: function(options){
wx.previewImage({
current: options.current,
urls: options.urls || [options.current]
})
},
playVoice: function(filePath){
wx.playVoice({
filePath: filePath
});
},
pauseVoice: function(){
wx.pauseVoice();
},
// 统计用户分享
countUserShareApp: function(){
this.sendRequest({
url: '/index.php?r=AppShop/UserShareApp'
});
},
// 调用微信支付接口
wxPay: function(param){
var _this = this;
wx.requestPayment({
'timeStamp': param.timeStamp,
'nonceStr': param.nonceStr,
'package': param.package,
'signType': 'MD5',
'paySign': param.paySign,
success: function(res){
_this.wxPaySuccess(param);
typeof param.success === 'function' && param.success();
},
fail: function(res){
if(res.errMsg === 'requestPayment:fail cancel'){
typeof param.fail === 'function' && param.fail();
return;
}
if(res.errMsg === 'requestPayment:fail'){
res.errMsg = '支付失败';
}
_this.showModal({
content: res.errMsg
})
_this.wxPayFail(param, res.errMsg);
typeof param.fail === 'function' && param.fail();
}
})
},
wxPaySuccess: function(param){
var orderId = param.orderId,
goodsType = param.goodsType,
formId = param.package.substr(10),
t_num = goodsType == 1 ? 'AT0104':'AT0009';
this.sendRequest({
hideLoading: true,
url: '/index.php?r=AppShop/SendXcxOrderCompleteMsg',
data: {
formId: formId,
t_num: t_num,
order_id: orderId
duoshanjia_微信小程序模板js代码前台前端H5页面源码.gz
175 浏览量
2023-08-09
14:59:32
上传
评论
收藏 469KB GZ 举报
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
wsnbb_2023
- 粉丝: 15
- 资源: 6004
最新资源
- 目标检测-零售食品LOGO检测数据集-40000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-30000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-20000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-10000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 基于GUI+MYSQL+JAVA图书管理系统文档说明+源码(高分大作业项目).zip
- 基于Qt使用C++实现图书管理系统源码+数据库(95分以上).zip
- 基于GUI+MYSQL+JAVA票务管理系统文档介绍+源码+数据库(高分大作业).zip
- 优先编码器除法电微分运算电路 全加器函数发生电路等电路经典Multisim仿真实验源文件合集(25个).zip
- 2331308JS课堂案例.zip
- STM32H750VBT6单片机最小系统开发板AD设计硬件(原理图+PCB+3D封装库)工程文件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)