Skip to content

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>

属性

名称类型默认值说明可选值
sizeStringmini组件尺寸large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你)
typeString""组件类型info(信息), primary(正常), error(错误), warning(警告), success(成功)
disabledBooleanfalse组件是否禁用false, true
stopBooleanfalse是否阻止事件冒泡(Tui统一写法处理事件冒泡)false, true
hoverBooleantrue是否有点击效果false, true
pathString""点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。-
mainClassString""组件根节点的样式-
nativeClassString""组件根节点原生样式-
effectString"normal"组件显示主题normal(正常), dark(深色), light(浅色), plain(镂空)
modelValueany``绑定列表数组的值,时时更新数据的拖拽顺序
itemClassString``统一设置拖拽子组件的样式

插槽

名称返回值说明
default-