Appearance
xtf-drag-layout
组件说明
xtf-drag-layout 是拖拽布局,用于通过触摸重排固定网格项目。当前实现读取 items 数据、通过 input 等事件反馈交互、提供实例方法。
- 实际 Demo 路由:
#/pages/components/xtf-drag-layout/index - Demo 源码
基础用法
1. 最小可用
提供能够直接看到或操作组件的最少业务内容。
vue
<template>
<view class="doc-minimum">
<XtfDragLayout :items="fixture" />
</view>
</template>
<script setup lang="uts">
import XtfDragLayout from "@/uni_modules/xtf-linkuiunix/components/xtf-drag-layout/xtf-drag-layout.uvue"
const fixture = [{ id: 'income', title: '收入' }, { id: 'expense', title: '支出' }] as Array<any>
</script>
<style>
.doc-minimum { display: flex; flex-direction: column; padding: 24rpx; }
</style>2. 核心数据与主要事件
使用组件真实数据入口,并记录当前源码声明的主要事件。
vue
<template>
<view class="doc-core">
<XtfDragLayout :items="fixture" @input="onPrimaryEvent" />
</view>
</template>
<script setup lang="uts">
import XtfDragLayout from "@/uni_modules/xtf-linkuiunix/components/xtf-drag-layout/xtf-drag-layout.uvue"
const fixture = [{ id: 'income', title: '收入' }, { id: 'expense', title: '支出' }] as Array<any>
function onPrimaryEvent(payload: any): void { console.log("xtf-drag-layout:input", payload) }
</script>
<style>
.doc-core { display: flex; flex-direction: column; padding: 24rpx; }
</style>3. 动态 disabled 状态
运行时切换 disabled,观察组件对应状态变化。
vue
<template>
<view class="doc-dynamic">
<XtfDragLayout :items="fixture" :disabled="state" />
<button class="doc-action-button" @click="toggleState">切换 disabled</button>
<text class="doc-state-text">disabled: {{ state }}</text>
</view>
</template>
<script setup lang="uts">
import XtfDragLayout from "@/uni_modules/xtf-linkuiunix/components/xtf-drag-layout/xtf-drag-layout.uvue"
import { ref } from "vue"
const fixture = [{ id: 'income', title: '收入' }, { id: 'expense', title: '支出' }] as Array<any>
const state = ref(false)
function toggleState(): void { state.value = !state.value; console.log("disabled", state.value) }
</script>
<style>
.doc-dynamic { display: flex; flex-direction: column; padding: 24rpx; }
.doc-action-button { margin-top: 16rpx; }
.doc-state-text { margin-top: 12rpx; color: #475569; font-size: 24rpx; }
</style>4. 定制 item 插槽
使用源码真实声明的 item slot 替换对应内容。
vue
<template>
<view class="doc-slot">
<XtfDragLayout :items="fixture">
<template #item="scope"><text class="doc-content-text">自定义 item 内容:{{ scope.item }}</text></template>
</XtfDragLayout>
</view>
</template>
<script setup lang="uts">
import XtfDragLayout from "@/uni_modules/xtf-linkuiunix/components/xtf-drag-layout/xtf-drag-layout.uvue"
const fixture = [{ id: 'income', title: '收入' }, { id: 'expense', title: '支出' }] as Array<any>
</script>
<style>
.doc-slot { display: flex; flex-direction: column; padding: 24rpx; }
.doc-content-text { color: #334155; font-size: 26rpx; }
</style>5. 调用 cancelDrag()
调用该公开实例能力;签名为 cancelDrag(): void。
vue
<template>
<view class="doc-method">
<XtfDragLayout :items="fixture" ref="componentRef" />
<button class="doc-action-button" @click="callMethod">调用该公开实例能力</button>
</view>
</template>
<script setup lang="uts">
import XtfDragLayout from "@/uni_modules/xtf-linkuiunix/components/xtf-drag-layout/xtf-drag-layout.uvue"
import { ref } from "vue"
const fixture = [{ id: 'income', title: '收入' }, { id: 'expense', title: '支出' }] as Array<any>
const componentRef = ref<any>(null)
function callMethod(): void { componentRef.value?.cancelDrag(); console.log("调用 cancelDrag") }
</script>
<style>
.doc-method { display: flex; flex-direction: column; padding: 24rpx; }
.doc-action-button { margin-top: 16rpx; }
</style>全部属性
| 属性 | 源码类型 | withDefaults 默认值 | 实际行为 / 范围 | 适用范围 |
|---|---|---|---|---|
value | DragItem[] | () => [] as DragItem[] | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 95 | 需要覆盖组件默认业务值时设置。 |
modelValue | DragItem[] | undefined | 参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 93 | 需要覆盖组件默认业务值时设置。 |
items | DragItem[] | undefined | 参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 94 | 数据驱动或选项渲染场景。 |
srcKey | string | "url" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:template 行 8 | 需要覆盖组件默认业务值时设置。 |
labelKey | string | "name" | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:template 行 9 | 需要提供业务文案或图标内容时设置。 |
idKey | string | "id" | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 138 | 需要覆盖组件默认业务值时设置。 |
cols | number | 4 | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 97、script 行 117 | 需要覆盖组件默认业务值时设置。 |
max | number | 9 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 101 | 需要覆盖组件默认业务值时设置。 |
layoutWidth | number | 0 | 设置对应区域宽度;消费位置:script 行 99、script 行 117 | 需要调整布局或视觉表现时设置。 |
layoutHeight | number | 0 | 设置对应区域高度;消费位置:script 行 103、script 行 117 | 需要调整布局或视觉表现时设置。 |
sideInset | number | 48 | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 99、script 行 117 | 需要覆盖组件默认业务值时设置。 |
imageWidth | number | 0 | 设置对应区域宽度;消费位置:script 行 112 | 需要调整布局或视觉表现时设置。 |
imageHeight | number | 0 | 设置对应区域高度;消费位置:script 行 112 | 需要调整布局或视觉表现时设置。 |
itemWidthKey | string | "width" | 兼容接收,当前实现未消费/不产生行为 | 仅用于兼容现有调用;当前版本不应依赖其效果。 |
itemHeightKey | string | "height" | 兼容接收,当前实现未消费/不产生行为 | 仅用于兼容现有调用;当前版本不应依赖其效果。 |
colSpanKey | string | "colSpan" | 兼容接收,当前实现未消费/不产生行为 | 仅用于兼容现有调用;当前版本不应依赖其效果。 |
rowSpanKey | string | "rowSpan" | 兼容接收,当前实现未消费/不产生行为 | 仅用于兼容现有调用;当前版本不应依赖其效果。 |
borderRadius | number | 16 | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 113、script 行 136 | 需要调整布局或视觉表现时设置。 |
padding | number | 8 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 128 | 需要覆盖组件默认业务值时设置。 |
gap | number | 12 | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 98、script 行 117 | 需要覆盖组件默认业务值时设置。 |
dragScale | number | 1.04 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 136 | 需要覆盖组件默认业务值时设置。 |
dragOpacity | number | 0.86 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 133 | 需要覆盖组件默认业务值时设置。 |
dragDamping | number | 0 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 129 | 需要覆盖组件默认业务值时设置。 |
snapDuration | number | 120 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 129 | 需要覆盖组件默认业务值时设置。 |
dragTransitionDuration | number | 120 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 136 | 需要覆盖组件默认业务值时设置。 |
dragMode | string | "longpress" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 117、script 行 142 | 需要覆盖组件默认业务值时设置。 |
immediate | boolean | false | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 117、script 行 142 | 需要覆盖组件默认业务值时设置。 |
longpressDuration | number | 350 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 155 | 需要覆盖组件默认业务值时设置。 |
dragHandle | boolean | false | 参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 117、script 行 157、template 行 11 | 需要覆盖组件默认业务值时设置。 |
handleOnly | boolean | false | 参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 117、script 行 157、template 行 11 | 需要覆盖组件默认业务值时设置。 |
disabled | boolean | false | 参与组件运行逻辑;源码在 10 处读取该值;消费位置:script 行 101、script 行 116、script 行 146、script 行 148 | 需要控制显示、可用性或交互状态时设置。 |
deletable | boolean | true | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 146、script 行 200 | 需要覆盖组件默认业务值时设置。 |
showDeleteButton | boolean | true | 开关对应显示或交互行为;消费位置:script 行 146 | 需要控制显示、可用性或交互状态时设置。 |
deleteIcon | string | "x" | 设置对应区域的图标名称;消费位置:template 行 12 | 需要提供业务文案或图标内容时设置。 |
deleteIconColor | string | "#ffffff" | 设置对应区域的颜色;消费位置:template 行 12 | 需要调整布局或视觉表现时设置。 |
deleteIconImage | string | "" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:template 行 12 | 需要覆盖组件默认业务值时设置。 |
deleteBgColor | string | "" | 设置对应区域的颜色;消费位置:script 行 106 | 需要调整布局或视觉表现时设置。 |
deleteSize | number | 36 | 设置对应元素尺寸;消费位置:script 行 106 | 需要调整布局或视觉表现时设置。 |
deletePosition | string | "top-right" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 107、script 行 108 | 需要覆盖组件默认业务值时设置。 |
deleteTrigger | string | "always" | 参与组件运行逻辑;源码在 5 处读取该值;消费位置:script 行 146、script 行 152 | 需要覆盖组件默认业务值时设置。 |
deleteLongpressDuration | number | 320 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 152 | 需要覆盖组件默认业务值时设置。 |
dragShadowColor | string | "#2563eb" | 设置对应区域的颜色;消费位置:script 行 113、script 行 136 | 需要调整布局或视觉表现时设置。 |
dragShadow | string | "" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 136 | 需要覆盖组件默认业务值时设置。 |
dragPlaceholderColor | string | "#dbeafe" | 设置对应区域的颜色;消费位置:script 行 113 | 需要调整布局或视觉表现时设置。 |
showLabel | boolean | true | 开关对应显示或交互行为;消费位置:template 行 9 | 需要控制显示、可用性或交互状态时设置。 |
showReadonlyMask | boolean | false | 开关对应显示或交互行为;消费位置:template 行 13 | 需要控制显示、可用性或交互状态时设置。 |
readonlyMaskText | string | "只读" | 设置对应区域的显示文案;消费位置:script 行 140 | 需要控制显示、可用性或交互状态时设置。 |
readonlyMaskTextKey | string | "readonlyText" | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 140 | 需要控制显示、可用性或交互状态时设置。 |
showAddButton | boolean | true | 开关对应显示或交互行为;消费位置:script 行 101 | 需要控制显示、可用性或交互状态时设置。 |
addText | string | "添加" | 设置对应区域的显示文案;消费位置:template 行 16 | 需要提供业务文案或图标内容时设置。 |
customClass | string | "" | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:template 行 2 | 需要调整布局或视觉表现时设置。 |
customStyle | UTSJSONObject | () => ({} as UTSJSONObject) | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:template 行 2 | 需要调整布局或视觉表现时设置。 |
itemClass | string | "" | 追加到对应内部区域的 class;消费位置:script 行 137 | 需要调整布局或视觉表现时设置。 |
itemStyle | UTSJSONObject | () => ({} as UTSJSONObject) | 覆盖或追加对应内部区域的样式对象;消费位置:script 行 130、script 行 134 | 需要调整布局或视觉表现时设置。 |
itemClassKey | string | "itemClass" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 137 | 需要覆盖组件默认业务值时设置。 |
itemStyleKey | string | "itemStyle" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 126 | 需要覆盖组件默认业务值时设置。 |
cardStyleKey | string | "cardStyle" | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 136 | 需要覆盖组件默认业务值时设置。 |
事件
| 事件名称 | 源码触发边界 | 回调参数 | 参数说明 |
|---|---|---|---|
input | handleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
update:modelValue | handleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
update:items | handleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
change | handleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
end | handleTouchEnd 内触发(script 行 196);参数表达式:items;前置 guard:activeIndex.value < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
reorder | handleTouchEnd 内触发(script 行 195);参数表达式:items、{ item: moving, from: dragFrom, to: movedIndex };前置 guard:activeIndex.value < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
remove | removeAt 内触发(script 行 202);参数表达式:{ item: removed, index: actualIndex, items: items };前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
add | emitAdd 内触发(script 行 141);参数表达式:无回调参数 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
插槽
| 插槽 | Scope 参数 | 实际渲染位置 |
|---|---|---|
item | { item, display-item, index, remove } | 仅在模板对应 <slot> 渲染位置生效。 |
handle | { item, index } | 仅在模板对应 <slot> 渲染位置生效。 |
delete | { item, display-item, index, remove } | 仅在模板对应 <slot> 渲染位置生效。 |
readonly-mask | { item, display-item, index } | 仅在模板对应 <slot> 渲染位置生效。 |
add | { add } | 仅在模板对应 <slot> 渲染位置生效。 |
方法
实例方法
| 方法 | 签名 / 返回值 | 调用边界 |
|---|---|---|
cancelDrag | cancelDrag(): void | 调用该公开实例能力;通过组件 ref 调用,参数和返回值按签名处理。 |
公开状态
| 状态 | 类型 / 包装 | 读取边界 |
|---|---|---|
| - | - | 当前组件没有公开状态。 |
主题说明
var(--xtf-color-border):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-primary):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-surface):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-text):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。
平台与实现边界
- 基线为 HBuilderX 5.26+ 与 uni-app x;当前报告已验证 Web Chromium 的对应 Demo,不据此承诺 Safari、小程序或 App 原生端等价。
- Android、iOS、HarmonyOS、Vapor 原生路径、触摸手势、字体、Canvas、安全区和系统权限能力,只有源码或完整性报告明确覆盖的部分才可视为已验证。
- 本文按当前源码生成,不补入旧版
xtf-linkui存在但迁移版未实现的 props、事件、slot 或方法。 - 当前仅兼容接收、未发现运行消费的 props:
itemWidthKey、itemHeightKey、colSpanKey、rowSpanKey。 - 详细公共边界见 平台与实现边界,逐项运行证据见项目根目录 COMPONENT_COMPLETENESS.md。