| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import {
- request
- } from '../request.uts'
- // 基础 URL 配置
- // #ifdef APP-ANDROID
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // #ifdef APP-IOS
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // #ifdef H5
- const BASE_URL = ''
- // #endif
- // #ifdef MP-WEIXIN
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // #ifdef MP-HARMONY
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // 获取枚举
- export function getEnums(params) {
- return request({
- url: "/enums",
- method: "get",
- params,
- custom: {
- showSuccess: true,
- loadingMsg: "获取枚举中...",
- },
- });
- }
- // 上传照片
- export function uploadPhoto(file) {
- const formData = new FormData();
- formData.append("file", file); // 假设上传的文件字段名为 'file'
- return request({
- url: "/upload",
- method: "post",
- data: formData,
- custom: {
- showSuccess: true,
- loadingMsg: "上传照片中...",
- },
- });
- }
- // 下载文件
- export function downloadFile(params) {
- return request({
- url: "/download",
- method: "get",
- params: params, // 传递文件名作为参数
- responseType: "blob", // 设置响应类型为 blob
- custom: {
- showSuccess: true,
- loadingMsg: "下载文件中...",
- },
- });
- }
- // 上传照片
- export function viewPhoto(params) {
- return request({
- url: "/view",
- method: "get",
- params: params,
- custom: {
- showSuccess: true,
- loadingMsg: "获取照片中...",
- },
- });
- }
- // 获取微信授权 URL
- export function getAuthUrl(params) {
- return request({
- url: "/client/wechat/auth-url",
- method: "get",
- params,
- custom: {
- showSuccess: true,
- loadingMsg: "获取微信授权 URL 中...",
- },
- });
- }
- /**
- * 获取微信JS-SDK配置
- * @param {string} url 当前页面URL,不包含#及其后面部分
- * @returns {Promise} 返回JS-SDK配置信息
- */
- export function getWxJsConfig(url) {
- return request({
- url: "/client/wechat/js-config",
- method: "get",
- params: {
- url
- },
- })
- .then((res) => {
- if (res.code === 200 && res.data) {
- return {
- code: 200,
- data: {
- appId: res.data.appId,
- timestamp: res.data.timestamp,
- nonceStr: res.data.nonceStr,
- signature: res.data.signature,
- jsApiList: Array.from(
- new Set(
- (res.data.jsApiList || []).concat([
- "getLocation",
- "chooseLocation",
- "chooseWXPay",
- "scanQRCode",
- "requestMerchantTransfer",
- ])
- )
- ),
- },
- };
- }
- throw new Error("获取微信配置失败");
- })
- .catch((error) => {
- console.error("获取微信JS-SDK配置失败:", error);
- return {
- code: 500,
- message: error.message || "获取微信配置失败",
- };
- });
- }
|