小程序滑动单元格

项目场景:小程序用户管理列表,通过单元格滑动实现"密码重置"、"删除"功能。

技术框架:uniapp、uview3、ts

效果如下:

前端页面:

html 复制代码
<template>
	<view class="fui-wrap">
		<view class="fui-page__hd">
			<view class="fui-page__title">{{data.title}}</view>
			<view class="fui-page__desc">{{data.sub_title}}</view>
		</view>
		<view class="">

		</view>
		<view class="u-page__swipe-action-item" :bottomLeft="0" v-for="(item,index) in data.list">
			<up-swipe-action>
				<up-swipe-action-item :options="buttons" @click="click" :name="item.StfID">
					<view class="swipe-action u-border-top u-border-bottom">
						<view class="swipe-action__content">
							<text style="min-height: 150rpx;"
								class="swipe-action__content__text">{{item.StfName}}/{{item.StfFullName}}</text>
						</view>
					</view>
				</up-swipe-action-item>
			</up-swipe-action>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { deluser_api, resetpwd_api, userlist_api } from '@/service/ZlfApi';
	import { onLoad, onUnload } from '@dcloudio/uni-app';
	import { ref } from 'vue';

	const buttons = ref([{
		text: '重置密码',
		style: {
			background: '#465CFF'
		}

	}, {
		text: '删除',
		style: {
			background: '#FF2B2B'
		}
	}])

	const data = ref({
		title: '用户管理',
		sub_title: '滑动重置密码、删除用户',
		list: [],
		// totalCount: 0,
	})

	onLoad(() => {
		list()
	})
	onUnload(() => {
		// uni.$off('manageRefresh') 
	})

	const click = (e : any) => {
		// console.log(index)
		let StfID = e.name
		if (e.index == 0) {
			// 重置密码
			resetpwd_api({ StfID: StfID }).then((res : any) => {
				if (res.code == 1) {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: res.msg,
						showCancel:false
					})
				} else {
					uni.showToast({
						icon: 'error',
						title: res.msg
					})
				}
			})
		}
		if (e.index == 1) {
			// 删除用户
			uni.showModal({
				title: '提示',
				content: '操作不可逆,确认删除?',
				success: function (res) {
					if (res.confirm) {
						// console.log('用户点击确定');
						deluser_api({ StfID: StfID }).then((res : any) => {
							if (res.code == 1) {
								uni.hideLoading()
								uni.showModal({
									title: '提示',
									content: res.msg,
									showCancel:false,
									success: function (res) {
											if (res.confirm) {
												list();
											}
										}
								})
							} else {
								uni.showToast({
									icon: 'error',
									title: res.msg
								})
							}
						})
					} else if (res.cancel) {
						// console.log('用户点击取消');
					}
				}
			});

		}
	}
	

	const list = async () => {
		// 发起请求,获取设备列表
		const res = await userlist_api()
		data.value.list = res.data
		console.log(data.value.list)
	}
</script>

<style lang="scss">
	.swipe-action {
		&__content {
			padding: 25rpx 0;

			&__text {
				font-size: 15px;
				color: $u-main-color;
				padding-left: 30rpx;
			}
		}
	}

	page {
		font-weight: normal;
		/* 非nvue端使用此变量改变list线条颜色,nvue端请查看文档 */
		/* --fui-color-border:#B2B2B2; */
	}

	.fui-section__title {
		margin-left: 32rpx;
	}

	.fui-list__item {
		flex: 1;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.fui-text__explain {
		font-size: 28rpx;
		color: #7F7F7F;
		flex-shrink: 0;
	}

	.fui-list__icon {
		width: 48rpx;
		height: 48rpx;
		margin-right: 24rpx;
	}
</style>
相关推荐
2501_915909062 小时前
iOS 上架 App Store 后推送收不到,APNs 证书和生产沙盒环境排查
android·小程序·https·uni-app·iphone·webview
骑着蜗牛撵大象3277 小时前
红外太阳能板缺陷检测:三端推理与数据集自动标注落地
开发语言·python·小程序·pyqt·yolov8·自动标注·红外缺陷检测
2501_915921439 小时前
iOS 上架 App Store 常见 ITMS 报错排查,哪些需要修改哪些是警告
android·ios·小程序·https·uni-app·iphone·webview
万岳科技系统开发10 小时前
短视频直播定制开发如何适配不同终端?APP、小程序与网页端的功能差异
小程序·音视频
weixin_1772972206910 小时前
盲盒小程序里,最该先做的页面不是抽盒页
小程序·app
什么嘻嘻果冻10 小时前
移动端页面和浏览动线在生成过程中怎样按照手机使用习惯组织安排
人工智能·低代码·小程序
科威网络11 小时前
小程序图片上传链路排障:从选图到服务端接收
缓存·性能优化·小程序
一铭111991 天前
微信小程序可视化搭建实战:模板、组件与发布验收
前端·低代码·微信小程序·小程序·页面设计·可视化搭建·发布验收
5G微创业1 天前
短视频去水印接口怎么对接?一篇讲清 GET 参数、返回字段与多语言示例
python·小程序·api·短视频·去水印
zhoulcc1 天前
为什么 uni-app 小程序里并排选项总变竖排?缺了 box-sizing 重置
前端·css·小程序·uni-app·box-sizing