1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /* wx.request */
- //const BASE_API_URL = 'https://api.itthealth.com/api'
- const BASE_API_URL = 'https://itt.chl6zk.store/api'
- const BASE_API_VERSION = '/v1'
- import itt from '../utils/util'
- const app = getApp()
- export const wxRequest = (url,data) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: BASE_API_URL + url + BASE_API_VERSION,
- data: data,
- header: {
- systemData:JSON.stringify({
- requestId: itt.getUUID(),
- loginToken: wx.getStorageSync('accessToken') || '',
- timestamp: new Date().getTime()
- })
- },
- method: 'POST',
- success (response) {
- if (response.statusCode !== 200) {
- reject(response.data.msg || '请求错误')
- } else {
- if (response.data.code !== '000' && response.data.code !== '102') {
- reject(response.data.msg || '请求错误')
- } else if (response.data.code == '102') {
- wx.hideLoading()
- // 重新登录
- wx.showModal({
- content: response.data.msg,
- confirmColor: '#333',
- showCancel: false,
- success (res) {
- if (res.confirm) {
- wx.clearStorageSync()
- app.globalData.isNeedHeadImg = false
- app.globalData.isNeedPhone = false
- app.globalData.userInfo.login = false
- app.globalData.accessToken = ''
- app.globalData.userInfo.headImg= ''
- app.globalData.userInfo.userName = ''
- app.globalData.userInfo.phoneNumber = ''
- app.globalData.selectedInex = 0
- wx.reLaunch({
- url: '/pages/index/index',
- })
- }
- }
- })
- } else {
- resolve(response.data)
- }
- }
- },
- fail (e) {
- reject('网络错误')
- }
- })
- })
- }
- export const wxUpload = (url, data) => {
- return new Promise((resolve, reject) => {
- wx.uploadFile({
- url: BASE_API_URL + url + BASE_API_VERSION,
- filePath: data.filePath,
- name: 'file',
- formData: {
- 'file': data.filePath
- },
- success (res){
- const data = res.data
- resolve(data)
- },
- fail () {
- reject('上传失败')
- }
- })
- })
- }
|