const util = {
API: 'http://你的域名/api/',
webSrc: 'http://你的域名/#/dayin_wx',
/**
* 获取窗口大小
*/
getWindowSize(that) {
let pages = getCurrentPages(); // 当前页面
// let beforePage = pages[pages.length - 2];
wx.getSystemInfo({
success: function (res) {
that.setData({
model: res.model,
width: res.windowWidth,
height: res.windowHeight,
topHeight: res.statusBarHeight + 46,
pageLength: pages.length
})
},
})
},
login(cb){
var that = this;
wx.login({
success(res) {
that.post('wx/user/login', { js_code: res.code }, function (res) {
if(res.code == -1){
wx.showToast({
title: res.data.msg + '',
icon: 'none'
})
}else if (res.code == 1) {
wx.setStorageSync("user", res.data)
wx.setStorageSync("token", res.token)
cb(res)
}
})
}
})
},
//post请求
post(url, data, success, fail) {
this.http('POST', url, data, success, fail)
},
get(url, data, success, fail) {
this.http('GET', url, data, success, fail)
},
http(method, url, data, success, fail) {
//通用post接口实现方法
var that = this;
let _data = data || {};
let _success = success || function (e) {
console.log(e)
};
let _fail = fail || function (e) {
console.log(e)
};
let _method = method || 'POST';
let _header = {
'content-type': 'application/x-www-form-urlencoded'
};
if (_method.toUpperCase() == 'GET') {
_header = {
'content-type': 'application/json'
};
}
if (wx.getStorageSync("token")) {
_header.token = wx.getStorageSync("token")
}
if (arguments.length == 2 && typeof _data == 'function') {
_success = _data
}
wx.request({
url: this.API + url,
method: _method,
header: _header,
data: _data,
success: function (res) {
if (typeof _success == 'function' && res.statusCode != 404 && res.statusCode != 500 && res.statusCode != 400) {
_success(res.data);
if (res.data.code == -1){
that.login(function (res) {
that.http(method, url, data, success, fail)
})
} else if(res.data.code != 1){
wx.showToast({
title: res.data.msg + '',
icon: 'none'
})
}
// if (res.data.code != 101 && res.data.code != -1){
// if (res.data.code != 1) {
// wx.showToast({
// title: res.data.msg + '',
// icon: 'none'
// })
// }
// _success(res.data);
// } else if (res.data.code != -1){
// that.login(function(res){
// that.http(method, url, data, success, fail)
// })
// }
} else {
if (typeof _success != 'function') {}
wx.showToast({
title: '接口 错误 ' + res.statusCode,
icon: 'none'
})
}
},
fail: function (res) {
console.log(`======== 接口 请求失败 ========`);
if (typeof _fail == 'function') {
_fail(res);
}
}
});
},
dateFormat(time, fmt) { //author: meizz
let date = new Date(parseInt(time))
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
},
navTo(e) {
let type = e.currentTarget.dataset.type
let names = e.currentTarget.dataset.names
let path = e.currentTarget.dataset.path
let nav = 'navigateTo'
if (type == 1) {
nav = 'navigateTo'
} else if (type == 2) {
nav = 'redirectTo'
} else if (type == 3) {
nav = 'switchTab'
}
let url = path
let _names = []
if (names) {
_names = names.split(',')
}
if (_names.length > 0) {
url += '?'
for (let i in _names) {
if (i == 0) {
url += _names[i] + '=' + e.currentTarget.dataset[_names[i]]
} else {
url += '&' + _names[i] + '=' + e.currentTarget.dataset[_names[i]]
}
}
}
wx[nav]({
url: url,
})
},
wxpay(msg, cb) {
wx.requestPayment({
timeStamp: msg.timestamp,
nonceStr: msg.nonceStr,
package: msg.package,
signType: 'MD5',
paySign: msg.paySign,
success(res) {
wx.showToast({
title: '发布成功',
})
util.post('help/update/state', {
state: 1,
is_pay: 1,
id: msg.oid
}, function (res) {
if (res.code == 1) {
if (cb) {
cb(true)
} else {
wx.redirectTo({
url: '/pages/order/detail/detail?id=' + msg.oid,
})
}
} else {
if (cb) {
cb(false)
} else {
wx.redirectTo({
url: '/pages/order/detail/detail?id=' + msg.oid,
})
}
}
})
},
fail(res) {
wx.showToast({
title: '支付失败',
icon: 'none'
})
if (cb) {
cb(false)
} else {
wx.redirectTo({
url: '/pages/order/detail/detail?id=' + msg.oid,
})
}
}
})
},
formatMsgTime(timespan) {
var dateTime = new Date(timespan);
var year = dateTime.getFullYear();
var month = dateTime.getMonth() + 1;
var day = dateTime.getDate();
var hour = dateTime.getHours();
var minute = dateTime.getMinutes();
var second = dateTime.getSeconds();
var now = new Date();
var now_new = now.getTime(); //typescript转换写法
var milliseconds = 0;
var timeSpanStr;
milliseconds = now_new - dateTime.getTime();
if (milliseconds <= 1000 * 60 * 1) {
timeSpanStr = '刚刚';
} else if (1000 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60) {
timeSpanStr = Math.round((milliseconds / (1000 * 60))) + '分钟前';
} else if (1000 * 60 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24) {
timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60)) + '小时前';
} else if (1000 * 60 * 60 * 24 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24 * 15) {
timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60 * 24)) + '天前';
} else if (milliseconds > 1000 * 60 * 60 * 24 * 15 && year == now.getFullYear()) {
timeSpanStr = month + '-' + day + ' ' + hour + ':' + minute;
} else {
timeSpanStr = timespan;
}
return timeSpanStr;
},
cancel(oid, name, cb) {
this.post('help/update/state', {
state: 4,
id: oid
}, function (res) {
if (res.code == 1) {
wx.showToast({
title: '取消成功',
})
cb(true)
} else {
cb(false)
wx.showToast({
title: '取消失败',
icon: 'none'
})
}
})
}
}
module.exports = util
没有合适的资源?快使用搜索试试~ 我知道了~
校园综合服务平台-v1版本的微信小程序.zip
共142个文件
png:41个
json:25个
wxss:23个
需积分: 5 0 下载量 6 浏览量
2024-02-01
18:16:27
上传
评论
收藏 719KB ZIP 举报
温馨提示
微信小程序
资源推荐
资源详情
资源评论
收起资源包目录
校园综合服务平台-v1版本的微信小程序.zip (142个子文件)
后台-首页.jpg 164KB
后台-快递代取.jpg 78KB
后台-接单员.jpg 76KB
后台-代理商.jpg 75KB
小程序-订单界面.jpg 20KB
小程序-首页.jpg 19KB
小程序-我的.jpg 17KB
小程序-申请接单.jpg 15KB
小程序-提现.jpg 13KB
util.js 8KB
banzu.js 7KB
register.js 5KB
detail.js 4KB
index.js 4KB
dayin.js 3KB
other.js 3KB
info.js 3KB
addressinfo.js 2KB
area.js 2KB
login.js 2KB
address.js 2KB
daiqu.js 2KB
cash.js 2KB
chooseaddress.js 2KB
mine.js 1KB
richtext.js 910B
app.js 863B
about.js 848B
payment.js 847B
order.js 354B
dy.js 310B
jdsm.js 281B
project.config.json 4KB
app.json 1KB
project.private.config.json 329B
sitemap.json 191B
order.json 79B
area.json 52B
jdsm.json 52B
register.json 46B
daiqu.json 46B
about.json 46B
chooseaddress.json 46B
mine.json 46B
address.json 46B
info.json 46B
addressinfo.json 46B
login.json 46B
dayin.json 46B
dy.json 46B
payment.json 46B
detail.json 40B
cash.json 40B
index.json 35B
banzu.json 35B
richtext.json 27B
other.json 2B
logo.png 110KB
t6.png 27KB
t4.png 25KB
t2.png 20KB
t8.png 17KB
sh.png 16KB
t5.png 10KB
2.png 8KB
d6.png 8KB
location.png 8KB
d3.png 8KB
6.png 8KB
d5.png 8KB
m.png 8KB
none.png 7KB
5.png 7KB
l2.png 7KB
1.png 6KB
dh.png 6KB
sh2.png 6KB
t3.png 6KB
t7.png 6KB
sh1.png 5KB
d4.png 5KB
t1.png 5KB
pjh.png 5KB
tx.png 4KB
d1.png 4KB
3.png 4KB
mt.png 3KB
bj.png 3KB
l1.png 3KB
l.png 3KB
search2.png 3KB
right.png 3KB
4.png 3KB
d2.png 3KB
cn.png 3KB
jt.png 3KB
mt2.png 2KB
ljt.png 2KB
jdsm.wxml 9KB
detail.wxml 4KB
共 142 条
- 1
- 2
资源评论
YOLO数据集工作室
- 粉丝: 483
- 资源: 1569
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功