1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import EventRequest from './EventRequest'
- import { getSign } from './util'
- const versionInfo = wx.getAccountInfoSync()
- const { envVersion = __wxConfig } = versionInfo.miniProgram
- let baseUrl = 'http://localhost:21028'
- // let baseUrl = 'https://api.huanart.com'
- let fileUrl = ''
- switch (envVersion) {
- case 'trial':
- case 'release':
- baseUrl = 'https://api.huanart.com'
- break
- default:
- break
- }
- fileUrl = `${baseUrl}/api/FileAuth/Transport`
- const http = new EventRequest({
- baseUrl,
- timeout: 60000,
- })
- http.setResponseInterceptor((_, rsp) => {
- return new Promise<any>((resolve, reject) => {
- if (rsp.statusCode === 200) {
- resolve(rsp.data)
- return
- } else {
- if (rsp.data && rsp.data.error && rsp.data.error.message) {
- wx.showModal({
- title: '请求出错',
- content: rsp.data.error.message,
- success() {},
- })
- reject(rsp.data.error)
- return
- }
- if (rsp.errMsg && rsp.errMsg.length > 0) {
- reject({ message: '服务器链接不成功' })
- return
- }
- if (rsp.timeout && rsp.timeout.length > 0) {
- reject({ message: rsp.timeout })
- return
- }
- }
- reject({ message: '与服务器通讯错误' })
- })
- })
- export default http
- export const uploadProps = (query: string = '') => {
- const token = getSign()
- const language = 'zh-Hans'
- if (token != null) {
- return {
- url: fileUrl + (query && query.length > 0 ? '?' + query : ''),
- header: {
- Authorization: `Bearer ${token}`,
- '.AspNetCore.Culture': `c=${language}|uic=${language}`,
- Accept: 'application/json',
- } as Record<string, any>,
- }
- }
- return undefined
- }
- export const weburl = baseUrl
|