http.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import EventRequest from './EventRequest'
  2. import { getSign } from './util'
  3. const versionInfo = wx.getAccountInfoSync()
  4. const { envVersion = __wxConfig } = versionInfo.miniProgram
  5. let baseUrl = 'https://api.laitin-art.com'
  6. // let baseUrl = 'http://localhost:21028'
  7. let fileUrl = ''
  8. // switch (envVersion) {
  9. // case 'develop':
  10. // baseUrl = 'http://localhost:21028'
  11. // break
  12. // // case 'trial':
  13. // // case 'release':
  14. // default:
  15. // baseUrl = 'https://api.laitin-art.com'
  16. // break
  17. // }
  18. fileUrl = `${baseUrl}/api/FileAuth/Transport`
  19. const http = new EventRequest({
  20. baseUrl,
  21. timeout: 60000,
  22. })
  23. http.setResponseInterceptor((_, rsp) => {
  24. return new Promise<any>((resolve, reject) => {
  25. if (rsp.statusCode === 200) {
  26. resolve(rsp.data)
  27. return
  28. } else {
  29. if (rsp.data && rsp.data.error && rsp.data.error.message) {
  30. wx.showModal({
  31. title: '请求出错',
  32. content: rsp.data.error.message,
  33. success() {},
  34. })
  35. reject(rsp.data.error)
  36. return
  37. }
  38. if (rsp.errMsg && rsp.errMsg.length > 0) {
  39. reject({ message: '服务器链接不成功' })
  40. return
  41. }
  42. if (rsp.timeout && rsp.timeout.length > 0) {
  43. reject({ message: rsp.timeout })
  44. return
  45. }
  46. }
  47. reject({ message: '与服务器通讯错误' })
  48. })
  49. })
  50. export default http
  51. export const uploadProps = (query: string = '') => {
  52. const token = getSign()
  53. const language = 'zh-Hans'
  54. if (token != null) {
  55. return {
  56. url: fileUrl + (query && query.length > 0 ? '?' + query : ''),
  57. header: {
  58. Authorization: `Bearer ${token}`,
  59. '.AspNetCore.Culture': `c=${language}|uic=${language}`,
  60. Accept: 'application/json',
  61. } as Record<string, any>,
  62. }
  63. }
  64. return undefined
  65. }
  66. export const weburl = baseUrl
  67. export const share = {
  68. imageUrl: weburl + '/share.jpg',
  69. title: '丽天画业线上商城'
  70. }