Appearance
Poster 海报卡片
模板标签:<qtx-poster>
单张海报卡片独立组件:由 Android
@QtComponent的QtxPosterController(归属 qtx-extra-ui / com.quicktvui.plugin.extraui)原生视图与 Vue 透传壳组成。
<qtx-poster> 可脱离列表单独使用(详情页海报位、浮层、分屏固定卡),同时作为列表 viewType=poster / image 的渲染内核;列表批量渲染仍走 RecycledViewPool。完整 API 表见 ./api(由 npm run docs:gen 生成),本页只描述使用语义,不复制 Props / Events / Methods 事实表。
原生侧共用 CardContent / ImageSource / ImageSourceResolver / AbsGlintMediaCardView / AbsGlintCardItemFactory 内核,图源覆盖 URL / LOCAL_RES / LOCAL_FILE / ASSET / APP_PACKAGE / DRAWABLE 六类,配合 generation 校验防止回收后画面错位,并维护 loading→ready→error→retry 状态机。
适用场景
- 详情页、浮层或分屏里只需要一张可聚焦、可点击的海报卡
- 需要
poster/image/imgUrl三别名择一取图,并区分网络图与localSrc本地资源 - 需要
base/text_bottom/text_float三种文本排布,或角标badge、宽高比aspectRatio、圆角cornerRadius - 需要图片加载链路的
imageLoadStart/imageLoadSuccess/imageLoadError与stateChange回调 - 需要通过 ref 的
setImageSource/setTitle/applyPatch/recycle/getState做局部更新
不适用场景
- 成百上千行的长列表逐行创建独立组件实例,应改用列表的 viewType 工厂 + 复用池
- 需要轮播、多帧切换或视频播放的运营位,本组件只负责单张静态海报
- 卡片内部需要任意复杂子树布局,应使用 qt-view / qt-text 组合,而不是把复杂结构放入原生卡片
Web 演示
Web 演示浏览器模拟演示 · TV 真机行为以实机为准
海报卡片(点击触发 @click)
形态:text_bottom
图源:https://cdn.example.com/poster/a.jpg
底部标题 / 副标题
getState 快照
state:ready
posterType:text_bottom
source:network
事件日志:—
浏览器模拟演示 · TV 真机行为以实机为准
最近事件:—
示例
vue
<template>
<div class="page" :width="1920" :height="1080">
<qtx-poster
ref="posterRef"
:poster="posterUrl"
:title="cardTitle"
subtitle="每周五更新"
posterType="text_bottom"
:aspectRatio="0.75"
:cornerRadius="16"
:focusable="true"
:width="360"
:height="480"
@click="onCardClick"
@imageLoadSuccess="onImageSuccess"
@imageLoadError="onImageError"
@stateChange="onStateChange"
/>
<div :width="600" :height="80">
<qt-text :text="statusText" :width="600" :height="80" />
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const posterUrl = ref('https://cdn.example.com/poster/a.jpg')
const cardTitle = ref('深海剧场')
const statusText = ref('就绪:等待图片加载')
const posterRef = ref<{ getState: () => string } | null>(null)
function onCardClick() {
statusText.value = `click → state=${posterRef.value?.getState()}`
}
function onImageSuccess() {
statusText.value = `imageLoadSuccess → state=${posterRef.value?.getState()}`
}
function onImageError() {
statusText.value = `imageLoadError → state=${posterRef.value?.getState()}`
}
function onStateChange() {
statusText.value = `stateChange → state=${posterRef.value?.getState()}`
}
</script>vue
<template>
<div class="page" :width="1920" :height="1080">
<div :width="1920" :height="440">
<!-- 三种文本形态 + 图源三别名(优先级 poster > image > imgUrl) -->
<qtx-poster
:poster="remotePoster"
title="无文本"
posterType="base"
:width="300"
:height="420"
@click="onAliasClick('poster')"
/>
<qtx-poster
image="https://cdn.example.com/poster/b.jpg"
title="底部标题"
subtitle="副标题在下方"
posterType="text_bottom"
:width="300"
:height="420"
@click="onAliasClick('image')"
/>
<qtx-poster
imgUrl="https://cdn.example.com/poster/c.jpg"
:floatTitle="floatTitle"
:floatSubtitle="floatSubtitle"
posterType="text_float"
:width="300"
:height="420"
@click="onAliasClick('imgUrl')"
/>
</div>
<div :width="1920" :height="420">
<!-- 本地图源 + 失败回退 -->
<qtx-poster
:localSrc="localRes"
:fallbackSrc="fallbackUrl"
:title="localTitle"
:posterType="activeType"
:width="300"
:height="400"
@imageLoadError="onImageError"
/>
<!-- 事件与 ref 方法主卡片 -->
<qtx-poster
ref="cardRef"
:poster="activeUrl"
:title="cardTitle"
:subtitle="cardSubtitle"
:badge="badge"
:posterType="activeType"
:aspectRatio="0.75"
:width="300"
:height="400"
@click="onCardClick"
@focus="onFocus"
@blur="onBlur"
@longClick="onLongClick"
@imageLoadStart="onImageLoadStart"
@imageLoadSuccess="onImageLoadSuccess"
@imageLoadError="onImageError"
@stateChange="onStateChange"
@bind="onBind"
@recycle="onRecycle"
@patch="onPatch"
@badgeClick="onBadgeClick"
/>
</div>
<div :width="1920" :height="80">
<div :width="240" :height="70" @click="switchType">
<qt-text :text="typeLabel" :width="240" :height="70" />
</div>
<div :width="240" :height="70" @click="useRemote">
<qt-text text="切网络图" :width="240" :height="70" />
</div>
<div :width="240" :height="70" @click="useLocal">
<qt-text text="切本地图" :width="240" :height="70" />
</div>
<div :width="240" :height="70" @click="useFallback">
<qt-text text="触发回退" :width="240" :height="70" />
</div>
<div :width="240" :height="70" @click="applyPatchToCard">
<qt-text text="打补丁" :width="240" :height="70" />
</div>
<div :width="240" :height="70" @click="clearCard">
<qt-text text="清空" :width="240" :height="70" />
</div>
</div>
<div :width="1200" :height="60">
<qt-text :text="statusText" :width="1200" :height="60" />
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const remotePoster = ref('https://cdn.example.com/poster/a.jpg')
const localRes = ref('res://drawable/poster_local')
const fallbackUrl = ref('https://cdn.example.com/poster/fallback.jpg')
const activeUrl = ref(remotePoster.value)
const activeType = ref('text_bottom')
const cardTitle = ref('事件与方法中枢')
const cardSubtitle = ref('可调用 setTitle / applyPatch')
const badge = ref('VIP')
const floatTitle = ref('浮层标题')
const floatSubtitle = ref('浮层副标题')
const localTitle = ref('本地资源海报')
const statusText = ref('就绪')
const typeLabel = ref('切换形态:text_bottom')
const cardRef = ref<{
setImageSource: (src: string) => void
setTitle: (t: string) => void
setSubtitle: (t: string) => void
setBadge: (b: string) => void
setPosterType: (t: string) => void
setAspectRatio: (r: number) => void
setLoadingState: (s: string) => void
applyPatch: (p: Record<string, unknown>) => void
cancelImageLoad: () => void
clear: () => void
recycle: () => void
requestFocus: () => void
getState: () => string
} | null>(null)
function onAliasClick(alias: string) {
statusText.value = `别名优先级演示:点击来自 ${alias}(poster > image > imgUrl)`
}
function switchType() {
const order = ['base', 'text_bottom', 'text_float']
const next = order[(order.indexOf(activeType.value) + 1) % order.length]
activeType.value = next
typeLabel.value = `切换形态:${next}`
cardRef.value?.setPosterType(next)
cardRef.value?.requestFocus()
statusText.value = `setPosterType(${next}) + requestFocus → state=${cardRef.value?.getState()}`
}
function useRemote() {
activeUrl.value = 'https://cdn.example.com/poster/a.jpg'
cardRef.value?.setImageSource(activeUrl.value)
cardRef.value?.setSubtitle('已切回网络 URL')
statusText.value = `setImageSource(URL) → state=${cardRef.value?.getState()}`
}
function useLocal() {
cardRef.value?.setImageSource(localRes.value)
cardTitle.value = '已切换本地资源'
cardRef.value?.setTitle(cardTitle.value)
statusText.value = `setImageSource(LOCAL_RES) → state=${cardRef.value?.getState()}`
}
function useFallback() {
cardRef.value?.setImageSource('https://cdn.example.com/poster/broken.jpg')
cardRef.value?.setLoadingState('loading')
statusText.value = `等待 imageLoadError → fallbackSrc 回退;state=${cardRef.value?.getState()}`
}
function applyPatchToCard() {
cardRef.value?.applyPatch({ badge: '补丁', title: '已应用补丁' })
cardRef.value?.setAspectRatio(1.0)
statusText.value = `applyPatch + setAspectRatio → state=${cardRef.value?.getState()}`
}
function clearCard() {
cardRef.value?.cancelImageLoad()
cardRef.value?.clear()
statusText.value = `cancelImageLoad + clear → state=${cardRef.value?.getState()}`
}
function onCardClick() {
statusText.value = `click → ${cardRef.value?.getState()}`
}
function onFocus() {
statusText.value = 'focus'
}
function onBlur() {
statusText.value = 'blur'
}
function onLongClick() {
cardRef.value?.setBadge('长按')
statusText.value = `longClick → setBadge → ${cardRef.value?.getState()}`
}
function onImageLoadStart() {
statusText.value = 'imageLoadStart'
}
function onImageLoadSuccess() {
cardRef.value?.setBadge('已加载')
statusText.value = `imageLoadSuccess → ${cardRef.value?.getState()}`
}
function onImageError() {
statusText.value = `imageLoadError → 回退 fallbackSrc;state=${cardRef.value?.getState()}`
}
function onStateChange() {
statusText.value = `stateChange → ${cardRef.value?.getState()}`
}
function onBind() {
statusText.value = 'bind'
}
function onRecycle() {
statusText.value = 'recycle'
}
function onPatch() {
statusText.value = 'patch'
}
function onBadgeClick() {
cardRef.value?.recycle()
statusText.value = `badgeClick → recycle → ${cardRef.value?.getState()}`
}
</script>示例是仓库里真实的 .vue 文件,由 qtx-tpl-loader 参与编译校验,属性与事件名均取自组件源码。
使用约束与易错点
- 图源三别名优先级为
poster>image>imgUrl;同时传入时只取最高优先级者,其余被忽略 localSrc与网络别名分属不同解析分支,fallbackSrc仅在主图加载失败(触发imageLoadError)后生效posterType取base/text_bottom/text_float;仅text_float使用floatTitle/floatSubtitlestate由内部状态机驱动,仅loading/ready/error三态;applyPatch与setLoadingState会改变它- 事件名为 camelCase(如
imageLoadSuccess、stateChange、badgeClick),独立组件经@QtEvent→ Vue emit 抛出 generation校验保证回收复用后不会把上一行图源贴到当前行;recycle用于归还前清理
已知边界
- 独立组件不适合在长列表里逐行实例化;长列表请用 viewType 工厂 + RecycledViewPool 复用同一渲染内核
- qtx-tpl-loader 的白名单只约束 qtx-list 的
#item插槽内 DOM 标签,不约束 qtx-* 原生组件标签 - 所有标签必须显式声明 width / height(px)
- 关联组件 QtxAppIcon 在 Android 11+ 需要宿主 AndroidManifest 声明
<queries>或权限以查询包可见性;未声明时packageName解析失败并触发iconLoadError后回退fallbackIcon - 关联组件 QtxAppIcon 的
banner是静态横幅形态,不轮播,也不是已恢复的 banner item 类型,且不注册viewType=banner - 独立组件与列表行的事件通道不同:独立组件走
@QtEvent→ Vue emit(如@click/@imageLoadError),列表行走item-click/item-focus;细粒度事件(badgeClick/imageLoadError/stateChange等)载荷含itemId/position/payload,而卡片主体的click在触摸路径由 Hippy 内建 onClick 通道派发、载荷为原生事件对象,两者结构不同 registerElement注册时通过eventNamesMap保留onXxx事件名;自定义 CLI 生成模板时不可移除该映射,否则所有细粒度事件会被框架静默丢弃
验证状态
- 文档编译门禁:docs-check 的示例编译、四表完整性与文风检查通过。
- 真机端到端(192.168.80.21:5555 / Android 9):props、ref 命令式方法、细粒度事件与
click载荷均已取证;逐项证据见docs/QTX_PRESET_ITEMS_DEVICE_CASES.json的deviceRun.independentComponents。 - 事件派发的两个缺陷(输入路由、
eventNamesMap事件名映射)已修复,根因与修法见docs/QTX_CARD_COMPONENTS_PLAN.md§11。 - 尚未覆盖:Android 11+ 包可见性在 11+ 设备复核(当前在线设备均为 Android 9)。
API 参考
以下表格由
npm run docs:gen从源码生成,禁止手工编辑;完整独立页见 Poster 海报卡片 API。
属性(Props · 30)
| 属性名 | 类型 | 必填 | 默认值 | 说明 | 事实源 |
|---|---|---|---|---|---|
aspectRatio | number | 否 | 0.72 | 卡片宽高比(宽 / 高),默认 0.72 | ts-types+vue-sfc+java |
badge | Record<string, any> | 否 | - | 角标数据(键值开放),默认空 | ts-types+vue-sfc+java |
clickPayload | Record<string, any> | 否 | - | 点击事件附带载荷(键值开放,随 click 事件回传),默认空 | ts-types+vue-sfc+java |
coord | Record<string, any> | 否 | - | 坐标 / 布局附加参数(键值开放),默认空 | ts-types+vue-sfc+java |
cornerRadius | number | 否 | 12 | 卡片圆角半径(px),默认 12 | ts-types+vue-sfc+java |
elevationShadow | boolean | 否 | false | 是否启用投影阴影,默认 false | ts-types+vue-sfc+java |
fallbackSrc | string | 否 | - | 主图加载失败时的兜底图地址,默认空 | ts-types+vue-sfc+java |
floatSubtitle | string | 否 | - | 浮层副标题(text_float 版式专用),默认空 | ts-types+vue-sfc+java |
floatTitle | string | 否 | - | 浮层标题(text_float 版式专用),默认空 | ts-types+vue-sfc+java |
focusable | boolean | 否 | true | 是否可获焦,默认 true | ts-types+vue-sfc+java |
focusBorder | boolean | 否 | true | 是否显示获焦描边,默认 true | ts-types+vue-sfc+java |
focusGlow | boolean | 否 | false | 是否显示获焦光晕,默认 false | ts-types+vue-sfc+java |
focusPayload | Record<string, any> | 否 | - | 获焦事件附带载荷(键值开放,随 focus 事件回传),默认空 | ts-types+vue-sfc+java |
focusScale | number | 否 | 1.05 | 获焦缩放倍率,默认 1.05 | ts-types+vue-sfc+java |
height | number | string | 否 | 0 | 卡片高度(数字自动补 px),默认 0 | ts-types |
image | string | 否 | - | 主图地址别名(优先级次于 poster),默认空 | ts-types+vue-sfc+java |
imgUrl | string | 否 | - | 主图地址别名(优先级最低),默认空 | ts-types+vue-sfc+java |
loadingDelayMs | number | 否 | 300 | 加载态延迟显示毫秒数,默认 300 | ts-types+vue-sfc+java |
localSrc | string | 否 | - | 本地图片资源(drawable / assets / file),默认空 | ts-types+vue-sfc+java |
maxLines | number | 否 | 1 | 标题最大行数,默认 1 | ts-types+vue-sfc+java |
placeholderColor | string | 否 | - | 占位图背景色,默认 #2E2E2E | ts-types+vue-sfc+java |
poster | string | 否 | - | 主图地址,三别名优先级 poster > image > imgUrl,默认空 | ts-types+vue-sfc+java |
posterType | 'base' | 'text_bottom' | 'text_float' | string | 否 | base | 海报版式:base / text_bottom / text_float,默认 base | ts-types+vue-sfc+java |
scaleType | string | 否 | fitCenter | 图片缩放类型(如 fitCenter / centerCrop),默认 fitCenter | ts-types+vue-sfc+java |
state | 'loading' | 'ready' | 'error' | string | 否 | loading | 卡片状态:loading / ready / error,默认 loading | ts-types+vue-sfc+java |
subtitle | string | 否 | - | 副标题文本,默认空 | ts-types+vue-sfc+java |
textColor | string | 否 | - | 标题颜色,默认 #FFFFFF | ts-types+vue-sfc+java |
textSize | number | 否 | 28 | 标题字号,默认 28 | ts-types+vue-sfc+java |
title | string | 否 | - | 主标题文本,默认空 | ts-types+vue-sfc+java |
width | number | string | 否 | 0 | 卡片宽度(数字自动补 px),默认 0 | ts-types |
事件(Events · 24)
| 事件名 | 载荷参数 | 说明 | 事实源 |
|---|---|---|---|
@badgeClick | payload: any | - | ts-types+vue-sfc |
@bind | payload: any | - | ts-types+vue-sfc |
@blur | payload: any | - | ts-types+vue-sfc |
@click | payload: any | - | ts-types+vue-sfc |
@focus | payload: any | - | ts-types+vue-sfc |
@imageLoadError | payload: any | - | ts-types+vue-sfc |
@imageLoadStart | payload: any | - | ts-types+vue-sfc |
@imageLoadSuccess | payload: any | - | ts-types+vue-sfc |
@longClick | payload: any | - | ts-types+vue-sfc |
@onBadgeClick | payload?: any | 角标被点击时触发 | vue-sfc+java |
@onBind | payload?: any | 内容绑定到卡片时触发,用于生命周期取证 | vue-sfc+java |
@onBlur | payload?: any | 卡片失去焦点时触发,载荷含 itemId / payload | vue-sfc+java |
@onClick | payload?: any | 卡片被点击时触发,载荷含 itemId / position / payload / source | vue-sfc+java |
@onFocus | payload?: any | 卡片获得焦点时触发,载荷含 itemId / payload | vue-sfc+java |
@onImageLoadError | payload?: any | 图源加载失败时触发,载荷含 source / kind / reason,可用于错误恢复 | vue-sfc+java |
@onImageLoadStart | payload?: any | 图源开始加载时触发,载荷含 source / kind | vue-sfc+java |
@onImageLoadSuccess | payload?: any | 图源加载成功时触发,载荷含 source / kind | vue-sfc+java |
@onLongClick | payload?: any | 卡片长按时触发,可用于长按菜单 | vue-sfc+java |
@onPatch | payload?: any | 局部刷新完成时触发,载荷含 patchKeys | vue-sfc+java |
@onRecycle | payload?: any | 卡片回收清理时触发 | vue-sfc+java |
@onStateChange | payload?: any | 状态机迁移时触发,载荷含 from / to | vue-sfc+java |
@patch | payload: any | - | ts-types+vue-sfc |
@recycle | payload: any | - | ts-types+vue-sfc |
@stateChange | payload: any | - | ts-types+vue-sfc |
方法(Methods / Expose · 15)
| 方法名 | 参数 | 返回值 | 说明 | 事实源 |
|---|---|---|---|---|
applyPatch | patch: Record<string, any> | void | 局部增量更新(按 patch 键原位刷新,不重建) | ts-types+vue-sfc+java |
cancelImageLoad | — | void | 取消当前进行中的图片加载 | ts-types+vue-sfc+java |
clear | — | void | 清空卡片内容 | ts-types+vue-sfc+java |
getNativeNode | — | any | 取原生节点代理(Base→gate→$el,带 nodeId) | ts-types+vue-sfc |
getState | — | Promise<QtxPosterState> | 读取当前卡片状态快照 | ts-types+vue-sfc+java |
if | — | — | - | vue-sfc |
recycle | — | void | 回收并重置卡片(复用前调用) | ts-types+vue-sfc+java |
requestFocus | — | Promise<string> | 请求焦点,返回聚焦结果标识 | ts-types+vue-sfc+java |
setAspectRatio | ratio: number | void | 设置卡片宽高比 | ts-types+vue-sfc+java |
setBadge | badge: Record<string, any> | null | void | 设置或清除角标(传 null 清除) | ts-types+vue-sfc+java |
setImageSource | source: string, kind?: string | void | 切换主图来源,kind 指定 local / network / asset 等 | ts-types+vue-sfc+java |
setLoadingState | loading: boolean | void | 显示 / 隐藏加载态 | ts-types+vue-sfc+java |
setPosterType | type: string | void | 切换海报版式 | ts-types+vue-sfc+java |
setSubtitle | text: string | void | 设置副标题文本 | ts-types+vue-sfc+java |
setTitle | text: string | void | 设置主标题文本 | ts-types+vue-sfc+java |
插槽(Slots · 1)
| 插槽名 | 说明 | 事实源 |
|---|---|---|
default | 默认内容插槽,承载组件子内容 | js/qtx/src/components/QtxPoster/QtxPoster.vue |