| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- const baseRequest = async (url, method, data = {}, loading = true) => {
- let header = {}
- return new Promise((reslove, reject) => {
- loading && uni.showLoading({
- title: '加载中'
- })
- uni.request({
- url: 'https://xnh.xazhima.com/prod-api/wap/business/weixin' + url,
- method: method || 'GET',
- header: header,
- timeout: 10000,
- data: data || {},
- success: (successData) => {
- const res = successData.data
- if (successData.statusCode == 200) {
- if (res.code === 200) {
- reslove(res)
- } else {
- uni.showToast({
- title: '登录信息失效'
- })
- }
- } else {
- uni.showToast({
- title: '网络连接失败,请稍后重试'
- })
- reject(res)
- }
- },
- fail: (msg) => {
- uni.showToast({
- title: '网络连接失败,请稍后重试'
- })
- reject(msg)
- },
- complete: () => {
- uni.hideLoading()
- },
- })
- })
- }
- const request = {
- getPath: (api, data, keys, loading) => {
- let newRequestPath = api;
- Object.keys(keys).forEach(function (key) {
- newRequestPath = newRequestPath.replace(
- "{" + key + "}",
- keys[key]
- );
- });
- return baseRequest(newRequestPath, 'GET', data, loading)
- }
- }
- // ['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
- // request[method] = (api, data, loading) => baseRequest(api, method, data, loading)
- // })
- export default request
|