微信sdk更新,修正上传门头照照片错误
This commit is contained in:
@@ -39,6 +39,10 @@ function formatWechatUploadError(e: unknown): string {
|
||||
return msg;
|
||||
}
|
||||
|
||||
function shouldFallbackToNativePicker(msg: string): boolean {
|
||||
return /permission|denied|接口未就绪|signature|JSSDK|签名校验|invalid signature|config:fail|未授权/i.test(msg);
|
||||
}
|
||||
|
||||
function acceptsImages(accept: string) {
|
||||
return accept.includes('image');
|
||||
}
|
||||
@@ -139,6 +143,7 @@ export default function OssUploadField({
|
||||
setUploading(true);
|
||||
setError('');
|
||||
try {
|
||||
weixinSdk.reset();
|
||||
await weixinSdk.init();
|
||||
await enqueueUpload(async () => {
|
||||
const files = await weixinSdk.chooseImages({
|
||||
@@ -152,6 +157,14 @@ export default function OssUploadField({
|
||||
if (!files[0]) return;
|
||||
await uploadSelectedFile(files[0]);
|
||||
});
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : '无法打开相册';
|
||||
if (/cancel/i.test(msg)) return;
|
||||
if (shouldFallbackToNativePicker(msg)) {
|
||||
openNativeFilePicker();
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
@@ -173,6 +186,10 @@ export default function OssUploadField({
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : '无法打开相册';
|
||||
if (/cancel/i.test(msg)) return;
|
||||
if (shouldFallbackToNativePicker(msg)) {
|
||||
openNativeFilePicker();
|
||||
return;
|
||||
}
|
||||
showUploadError(formatWechatUploadError(e));
|
||||
}
|
||||
return;
|
||||
@@ -208,19 +225,17 @@ export default function OssUploadField({
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{!useWechatPicker && (
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept={resolvedAccept}
|
||||
className="partner-oss-upload-input"
|
||||
disabled={busy}
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) void uploadSelectedFile(file);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept={resolvedAccept}
|
||||
className="partner-oss-upload-input"
|
||||
disabled={busy}
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) void uploadSelectedFile(file);
|
||||
}}
|
||||
/>
|
||||
{isImage ? (
|
||||
<button {...triggerProps} className={`partner-upload-preview${wide ? ' partner-upload-preview--wide' : ''}`}>
|
||||
<img src={value} alt={label ?? '已上传'} />
|
||||
|
||||
Reference in New Issue
Block a user