feat(mini): v4.0.8 客服卡片主包落地、定位误报修复,合伙人微信内预览保存海报
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { isHttpImageUrl } from '@dukang/weixin-sdk';
|
||||
import { toastSuccess } from './toast';
|
||||
import { isWechatEnv, weixinSdk } from './weixin';
|
||||
|
||||
export { isHttpImageUrl };
|
||||
|
||||
export function blobToDataUrl(blob: Blob): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => resolve(String(reader.result || ''));
|
||||
reader.onerror = () => reject(new Error('读取图片失败'));
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信内用 previewImage 打开可公网访问的图片,用户长按即可保存。
|
||||
* blob / data URL 不能走该接口。
|
||||
*/
|
||||
export async function previewSaveableImage(url: string): Promise<boolean> {
|
||||
const href = url.trim();
|
||||
if (!isWechatEnv() || !isHttpImageUrl(href)) return false;
|
||||
try {
|
||||
await weixinSdk.previewImage(href);
|
||||
toastSuccess('请长按图片保存到相册');
|
||||
return true;
|
||||
} catch {
|
||||
toastSuccess('请长按上方图片保存到相册');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user