public.uts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {
  2. request
  3. } from '../request.uts'
  4. // 基础 URL 配置
  5. // #ifdef APP-ANDROID
  6. const BASE_URL = 'https://dev.xiaodingyun.cn'
  7. // #endif
  8. // #ifdef APP-IOS
  9. const BASE_URL = 'https://dev.xiaodingyun.cn'
  10. // #endif
  11. // #ifdef H5
  12. const BASE_URL = ''
  13. // #endif
  14. // #ifdef MP-WEIXIN
  15. const BASE_URL = 'https://dev.xiaodingyun.cn'
  16. // #endif
  17. // #ifdef MP-HARMONY
  18. const BASE_URL = 'https://dev.xiaodingyun.cn'
  19. // #endif
  20. // 获取枚举
  21. export function getEnums(params) {
  22. return request({
  23. url: "/enums",
  24. method: "get",
  25. params,
  26. custom: {
  27. showSuccess: true,
  28. loadingMsg: "获取枚举中...",
  29. },
  30. });
  31. }
  32. // 上传照片
  33. export function uploadPhoto(file) {
  34. const formData = new FormData();
  35. formData.append("file", file); // 假设上传的文件字段名为 'file'
  36. return request({
  37. url: "/upload",
  38. method: "post",
  39. data: formData,
  40. custom: {
  41. showSuccess: true,
  42. loadingMsg: "上传照片中...",
  43. },
  44. });
  45. }
  46. // 下载文件
  47. export function downloadFile(params) {
  48. return request({
  49. url: "/download",
  50. method: "get",
  51. params: params, // 传递文件名作为参数
  52. responseType: "blob", // 设置响应类型为 blob
  53. custom: {
  54. showSuccess: true,
  55. loadingMsg: "下载文件中...",
  56. },
  57. });
  58. }
  59. // 上传照片
  60. export function viewPhoto(params) {
  61. return request({
  62. url: "/view",
  63. method: "get",
  64. params: params,
  65. custom: {
  66. showSuccess: true,
  67. loadingMsg: "获取照片中...",
  68. },
  69. });
  70. }
  71. // 获取微信授权 URL
  72. export function getAuthUrl(params) {
  73. return request({
  74. url: "/client/wechat/auth-url",
  75. method: "get",
  76. params,
  77. custom: {
  78. showSuccess: true,
  79. loadingMsg: "获取微信授权 URL 中...",
  80. },
  81. });
  82. }
  83. /**
  84. * 获取微信JS-SDK配置
  85. * @param {string} url 当前页面URL,不包含#及其后面部分
  86. * @returns {Promise} 返回JS-SDK配置信息
  87. */
  88. export function getWxJsConfig(url) {
  89. return request({
  90. url: "/client/wechat/js-config",
  91. method: "get",
  92. params: {
  93. url
  94. },
  95. })
  96. .then((res) => {
  97. if (res.code === 200 && res.data) {
  98. return {
  99. code: 200,
  100. data: {
  101. appId: res.data.appId,
  102. timestamp: res.data.timestamp,
  103. nonceStr: res.data.nonceStr,
  104. signature: res.data.signature,
  105. jsApiList: Array.from(
  106. new Set(
  107. (res.data.jsApiList || []).concat([
  108. "getLocation",
  109. "chooseLocation",
  110. "chooseWXPay",
  111. "scanQRCode",
  112. "requestMerchantTransfer",
  113. ])
  114. )
  115. ),
  116. },
  117. };
  118. }
  119. throw new Error("获取微信配置失败");
  120. })
  121. .catch((error) => {
  122. console.error("获取微信JS-SDK配置失败:", error);
  123. return {
  124. code: 500,
  125. message: error.message || "获取微信配置失败",
  126. };
  127. });
  128. }