123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- let app = getApp();
- //返回首页
- function goHome(back = false) {
- const URL = "/pages/yuesuo/yuesuo"
- if (back) {
- wx.navigateTo({
- url: URL
- })
- } else {
- wx.reLaunch({
- url: URL
- })
- }
- }
- var loadingNum = 0;
- function request(url, method = 'GET', postData, loading = false) {
- method = method.toUpperCase();
- loadingNum += 1;
- if (loading) {
- wx.showLoading({
- title: '加载中...',
- })
- }
- return new Promise((resolve, reject) => {
- wx.request({
- url: app.globalData.url + url,
- data: postData,
- header: {
- "Content-Type": "application/x-www-form-urlencoded",
- "Accept": "application/json"
- },
- method: method,
- success: function(res) {
- resolve(res.data);
- },
- fail: function(error) {
- app.timeOut()
- reject(error); //请求失败
- },
- complete: function() {
- loadingNum -= 1;
- if (loading && loadingNum < 1) {
- wx.hideLoading();
- }
- }
- })
- })
- }
- function getData(url, postData, loading = false) {
- return request(url, 'GET', postData, loading = false);
- }
- function postData(url, postData, loading = false) {
- return request(url, 'POST', postData, loading = false);
- }
- module.exports = {
- formatTime,
- getData,
- postData,
- goHome
- }
|