fix:相机优化
This commit is contained in:
@@ -71,7 +71,6 @@ export default function ImageUpload({
|
||||
const { message } = App.useApp()
|
||||
const isMobile = useIsMobile()
|
||||
const [isDragging, setIsDragging] = useState(false)
|
||||
const cameraInputRef = useRef<HTMLInputElement | null>(null)
|
||||
const dragCounterRef = useRef(0)
|
||||
const targetIdRef = useRef(0)
|
||||
const valueRef = useRef(value)
|
||||
@@ -258,21 +257,25 @@ export default function ImageUpload({
|
||||
</Upload>
|
||||
{cameraEnabled && value.length < maxCount ? (
|
||||
<div className="image-upload-camera">
|
||||
<input
|
||||
ref={cameraInputRef}
|
||||
type="file"
|
||||
accept={cameraInputProps.accept}
|
||||
capture={cameraInputProps.capture}
|
||||
className="image-upload-camera-input"
|
||||
onChange={(event) => void handleCameraSelect(event)}
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<CameraOutlined />}
|
||||
onClick={() => cameraInputRef.current?.click()}
|
||||
>
|
||||
拍照
|
||||
</Button>
|
||||
{/*
|
||||
相机入口用「透明原生 input 铺满按钮」的方式:
|
||||
用户手指直接点在 input 上,浏览器才会把它当作拍照手势;
|
||||
旧实现把 input 移到 left:-9999px 再由按钮脚本 .click(),部分安卓 WebView
|
||||
会把相机 intent 降级成文件选择(表现为点了「拍照」却弹出文件浏览)。
|
||||
*/}
|
||||
<span className="camera-pick-trigger">
|
||||
<input
|
||||
type="file"
|
||||
accept={cameraInputProps.accept}
|
||||
capture={cameraInputProps.capture}
|
||||
className="image-upload-camera-input"
|
||||
aria-label="拍照"
|
||||
onChange={(event) => void handleCameraSelect(event)}
|
||||
/>
|
||||
<Button size="small" icon={<CameraOutlined />} tabIndex={-1}>
|
||||
拍照
|
||||
</Button>
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
{showPasteHint ? (
|
||||
|
||||
@@ -50,7 +50,6 @@ export default function VideoUpload({
|
||||
const { message } = App.useApp()
|
||||
const isMobile = useIsMobile()
|
||||
const inputRef = useRef<HTMLInputElement | null>(null)
|
||||
const cameraInputRef = useRef<HTMLInputElement | null>(null)
|
||||
const [phase, setPhase] = useState<'idle' | 'compressing' | 'uploading'>('idle')
|
||||
const [progress, setProgress] = useState(0)
|
||||
|
||||
@@ -144,16 +143,6 @@ export default function VideoUpload({
|
||||
style={{ display: 'none' }}
|
||||
onChange={handleSelect}
|
||||
/>
|
||||
{cameraEnabled ? (
|
||||
<input
|
||||
ref={cameraInputRef}
|
||||
type="file"
|
||||
accept={cameraInputProps.accept}
|
||||
capture={cameraInputProps.capture}
|
||||
className="worker-acceptance-video-camera-input"
|
||||
onChange={handleSelect}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{value ? (
|
||||
<div className="worker-acceptance-video-preview">
|
||||
@@ -170,14 +159,22 @@ export default function VideoUpload({
|
||||
</Typography.Text>
|
||||
<Space size={8} wrap>
|
||||
{cameraEnabled ? (
|
||||
<Button
|
||||
size="small"
|
||||
icon={<CameraOutlined />}
|
||||
disabled={!canPick}
|
||||
onClick={() => cameraInputRef.current?.click()}
|
||||
>
|
||||
重拍
|
||||
</Button>
|
||||
// 透明原生 input 铺满按钮:真实手势点 input 才会被当作「拍摄」,
|
||||
// 脚本 click 在部分安卓 WebView 会退化成文件选择。
|
||||
<span className="camera-pick-trigger">
|
||||
<input
|
||||
type="file"
|
||||
accept={cameraInputProps.accept}
|
||||
capture={cameraInputProps.capture}
|
||||
className="worker-acceptance-video-camera-input"
|
||||
aria-label="重拍验收视频"
|
||||
disabled={!canPick}
|
||||
onChange={handleSelect}
|
||||
/>
|
||||
<Button size="small" icon={<CameraOutlined />} disabled={!canPick} tabIndex={-1}>
|
||||
重拍
|
||||
</Button>
|
||||
</span>
|
||||
) : null}
|
||||
<Button size="small" disabled={!canPick} onClick={() => inputRef.current?.click()}>
|
||||
替换
|
||||
@@ -203,14 +200,26 @@ export default function VideoUpload({
|
||||
) : (
|
||||
<Space size={8} wrap>
|
||||
{cameraEnabled ? (
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<CameraOutlined />}
|
||||
disabled={!canPick}
|
||||
onClick={() => cameraInputRef.current?.click()}
|
||||
>
|
||||
拍摄验收视频
|
||||
</Button>
|
||||
// 同「重拍」:透明原生 input 铺满按钮,靠真实手势调起系统相机。
|
||||
<span className="camera-pick-trigger">
|
||||
<input
|
||||
type="file"
|
||||
accept={cameraInputProps.accept}
|
||||
capture={cameraInputProps.capture}
|
||||
className="worker-acceptance-video-camera-input"
|
||||
aria-label="拍摄验收视频"
|
||||
disabled={!canPick}
|
||||
onChange={handleSelect}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<CameraOutlined />}
|
||||
disabled={!canPick}
|
||||
tabIndex={-1}
|
||||
>
|
||||
拍摄验收视频
|
||||
</Button>
|
||||
</span>
|
||||
) : null}
|
||||
<Button
|
||||
icon={<VideoCameraOutlined />}
|
||||
|
||||
@@ -327,18 +327,33 @@ select {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/*
|
||||
* 相机 file input 用「移出视口」隐藏,而不是 display:none:
|
||||
* 部分 iOS Safari 版本不允许对 display:none 的 file input 触发 .click(),会表现为点了没反应。
|
||||
/**
|
||||
* 移动端系统相机入口:
|
||||
* 原生 input 透明铺满按钮,用户手指直接点在 input 上(真实手势),
|
||||
* 浏览器才更愿意按 capture="environment" 调起相机。
|
||||
*
|
||||
* 旧实现把 input 移到 left:-9999px 再由按钮脚本 .click():
|
||||
* iOS Safari 会点了没反应,部分安卓 WebView 则把相机 intent 降级成文件选择
|
||||
* (表现为点「拍照」却弹出文件浏览)。
|
||||
*/
|
||||
.image-upload-camera-input,
|
||||
.worker-acceptance-video-camera-input {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: -9999px;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.camera-pick-trigger {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* 视觉按钮只负责外观,点击统一由上层透明 input 接收(避免脚本 click 触发降级) */
|
||||
.camera-pick-trigger .ant-btn {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ export function resolveCameraEntryEnabled(options: ResolveCameraEntryOptions): b
|
||||
*
|
||||
* `capture="environment"` 让移动浏览器优先打开后置摄像头;iOS Safari 的部分版本会
|
||||
* 忽略该属性并弹出「拍照 / 从相册选择」菜单,属于预期内的降级行为。
|
||||
*
|
||||
* 用法约束(安卓兼容性):input 必须**透明铺满按钮**、由用户手指直接点到它
|
||||
* (见 base.css 的 `.camera-pick-trigger` / `*-camera-input`)。离屏 + 脚本 `.click()`
|
||||
* 在部分安卓 WebView 上会让浏览器把相机 intent 退化成文件选择。
|
||||
*/
|
||||
export function cameraCaptureInputProps(kind: CameraCaptureKind): {
|
||||
accept: string
|
||||
|
||||
Reference in New Issue
Block a user