fix:提交修复6个问题

This commit is contained in:
ljy
2026-07-08 23:01:18 +08:00
parent 99be8e0237
commit ab9654564e
43 changed files with 3671 additions and 277 deletions
@@ -26,6 +26,17 @@ type OssUploadFieldProps = {
const DEFAULT_MAX_MB = 10;
function formatWechatUploadError(e: unknown): string {
const msg = e instanceof Error ? e.message : '无法打开相册';
if (/invalid signature/i.test(msg)) {
return '微信 JSSDK 签名校验失败:请确认公众号已配置 JS 接口安全域名为 user.runxian.top,并刷新页面后重试';
}
if (/permission|denied|拒绝/i.test(msg)) {
return '微信选图权限被拒绝,请在微信设置中允许相册/相机访问后重试';
}
return msg;
}
export default function OssUploadField({
value,
onChange,
@@ -48,7 +59,7 @@ export default function OssUploadField({
const resolvedAccept =
accept ?? (mediaType === 'VIDEO' ? 'video/*' : mediaType === 'FILE' ? 'image/*,.pdf' : 'image/*');
const useWechatPicker = isWechatEnv() && mediaType !== 'VIDEO';
const useWechatPicker = isWechatEnv() && mediaType === 'IMAGE';
const needsAuth = useWechatPicker && needsWechatAuth(profile, clientConfig) && wechatReady !== true;
useEffect(() => {
@@ -100,6 +111,22 @@ export default function OssUploadField({
}
}
function openNativeFilePicker() {
inputRef.current?.click();
}
async function pickWechatImage() {
const files = await weixinSdk.chooseImages({
count: 1,
sourceType: ['album', 'camera'],
});
if (files?.[0]) {
await uploadSelectedFile(files[0]);
return;
}
throw new Error('未能获取图片,请重试');
}
async function pickFile() {
if (uploading || authorizing) return;
setError('');
@@ -111,27 +138,17 @@ export default function OssUploadField({
if (useWechatPicker) {
try {
const files = await weixinSdk.chooseImages({
count: 1,
sourceType: ['album', 'camera'],
});
if (files?.[0]) {
await uploadSelectedFile(files[0]);
return;
}
setError('未能获取图片,请重试');
await pickWechatImage();
} catch (e) {
const msg = e instanceof Error ? e.message : '无法打开相册';
if (!/cancel/i.test(msg)) {
setError(/permission|auth|denied|授权|拒绝/i.test(msg)
? '微信选图授权失败,请刷新页面后重试'
: msg);
}
if (/cancel/i.test(msg)) return;
setError(formatWechatUploadError(e));
openNativeFilePicker();
}
return;
}
inputRef.current?.click();
openNativeFilePicker();
}
const isImage = mediaType === 'IMAGE' && value;
@@ -165,6 +182,7 @@ export default function OssUploadField({
ref={inputRef}
type="file"
accept={resolvedAccept}
capture={mediaType === 'FILE' && isWechatEnv() ? 'environment' : undefined}
className="partner-oss-upload-input"
disabled={busy}
onChange={(e) => {