uniapp 小程序 周选择器

devtools/2024/11/13 10:10:58/

这里贴出来的是子组件的代码,父组件只是打开了一下popup

//  打开了一下popup
$refs.popup.open('bottom')
如果不想用子组件的话,直接打开popup就可以用
<template><uni-popup ref="popup" type="bottom" background-color="#fff"><view class="my_popup"><view class="my_selectDeta"><view class="my_button" @click="iconClose">取消</view><view class="my_button" type="primary" @click="confirm">确定</view></view><picker-view :value="selectValue" class="picker-view" @change="pickerChange"><picker-view-column><view v-for="(item, index) in years" :key="index" class="year-item">{{ item }}年</view></picker-view-column><picker-view-column><view v-for="(item, index) in weeks" :key="index" class="weeks-item">{{ `第${index + 1}周(` + item + ')' }}</view></picker-view-column></picker-view></view></uni-popup>
</template><script>
export default {props: {},data() {return {selectValue: [0, 0],years: [],year: '', // 当前年// weeks: [],week: '', // 当前周myDate: new Date(),}},// watch: {//   year: {//     handler(newValue) {//       const index = this.years.findIndex((item) => item == newValue);//       this.selectValue = [index, 0];//     },//     deep: true // 深度监听父组件传过来对象变化//   },// },computed: {weeks() {const ONE_DAY = 24 * 3600 * 1000;let firstDay =new Date(this.year + '/01/01').getDay() == 0? 7: new Date(this.year + '/01/01').getDay();let weeklist = [];let firstweekday = '';let endweekday = new Date(this.year + '/12/28').getTime();if (firstDay > 4) {firstweekday =new Date(this.year + '/01/01').getTime() +(8 - firstDay) * ONE_DAY;} else if (firstDay <= 4) {firstweekday =new Date(this.year + '/01/01').getTime() -(firstDay - 1) * ONE_DAY;}for (let i = 0; i < 54; i++) {let numWeek = i * 7 * ONE_DAY;let firstday = firstweekday + numWeek;let endday = firstday + 6 * ONE_DAY;if (firstday <= endweekday) {weeklist.push(`${uni.$u.timeFormat(firstday, 'mm/dd')}-${uni.$u.timeFormat(endday, 'mm/dd')}`);}}console.log("computed-weeklist", weeklist)return weeklist;},},mounted() {this.init();},methods: {pickerChange(e) {const currentData = e.detail.valuethis.year = this.years[currentData[0]];this.week = this.weeks[currentData[1]];console.log("pickerChange", e, this.year, this.week);},// 初始化时的默认当前周init(data = new Date()) {for (let i = this.myDate.getFullYear(); i <= this.myDate.getFullYear() + 10; i++) {this.years.push(i);}let beginTime = uni.$u.timeFormat(this.getWeek(0, data), 'mm/dd')let endTime = uni.$u.timeFormat(this.getWeek(1, data), 'mm/dd');this.year = data ? new Date(data).getFullYear() : this.myDate.getFullYear()this.week = `${beginTime}-${endTime}`this.selectValue = [this.years.indexOf(this.year), this.weeks.indexOf(this.week)]console.log('weeks-init', this.year, this.years, this.week, this.weeks, beginTime, endTime, this.selectValue);// this.$nextTick(() => {//   this.selectValue = [this.years.indexOf(this.year), this.weeks.indexOf(this.week)]// })// this.$emit('changeWeekTime', this.dateObj)},// 获取当前周getWeek(type, data = "") {let now = new Date(data)let day = now.getDay() //返回星期几的某一天;if (!type) {let dayNumber = day == 0 ? 6 : day - 1now.setDate(now.getDate() - dayNumber)} else {let dayNumber = day == 0 ? 0 : 7 - daynow.setDate(now.getDate() + dayNumber)}let date = now.getDate()let month = now.getMonth() + 1//年-月-日let s = now.getFullYear() + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' +date :date)let datebefore = nowreturn datebefore},iconClose() {this.$refs.popup.close()},changeDateObj() {const [firstWeek, lastWeek] = this.week.split('-').map((item) => item.replace('/', '-'));return this.year + '-' + firstWeek + '至' + this.year + '-' + lastWeek},confirm() {console.log("confirm", this.year, this.week)let obj = {type: '4',date: this.changeDateObj()}uni.setStorageSync('weChatData', obj)uni.reLaunch({url: '/hxz/weChat/index'})this.iconClose();}},
}
</script>
<style scoped lang="scss">
.my_popup {height: 550rpx;border-radius: 8rpx 8rpx 0 0;position: relative;font-weight: 500;color: #1b1d21;.my_selectDeta {display: flex;justify-content: space-between;padding: 20rpx 40rpx;box-sizing: border-box;color: rgb(96, 98, 102);border-bottom: 1px solid #f5f7f8;}.my_button {display: flex;align-items: center;justify-content: center;}.picker-view {width: 100%;height: 600rpx;}}.year-item,
.weeks-item {display: flex;align-items: center;justify-content: center;
}
</style>

http://www.ppmy.cn/devtools/132886.html

相关文章

【论文速读】| PathSeeker:使用基于强化学习的越狱攻击方法探索大语言模型的安全漏洞

基本信息 原文标题: PathSeeker: Exploring LLM Security Vulnerabilities with a Reinforcement Learning-Based Jailbreak Approach 原文作者: Zhihao Lin, Wei Ma, Mingyi Zhou, Yanjie Zhao, Haoyu Wang, Yang Liu, Jun Wang, Li Li 作者单位: Beihang University, Nany…

FastReport将停止 .NET Framework 上的 WebReport 更新

从2024/ 12 /1 日起&#xff0c;Fastreport将停止发布更新和提供对 FastReport.Web (.NET Framework) 的技术支持。该库一直是使用 Online Designer 的许多项目中报告的核心。这些更改意味着 FastReport.Web (Legacy) 库&#xff08;FastReport.Net包的一部分&#xff09;将不再…

php伪协议介绍

PHP伪协议共有12种,具体如下: file:// — 访问本地文件系统http:// — 访问 HTTP(s) 网址ftp:// — 访问 FTP(s) URLsphp:// — 访问各个输入/输出流(I/O streams)php://stdin, php://stdout 和 php://stderrphp://inputphp://outputphp://memory 和 php://tempphp://filte…

原生html+js输入框下拉多选带关闭模块完整案例

<!DOCTYPE html> <html> <head> <title>多选下拉框</title> <style> * { box-sizing: border-box; margin: 0; padding: 0; } .multi-select-container { position: relative; width: 300px; margin: 20px; font-family: Arial, sans-seri…

JAVA题目笔记(十三) 爬虫

一、网络爬取 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.regex.Matcher; import java.util.regex.Pattern;public class Main {public static v…

千帆模型gpt智能聊天机器人

首先是调用接口,需要调用的接口ACCESS_KEY和SECRET_KEY # codingutf-8 import os import qianfandef gpt(question):with open("QIANFAN_ACCESS_KEY",r,encodingutf-8) as f:QIANFAN_ACCESS_KEY f.read()with open("QIANFAN_SECRET_KEY","r",e…

qt QHttpMultiPart详解

1. 概述 QHttpMultiPart是Qt框架中用于处理HTTP多部分请求的类。它类似于RFC 2046中描述的MIME multipart消息&#xff0c;允许在单个HTTP请求中包含多个数据部分&#xff0c;如文件、文本等。这种多部分请求在上传文件或发送带有附件的邮件等场景中非常有用。QHttpMultiPart类…

MongoDB笔记01-概念与安装

文章目录 前言一、MongoDB相关概念1.1 业务应用场景具体的应用场景什么时候选择MongoDB 1.2 MongoDB简介1.3 体系结构1.4 数据模型1.5 MongoDB的特点 二、本地单机部署2.1 Windows系统中的安装启动第一步&#xff1a;下载安装包第二步&#xff1a;解压安装启动1.命令行参数方式…