Compare commits
No commits in common. "2f317e296055801194d5b670b147650e2b401091" and "a3313064c0e55f516bddaeba9115da22da7163e8" have entirely different histories.
2f317e2960
...
a3313064c0
@ -6,10 +6,6 @@ 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(/\/+$/, "");
|
||||||
}
|
}
|
||||||
@ -18,11 +14,6 @@ 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;
|
||||||
@ -84,12 +75,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 normalizeCorpId(corpId);
|
if (corpId) return String(corpId).trim();
|
||||||
|
|
||||||
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 normalizeCorpId(qCorpId);
|
if (qCorpId) return String(qCorpId).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
@ -102,7 +93,7 @@ export function initApiContextFromAppOptions(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolveApiContext(corpId) {
|
export function resolveApiContext(corpId) {
|
||||||
const normalizedCorpId = normalizeCorpId(corpId);
|
const normalizedCorpId = String(corpId || "").trim();
|
||||||
|
|
||||||
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, normalizeCorpId } from "./api-base-config";
|
import { buildApiUrl, getDefaultUploadUrl } from "./api-base-config";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
header: {
|
header: {
|
||||||
@ -96,12 +96,6 @@ 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,
|
||||||
@ -207,13 +201,12 @@ export default request;
|
|||||||
export const uploadUrl = getDefaultUploadUrl();
|
export const uploadUrl = getDefaultUploadUrl();
|
||||||
|
|
||||||
export function getFullPath(path, corpId) {
|
export function getFullPath(path, corpId) {
|
||||||
return buildApiUrl(path, normalizeCorpId(corpId));
|
return buildApiUrl(path, corpId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function upload(path, corpId) {
|
export function upload(path, corpId) {
|
||||||
const normalizedCorpId = normalizeCorpId(corpId);
|
const currentUploadUrl = buildApiUrl("/upload", corpId);
|
||||||
const currentUploadUrl = buildApiUrl("/upload", normalizedCorpId);
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
url: currentUploadUrl,
|
url: currentUploadUrl,
|
||||||
@ -223,7 +216,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, normalizedCorpId) : '')
|
resolve(url ? getFullPath(url, corpId) : '')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user