no message
This commit is contained in:
parent
c22f57b281
commit
196a67d6fd
@ -6,6 +6,10 @@ export const CORP_API_BASE_URL_MAP = {
|
|||||||
wwa54dfba0b5441ef1: "https://crm.gykqyy.com/ykt/",
|
wwa54dfba0b5441ef1: "https://crm.gykqyy.com/ykt/",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const CORP_ID_ALIAS_MAP = {
|
||||||
|
"wpLgjyawAAeRkCPQMp9-z5q-xEzK64nA": "wwa54dfba0b5441ef1",
|
||||||
|
};
|
||||||
|
|
||||||
function normalizeBaseUrl(url) {
|
function normalizeBaseUrl(url) {
|
||||||
return String(url || "").replace(/\/+$/, "");
|
return String(url || "").replace(/\/+$/, "");
|
||||||
}
|
}
|
||||||
@ -14,6 +18,11 @@ function getDefaultBaseUrl() {
|
|||||||
return normalizeBaseUrl(env.MP_API_BASE_URL);
|
return normalizeBaseUrl(env.MP_API_BASE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function normalizeCorpId(corpId) {
|
||||||
|
const normalizedCorpId = String(corpId || "").trim();
|
||||||
|
return CORP_ID_ALIAS_MAP[normalizedCorpId] || normalizedCorpId;
|
||||||
|
}
|
||||||
|
|
||||||
function readCachedContext() {
|
function readCachedContext() {
|
||||||
if (typeof uni === "undefined" || typeof uni.getStorageSync !== "function") {
|
if (typeof uni === "undefined" || typeof uni.getStorageSync !== "function") {
|
||||||
return null;
|
return null;
|
||||||
@ -75,12 +84,12 @@ function parseQueryString(queryString) {
|
|||||||
export function getCorpIdFromAppOptions(options = {}) {
|
export function getCorpIdFromAppOptions(options = {}) {
|
||||||
const query = options.query || options || {};
|
const query = options.query || options || {};
|
||||||
const corpId = query.corpId || query.corpid || query.corp_id;
|
const corpId = query.corpId || query.corpid || query.corp_id;
|
||||||
if (corpId) return String(corpId).trim();
|
if (corpId) return normalizeCorpId(corpId);
|
||||||
|
|
||||||
if (typeof query.q === "string") {
|
if (typeof query.q === "string") {
|
||||||
const qParams = parseQueryString(safeDecode(query.q));
|
const qParams = parseQueryString(safeDecode(query.q));
|
||||||
const qCorpId = qParams.corpId || qParams.corpid || qParams.corp_id;
|
const qCorpId = qParams.corpId || qParams.corpid || qParams.corp_id;
|
||||||
if (qCorpId) return String(qCorpId).trim();
|
if (qCorpId) return normalizeCorpId(qCorpId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
@ -93,7 +102,7 @@ export function initApiContextFromAppOptions(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolveApiContext(corpId) {
|
export function resolveApiContext(corpId) {
|
||||||
const normalizedCorpId = String(corpId || "").trim();
|
const normalizedCorpId = normalizeCorpId(corpId);
|
||||||
|
|
||||||
if (normalizedCorpId) {
|
if (normalizedCorpId) {
|
||||||
const configuredBaseUrl = CORP_API_BASE_URL_MAP[normalizedCorpId];
|
const configuredBaseUrl = CORP_API_BASE_URL_MAP[normalizedCorpId];
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { loading, hideLoading } from "./widget";
|
import { loading, hideLoading } from "./widget";
|
||||||
import { buildApiUrl, getDefaultUploadUrl } from "./api-base-config";
|
import { buildApiUrl, getDefaultUploadUrl, normalizeCorpId } from "./api-base-config";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
header: {
|
header: {
|
||||||
@ -96,6 +96,12 @@ async function refreshAccessToken() {
|
|||||||
const request = async (options = {}, showLoading = true) => {
|
const request = async (options = {}, showLoading = true) => {
|
||||||
// 合并用户传入的配置和默认配置
|
// 合并用户传入的配置和默认配置
|
||||||
if (!options.data) options.data = {};
|
if (!options.data) options.data = {};
|
||||||
|
if (options.data.corpId) {
|
||||||
|
options.data = {
|
||||||
|
...options.data,
|
||||||
|
corpId: normalizeCorpId(options.data.corpId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
@ -201,12 +207,13 @@ export default request;
|
|||||||
export const uploadUrl = getDefaultUploadUrl();
|
export const uploadUrl = getDefaultUploadUrl();
|
||||||
|
|
||||||
export function getFullPath(path, corpId) {
|
export function getFullPath(path, corpId) {
|
||||||
return buildApiUrl(path, corpId);
|
return buildApiUrl(path, normalizeCorpId(corpId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function upload(path, corpId) {
|
export function upload(path, corpId) {
|
||||||
const currentUploadUrl = buildApiUrl("/upload", corpId);
|
const normalizedCorpId = normalizeCorpId(corpId);
|
||||||
|
const currentUploadUrl = buildApiUrl("/upload", normalizedCorpId);
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
url: currentUploadUrl,
|
url: currentUploadUrl,
|
||||||
@ -216,7 +223,7 @@ export function upload(path, corpId) {
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
try {
|
try {
|
||||||
const url = JSON.parse(res.data).filePath;
|
const url = JSON.parse(res.data).filePath;
|
||||||
resolve(url ? getFullPath(url, corpId) : '')
|
resolve(url ? getFullPath(url, normalizedCorpId) : '')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user