Skip to content

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 默认值实际行为 / 范围适用范围
valueDragItem[]() => [] as DragItem[]参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 95需要覆盖组件默认业务值时设置。
modelValueDragItem[]undefined参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 93需要覆盖组件默认业务值时设置。
itemsDragItem[]undefined参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 94数据驱动或选项渲染场景。
srcKeystring"url"参与组件运行逻辑;源码在 2 处读取该值;消费位置:template 行 8需要覆盖组件默认业务值时设置。
labelKeystring"name"参与组件运行逻辑;源码在 1 处读取该值;消费位置:template 行 9需要提供业务文案或图标内容时设置。
idKeystring"id"参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 138需要覆盖组件默认业务值时设置。
colsnumber4参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 97、script 行 117需要覆盖组件默认业务值时设置。
maxnumber9参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 101需要覆盖组件默认业务值时设置。
layoutWidthnumber0设置对应区域宽度;消费位置:script 行 99、script 行 117需要调整布局或视觉表现时设置。
layoutHeightnumber0设置对应区域高度;消费位置:script 行 103、script 行 117需要调整布局或视觉表现时设置。
sideInsetnumber48参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 99、script 行 117需要覆盖组件默认业务值时设置。
imageWidthnumber0设置对应区域宽度;消费位置:script 行 112需要调整布局或视觉表现时设置。
imageHeightnumber0设置对应区域高度;消费位置:script 行 112需要调整布局或视觉表现时设置。
itemWidthKeystring"width"兼容接收,当前实现未消费/不产生行为仅用于兼容现有调用;当前版本不应依赖其效果。
itemHeightKeystring"height"兼容接收,当前实现未消费/不产生行为仅用于兼容现有调用;当前版本不应依赖其效果。
colSpanKeystring"colSpan"兼容接收,当前实现未消费/不产生行为仅用于兼容现有调用;当前版本不应依赖其效果。
rowSpanKeystring"rowSpan"兼容接收,当前实现未消费/不产生行为仅用于兼容现有调用;当前版本不应依赖其效果。
borderRadiusnumber16参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 113、script 行 136需要调整布局或视觉表现时设置。
paddingnumber8参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 128需要覆盖组件默认业务值时设置。
gapnumber12参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 98、script 行 117需要覆盖组件默认业务值时设置。
dragScalenumber1.04参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 136需要覆盖组件默认业务值时设置。
dragOpacitynumber0.86参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 133需要覆盖组件默认业务值时设置。
dragDampingnumber0参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 129需要覆盖组件默认业务值时设置。
snapDurationnumber120参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 129需要覆盖组件默认业务值时设置。
dragTransitionDurationnumber120参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 136需要覆盖组件默认业务值时设置。
dragModestring"longpress"参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 117、script 行 142需要覆盖组件默认业务值时设置。
immediatebooleanfalse参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 117、script 行 142需要覆盖组件默认业务值时设置。
longpressDurationnumber350参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 155需要覆盖组件默认业务值时设置。
dragHandlebooleanfalse参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 117、script 行 157、template 行 11需要覆盖组件默认业务值时设置。
handleOnlybooleanfalse参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 117、script 行 157、template 行 11需要覆盖组件默认业务值时设置。
disabledbooleanfalse参与组件运行逻辑;源码在 10 处读取该值;消费位置:script 行 101、script 行 116、script 行 146、script 行 148需要控制显示、可用性或交互状态时设置。
deletablebooleantrue参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 146、script 行 200需要覆盖组件默认业务值时设置。
showDeleteButtonbooleantrue开关对应显示或交互行为;消费位置:script 行 146需要控制显示、可用性或交互状态时设置。
deleteIconstring"x"设置对应区域的图标名称;消费位置:template 行 12需要提供业务文案或图标内容时设置。
deleteIconColorstring"#ffffff"设置对应区域的颜色;消费位置:template 行 12需要调整布局或视觉表现时设置。
deleteIconImagestring""参与组件运行逻辑;源码在 2 处读取该值;消费位置:template 行 12需要覆盖组件默认业务值时设置。
deleteBgColorstring""设置对应区域的颜色;消费位置:script 行 106需要调整布局或视觉表现时设置。
deleteSizenumber36设置对应元素尺寸;消费位置:script 行 106需要调整布局或视觉表现时设置。
deletePositionstring"top-right"参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 107、script 行 108需要覆盖组件默认业务值时设置。
deleteTriggerstring"always"参与组件运行逻辑;源码在 5 处读取该值;消费位置:script 行 146、script 行 152需要覆盖组件默认业务值时设置。
deleteLongpressDurationnumber320参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 152需要覆盖组件默认业务值时设置。
dragShadowColorstring"#2563eb"设置对应区域的颜色;消费位置:script 行 113、script 行 136需要调整布局或视觉表现时设置。
dragShadowstring""参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 136需要覆盖组件默认业务值时设置。
dragPlaceholderColorstring"#dbeafe"设置对应区域的颜色;消费位置:script 行 113需要调整布局或视觉表现时设置。
showLabelbooleantrue开关对应显示或交互行为;消费位置:template 行 9需要控制显示、可用性或交互状态时设置。
showReadonlyMaskbooleanfalse开关对应显示或交互行为;消费位置:template 行 13需要控制显示、可用性或交互状态时设置。
readonlyMaskTextstring"只读"设置对应区域的显示文案;消费位置:script 行 140需要控制显示、可用性或交互状态时设置。
readonlyMaskTextKeystring"readonlyText"参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 140需要控制显示、可用性或交互状态时设置。
showAddButtonbooleantrue开关对应显示或交互行为;消费位置:script 行 101需要控制显示、可用性或交互状态时设置。
addTextstring"添加"设置对应区域的显示文案;消费位置:template 行 16需要提供业务文案或图标内容时设置。
customClassstring""参与组件运行逻辑;源码在 1 处读取该值;消费位置:template 行 2需要调整布局或视觉表现时设置。
customStyleUTSJSONObject() => ({} as UTSJSONObject)参与组件运行逻辑;源码在 1 处读取该值;消费位置:template 行 2需要调整布局或视觉表现时设置。
itemClassstring""追加到对应内部区域的 class;消费位置:script 行 137需要调整布局或视觉表现时设置。
itemStyleUTSJSONObject() => ({} as UTSJSONObject)覆盖或追加对应内部区域的样式对象;消费位置:script 行 130、script 行 134需要调整布局或视觉表现时设置。
itemClassKeystring"itemClass"参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 137需要覆盖组件默认业务值时设置。
itemStyleKeystring"itemStyle"参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 126需要覆盖组件默认业务值时设置。
cardStyleKeystring"cardStyle"参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 136需要覆盖组件默认业务值时设置。

事件 ​

事件名称源码触发边界回调参数参数说明
inputhandleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0
removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0
(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
update:modelValuehandleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0
removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0
(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
update:itemshandleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0
removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0
(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
changehandleTouchEnd 内触发(script 行 195);参数表达式:items;前置 guard:activeIndex.value < 0
removeAt 内触发(script 行 202);参数表达式:items;前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0
(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
endhandleTouchEnd 内触发(script 行 196);参数表达式:items;前置 guard:activeIndex.value < 0(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
reorderhandleTouchEnd 内触发(script 行 195);参数表达式:items、{ item: moving, from: dragFrom, to: movedIndex };前置 guard:activeIndex.value < 0(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
removeremoveAt 内触发(script 行 202);参数表达式:{ item: removed, index: actualIndex, items: items };前置 guard:props.disabled || !props.deletable || index < 0 || index >= localItems.value.length、actualIndex < 0(...args: any[])表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。
addemitAdd 内触发(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> 渲染位置生效。

方法 ​

实例方法 ​

方法签名 / 返回值调用边界
cancelDragcancelDrag(): 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。

MIT Licensed