var app = getApp();
/**
* 公共微信https请求封装
* @param url
* @param type
* @param data
* @param callBack
*/
function https(url, type, data, callBack, header) {
if (!data.isHideLoad) {
wx.showLoading({
title: '加载中',
})
}
wx.showNavigationBarLoading();
wx.request({
url: url,
method: type,
data: data,
header: header ? header : ( {
"Content-Type": "application/json",
"Authorization": "Bearer " + wx.getStorageSync('token')
}),
success: function (res) {
callBack(res.data);
},
fail: function (error) {
showToast("收收请求失败");
},
complete: function (res) {
console.log(res);
if (res.statusCode === 401) {
showToast("收收请求未授权");
}
wx.hideLoading();
wx.stopPullDownRefresh();
wx.hideNavigationBarLoading();
}
})
}
/**
* 接口API授权 type 1.是公共授权 2.登录授权 immediately立刻执行授权
*/
function authorization(type, callback, immediately) {
var timePromise1 = undefined;
var timePromise2 = undefined;
var that = this;
if (type == 1) { //1.是公共授权
var auth1 = function () {
//获取公共接口授权token 公共接口授权token两个小时失效 超过两个小时重新请求
if (!wx.getStorageSync("userid") && (immediately || (!wx.getStorageSync("token") || wx.getStorageSync("token") == "undefined" || ((new Date().getTime() - new Date(wx.getStorageSync("expires_in")).getTime()) / 1000) > 7199))) {
clearInterval(timePromise2);
that.https(app.globalData.api + "/token", "POST", {grant_type: 'client_credentials'},
function (data) {
if (data.access_token) {
wx.setStorageSync('token', data.access_token);//公共接口授权token
wx.setStorageSync('expires_in', new Date());//公共接口授权token 有效时间
}
callback.call(that, data)
}, {
'Authorization': 'Basic MTcwNjE0MDAwMTozNzliYjljNi1kNTYwLTQzMjUtYTQxMi0zMmIyMjRlMjg3NDc=',
'Content-Type': 'application/x-www-form-urlencoded'
}
)
} else { //没有执行授权
callback.call(that)
}
}
auth1();
timePromise1 = setInterval(auth1, 7199000);
} else if (type == 2) { //2.登录授权
var auth2 = function () {
//获取登录接口授权token 登录接口授权token两个小时失效 超过两个小时重新请求
if (wx.getStorageSync("userid") && (immediately || ((new Date().getTime() - new Date(wx.getStorageSync("expires_in")).getTime()) / 1000) > 7199)) {
clearInterval(timePromise1);
that.https(app.globalData.api + "/token", "POST", {
grant_type: 'password',
username: wx.getStorageSync("userid"),
password: wx.getStorageSync("usersecret")
},
function (data) {
if (data.access_token) {
wx.setStorageSync('token', data.access_token);//登录接口授权token
wx.setStorageSync('expires_in', new Date());//登录接口授权token 有效时间
}
callback.call(that, data)
}, {
'Authorization': 'Basic MTcwNjE0MDAwMTozNzliYjljNi1kNTYwLTQzMjUtYTQxMi0zMmIyMjRlMjg3NDc=',
'Content-Type': 'application/x-www-form-urlencoded'
}
)
} else { //没有执行授权
callback.call(that)
}
}
auth2();
timePromise2 = setInterval(auth2, 7199000);
}
}
/**
* 是否登录
*/
function isLogin() {
return wx.getStorageSync("userid") ? true : false;
}
/**
* 是否登录提示
*/
function isLoginModal(isShow) {
if (!wx.getStorageSync("userid")) {
if (isShow) {
wx.showModal({
title: '收收提示',
content: "登录收收,体验更完善功能",
showCancel: true,
confirmColor: "#00ACFF",
confirmText: "登录",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/account/login'
})
console.log('用户点击确定');
} else if (res.cancel) {
//返回上一页
wx.navigateBack({
delta: 1
})
}
}
})
} else {
wx.navigateTo({
url: '/pages/account/login'
})
}
}
}
/**
* Toast提示框
*/
function showToast(title, icon, duration) {
wx.showToast({
title: title || "",
icon: icon || 'success',
duration: duration || 2000
})
}
/**
* Modal显示模态弹窗
*/
function showModal(title, content, confirmText, cancelText, callback, showCancel) {
var that = this;
wx.showModal({
title: title,
content: content,
confirmText: confirmText,
cancelText: cancelText,
showCancel: showCancel || true,
confirmColor: "#00ACFF",
cancelColor: "#33cd5f",
success: function (res) {
callback.call(that, res)
/* if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}*/
}
})
}
/**
* toolTip方法 type 1是提示色 2是警告色
*/
function toolTip(that, msg, type) {
//提示字段值
that.setData(
{
popMsg: msg,
popType: type == 1 ? "tool-tip-message-success" : "tool-tip-message" || "tool-tip-message"
}
);
}
/**
* 调用验证表单方法
*/
function wxValidate(e, that, callback) {
toolTip(that, "")
const params = e.detail.value
/* console.log(params);*/
if (!that.WxValidate.checkForm(e)) {
const error = that.WxValidate.errorList
//提示字段值
toolTip(that, error[0].msg)
/* console.log(error)*/
return false
} else {
callback.call(this)
}
}
/**
* 改变验证码按钮状态
*/
function verifyCodeBtn(e, that) {
if (e.currentTarget.id == 'user' && (/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value))) {
that.setData({
vcdisabled: false
})
} else if (e.currentTarget.id == 'user' && !(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value))) {
that.setData({
vcdisabled: true
})
}
}
/**
* 获取验证码公共方法
*/
function getVerifyCode(account, that, callback) {
var second = 120,
timePromise = undefined;
timePromise = setInterval(function () {
if (second <= 0) {
clearInterval(timePromise);
that.setData({
paracont: "重发验证码",
vcdisabled: false
})
} else {
that.setData({
paracont: second + "秒后重试",
vcdisabled: true
})
second--;
}
}, 1000, 122);
this.https(app.globalData.api + "/api/util/send_sms_validcode/" + account, "GET", {},
function (data) {
if (data.code == 1001) {
callba
没有合适的资源?快使用搜索试试~ 我知道了~
物品回收微信小程序源码.rar
共100个文件
wxss:22个
js:21个
json:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 128 浏览量
2023-06-11
13:35:16
上传
评论
收藏 1.37MB RAR 举报
温馨提示
物品回收微信小程序源码.rar
资源推荐
资源详情
资源评论
收起资源包目录
物品回收微信小程序源码.rar (100个子文件)
shoushou.iml 336B
head.jpg 32KB
util.js 18KB
validate.js 13KB
login.js 6KB
register.js 6KB
order.js 5KB
organizingdata.js 4KB
information.js 4KB
recharge.js 3KB
referenceprice.js 3KB
news.js 2KB
index.js 2KB
account.js 2KB
help.js 2KB
app.js 1KB
accountinfo.js 1KB
findpassword.js 1018B
wallet.js 950B
setting.js 928B
searchaddresstemplate.js 876B
addresstemplate.js 870B
logs.js 266B
app.json 2KB
news.json 73B
order.json 61B
referenceprice.json 55B
logs.json 54B
findpassword.json 46B
information.json 46B
accountinfo.json 46B
addresstemplate.json 46B
organizingdata.json 46B
searchaddresstemplate.json 46B
wallet.json 40B
index.json 40B
login.json 40B
recharge.json 40B
register.json 40B
setting.json 40B
account.json 40B
help.json 40B
referenceprice-off.png 9KB
news-off.png 8KB
account-off.png 7KB
kefu.png 7KB
buttom.png 6KB
referenceprice-on.png 6KB
news-on.png 6KB
money_bag.png 5KB
account-on.png 4KB
order-off.png 4KB
money_bag_fill.png 4KB
home-off.png 4KB
home-on.png 4KB
order-on.png 3KB
account.wxml 4KB
order.wxml 4KB
register.wxml 4KB
organizingdata.wxml 4KB
index.wxml 3KB
information.wxml 3KB
login.wxml 3KB
wallet.wxml 2KB
accountinfo.wxml 2KB
referenceprice.wxml 2KB
setting.wxml 1KB
searchaddresstemplate.wxml 1KB
recharge.wxml 1KB
news.wxml 963B
addresstemplate.wxml 630B
findpassword.wxml 332B
help.wxml 232B
logs.wxml 188B
font.wxss 81KB
ionic.wxss 46KB
iconfont.wxss 9KB
app.wxss 6KB
order.wxss 1KB
index.wxss 1KB
information.wxss 1KB
account.wxss 785B
referenceprice.wxss 606B
login.wxss 259B
news.wxss 228B
wallet.wxss 199B
recharge.wxss 164B
logs.wxss 106B
searchaddresstemplate.wxss 99B
organizingdata.wxss 39B
addresstemplate.wxss 38B
findpassword.wxss 37B
accountinfo.wxss 36B
register.wxss 33B
setting.wxss 32B
help.wxss 26B
modules.xml 268B
misc.xml 243B
encodings.xml 238B
vcs.xml 180B
共 100 条
- 1
资源评论
IT技术猿猴
- 粉丝: 1w+
- 资源: 789
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功