feat(mini): v4.0.8 客服卡片主包落地、定位误报修复,合伙人微信内预览保存海报
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { ensureJssdkReady } from './jssdk';
|
||||
import type { WeixinSdkConfig } from './types';
|
||||
|
||||
export function isHttpImageUrl(url?: string | null): url is string {
|
||||
return !!url && /^https?:\/\//i.test(url.trim());
|
||||
}
|
||||
|
||||
/** 微信内预览图片,便于长按保存到相册(须是可公网访问的 http(s) 地址) */
|
||||
export async function previewWechatImage(config: WeixinSdkConfig, url: string): Promise<void> {
|
||||
const href = url.trim();
|
||||
if (!isHttpImageUrl(href)) {
|
||||
throw new Error('图片地址无效');
|
||||
}
|
||||
|
||||
await ensureJssdkReady({
|
||||
apiBase: config.apiBase ?? '/api/v1',
|
||||
clientApp: config.clientApp,
|
||||
getAccessToken: config.getAccessToken,
|
||||
});
|
||||
|
||||
if (!window.wx?.previewImage) {
|
||||
throw new Error('微信预览图片不可用');
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
window.wx!.previewImage!({
|
||||
current: href,
|
||||
urls: [href],
|
||||
success: () => resolve(),
|
||||
fail: (res) => reject(new Error(res?.errMsg || '预览失败')),
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user