Appearance
快速开始
本文由维护者/AI 撰写,属于「语义层」;API 表一律见各组件的
api.md(由源码生成)。给 AI / 第三方接入方:qtx 是 QuickTVUI 平台之上的扩展库。工程初始化、路由、生命周期、按键、装机链路与完整双页示例统一见 给 AI 的接入契约;本文只给出组件库接入的最短路径。
前置条件与安装
宿主工程由 quicktvui-template 生成,使用 createESApp + createESRouter,不要用通用 Vue 的 createApp + vue-router。依赖来自 js/qtx/package.json 的 peerDependencies:
| 依赖 | 版本 |
|---|---|
@extscreen/es3-core / @extscreen/es3-vue | >=3.0.0 |
vue | >=3.2.0 |
| 常见宿主依赖 | @extscreen/es3-component / @extscreen/es3-router / @quicktvui/quicktvui3(^3.0.0 系列) |
bash
# 跟随 alpha 渠道最新发布;不要用 @latest / 不带版本
npm i @quicktvui/qtx@alpha@alpha 指向 alpha 渠道最后一次发布;npm i @quicktvui/qtx(等于 @latest)可能拿到滞后版本,因为 latest 不随 --tag alpha 发布更新。需要锁定版本时改成具体版本号。
在宿主入口注册插件(src/main.ts):
ts
import { createESApp } from '@extscreen/es3-core'
import { ESComponent } from '@extscreen/es3-component'
import { createESRouter } from '@extscreen/es3-router'
import { QuickTVUI } from '@quicktvui/quicktvui3'
import qtx from '@quicktvui/qtx'
import App from './App.vue'
import routes from './routes'
const router = createESRouter({ main: 'index', error: 'error', limit: 10, routes })
const app = createESApp(App, router)
app.use(ESComponent)
app.use(QuickTVUI)
app.use(qtx)App.vue 用 <es-router-view /> 承载路由页,并在 setup() 内定义、返回 onESCreate / onESCreated / onBackPressed;完整文件见 接入契约第 3 节 与仓库 examples/tv-app/。
qtx不含播放器实现。视频播放由宿主集成平台 ES SDK(es-player-manager/es-video-player)提供,接入前需installESPlayerLog等 player manager 插件。详见 工程总览。
最小可用页面
框架不是浏览器:没有 window / document / DOM API;禁止 p / img / a / ul / li / h1~h6 / label / button / section / main / article 等标准 HTML 语义标签。div / span 是框架允许的容器,qt-text / qt-image / qt-view 是平台组件,可与 qtx-* 同页共存。每个标签和组件都必须显式声明 width 与 height(px),根容器为 1920×1080,每页至少一个 :autofocus="true" 节点。
vue
<template>
<div class="page" :width="1920" :height="1080">
<qt-text text="我的第一个 qtx 页面" :width="900" :height="60" />
<qtx-list :items="rows" :columns="2" key-field="id" :width="1920" :height="880" @item-click="onItemClick">
<template #item="{ item }">
<div :width="900" :height="220" :focusable="true" :autofocus="true">
<qt-text :text="item.title" :width="900" :height="60" />
<qt-text :text="item.subtitle" :width="900" :height="50" />
</div>
</template>
</qtx-list>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useESRouter } from '@extscreen/es3-router'
import type { QtxListItemEvent } from '@quicktvui/qtx'
export default defineComponent({
setup() {
const router = useESRouter()
// rows 必须定义并 return,不能只写 :items="rows"
const rows = ref([
{ id: '1', title: '热播推荐', subtitle: '本周更新 12 部' },
{ id: '2', title: '猜你在追', subtitle: '续播第 8 集' },
])
function onESCreate(params: Record<string, unknown>) {}
function onItemClick(event: QtxListItemEvent) {
const id = event?.item?.id
if (id) router.push({ name: 'detail', params: { id: String(id) } })
}
function onBackPressed() { router.back() }
return { rows, onESCreate, onItemClick, onBackPressed }
},
})
</script>完整可编译版本见 QtxList 基础示例;多页面 + 路由 + 数据层 + 焦点 + 返回键的完整工程见 接入契约第 3 节。
平台按精确函数名回调:onESCreate / onBackPressed / onKeyDown / onKeyUp 必须定义在 setup() 内并出现在 return 中。<qtx-button> 的确认动作可用 @click(Vue attrs 透传到原生 onClick),生成 API 表里的 @onButtonCustomEvent 是另一条自定义事件通道;其他组件一律按各自生成页的事件表接线。
数据怎么驱动
qtx-list 以 :items 数组为默认权威数据源,直接改数组即可自动同步(纯尾增走原子追加,不闪不丢焦点)。命令式 API setListData(items) / clearItems() 会把传入数组作为权威快照,父组件替换 :items 引用才回到 props 驱动。详见 QtxList API 与 TV 焦点模型。
全库组件概览
上面的最小页面用的是列表组件,但 @quicktvui/qtx 还包括按钮、开关、选择器、键盘、Portal、Tabs 等 21 个公开组件(另有 1 个内部组件暂不对外提供),以及模板编译器、Android 原生桥接和 CLI 工具链。按需要继续看:
- 组件索引 —— 21 个公开组件,每个都有生成 API 页与可编译示例
- 给 AI 的接入契约 —— 依赖矩阵、宿主接入、完整工程示例、装机链路与资料边界
- 仓库地图 —— 全库七层结构:原生 → 代码生成 → Vue → 编译 → Demo → 验证 → 文档
- 运行时 API ——
installQtx/ensureQtxReady/ 主题 / Portal 协调 - 模板能力矩阵 —— 哪些写法能编译、哪些会回落
- Android 原生模块 —— 需要改原生属性时从这里找
@QtComponent控制器
下一步
- 给 AI 的接入契约 —— 从零搭一个可上机的双页 TV 应用
- 组件索引
- API 参考索引
- 文档契约 —— 如果你是 AI 或贡献者,先读这个