Compare commits
9
Commits
v1.3.0
...
d8487807cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8487807cd | ||
|
|
7349bb3429 | ||
|
|
0796e73ab1 | ||
|
|
6885015825 | ||
|
|
2556fc26ff | ||
|
|
bdaee75b81 | ||
|
|
38038b9461 | ||
|
|
a50f134b25 | ||
|
|
f8140bb70b |
@@ -93,6 +93,13 @@ export const COMPONENT_LIST: ComponentMeta[] = [
|
|||||||
category: "布局组件",
|
category: "布局组件",
|
||||||
entry: "src/components/master-detail-page/index.vue"
|
entry: "src/components/master-detail-page/index.vue"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "DropdownFilter",
|
||||||
|
title: "DropdownFilter 筛选栏",
|
||||||
|
description: "列表页顶部的搜索框与下拉筛选,取值和事件统一收口。",
|
||||||
|
category: "布局组件",
|
||||||
|
entry: "src/components/dropdown-filter/index.vue"
|
||||||
|
},
|
||||||
|
|
||||||
// ---------- 编辑器组件 ----------
|
// ---------- 编辑器组件 ----------
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
# DropdownFilter 筛选栏
|
||||||
|
|
||||||
|
列表页顶部的「搜索框 + 下拉筛选」。结构、取值和事件统一收在组件里,
|
||||||
|
数据从哪来、什么时候发请求、怎么同步到 URL,仍归业务。
|
||||||
|
|
||||||
|
外观不写在组件里,而是由 `page-layout.less` 的 `.tui-filters` 提供——
|
||||||
|
手写同样结构(`.tui-filters` 包住 `.t-input` 和 `.menus`)会得到同一套样式,
|
||||||
|
从旧项目搬过来的筛选栏只需要换一个根类名。
|
||||||
|
|
||||||
|
## 基础用法
|
||||||
|
|
||||||
|
:::preview 搜索 + 下拉筛选 || 输入关键词、切换品类或状态,观察筛选栏与列表的联动
|
||||||
|
|
||||||
|
demo-preview=../demos/dropdown-filter/basic.vue
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<dropdown-filter
|
||||||
|
v-model="keyword"
|
||||||
|
:filters="filters"
|
||||||
|
placeholder="搜索产品名称或编码"
|
||||||
|
@filter-change="handleFilterChange"
|
||||||
|
>
|
||||||
|
<template #suffix-icon>
|
||||||
|
<t-button size="extra-small" theme="primary" variant="outline" content="选择" />
|
||||||
|
</template>
|
||||||
|
</dropdown-filter>
|
||||||
|
```
|
||||||
|
|
||||||
|
`filters` 的每一项对应一个 `t-dropdown-item`,`label` 由业务算好——
|
||||||
|
组件不会根据 `value` 反查选项文本:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const filters = computed<DropdownFilterItem[]>(() => [
|
||||||
|
{
|
||||||
|
key: "category",
|
||||||
|
label: categoryOptions.find(item => item.value === category.value)?.label || "全部品类",
|
||||||
|
value: category.value,
|
||||||
|
options: categoryOptions
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 一个事件管全部筛选
|
||||||
|
|
||||||
|
`filter-change` 同时承载搜索框和下拉项,业务只接一个口:
|
||||||
|
|
||||||
|
| 来源 | `key` | 说明 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 搜索框 | `keyword` | 固定值,值已转成字符串 |
|
||||||
|
| 下拉项 | 配置里的 `key` | 值原样来自 TDesign DropdownItem |
|
||||||
|
|
||||||
|
`v-model` 照常可用,用来读搜索框内容;只接 `filter-change` 也能跑通。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function handleFilterChange(change: DropdownFilterChange): void {
|
||||||
|
if (change.key === "keyword") {
|
||||||
|
// 这里做防抖,组件不管节流
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 其余 key 直接写回对应的 ref,再重新拉数据
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
搜索框每次输入都会触发事件,防抖放在业务侧——不同页面的输入成本差别很大,
|
||||||
|
组件里定一个固定间隔只会在某些页面上变成累赘。
|
||||||
|
|
||||||
|
## 放进列表页骨架
|
||||||
|
|
||||||
|
筛选栏要贴在内容区顶部、滚上去被毛玻璃盖住,需要页面骨架配合:
|
||||||
|
|
||||||
|
- 页面根节点:`tui-page-layout` + `tui-navbar`
|
||||||
|
- 内容区(`MasterDetailPage` 自带,或者手写 `main`):追加 `list`
|
||||||
|
- 滚动容器:`t-pull-down-refresh` 加 `pull-refresh`
|
||||||
|
- 筛选栏:`DropdownFilter`,或者手写 `.tui-filters`
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<div class="tui-page-layout tui-navbar">
|
||||||
|
<t-navbar fixed title="库存流水" left-arrow @left-click="$router.back()" />
|
||||||
|
<master-detail-page class="list" :split="isWide" :selected="!!selectedId">
|
||||||
|
<template #master>
|
||||||
|
<t-pull-down-refresh class="pull-refresh" v-model="isRefreshing" @refresh="reload">
|
||||||
|
<dropdown-filter v-model="keyword" :filters="filters" @filter-change="handleFilterChange" />
|
||||||
|
<t-cell-group theme="card">
|
||||||
|
<!-- 列表 -->
|
||||||
|
</t-cell-group>
|
||||||
|
</t-pull-down-refresh>
|
||||||
|
</template>
|
||||||
|
</master-detail-page>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
这三层各管一件事,缺一层都会露馅:
|
||||||
|
|
||||||
|
| 位置 | 类名 | 作用 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 内容区 | `list` | 清掉内容区自己的上下内边距,间距改由滚动容器承担 |
|
||||||
|
| 滚动容器 | `pull-refresh` | 接管滚动,撑满剩余高度,底部让出安全区 |
|
||||||
|
| 筛选栏 | `tui-filters` | 吸顶、毛玻璃、搜索框与菜单连成一块 |
|
||||||
|
|
||||||
|
### 菜单展开时筛选栏被滚走
|
||||||
|
|
||||||
|
TDesign 展开下拉菜单时会往 `.t-pull-down-refresh__track` 写 `overflow: hidden`,
|
||||||
|
track 一旦成为滚动容器,`sticky` 就失效。骨架里已经处理了两条路:
|
||||||
|
|
||||||
|
- 浏览器支持 `:has()`:滚动容器里出现 `.tui-filters` 就自动放开 `overflow`
|
||||||
|
- 不支持,或者筛选栏被别的元素包了一层:给滚动容器加 `has-dropdown-filter`
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<t-pull-down-refresh class="pull-refresh has-dropdown-filter" v-model="isRefreshing" @refresh="reload">
|
||||||
|
```
|
||||||
|
|
||||||
|
## 深色模式
|
||||||
|
|
||||||
|
筛选栏只用 TDesign 语义变量(`--td-bg-color-container`、`--td-component-border`),
|
||||||
|
深色主题下由 TDesign 的变量切换接管,不需要额外写一套。
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
<api-table name="DropdownFilter" />
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# 组件总览
|
# 组件总览
|
||||||
|
|
||||||
共 21 个组件,分为布局、编辑器、交互与 AI 对话四类。
|
共 22 个组件,分为布局、编辑器、交互与 AI 对话四类。
|
||||||
|
|
||||||
## 布局组件
|
## 布局组件
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
| [MasterDetail](/components/master-detail) | 宽屏下列表与详情并排,窄屏只渲染列表。 |
|
| [MasterDetail](/components/master-detail) | 宽屏下列表与详情并排,窄屏只渲染列表。 |
|
||||||
| [PaneTransition](/components/pane-transition) | 与路由无关的左右推入效果,用于栏位内部的视图切换。 |
|
| [PaneTransition](/components/pane-transition) | 与路由无关的左右推入效果,用于栏位内部的视图切换。 |
|
||||||
| [MasterDetailPage](/components/master-detail-page) | 把列表页骨架、主从分栏与栏内过渡打包成一个组件,列表页不再手写 master-detail。 |
|
| [MasterDetailPage](/components/master-detail-page) | 把列表页骨架、主从分栏与栏内过渡打包成一个组件,列表页不再手写 master-detail。 |
|
||||||
|
| [DropdownFilter](/components/dropdown-filter) | 列表页顶部的搜索框与下拉筛选,取值和事件统一收口。 |
|
||||||
|
|
||||||
## 编辑器组件
|
## 编辑器组件
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,30 @@ demo-preview=../demos/master-detail-page/sub.vue
|
|||||||
第三层只在分栏形态下成立:`split` 为 false 时 `sub` 被忽略,
|
第三层只在分栏形态下成立:`split` 为 false 时 `sub` 被忽略,
|
||||||
子页要走整页路由,由详情页自己判断(`usePane().openSub()` 会返回 false)。
|
子页要走整页路由,由详情页自己判断(`usePane().openSub()` 会返回 false)。
|
||||||
|
|
||||||
|
### 列表要留着的时候:`sub-mode="cover"`
|
||||||
|
|
||||||
|
上面那种是「同一条记录继续往下钻」,列表可以不要了。但如果从详情跳进的是**另一个模块**
|
||||||
|
的页面,用户还得对着列表核对,`shift` 把列表推走就错了。
|
||||||
|
|
||||||
|
传 `sub-mode="cover"`:主栏不动、子页直接盖住详情栏,详情原地保活(返回时滚动位置和状态都在)。
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<master-detail-page :split="isWide" :selected="!!selectedId" :sub="!!subView" sub-mode="cover">
|
||||||
|
<template #master><!-- 资金流水列表 --></template>
|
||||||
|
<template #detail><fund-record-detail :record-id="selectedId" /></template>
|
||||||
|
<template #sub><sales-order-detail :order-id="orderPane.orderId" /></template>
|
||||||
|
</master-detail-page>
|
||||||
|
```
|
||||||
|
|
||||||
|
| 状态 | 主栏 | 右栏 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 选中 | 列表 | 详情 |
|
||||||
|
| `sub` 为 true | 列表(不动) | 子页 |
|
||||||
|
|
||||||
|
两种模式共用同一套 `sub` / `subView` 状态,层级、历史和 `pane.close()` 的行为完全一致,
|
||||||
|
只影响布局。子页里再换一层(订单详情 → 取消订单)仍然是给 `#sub` 里的内容换 `:key`,
|
||||||
|
外层 `PaneTransition` 自动接上。
|
||||||
|
|
||||||
### 谁来决定子页
|
### 谁来决定子页
|
||||||
|
|
||||||
详情页发起,列表页编排:
|
详情页发起,列表页编排:
|
||||||
@@ -100,6 +124,18 @@ const { selectedId, subView } = useMasterDetailPane({
|
|||||||
子页里的返回调 `usePane().close()`,会关掉最上面一层;`pane.close(true)` 表示
|
子页里的返回调 `usePane().close()`,会关掉最上面一层;`pane.close(true)` 表示
|
||||||
子页里改过数据,回到详情时宿主会重新拉一次。
|
子页里改过数据,回到详情时宿主会重新拉一次。
|
||||||
|
|
||||||
|
宿主需要给子页标识补前缀(例如标明"叠在哪一单上")时,用 `providePane` 在页面最外层
|
||||||
|
换一套派生上下文,别在中间塞容器组件——那会切断栏内骨架的直系选择器:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const { selectedId, subView, openSub, close } = useMasterDetailPane({ … });
|
||||||
|
|
||||||
|
providePane({
|
||||||
|
close: saved => close(saved),
|
||||||
|
openSub: view => openSub(buildView(orderPane.value.orderId, view))
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
子页内部不要再套一层 `MasterDetailPage` 分栏——右栏本来就不宽,
|
子页内部不要再套一层 `MasterDetailPage` 分栏——右栏本来就不宽,
|
||||||
需要列表就用单栏形态(`split` 传 false)。
|
需要列表就用单栏形态(`split` 传 false)。
|
||||||
|
|
||||||
|
|||||||
@@ -244,6 +244,55 @@ function openSub(view: string): boolean {
|
|||||||
|
|
||||||
用 `useMasterDetailPane` 的话这些它都包了,把 `:sub="!!subView"` 接上即可。
|
用 `useMasterDetailPane` 的话这些它都包了,把 `:sub="!!subView"` 接上即可。
|
||||||
|
|
||||||
|
### 第三层的两种呈现
|
||||||
|
|
||||||
|
同样是第三层,用户要不要继续看列表,决定了完全不同的排布:
|
||||||
|
|
||||||
|
| `sub-mode` | 主栏 | 右栏 | 用在什么场景 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `shift`(默认) | 详情 | 子页 | 同一条记录继续往下钻,列表已经不用看了 |
|
||||||
|
| `cover` | 列表(不动) | 子页 | 从详情跳进**另一个模块**的页面,列表要一直在眼前 |
|
||||||
|
|
||||||
|
`cover` 的典型例子:资金流水列表 → 某条流水的详情 → 点「交易订单详情」。
|
||||||
|
这时订单是另一个模块的整页,但用户还在按资金流水核对,列表必须留着。
|
||||||
|
`shift` 会把列表整列推走,正好相反。
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<master-detail :split="isWide" :detail-empty="!selectedId" :sub="!!subView" sub-mode="cover">
|
||||||
|
<template #master><!-- 资金流水列表 --></template>
|
||||||
|
<template #detail>
|
||||||
|
<fund-record-detail :record-id="selectedId" />
|
||||||
|
</template>
|
||||||
|
<template #sub>
|
||||||
|
<sales-order-detail :order-id="orderPane.orderId" />
|
||||||
|
</template>
|
||||||
|
</master-detail>
|
||||||
|
```
|
||||||
|
|
||||||
|
`cover` 下详情不参与位移,只原地淡出——**保活**,返回时滚动位置和内部表单状态都还在,
|
||||||
|
不会像 `v-if` 重建那样重新拉一次接口。
|
||||||
|
|
||||||
|
两种模式共用同一套 `sub` / `subView` 状态,只是布局不同:层级、历史和 `pane.close()` 的行为完全一致。
|
||||||
|
|
||||||
|
### 右栏里的页面怎么带上前缀
|
||||||
|
|
||||||
|
子页标识由内容页发起(`pane.openSub("payment")`),但宿主可能需要在前面补上"叠在哪一条上",
|
||||||
|
例如 `sales-order:<订单 id>:payment`。别在中间塞一层容器组件去改写——容器会切断
|
||||||
|
`.detail > .tui-page-layout` / `.sub > .tui-page-layout` 这些直系选择器,栏内导航栏会退回 `fixed`
|
||||||
|
飘到视口顶上。用 `providePane` 在页面最外层换一套派生上下文:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const { selectedId, subView, openSub, close } = useMasterDetailPane({ … });
|
||||||
|
|
||||||
|
providePane({
|
||||||
|
close: saved => close(saved),
|
||||||
|
// 订单页发的是 `payment`,补上订单 id 后宿主的 #sub 才知道渲染谁
|
||||||
|
openSub: view => openSub(isOrderView(view) ? view : buildView(orderId, view))
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
它只在当前组件的后代里生效,并会遮蔽上层的同一套上下文,所以 `close` 要原样转发。
|
||||||
|
|
||||||
### 切换动画
|
### 切换动画
|
||||||
|
|
||||||
右栏换视图没有路由变化,所以不能用 `PageTransition`,改用 `PaneTransition`(只做效果,不绑定路由):
|
右栏换视图没有路由变化,所以不能用 `PageTransition`,改用 `PaneTransition`(只做效果,不绑定路由):
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
<template>
|
||||||
|
<div class="demo">
|
||||||
|
<div class="stage">
|
||||||
|
<div class="tui-page-content list">
|
||||||
|
<t-pull-down-refresh class="pull-refresh" :value="false">
|
||||||
|
<dropdown-filter
|
||||||
|
v-model="keyword"
|
||||||
|
:filters="filters"
|
||||||
|
placeholder="搜索产品名称或编码"
|
||||||
|
@filter-change="handleFilterChange"
|
||||||
|
>
|
||||||
|
<template #suffix-icon>
|
||||||
|
<t-button size="extra-small" theme="primary" variant="outline" content="选择" />
|
||||||
|
</template>
|
||||||
|
</dropdown-filter>
|
||||||
|
<div class="list-body">
|
||||||
|
<t-cell-group v-if="visibleList.length" theme="card">
|
||||||
|
<t-cell
|
||||||
|
v-for="item in visibleList"
|
||||||
|
:key="item.id"
|
||||||
|
:title="item.name"
|
||||||
|
:description="item.code"
|
||||||
|
:note="item.status === 'on' ? '在售' : '停售'"
|
||||||
|
/>
|
||||||
|
</t-cell-group>
|
||||||
|
<p v-else class="empty" v-text="'没有匹配的产品'" />
|
||||||
|
</div>
|
||||||
|
</t-pull-down-refresh>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="log">
|
||||||
|
<span v-text="'最近一次 filter-change:'" />
|
||||||
|
<code v-text="lastChange" />
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, ref } from "vue";
|
||||||
|
import {
|
||||||
|
DropdownFilter,
|
||||||
|
type DropdownFilterChange,
|
||||||
|
type DropdownFilterItem,
|
||||||
|
type DropdownFilterOption
|
||||||
|
} from "timi-tdesign-mobile";
|
||||||
|
|
||||||
|
const keyword = ref("");
|
||||||
|
const category = ref("all");
|
||||||
|
const status = ref("all");
|
||||||
|
const lastChange = ref("—");
|
||||||
|
|
||||||
|
const productList = [
|
||||||
|
{ id: "p1", name: "氨基酸洁面慕斯", code: "P-1001", category: "cleanser", status: "on" },
|
||||||
|
{ id: "p2", name: "玻尿酸精华液", code: "P-1002", category: "serum", status: "on" },
|
||||||
|
{ id: "p3", name: "烟酰胺原液", code: "P-1003", category: "serum", status: "off" },
|
||||||
|
{ id: "p4", name: "舒缓修护面霜", code: "P-1004", category: "cream", status: "on" },
|
||||||
|
{ id: "p5", name: "清透防晒乳", code: "P-1005", category: "cream", status: "off" },
|
||||||
|
{ id: "p6", name: "氨基酸洗发水", code: "P-1006", category: "body", status: "on" }
|
||||||
|
];
|
||||||
|
|
||||||
|
const categoryOptions: DropdownFilterOption[] = [
|
||||||
|
{ label: "全部品类", value: "all" },
|
||||||
|
{ label: "洁面", value: "cleanser" },
|
||||||
|
{ label: "精华", value: "serum" },
|
||||||
|
{ label: "面霜", value: "cream" },
|
||||||
|
{ label: "身体护理", value: "body" }
|
||||||
|
];
|
||||||
|
|
||||||
|
const statusOptions: DropdownFilterOption[] = [
|
||||||
|
{ label: "全部状态", value: "all" },
|
||||||
|
{ label: "在售", value: "on" },
|
||||||
|
{ label: "停售", value: "off" }
|
||||||
|
];
|
||||||
|
|
||||||
|
const filters = computed<DropdownFilterItem[]>(() => [
|
||||||
|
{
|
||||||
|
key: "category",
|
||||||
|
label: categoryOptions.find(item => item.value === category.value)?.label || "全部品类",
|
||||||
|
value: category.value,
|
||||||
|
options: categoryOptions
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "status",
|
||||||
|
label: statusOptions.find(item => item.value === status.value)?.label || "全部状态",
|
||||||
|
value: status.value,
|
||||||
|
options: statusOptions
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const visibleList = computed(() => {
|
||||||
|
const text = keyword.value.trim().toLowerCase();
|
||||||
|
return productList.filter(item => {
|
||||||
|
const matchedText = !text || `${item.name}${item.code}`.toLowerCase().includes(text);
|
||||||
|
const matchedCategory = category.value === "all" || item.category === category.value;
|
||||||
|
const matchedStatus = status.value === "all" || item.status === status.value;
|
||||||
|
return matchedText && matchedCategory && matchedStatus;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleFilterChange(change: DropdownFilterChange): void {
|
||||||
|
lastChange.value = `${change.key} = ${String(change.value)}`;
|
||||||
|
if (change.key === "category") {
|
||||||
|
category.value = String(change.value);
|
||||||
|
}
|
||||||
|
if (change.key === "status") {
|
||||||
|
status.value = String(change.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.demo {
|
||||||
|
.stage {
|
||||||
|
height: 20rem;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: .75rem;
|
||||||
|
background: var(--vp-c-bg-alt);
|
||||||
|
|
||||||
|
.tui-page-content {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pull-refresh {
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-body {
|
||||||
|
margin: 0 1rem 1rem;
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
margin: 0;
|
||||||
|
padding: 2rem 0;
|
||||||
|
font-size: .8125rem;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--vp-c-text-3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.log {
|
||||||
|
margin: .75rem 0 0;
|
||||||
|
font-size: .8125rem;
|
||||||
|
color: var(--vp-c-text-3);
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--vp-c-brand-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
"module": "./dist/timi-tdesign-mobile.mjs",
|
"module": "./dist/timi-tdesign-mobile.mjs",
|
||||||
"style": "./dist/timi-tdesign-mobile.css",
|
"style": "./dist/timi-tdesign-mobile.css",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.3.0",
|
"version": "1.5.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "pnpm run -C docs dev",
|
"dev": "pnpm run -C docs dev",
|
||||||
|
|||||||
@@ -6,6 +6,19 @@
|
|||||||
*/
|
*/
|
||||||
:root {
|
:root {
|
||||||
--tui-split-duration: 320ms;
|
--tui-split-duration: 320ms;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全区统一入口,四个方向都从这里取。
|
||||||
|
*
|
||||||
|
* --safe-area-inset-* 由 Capacitor 原生层按 WindowInsets 注入:Android WebView
|
||||||
|
* 不实现 env(safe-area-inset-*),恒返回 0,只有原生注入的变量才是真实值。
|
||||||
|
* iOS / 浏览器没有这套变量,回退到 env()。
|
||||||
|
* 使用方要自己接管安全区时,覆盖这几个 --tui-safe-* 即可。
|
||||||
|
*/
|
||||||
|
--tui-safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
|
||||||
|
--tui-safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
|
||||||
|
--tui-safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
|
||||||
|
--tui-safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,6 +31,11 @@
|
|||||||
*
|
*
|
||||||
* .tui-page-content 使用绝对定位铺满上级容器,因此上级必须是
|
* .tui-page-content 使用绝对定位铺满上级容器,因此上级必须是
|
||||||
* PageTransition 渲染出的定位容器,不要在普通 div 中直接使用。
|
* PageTransition 渲染出的定位容器,不要在普通 div 中直接使用。
|
||||||
|
*
|
||||||
|
* 顶部安全区从 --tui-safe-top 取(定义在 :root,Capacitor 注入优先、env() 兜底)。
|
||||||
|
* 这个取值能成立的前提是窗口真的 edge-to-edge:Android 15+ 由系统强制,
|
||||||
|
* Android 15 以下需要在 MainActivity 里调 WindowCompat.setDecorFitsSystemWindows(false)。
|
||||||
|
* 窗口没全屏却按全屏补安全区,顶部就会多出一条状态栏高度的空白。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,13 +50,70 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding-top: var(--tui-detail-empty-inset, calc(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) + 48px));
|
padding-top: var(--tui-detail-empty-inset, calc(var(--tui-safe-top, 0px) + 48px));
|
||||||
// 必须有不透明背景:切换视图时它和旧内容同时在场,
|
// 必须有不透明背景:切换视图时它和旧内容同时在场,
|
||||||
// 透明的话提示文字会浮在还在滑出的页面上,看起来像重影。
|
// 透明的话提示文字会浮在还在滑出的页面上,看起来像重影。
|
||||||
background: var(--tui-detail-empty-background, var(--td-bg-color-page));
|
background: var(--tui-detail-empty-background, var(--td-bg-color-page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页顶部的筛选栏:搜索框 + 下拉菜单贴在内容区顶部,展开的菜单和搜索框连成一块。
|
||||||
|
*
|
||||||
|
* 由 `DropdownFilter` 使用,也接受手写结构——只要根节点挂上这个类,
|
||||||
|
* 内部的 `.t-input` / `.menus` 就按同一套样式渲染。`z-index` 让整条栏浮在列表之上,
|
||||||
|
* 毛玻璃背景用 `::after` 单独一层,往下渐隐,内容滚过去才有层次感。
|
||||||
|
*/
|
||||||
|
.tui-filters {
|
||||||
|
top: -1rem;
|
||||||
|
margin: -1rem 0 0;
|
||||||
|
padding: 1rem 1rem 0;
|
||||||
|
z-index: 10;
|
||||||
|
position: sticky;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
mask: linear-gradient(to top, transparent 0%, #000 60%);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
content: "";
|
||||||
|
z-index: -1;
|
||||||
|
position: absolute;
|
||||||
|
backdrop-filter: blur(var(--tui-backdrop-blur, 10px));
|
||||||
|
-webkit-mask: linear-gradient(to top, transparent 0%, #000 60%);
|
||||||
|
-webkit-backdrop-filter: blur(var(--tui-backdrop-blur, 10px));
|
||||||
|
}
|
||||||
|
|
||||||
|
.t-input {
|
||||||
|
--td-button-border-radius: 99rem;
|
||||||
|
|
||||||
|
border: 1px solid var(--td-component-border);
|
||||||
|
height: 2.25rem;
|
||||||
|
padding: .25rem .25rem .25rem .75rem;
|
||||||
|
z-index: 2;
|
||||||
|
position: relative;
|
||||||
|
border-radius: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
--td-tab-item-height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menus {
|
||||||
|
--td-spacer-1: 6px;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid rgba(148, 163, 184, .18);
|
||||||
|
z-index: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
margin-top: -1rem;
|
||||||
|
border-top: none;
|
||||||
|
padding-top: .8rem;
|
||||||
|
border-radius: 0 0 1rem 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.tui-page-layout {
|
.tui-page-layout {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -54,8 +129,8 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-top: calc(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) + 48px + 1rem);
|
padding-top: calc(var(--tui-safe-top, 0px) + 48px + 1rem);
|
||||||
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
|
padding-bottom: calc(var(--tui-safe-bottom, 0px) + 1rem);
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
&.scroll {
|
&.scroll {
|
||||||
@@ -72,11 +147,53 @@
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页的滚动容器。
|
||||||
|
*
|
||||||
|
* 内容区自己不滚动(`tui-page-content` 默认 `overflow: hidden`),
|
||||||
|
* 列表页把滚动权交给这个容器:外层只分配高度,`t-pull-down-refresh` 负责滚。
|
||||||
|
* track 撑满高度并纵向排列,空态才能垂直居中。
|
||||||
|
*/
|
||||||
|
.pull-refresh {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-bottom: calc(var(--tui-safe-bottom, 0px) + 1rem);
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
|
||||||
|
.t-pull-down-refresh__track {
|
||||||
|
gap: 1rem;
|
||||||
|
display: flex;
|
||||||
|
min-height: 100%;
|
||||||
|
height: auto;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 筛选菜单展开时 TDesign 会给 track 写 `overflow: hidden`,
|
||||||
|
* 那会让 track 变成 sticky 的滚动容器,筛选栏跟着整条滚走。
|
||||||
|
* 有 `:has()` 时自动识别,没有时由 `.has-dropdown-filter` 兜底。
|
||||||
|
*/
|
||||||
|
@supports selector(:has(*)) {
|
||||||
|
&:has(.tui-filters) .t-pull-down-refresh__track {
|
||||||
|
overflow: visible !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.has-dropdown-filter {
|
||||||
|
|
||||||
|
.t-pull-down-refresh__track {
|
||||||
|
overflow: visible !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.tui-navbar {
|
&.tui-navbar {
|
||||||
--tui-nav-height: calc(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) + 48px);
|
--tui-nav-height: calc(var(--tui-safe-top, 0px) + 48px);
|
||||||
--td-navbar-padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
|
--td-navbar-padding-top: var(--tui-safe-top, 0px);
|
||||||
|
|
||||||
.t-navbar__content,
|
.t-navbar__content,
|
||||||
.t-navbar__placeholder {
|
.t-navbar__placeholder {
|
||||||
@@ -101,6 +218,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页的顶部间距必须落在真正的滚动容器上,内容才能穿进导航栏的毛玻璃层。
|
||||||
|
* 分栏形态下内容区不滚动、滚动的是主栏里的列表容器,间距的落点一样,
|
||||||
|
* 所以两种形态共用这一条。
|
||||||
|
*/
|
||||||
|
&.tui-navbar .tui-page-content.list {
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
|
||||||
|
.pull-refresh {
|
||||||
|
padding-top: calc(var(--tui-nav-height) + 1rem);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +241,7 @@
|
|||||||
.tui-app-shell.is-rail {
|
.tui-app-shell.is-rail {
|
||||||
|
|
||||||
.rail {
|
.rail {
|
||||||
padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
|
padding-top: var(--tui-safe-top, 0px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.t-navbar--fixed .t-navbar__content {
|
.t-navbar--fixed .t-navbar__content {
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ defineExpose({
|
|||||||
flex: none;
|
flex: none;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: var(--ai-msg-padding-top, .5rem) 1rem calc(var(--ai-chat-bottom-area-height, 4.5rem) + 1.5rem + env(safe-area-inset-bottom, 0px));
|
padding: var(--ai-msg-padding-top, .5rem) 1rem calc(var(--ai-chat-bottom-area-height, 4.5rem) + 1.5rem + var(--tui-safe-bottom, 0px));
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ defineExpose({
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
.bottom-area {
|
.bottom-area {
|
||||||
inset: auto 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
|
inset: auto 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||||
width: auto;
|
width: auto;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ function onTabChange(value: AppShellValue): void {
|
|||||||
position: relative;
|
position: relative;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-left: env(safe-area-inset-left, 0);
|
padding-left: var(--tui-safe-left, 0);
|
||||||
border-right: 1px solid var(--td-component-border);
|
border-right: 1px solid var(--td-component-border);
|
||||||
background: var(--tui-rail-background, var(--td-bg-color-container));
|
background: var(--tui-rail-background, var(--td-bg-color-container));
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ function onTabChange(value: AppShellValue): void {
|
|||||||
|
|
||||||
.rail-extra {
|
.rail-extra {
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0));
|
padding-bottom: calc(.75rem + var(--tui-safe-bottom, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ function onTabChange(value: AppShellValue): void {
|
|||||||
|
|
||||||
flex: none;
|
flex: none;
|
||||||
border-top: 1px solid var(--td-component-border);
|
border-top: 1px solid var(--td-component-border);
|
||||||
padding-bottom: env(safe-area-inset-bottom, 0);
|
padding-bottom: var(--tui-safe-bottom, 0);
|
||||||
background: var(--tui-tabbar-background, var(--td-bg-color-container));
|
background: var(--tui-tabbar-background, var(--td-bg-color-container));
|
||||||
|
|
||||||
:deep(.t-tab-bar-item) {
|
:deep(.t-tab-bar-item) {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ defineSlots<BottomPopupSlots>();
|
|||||||
|
|
||||||
.body {
|
.body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 0 0 env(safe-area-inset-bottom, 0);
|
padding: 0 0 var(--tui-safe-bottom, 0);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import view from "./index.vue";
|
||||||
|
import { WebToolkit } from "timi-web";
|
||||||
|
|
||||||
|
export const DropdownFilter = WebToolkit.withInstall(view);
|
||||||
|
export default DropdownFilter;
|
||||||
|
|
||||||
|
export type {
|
||||||
|
DropdownFilterChange,
|
||||||
|
DropdownFilterItem,
|
||||||
|
DropdownFilterOption,
|
||||||
|
DropdownFilterProps
|
||||||
|
} from "./type";
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-filters dropdown-filter">
|
||||||
|
<t-input
|
||||||
|
:model-value="props.modelValue"
|
||||||
|
class="search-input"
|
||||||
|
type="search"
|
||||||
|
borderless
|
||||||
|
clearable
|
||||||
|
:placeholder="props.placeholder"
|
||||||
|
@update:model-value="handleKeywordChange"
|
||||||
|
>
|
||||||
|
<template v-if="$slots['suffix-icon']" #suffix-icon>
|
||||||
|
<slot name="suffix-icon" />
|
||||||
|
</template>
|
||||||
|
</t-input>
|
||||||
|
<configured-dropdown-menu
|
||||||
|
:filters="props.filters"
|
||||||
|
:menu-props="props.menuProps"
|
||||||
|
@filter-change="handleDropdownChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { defineComponent, h, type PropType } from "vue";
|
||||||
|
import { DropdownItem, DropdownMenu } from "tdesign-mobile-vue";
|
||||||
|
import type { DropdownMenuProps, DropdownValue } from "tdesign-mobile-vue";
|
||||||
|
import type { DropdownFilterChange, DropdownFilterItem, DropdownFilterProps } from "./type";
|
||||||
|
|
||||||
|
defineOptions({ name: "DropdownFilter" });
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<DropdownFilterProps>(), {
|
||||||
|
modelValue: "",
|
||||||
|
placeholder: "搜索"
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: string];
|
||||||
|
"filter-change": [change: DropdownFilterChange];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TDesign 的 DropdownMenu 只收直接子节点里的 TDropdownItem——它在内部遍历
|
||||||
|
* `slots.default()` 并比对组件名。模板里写 `v-for` 会被编译成一个 Fragment,
|
||||||
|
* 比对失败,整条菜单就是空的;渲染函数手动铺平的数组才是它要的形状。
|
||||||
|
*/
|
||||||
|
const ConfiguredDropdownMenu = defineComponent({
|
||||||
|
name: "ConfiguredDropdownMenu",
|
||||||
|
props: {
|
||||||
|
filters: {
|
||||||
|
type: Array as PropType<DropdownFilterItem[]>,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
menuProps: {
|
||||||
|
type: Object as PropType<DropdownMenuProps & { class?: string }>,
|
||||||
|
default: undefined
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ["filter-change"],
|
||||||
|
setup(menu, { emit: emitMenu }) {
|
||||||
|
return () => h(DropdownMenu, {
|
||||||
|
...menu.menuProps,
|
||||||
|
class: ["menus", menu.menuProps?.class]
|
||||||
|
}, {
|
||||||
|
default: () => menu.filters.map(filter => h(DropdownItem, {
|
||||||
|
key: filter.key,
|
||||||
|
modelValue: filter.value,
|
||||||
|
label: filter.label,
|
||||||
|
options: filter.options,
|
||||||
|
multiple: filter.multiple,
|
||||||
|
optionsColumns: filter.optionsColumns,
|
||||||
|
disabled: filter.disabled,
|
||||||
|
onChange: (value: DropdownValue) => emitMenu("filter-change", { key: filter.key, value })
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索框的变化同时算一次筛选变化,业务只接 `filter-change` 也能跑通;
|
||||||
|
* key 固定为 `keyword`,免得每个页面再自己起一套约定。
|
||||||
|
*/
|
||||||
|
function handleKeywordChange(value: string | number): void {
|
||||||
|
const keyword = String(value ?? "");
|
||||||
|
emit("update:modelValue", keyword);
|
||||||
|
emit("filter-change", { key: "keyword", value: keyword });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDropdownChange(change: DropdownFilterChange): void {
|
||||||
|
emit("filter-change", change);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import type { DropdownMenuProps, DropdownValue } from "tdesign-mobile-vue";
|
||||||
|
|
||||||
|
/** 下拉筛选里的一个选项。 */
|
||||||
|
export interface DropdownFilterOption {
|
||||||
|
/** 选项文本。 */
|
||||||
|
label: string;
|
||||||
|
/** 选项值,原样交给 TDesign DropdownItem。 */
|
||||||
|
value: DropdownValue;
|
||||||
|
/** 是否禁用。 */
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 一个筛选项的完整配置。 */
|
||||||
|
export interface DropdownFilterItem {
|
||||||
|
/** 筛选项标识,随 `filter-change` 一起抛出。 */
|
||||||
|
key: string;
|
||||||
|
/** 当前值对应的展示文本,由业务算好。 */
|
||||||
|
label: string;
|
||||||
|
/** 当前值,配合 `v-model` 由业务侧回填。 */
|
||||||
|
value: DropdownValue;
|
||||||
|
/** 可选项。 */
|
||||||
|
options: DropdownFilterOption[];
|
||||||
|
/** 是否多选。 */
|
||||||
|
multiple?: boolean;
|
||||||
|
/** 选项列数。 */
|
||||||
|
optionsColumns?: string | number;
|
||||||
|
/** 是否禁用。 */
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `filter-change` 的事件参数。 */
|
||||||
|
export interface DropdownFilterChange {
|
||||||
|
/** 触发变化的筛选项标识;搜索框固定为 `keyword`。 */
|
||||||
|
key: string;
|
||||||
|
/** 变化后的值。 */
|
||||||
|
value: DropdownValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** DropdownFilter 的 props。 */
|
||||||
|
export interface DropdownFilterProps {
|
||||||
|
/** 搜索框内容,配合 `v-model` 使用。 */
|
||||||
|
modelValue?: string;
|
||||||
|
/** 搜索框占位文本,默认「搜索」。 */
|
||||||
|
placeholder?: string;
|
||||||
|
/** 下拉筛选项,按数组顺序渲染。 */
|
||||||
|
filters: DropdownFilterItem[];
|
||||||
|
/** 透传给 TDesign DropdownMenu 的属性。 */
|
||||||
|
menuProps?: DropdownMenuProps;
|
||||||
|
}
|
||||||
+11
-1
@@ -18,6 +18,7 @@ import AttachmentSelector from "./attachment-selector";
|
|||||||
import Space from "./space";
|
import Space from "./space";
|
||||||
import { Timeline, TimelineItem } from "./timeline";
|
import { Timeline, TimelineItem } from "./timeline";
|
||||||
import CardContainer from "./card-container";
|
import CardContainer from "./card-container";
|
||||||
|
import DropdownFilter from "./dropdown-filter";
|
||||||
import {
|
import {
|
||||||
AiChatComposer,
|
AiChatComposer,
|
||||||
AiChatMessageList,
|
AiChatMessageList,
|
||||||
@@ -46,6 +47,7 @@ export default [
|
|||||||
Timeline,
|
Timeline,
|
||||||
TimelineItem,
|
TimelineItem,
|
||||||
CardContainer,
|
CardContainer,
|
||||||
|
DropdownFilter,
|
||||||
AiChatComposer,
|
AiChatComposer,
|
||||||
AiChatMessageList,
|
AiChatMessageList,
|
||||||
AiChatPanel,
|
AiChatPanel,
|
||||||
@@ -73,6 +75,7 @@ export {
|
|||||||
Timeline,
|
Timeline,
|
||||||
TimelineItem,
|
TimelineItem,
|
||||||
CardContainer,
|
CardContainer,
|
||||||
|
DropdownFilter,
|
||||||
AiChatComposer,
|
AiChatComposer,
|
||||||
AiChatMessageList,
|
AiChatMessageList,
|
||||||
AiChatPanel,
|
AiChatPanel,
|
||||||
@@ -80,7 +83,7 @@ export {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export { createLayoutContext, provideLayout, useLayout } from "./app-shell";
|
export { createLayoutContext, provideLayout, useLayout } from "./app-shell";
|
||||||
export { useExpandToMaster, useMasterDetail, useMasterDetailPane, usePane } from "../composables/use-master-detail";
|
export { useExpandToMaster, useMasterDetail, useMasterDetailPane, usePane, providePane } from "../composables/use-master-detail";
|
||||||
export type { ExpandToMasterOptions, PaneContext, PaneDirection, UseMasterDetailOptions, UseMasterDetailPaneOptions, UseMasterDetailPaneReturn, UseMasterDetailReturn } from "../composables/use-master-detail";
|
export type { ExpandToMasterOptions, PaneContext, PaneDirection, UseMasterDetailOptions, UseMasterDetailPaneOptions, UseMasterDetailPaneReturn, UseMasterDetailReturn } from "../composables/use-master-detail";
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
@@ -134,6 +137,13 @@ export type {
|
|||||||
CardContainerProps
|
CardContainerProps
|
||||||
} from "./card-container";
|
} from "./card-container";
|
||||||
|
|
||||||
|
export type {
|
||||||
|
DropdownFilterChange,
|
||||||
|
DropdownFilterItem,
|
||||||
|
DropdownFilterOption,
|
||||||
|
DropdownFilterProps
|
||||||
|
} from "./dropdown-filter";
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
AttachmentSelectorItem,
|
AttachmentSelectorItem,
|
||||||
AttachmentSelectorProps,
|
AttachmentSelectorProps,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
:top-inset="topInset"
|
:top-inset="topInset"
|
||||||
:detail-empty="!selected"
|
:detail-empty="!selected"
|
||||||
:sub="sub"
|
:sub="sub"
|
||||||
|
:sub-mode="subMode"
|
||||||
>
|
>
|
||||||
<template #master>
|
<template #master>
|
||||||
<div class="tui-master-wrap">
|
<div class="tui-master-wrap">
|
||||||
@@ -54,7 +55,8 @@ const props = withDefaults(defineProps<MasterDetailPageProps>(), {
|
|||||||
direction: "forward",
|
direction: "forward",
|
||||||
masterWidth: 380,
|
masterWidth: 380,
|
||||||
topInset: "",
|
topInset: "",
|
||||||
sub: false
|
sub: false,
|
||||||
|
subMode: "shift"
|
||||||
});
|
});
|
||||||
|
|
||||||
defineSlots<{
|
defineSlots<{
|
||||||
|
|||||||
@@ -19,9 +19,16 @@ export interface MasterDetailPageProps {
|
|||||||
/**
|
/**
|
||||||
* 是否进入第三层:主栏换成详情内容,右栏显示 `#sub` 槽。
|
* 是否进入第三层:主栏换成详情内容,右栏显示 `#sub` 槽。
|
||||||
*
|
*
|
||||||
* 三层依次是:列表 → 详情 → 子页。进入时列表整列滑出左侧、详情退到主栏,
|
* 三层依次是:列表 → 详情 → 子页。只有分栏形态下有效,
|
||||||
* 返回时反向还原成「列表 + 详情」。只有分栏形态下有效,
|
|
||||||
* 窄屏请让子页走整页路由(`usePane().openSub()` 会返回 false)。
|
* 窄屏请让子页走整页路由(`usePane().openSub()` 会返回 false)。
|
||||||
*/
|
*/
|
||||||
sub?: boolean;
|
sub?: boolean;
|
||||||
|
/**
|
||||||
|
* 第三层的呈现方式,默认 `shift`。
|
||||||
|
*
|
||||||
|
* - `shift`:列表整列滑出、详情退到主栏,适合同一条记录继续往下钻;
|
||||||
|
* - `cover`:主栏不动、子页盖住详情栏,适合从详情跳进另一个模块的页面,
|
||||||
|
* 列表要一直留在眼前(详情原地保活,返回时滚动位置和状态都在)。
|
||||||
|
*/
|
||||||
|
subMode?: "shift" | "cover";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
:class="{
|
:class="{
|
||||||
split: isSplit,
|
split: isSplit,
|
||||||
'is-collapsed': isSplit && detailEmpty,
|
'is-collapsed': isSplit && detailEmpty,
|
||||||
'has-sub': isSplit && showSub
|
'has-sub': isSplit && showSub,
|
||||||
|
'is-sub-cover': isSplit && showSub && subMode === 'cover'
|
||||||
}"
|
}"
|
||||||
:style="rootStyle"
|
:style="rootStyle"
|
||||||
>
|
>
|
||||||
@@ -44,7 +45,8 @@ const props = withDefaults(defineProps<MasterDetailProps>(), {
|
|||||||
emptyText: "",
|
emptyText: "",
|
||||||
topInset: "",
|
topInset: "",
|
||||||
detailEmpty: false,
|
detailEmpty: false,
|
||||||
sub: false
|
sub: false,
|
||||||
|
subMode: "shift"
|
||||||
});
|
});
|
||||||
|
|
||||||
defineSlots<{
|
defineSlots<{
|
||||||
@@ -231,6 +233,35 @@ const rootStyle = computed<StyleValue>(() => ({
|
|||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三层的 cover 形态:右栏换人,主栏不动。
|
||||||
|
*
|
||||||
|
* shift 是"整条轨道左移",用户已经不看列表了;cover 针对的相反——
|
||||||
|
* 从详情跳进别的模块,列表本身要一直留在眼前。
|
||||||
|
* 详情不参与位移,只原地淡出(保活,返回时滚动位置和内部状态都还在),
|
||||||
|
* 子页像换班一样滑进右栏。
|
||||||
|
*/
|
||||||
|
&.has-sub.is-sub-cover {
|
||||||
|
|
||||||
|
.master {
|
||||||
|
left: 0;
|
||||||
|
right: calc(100% - var(--tui-master-width));
|
||||||
|
border-right-color: var(--td-component-border, rgba(0, 0, 0, .08));
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail {
|
||||||
|
left: var(--tui-master-width);
|
||||||
|
right: 0;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sub {
|
||||||
|
left: var(--tui-master-width);
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -31,4 +31,15 @@ export interface MasterDetailProps {
|
|||||||
* 只有分栏形态下有效,窄屏请让子页走整页路由。
|
* 只有分栏形态下有效,窄屏请让子页走整页路由。
|
||||||
*/
|
*/
|
||||||
sub?: boolean;
|
sub?: boolean;
|
||||||
|
/**
|
||||||
|
* 第三层的呈现方式,默认 `shift`。
|
||||||
|
*
|
||||||
|
* - `shift`:整条轨道左移,列表滑出、详情退到主栏。适合同一条记录继续往下钻,
|
||||||
|
* 用户已经不需要再看列表了。
|
||||||
|
* - `cover`:主栏不动,子页直接盖住详情栏(详情原地保活,返回时滚动位置和内部状态都在)。
|
||||||
|
* 适合从详情跳进**另一个模块**的页面——列表本身是用户要一直看的东西。
|
||||||
|
*
|
||||||
|
* 两种方式共用同一套 `sub` / `subView` 状态,切换只影响布局,不影响层级和历史的处理。
|
||||||
|
*/
|
||||||
|
subMode?: "shift" | "cover";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ async function onConfirm() {
|
|||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.popup {
|
.popup {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
|
padding: 0 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||||
background: var(--td-bg-color-container);
|
background: var(--td-bg-color-container);
|
||||||
|
|
||||||
.field {
|
.field {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ function onConfirm() {
|
|||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.link-form {
|
.link-form {
|
||||||
gap: .75rem;
|
gap: .75rem;
|
||||||
padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
|
padding: 0 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ async function onConfirm() {
|
|||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.popup {
|
.popup {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
|
padding: 0 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
background: var(--td-bg-color-container);
|
background: var(--td-bg-color-container);
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ watch(() => props.active, (active) => {
|
|||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.table-picker {
|
.table-picker {
|
||||||
padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
|
padding: 0 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||||
display: flex;
|
display: flex;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background: var(--td-bg-color-container, #fff);
|
background: var(--td-bg-color-container, #fff);
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ function confirmColor() {
|
|||||||
|
|
||||||
.heading-picker {
|
.heading-picker {
|
||||||
width: min(22rem, calc(100vw - 2rem));
|
width: min(22rem, calc(100vw - 2rem));
|
||||||
padding: .5rem .75rem calc(.5rem + env(safe-area-inset-bottom));
|
padding: .5rem .75rem calc(.5rem + var(--tui-safe-bottom, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-popup {
|
.color-picker-popup {
|
||||||
|
|||||||
@@ -86,6 +86,24 @@ export function usePane(): PaneContext | null {
|
|||||||
return inject(PANE_KEY, null);
|
return inject(PANE_KEY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把一套栏内上下文提供给后代。
|
||||||
|
*
|
||||||
|
* 用在"页面要改写子页标识"的场合:列表页在最外层 provide 一套派生上下文,
|
||||||
|
* 右栏里的页面调 `openSub()` 时标识先经过它,不必在中间塞一层容器组件。
|
||||||
|
*
|
||||||
|
* 不要用容器组件代替它:栏内页面的骨架样式(导航栏退化成栏内头部、内容区铺满)
|
||||||
|
* 挂在 `.detail > .tui-page-layout` 这类直系选择器上,多包一层就全落空。
|
||||||
|
*
|
||||||
|
* 注意 provide 只在当前组件的后代里生效,且会遮蔽上层的同一套上下文,
|
||||||
|
* 所以派生时要把 `close` / `openSub` 转发给宿主,别自己重写一套。
|
||||||
|
*
|
||||||
|
* @param context 派生出来的上下文,通常转发 `usePane()` 拿到的宿主上下文
|
||||||
|
*/
|
||||||
|
export function providePane(context: PaneContext): void {
|
||||||
|
provide(PANE_KEY, context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主从布局的选中态管理。
|
* 主从布局的选中态管理。
|
||||||
*
|
*
|
||||||
@@ -99,7 +117,7 @@ export function useMasterDetail(options: UseMasterDetailOptions = {}): UseMaster
|
|||||||
const isWide = layout.isWide;
|
const isWide = layout.isWide;
|
||||||
|
|
||||||
// 右栏里的页面通过 usePane().close() 把控制权交回来
|
// 右栏里的页面通过 usePane().close() 把控制权交回来
|
||||||
provide(PANE_KEY, {
|
providePane({
|
||||||
close: (saved = false) => options.onClose?.(saved),
|
close: (saved = false) => options.onClose?.(saved),
|
||||||
openSub: view => options.onOpenSub?.(view) ?? false
|
openSub: view => options.onOpenSub?.(view) ?? false
|
||||||
});
|
});
|
||||||
@@ -226,6 +244,13 @@ export interface UseMasterDetailPaneReturn {
|
|||||||
openSub: (view: string) => boolean;
|
openSub: (view: string) => boolean;
|
||||||
/** 关闭子页面,回到详情层。 */
|
/** 关闭子页面,回到详情层。 */
|
||||||
closeSub: () => void;
|
closeSub: () => void;
|
||||||
|
/**
|
||||||
|
* 关闭右栏最上面一层:有子页先关子页,其次关编辑,最后关详情。
|
||||||
|
*
|
||||||
|
* 和 `usePane().close()` 是同一套逻辑,给"页面要派生一套栏内上下文"时转发用
|
||||||
|
* (见 `providePane`)。
|
||||||
|
*/
|
||||||
|
close: (saved?: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -313,7 +338,11 @@ export function useMasterDetailPane(options: UseMasterDetailPaneOptions): UseMas
|
|||||||
? options.edit(id)
|
? options.edit(id)
|
||||||
: options.detail(id)),
|
: options.detail(id)),
|
||||||
onOpenSub: requestSub,
|
onOpenSub: requestSub,
|
||||||
onClose: saved => {
|
onClose: saved => closePane(saved)
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 关闭右栏最上面一层;页面派生上下文时原样转发这一个。 */
|
||||||
|
function closePane(saved = false): void {
|
||||||
if (popPane(saved)) {
|
if (popPane(saved)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -340,7 +369,6 @@ export function useMasterDetailPane(options: UseMasterDetailPaneOptions): UseMas
|
|||||||
// 关闭详情:右滑出,回到空栏
|
// 关闭详情:右滑出,回到空栏
|
||||||
selectedId.value = "";
|
selectedId.value = "";
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
function openDetail(id: string): void {
|
function openDetail(id: string): void {
|
||||||
// 正在编辑时直接点列表里另一项:栈顶是编辑层,就地改成新客户的详情的话,
|
// 正在编辑时直接点列表里另一项:栈顶是编辑层,就地改成新客户的详情的话,
|
||||||
@@ -494,7 +522,8 @@ export function useMasterDetailPane(options: UseMasterDetailPaneOptions): UseMas
|
|||||||
openDetail,
|
openDetail,
|
||||||
openEdit,
|
openEdit,
|
||||||
openSub: requestSub,
|
openSub: requestSub,
|
||||||
closeSub
|
closeSub,
|
||||||
|
close: closePane
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user