init
This commit is contained in:
18
common/api.js
Normal file
18
common/api.js
Normal file
@ -0,0 +1,18 @@
|
||||
import request from './request.js';
|
||||
|
||||
// 获取二维码详细信息
|
||||
export function getInfo(data) {
|
||||
return request({
|
||||
url: '/mobile/getInfo',
|
||||
method:'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
// 客户填写订单信息
|
||||
export function addOrder(data) {
|
||||
return request({
|
||||
url: '/mobile/addOrder',
|
||||
method:'post',
|
||||
data
|
||||
})
|
||||
}
|
22
common/date.js
Normal file
22
common/date.js
Normal file
@ -0,0 +1,22 @@
|
||||
export function formatDate(date, fmt) {
|
||||
if (/(y+)/.test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
|
||||
}
|
||||
let o = {
|
||||
'M+': date.getMonth() + 1,
|
||||
'd+': date.getDate(),
|
||||
'h+': date.getHours(),
|
||||
'm+': date.getMinutes(),
|
||||
's+': date.getSeconds()
|
||||
}
|
||||
for (let k in o) {
|
||||
let str = o[k] + '';
|
||||
if (new RegExp(`(${k})`).test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
|
||||
}
|
||||
}
|
||||
return fmt;
|
||||
};
|
||||
function padLeftZero(str) {
|
||||
return ('00' + str).substr(str.length);
|
||||
}
|
39
common/request.js
Normal file
39
common/request.js
Normal file
@ -0,0 +1,39 @@
|
||||
const request = (config) => {
|
||||
uni.showLoading({
|
||||
title: '数据加载中...',
|
||||
mask: true
|
||||
})
|
||||
// 处理 apiUrl
|
||||
config.url = 'http://192.168.0.125:1777' + config.url;
|
||||
if(!config.data){
|
||||
config.data = {};
|
||||
}
|
||||
// if (config.url.indexOf('/distribution') !== -1) {
|
||||
// config.header = {
|
||||
// token: uni.getStorageSync('fxToken')
|
||||
// }
|
||||
// }
|
||||
// else if (config.url.indexOf('.do') !== -1) {
|
||||
// config.header = {
|
||||
// token: uni.getStorageSync('token')
|
||||
// }
|
||||
// }
|
||||
console.log(JSON.stringify(config.data));
|
||||
let promise = new Promise(function(resolve, reject) {
|
||||
uni.request(config).then(responses => {
|
||||
// 异常
|
||||
if (responses[0]) {
|
||||
reject({message : "网络超时"});
|
||||
} else {
|
||||
let response = responses[1].data; // 如果返回的结果是data.data的,嫌麻烦可以用这个,return res,这样只返回一个data
|
||||
resolve(response);
|
||||
}
|
||||
uni.hideLoading()
|
||||
}).catch(error => {
|
||||
reject(error);
|
||||
})
|
||||
})
|
||||
return promise;
|
||||
};
|
||||
|
||||
export default request;
|
Reference in New Issue
Block a user