-
Notifications
You must be signed in to change notification settings - Fork 280
fix(swiper): 修改初始值时不生效问题 #3293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(swiper): 修改初始值时不生效问题 #3293
Changes from all commits
e5f690a
f7373db
7b1861b
0f85289
1cbfeb2
0f45e32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
PreviewVideoOption, | ||
WebImagePreviewProps, | ||
} from '@/types' | ||
import { mergeProps } from '@/utils' | ||
|
||
interface Store { | ||
scale: number | ||
|
@@ -42,7 +43,7 @@ const defaultProps = { | |
closeIconPosition: 'top-right', | ||
onChange: () => {}, | ||
onClose: () => {}, | ||
} as WebImagePreviewProps | ||
} as unknown as WebImagePreviewProps | ||
export const ImagePreview: FunctionComponent<Partial<WebImagePreviewProps>> = ( | ||
props | ||
) => { | ||
|
@@ -63,7 +64,8 @@ export const ImagePreview: FunctionComponent<Partial<WebImagePreviewProps>> = ( | |
closeIconPosition, | ||
onClose, | ||
onChange, | ||
} = { ...defaultProps, ...props } | ||
...rest | ||
} = mergeProps(defaultProps, props) | ||
const classPrefix = 'nut-imagepreview' | ||
const ref = useRef<HTMLDivElement | null>(null) | ||
const [innerNo, setInnerNo] = usePropsValue<number>({ | ||
|
@@ -218,17 +220,15 @@ export const ImagePreview: FunctionComponent<Partial<WebImagePreviewProps>> = ( | |
> | ||
{showPop && ( | ||
<Swiper | ||
autoPlay={!!duration} | ||
duration={duration} | ||
autoplay={!!duration} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain需要验证 Swiper 组件的 autoplay 属性要求 属性名称从
Also applies to: 231-231 🏁 Script executed: #!/bin/bash
# 描述:检查 Swiper 组件对 autoplay 和 duration 属性的要求
# 预期:确认 Swiper 组件的正确 API 用法
# 查找 Swiper 组件的类型定义和实现
rg -A 5 -B 5 "autoplay" src/packages/swiper/
rg -A 5 -B 5 "duration" src/packages/swiper/
# 查找 Swiper 组件的 props 接口定义
ast-grep --pattern 'interface $_ {
$$$
autoplay$$$
$$$
}' Length of output: 21029 确认 Swiper 经验证,Swiper 组件的 请在以下位置恢复数值传参以保持原有功能: • 文件: - autoplay={!!duration}
+ autoplay={duration} // 传入数值,或改为 autoplay={duration || 0} • 如有移除对 Swiper 的 <Swiper
…
autoplay={duration}
+ duration={duration}
{...rest}
/> 🤖 Prompt for AI Agents
|
||
className={`${classPrefix}-swiper`} | ||
loop | ||
style={{ | ||
'--nutui-indicator-color': indicatorColor, | ||
}} | ||
direction="horizontal" | ||
onChange={(page) => slideChangeEnd(page)} | ||
defaultValue={innerNo > maxNo ? maxNo - 1 : innerNo - 1} | ||
indicator={indicator} | ||
{...rest} | ||
> | ||
{[ | ||
...videos.map((item) => ({ type: 'video', data: item })), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { BaseImagePreview } from './base' | ||
import { WebSwiperProps } from '@/types' | ||
|
||
export interface WebImagePreviewProps extends BaseImagePreview {} | ||
type props = BaseImagePreview & Omit<WebSwiperProps, 'autoPlay' | 'indicator'> | ||
export interface WebImagePreviewProps extends Omit<props, 'autoplay'> {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { BaseImagePreview } from './base' | ||
import { TaroSwiperProps } from '@/types' | ||
|
||
export interface TaroImagePreviewProps | ||
extends Omit<BaseImagePreview, 'autoPlay'> { | ||
type props = Omit<BaseImagePreview, 'autoPlay'> & | ||
Omit<TaroSwiperProps, 'autoPlay' | 'autoplay' | 'indicator'> | ||
export interface TaroImagePreviewProps extends props { | ||
autoPlay: boolean | ||
showMenuByLongpress: boolean | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
类型断言可能隐藏类型问题
使用
as unknown as WebImagePreviewProps
双重类型断言会绕过 TypeScript 的类型检查。建议检查defaultProps
与WebImagePreviewProps
接口的实际类型不匹配问题,并修复根本原因而不是使用类型断言。🏁 Script executed:
Length of output: 10141
🏁 Script executed:
Length of output: 1277
🏁 Script executed:
Length of output: 622
强化类型定义:移除双重断言
as unknown as WebImagePreviewProps
双重断言会完全绕过编译时检查,建议改为让类型系统正确推导或校验:
defaultProps
上显式声明类型mergeProps
签名,使其返回准确类型WebImagePreviewProps
,无需任何as unknown as
待修改位置:
🤖 Prompt for AI Agents