12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /**
- * 网络请求
- * @param {Object} req
- */
- export function request(req) {
- let header = {
- 'Content-type': 'application/x-www-form-urlencoded'
- }
- if (req.header) {
- header = Object.assign(header, req.header)
- }
- uni.request({
- url: req.url,
- data: req.data || {},
- header: header,
- method: req.method || "GET",
- dataType: req.dataType || "json",
- success: function(res) {
- console.info('--- request success >>>', res)
- if (req.success) {
- req.success(res.data)
- }
- },
- fail: function(res) {
- console.warn('--- request fail >>>', res)
- uni.showToast({
- title: '网络异常~',
- icon: 'none'
- })
- if (req.fail) {
- req.fail(res)
- }
- },
- complete: function(res) {
- if (res.statusCode !== 200) {
- console.log('--- request http error >>>', res)
- }
- if (req.complete) {
- req.complete(res)
- }
- }
- })
- }
|