Drag (拖拽排序)
自研拖拽算法,丝滑不卡顿
支持平台
安卓 | ios | 鸿蒙 | web | 微信小程序 |
---|---|---|---|---|
√ | √ | √ | √ | √ |
示例代码
html
<template>
<t-page>
<t-card main-class="mltr-30" title="Drag 拖拽排序" sub-title="自研拖拽算法,丝滑不卡顿"></t-card>
<t-drag main-class="fl fww tdr ptlr-30" v-model="list1" item-class="w-180">
<template v-slot:default="{item,index}">
<t-view main-class="fc mr-30 tdb r-8 fl h-60">
<t-text :stop="true">{{(item as UTSJSONObject).getString('title')}}</t-text>
</t-view>
</template>
</t-drag>
<t-drag main-class="fl fww tdr ptlr-30" v-if="area==1" v-model="list" item-class="h-170 w-170">
<template v-slot:default="{item,index}">
<t-view main-class="fc mr-30 tdb tdr h-150">
<t-text :stop="true">{{(item as UTSJSONObject).getString('title')}}</t-text>
</t-view>
</template>
</t-drag>
<t-drag main-class="fl fww tdr ptlr-30" v-if="area==2" v-model="list" item-class="h-170 w-100%">
<template v-slot:default="{item,index}">
<t-view main-class="fc mr-30 tdb tdr h-150">
<t-text :stop="true">{{(item as UTSJSONObject).getString('title')}}</t-text>
<t-button type="p" size="mini" @click="del1(0)">删除</t-button>
</t-view>
</template>
</t-drag>
<t-popup direction="bottom" ref='popupbottom' :show-footer="false" :closeable="false">
<t-drag main-class="fl fww tdr ptlr-30" v-model="list" item-class="h-200 w-200">
<template v-slot:default="{item}">
<t-view main-class="fc mr-30 tdb tdr b h-170">
<t-text :stop="true">{{(item as UTSJSONObject).getString('title')}}</t-text>
</t-view>
</template>
</t-drag>
</t-popup>
<t-row main-class="p-30">
<t-button type="p" @click="area=1" main-class="mr-30 f">宫格模式</t-button>
<t-button type="p" @click="area=2" main-class="f">列表模式</t-button>
</t-row>
<t-button @click="show" main-class="m-30" type="p">弹层测试</t-button>
<t-row main-class="p-30">
<t-button main-class="mr-30 f" type="p" @click="add">增加数据</t-button>
<t-button main-class="f" type="p" @click="del">减少数据</t-button>
</t-row>
</t-page>
</template>
<script setup>
import { TuiGuid, getRandomInt } from '@/uni_modules/tui-plugins';
const list = ref<UTSJSONObject[]>([
{ id: '1', title: '1' },
{ id: '2', title: '2' },
{ id: '3', title: '3' },
{ id: '4', title: '4' },
{ id: '5', title: '5' },
{ id: '6', title: '6' },
{ id: '7', title: '7' },
{ id: '8', title: '8' },
{ id: '9', title: '9' },
{ id: '10', title: '10' },
{ id: '11', title: '11' },
{ id: '12', title: '12' },
{ id: '13', title: '13' },
{ id: '14', title: '14' },
{ id: '15', title: '15' }
])
const list1 = ref<UTSJSONObject[]>([
{ id: '1', title: '首页' },
{ id: '2', title: '商品管理' },
{ id: '3', title: '订单管理' },
])
const area = ref<number>(1)
const popupbottom = ref<ComponentPublicInstance | null>(null)
function show() {
(popupbottom.value as ComponentPublicInstance).$callMethod('show')
}
function test() {
console.log('testtest')
}
function add() {
list.value.push({ id: TuiGuid(getRandomInt(5, 15)), title: TuiGuid(getRandomInt(5, 15)) })
}
function del1(index : number) {
list.value.splice(index, 1)
console.log(list.value.length)
}
function del() {
list.value.splice(0, 1)
}
</script>
属性
名称 | 类型 | 默认值 | 说明 | 可选值 |
---|---|---|---|---|
size | String | mini | 组件尺寸 | large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你) |
type | String | "" | 组件类型 | info(信息), primary(正常), error(错误), warning(警告), success(成功) |
disabled | Boolean | false | 组件是否禁用 | false, true |
stop | Boolean | false | 是否阻止事件冒泡(Tui统一写法处理事件冒泡) | false, true |
hover | Boolean | true | 是否有点击效果 | false, true |
path | String | "" | 点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。 | - |
mainClass | String | "" | 组件根节点的样式 | - |
nativeClass | String | "" | 组件根节点原生样式 | - |
effect | String | "normal" | 组件显示主题 | normal(正常), dark(深色), light(浅色), plain(镂空) |
modelValue | any | `` | 绑定列表数组的值,时时更新数据的拖拽顺序 | |
itemClass | String | `` | 统一设置拖拽子组件的样式 |
插槽
名称 | 返回值 | 说明 |
---|---|---|
default | - |