diff --git a/src/app.wpy b/src/app.wpy index a1754b9..4300c84 100755 --- a/src/app.wpy +++ b/src/app.wpy @@ -1,96 +1,105 @@ - diff --git a/src/utils/wxRequest.js b/src/utils/wxRequest.js index 26766f3..1652586 100755 --- a/src/utils/wxRequest.js +++ b/src/utils/wxRequest.js @@ -1,28 +1,53 @@ -import wepy from 'wepy'; -import util from './util'; -import md5 from './md5'; +import wepy from 'wepy' +import util from './util' +import md5 from './md5' import tip from './tip' -const API_SECRET_KEY = 'www.mall.cycle.com' -const TIMESTAMP = util.getCurrentTime() -const SIGN = md5.hex_md5((TIMESTAMP + API_SECRET_KEY).toLowerCase()) - -const wxRequest = async(params = {}, url) => { - tip.loading(); - let data = params.query || {}; - data.sign = SIGN; - data.time = TIMESTAMP; - let res = await wepy.request({ - url: url, - method: params.method || 'GET', - data: data, - header: { 'Content-Type': 'application/json' }, - }); - tip.loaded(); - return res; -}; - +const appendInfo = () => { + const API_SECRET_KEY = 'https://github.com/dyq086/wepy-mall/tree/master/src' + const TIMESTAMP = util.getCurrentTime() + const SIGN = md5.hex_md5((TIMESTAMP + API_SECRET_KEY).toLowerCase()) + const MORE = 'more......' + return { + API_SECRET_KEY: API_SECRET_KEY, + TIMESTAMP: TIMESTAMP, + SIGN: SIGN, + MORE: MORE + } +} +const wxRequest = async (params = {}, url) => { + console.log('wxRequest') + const c = wx.getStorageSync('onNetworkStatusChange') + if (!c.isConnected) { + wx.showToast({ + title: '无网络', + icon: 'loading', + duration: 2000 + }) + return + } + tip.loading() + let data = params.query || {} + const header = params.header || { + 'Content-Type': 'application/json' + } + const isAppend = params.isAppend || false + if (isAppend) { + const a = appendInfo() + for (const k in a) { + data[k] = a.k + } + } + const res = await wepy.request({ + url: url, + method: params.method || 'GET', + data: data, + header: header + }) + tip.loaded() + return res +} module.exports = { - wxRequest + wxRequest }