当前位置: 首页 > news >正文

自定义picker-view组件

1.示例

2.代码

<template><u-popupv-model="show"mode="bottom":safe-area-inset-bottom="true"mask-close-able@close="clickCancel"><view class="popup-con"><view class="title"><image :src="useImageUrl('', 'close')" alt="" class="close" @click="clickCancel" /><view class="title">{{ props.title == "paly" ? "种类" : "开奖期号" }}</view><view class="confirm" @click="clickDefine">确认</view></view><view class="picker-container"><picker-viewv-if="props.listData.length > 0"indicator-class="select-line"class="custom-picker":immediate-change="true"@change="handleChange":value="[currentIndex]"><picker-view-column><viewv-for="(item, index) in props.listData":key="index"class="picker-item":style="getItemStyle(index)"><text v-if="item.date">第{{ item.lable }}期-{{ formatDate(item.date) }}</text><text v-else>{{ item.lable }}</text></view></picker-view-column></picker-view></view></view></u-popup>
</template><script setup lang="ts">
import { ref, watch } from "vue";
import { useImageUrl } from "/@/cool/utils/comm";interface PickerItem {lable: string;date?: Date | string;
}
const props = defineProps({show: {type: Boolean,default: false,},title: {type: String,default: "",},listData: {type: Array as () => PickerItem[],default: () => [],},
});const show = ref(false);
const currentIndex = ref(0);
const selectedData = ref<any>(null);watch(() => props.show,(val) => {show.value = val;},
);const handleChange = (e:any) => {const val = e.detail.value[0];currentIndex.value = val;selectedData.value = props.listData[val];
};const getItemStyle = (index: number) => {const isActive = currentIndex.value === index;return {height: "94rpx",lineHeight: "94rpx",fontSize: isActive ? "36rpx" : "30rpx",fontWeight: isActive ? "500" : "400",color: isActive ? "#1D2129" : "#86909C",display: "flex",justifyContent: "center",alignItems: "center",};
};const formatDate = (dateStr: any) => {return dateStr ? dateStr.replace(/-/g, "/") : "";
};const emits = defineEmits(["confirm", "cancel"]);const clickDefine = () => {emits("confirm", selectedData.value);
};const clickCancel = () => {emits("cancel");
};
const updatedIndex = (e: number) => {currentIndex.value = e;
};
defineExpose({updatedIndex,
});
</script><style lang="scss" scoped>
.popup-con {padding: 32rpx 38rpx;
}
.title {display: flex;align-items: center;justify-content: space-between;position: relative;height: 50rpx;.close {width: 40rpx;height: 40rpx;position: absolute;}.title {color: #1d2129;text-align: center;font-family: "PingFang SC";font-size: 36rpx;font-style: normal;font-weight: 500;line-height: 50rpx;position: absolute;left: 50%;transform: translateX(-50%);}.confirm {color: #ff7d12;text-align: center;font-family: "PingFang SC";font-size: 32rpx;font-style: normal;font-weight: 500;line-height: 48rpx;position: absolute;right: 0;}
}
::v-deep .select-line {height: 94rpx;
}
::v-deep .select-line::after {border-bottom: 2rpx solid #fff;
}
::v-deep .select-line::before {border-top: 2rpx solid #fff;
}
.picker-container {width: 100%;height: 280rpx;background-color: #fff;overflow: hidden;margin-top: 20rpx;.custom-picker {width: 100%;height: 100%;.picker-item {height: 88rpx;text-align: center;transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);will-change: transform, font-size;}}
}
</style>

http://www.dtcms.com/a/311878.html

相关文章:

  • IO流中的字节流
  • Java中的sort()排序详解
  • STM32CubeIDE新建项目过程记录备忘(五)中断方式的USART串口通信
  • 浏览器的全局焦点事件
  • 内循环全部满足条件后,为true
  • 大型地面光伏电站开发建设流程
  • IO流-字节流
  • c++--模板--实例化
  • ARM处理器概述及对比
  • 2025熵密杯 -- 初始谜题 -- Reproducibility
  • 基于落霞归雁思维框架的应用与实践研究
  • 计数组合学7.11(RSK算法)
  • Android动画实现控件形状、大小逐渐过渡
  • 智能制造——解读CMMM评估手册【附全文阅读】
  • DyWA:用于可推广的非抓握操作的动态自适应世界动作模型
  • 硅基计划3.0 学习总结 伍 优先级队列排序初识
  • 【Vue3】Class绑定:从基础到高级的完整指南
  • Web前端实现银河粒子流动特效的3种技术方案对比与实践
  • 【完结篇】华为OpenStack架构学习9篇 连载—— 09 OpenStack编排管理【附全文阅读】
  • 深入 Go 底层原理(三):Goroutine 的调度策略
  • OSPF综合
  • VS Code高效开发指南:快捷键与配置优化详解
  • 深入 Go 底层原理(十二):map 的实现与哈希冲突
  • Mybatis学习之获取参数值(四)
  • 字符串(java不死)
  • c++之基础B(进制转换)(第三课)
  • 详解Python标准库之并发执行
  • AI Agent开发学习系列 - LangGraph(3): 有多个输入的Graph
  • C#多数据库批量执行脚本工具
  • OneCode3.0 核心表达式技术深度剖析:从架构设计到动态扩展