123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import EventRequest from './EventRequest'
- import { getSign } from './util'
- const versionInfo = wx.getAccountInfoSync()
- const { envVersion = __wxConfig } = versionInfo.miniProgram
- let baseUrl = 'https://api.laitin-art.com'
- // let baseUrl = 'http://localhost:21028'
- let fileUrl = ''
- // switch (envVersion) {
- // case 'develop':
- // baseUrl = 'http://localhost:21028'
- // break
- // // case 'trial':
- // // case 'release':
- // default:
- // baseUrl = 'https://api.laitin-art.com'
- // 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
- export const share = {
- imageUrl: weburl + '/share.jpg',
- title: '丽天画业线上商城'
- }
|