微信sdk更新,修正上传门头照照片错误
This commit is contained in:
@@ -9,6 +9,20 @@ let scriptPromise: Promise<void> | null = null;
|
||||
let configured = false;
|
||||
let configuredUrl: string | null = null;
|
||||
|
||||
function pathnameOf(url: string): string {
|
||||
try {
|
||||
return new URL(url).pathname;
|
||||
} catch {
|
||||
return url.split('?')[0];
|
||||
}
|
||||
}
|
||||
|
||||
/** 清除 JSSDK 配置缓存(路由切换后须重新 wx.config) */
|
||||
export function resetJssdkConfig(): void {
|
||||
configured = false;
|
||||
configuredUrl = null;
|
||||
}
|
||||
|
||||
/** 参与 JSSDK 签名的页面 URL(去掉 hash、query;SPA 步骤参数不参与签名) */
|
||||
export function normalizeJssdkPageUrl(rawUrl: string): string {
|
||||
try {
|
||||
@@ -19,12 +33,20 @@ export function normalizeJssdkPageUrl(rawUrl: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** iOS 微信内 SPA:签名 URL 须用首次进入页面的入口 URL,而非路由跳转后的当前 URL */
|
||||
/** iOS 微信内 SPA:同 pathname 内复用入口 URL;跨路由时更新入口并失效旧签名 */
|
||||
export function captureIosJssdkEntryUrl(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (!isIosDevice() || !isWechatBrowser() || isWechatDevTools()) return;
|
||||
if (sessionStorage.getItem(IOS_ENTRY_URL_KEY)) return;
|
||||
sessionStorage.setItem(IOS_ENTRY_URL_KEY, normalizeJssdkPageUrl(window.location.href));
|
||||
const current = normalizeJssdkPageUrl(window.location.href);
|
||||
const existing = sessionStorage.getItem(IOS_ENTRY_URL_KEY);
|
||||
if (!existing) {
|
||||
sessionStorage.setItem(IOS_ENTRY_URL_KEY, current);
|
||||
return;
|
||||
}
|
||||
if (pathnameOf(existing) !== pathnameOf(current)) {
|
||||
sessionStorage.setItem(IOS_ENTRY_URL_KEY, current);
|
||||
resetJssdkConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取参与 JSSDK 签名的 URL */
|
||||
@@ -32,7 +54,9 @@ export function getJssdkSignUrl(rawUrl?: string): string {
|
||||
const current = normalizeJssdkPageUrl(rawUrl ?? (typeof window !== 'undefined' ? window.location.href : ''));
|
||||
if (typeof window !== 'undefined' && isIosDevice() && isWechatBrowser() && !isWechatDevTools()) {
|
||||
const entry = sessionStorage.getItem(IOS_ENTRY_URL_KEY);
|
||||
if (entry) return entry;
|
||||
if (entry && pathnameOf(entry) === pathnameOf(current)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
@@ -139,6 +163,9 @@ export async function ensureJssdkReady(options: {
|
||||
}): Promise<void> {
|
||||
captureIosJssdkEntryUrl();
|
||||
const pageUrl = options.url ?? getJssdkSignUrl();
|
||||
if (configuredUrl && pathnameOf(configuredUrl) !== pathnameOf(pageUrl)) {
|
||||
resetJssdkConfig();
|
||||
}
|
||||
if (!isJssdkReady()) {
|
||||
await initWechatJssdk({ ...options, url: pageUrl });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user