当前位置:网站首页>uniapp uview uselect 时间选择 日期生成代码
uniapp uview uselect 时间选择 日期生成代码
2022-08-09 03:13:00 【阿里巴巴首席技术官】
需求, 时间需要显示当前日期往后 小时显示今天的之后的小时 , 分钟显示 00 / 15 / 30 /45
最终效果如下
代码
/**
* 获取未来天数列表
*
* @param dayCount 获取未来几天?
* @returns {*[]} 未来天数列表
*/
function getFutureDays(dayCount) {
if (dayCount <= 1) {
throw new Error("getFutureDays参数 dayCount最少指定一天");
}
// 一天的时间
let oneDayTime = 24 * 60 * 60 * 1000;
let list = []
for (let i = 0; i < dayCount; i++) {
let lastDay = new Date(new Date().getTime() + i * oneDayTime);
let year = lastDay.getFullYear();
let month = lastDay.getMonth() + 1;
let day = lastDay.getDate()
if (month < 10) month = '0' + month;
if (day < 10) day = '0' + day;
let labelTime = month + '月' + day + '日';
let valueTime = year + '-' + month + '-' + day;
let label = {label: labelTime, value: valueTime}
list.push(label)
}
list[0].label += " (今天)";
if (dayCount > 1) {
list[1].label += " (明天)";
}
if (dayCount > 2) {
list[2].label += " (后天)";
}
return list;
}
/**
* 获取今天的小时列表
*/
function getTodayHourList() {
// 当前小时(24制)
let currentHour = new Date().getHours();
// 剩余小时个数
let hourCount = 24 - currentHour;
let list = [];
for (let i = 1; i < hourCount; i++) {
let label = {label: currentHour+i + '点', value: currentHour+i}
if (i < 10) {
label.value = '0' + label.value
}
list.push(label);
}
return list;
}
/**
* 获取一天的小时列表
* @returns {*[]} 一天的小时列表
*/
function getHourList(){
let list = [];
for (let i = 0; i < 24; i++) {
let label = {label: i + '点', value: i}
if (i < 10) {
label.value = '0' + label.value
}
list.push(label);
}
return list;
}
/**
* 获取分钟列表
*/
function getMinutesList() {
return [
{label: '00分', value: 0},
{label: '15分', value: 15},
{label: '30分', value: 30},
{label: '45分', value: 45}
]
}
/**
* 获取下单需要的时间列表
*/
export function getCreateOrderTimeList(){
// 获取的天数
let dayCount = 15;
// 1.获取天数
let dayList = getFutureDays(dayCount);
// 3.获取分钟
let minutes = getMinutesList();
// 组装数据
for (let i = 0; i < dayList.length; i++) {
dayList[i].children = i === 0 ? getTodayHourList() : getHourList();
let tempHourList = dayList[i].children;
for (let j = 0; j < tempHourList.length; j++) {
tempHourList[j].children = minutes;
}
}
return dayList;
}
使用方式 直接调用此方法
getCreateOrderTimeList();
返回值放入u-select上的list属性上即可!
边栏推荐
- 马斯克被因狗狗币被索赔2580亿美元 操纵价格牟利?狗狗币已下跌92%
- 书签收藏难整理?这款书签工具管理超方便
- A separate machine is connected to the spark cluster of cdh, and the task is submitted remotely (absolutely successful, I have tested it n times)
- 渗透测试-域环境下的信息收集
- 【问题记录】pip 安装报错 Failed to establish a new connection
- Linux安装Redis
- 掌握 TypeToken 原理及泛型擦除
- powershell execution strategy
- 创建一个DAPP的全流程
- 2022-08-08 The fifth group Gu Xiangquan study notes day31-collection-junit unit test
猜你喜欢
Celery进阶_任务优先级分配
甲乙丙丁加工零件,加工的总数是370, 如果甲加工的零件数多10,如果乙加工的零件数少20,如果丙加工的 零件数乘以2,如果丁加工的零件数除以2,四个人的加工数量相等,求甲乙丙丁各自加工多少个零件?
Shell脚本:正则表达式
powershell 执行策略
2022-08-08 第五小组 顾祥全 学习笔记 day31-集合-IO流-File类
Embedded system driver advanced [2] - platform bus driver development _ basic framework
JSP入门
1.02亿美元从数字资产基金撤出!BTC价格已经触底!预示下跌趋势即将逆转?
掌握 TypeToken 原理及泛型擦除
A separate machine is connected to the spark cluster of cdh, and the task is submitted remotely (absolutely successful, I have tested it n times)
随机推荐
非关系型数据库MongoDB:(二)副本集部署说明、数据迁移、限制内存、启用mongo认证
126. 单词接龙 II
LeetCode_43_字符串相乘
Deep learning - in the recognition, for example, this paper discusses how to preserve the neural network model
Matlab optimization method -- 0.618 method
Win10开始菜单打不开怎么办?
SQL注入(1)
Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺用于科研实验
三箭资本濒临破产?市场陷入1907年恐慌之中?加密监管不可避免
以赛促练-力扣第84场双周赛反思以及第305场周赛补题
Introduction to the JSP
通过kvm创建共享磁盘
Hcip MPLS experiment
Win7电脑无法进入睡眠模式?
如何实现有状态转化操作
ros入门(安装)
i18n 国际化
那些关于DOM的常见Hook封装(一)
Talk about those marketing tools - coupons
Chapter3 numpy创建数组