123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /**
- * 网络请求公用方式,以后都这样用
- * 2018-5-10 16:57
- */
- var isTest = require('../utils/wxconstant.js').isTest()
- function request(url, params, success, fail) {
- this.requestLoading(url, params, "", success, fail)
- }
- function requestLoading(url, params, message, method,success, fail) {
- wx.showNavigationBarLoading()
- if (message != "") {
- wx.showLoading({
- title: message,
- })
- }
- wx.request({
- url: url,
- data: params,
- header: {
- //'Content-Type': 'application/json'
- 'content-type': 'application/x-www-form-urlencoded'
- },
- method: method,
- success: function (res) {
- if (isTest){
- console.log(method+':'+url + JSON.stringify(params), res)
- }
- wx.hideNavigationBarLoading()
- if (message != "") {
- wx.hideLoading()
- }
- if (res.statusCode == 200) {
- success(res)
- } else {
- fail()
- }
- },
- fail: function (res) {
- wx.hideNavigationBarLoading()
- if (message != "") {
- wx.hideLoading()
- }
- fail()
- },
- complete: function (res) {
- },
- })
- }
- module.exports = {
- request: request,
- requestLoading: requestLoading,
- }
- //引用:
- // var that = this
- // var data = { openid: wx.getStorageSync('openid') }
- // var url = baseUrl + BASEURL.getUrl.getAllNorm
- // netUtil.requestLoading(url, data, '正在加载数据...', 'POST', function (res) {
- // }, function (res) {
- // wx.showToast({
- // title: '加载数据失败',
- // icon: 'none',
- // duration: 2000
- // })
- // })
|