提交app
This commit is contained in:
@@ -107,39 +107,61 @@ function formatTime(time, option) {
|
||||
}
|
||||
// 获取当天日期(年月日)
|
||||
function getToday() {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需+1
|
||||
const day = String(today.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
const today = new Date()
|
||||
const year = today.getFullYear()
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0') // 月份从0开始,需+1
|
||||
const day = String(today.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
// 获取当天日期 往前推30天
|
||||
function getBeforeDays(days = 30) {
|
||||
const today = new Date();
|
||||
// 计算往前推N天的时间戳(1天=86400000毫秒)
|
||||
const beforeDate = new Date(today.getTime() - days * 24 * 60 * 60 * 1000);
|
||||
return formatDate(beforeDate);
|
||||
const today = new Date()
|
||||
// 计算往前推N天的时间戳(1天=86400000毫秒)
|
||||
const beforeDate = new Date(today.getTime() - days * 24 * 60 * 60 * 1000)
|
||||
return formatDate(beforeDate)
|
||||
}
|
||||
function formatDate(date) {
|
||||
const year = date.getFullYear();
|
||||
// 月份从0开始,补零到2位
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
// 日期补零到2位
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
const year = date.getFullYear()
|
||||
// 月份从0开始,补零到2位
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
// 日期补零到2位
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
// 获取3个月前的日期
|
||||
function getThreeMonthsAgo() {
|
||||
const threeMonthsAgo = new Date();
|
||||
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3); // 月份减3
|
||||
const year = threeMonthsAgo.getFullYear();
|
||||
const month = String(threeMonthsAgo.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(threeMonthsAgo.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
const threeMonthsAgo = new Date()
|
||||
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3) // 月份减3
|
||||
const year = threeMonthsAgo.getFullYear()
|
||||
const month = String(threeMonthsAgo.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(threeMonthsAgo.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
//获取月最后一天
|
||||
function getMonthFirstAndLastDay(monthStr) {
|
||||
// 1. 校验输入格式(正则匹配YYYY-MM)
|
||||
const reg = /^\d{4}-\d{2}$/
|
||||
if (!reg.test(monthStr)) {
|
||||
throw new Error('输入格式错误,请传入"YYYY-MM"格式的字符串,例如:2026-03')
|
||||
}
|
||||
|
||||
// 2. 拆分年、月
|
||||
const [year, month] = monthStr.split('-').map(Number)
|
||||
|
||||
// 3. 生成当月第一天(直接拼接01)
|
||||
const firstDay = `${year}-${String(month).padStart(2, '0')}-01`
|
||||
|
||||
// 4. 生成当月最后一天(核心:利用Date的特性,下个月0号 = 当月最后一天)
|
||||
// 注意:月份是0开始的(0=1月,11=12月),所以month+1是下一个月
|
||||
const lastDayDate = new Date(year, month, 0) // 下个月0号 = 当月最后一天
|
||||
const lastDay = `${year}-${String(month).padStart(2, '0')}-${String(lastDayDate.getDate()).padStart(2, '0')}`
|
||||
|
||||
return {
|
||||
firstDay,
|
||||
lastDay,
|
||||
}
|
||||
}
|
||||
|
||||
const h5Helper = {
|
||||
isAndroid: function () {
|
||||
@@ -167,7 +189,7 @@ const getUserLocation = (call) => {
|
||||
success: function (address) {
|
||||
call(address)
|
||||
},
|
||||
fail: (err) => {
|
||||
fail: (err) => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '定位失败,请打开定位权限',
|
||||
@@ -309,12 +331,14 @@ const getDictData = (key) => {
|
||||
resolve(dictData.filter((item) => item.code === key)[0]?.children || [])
|
||||
} else {
|
||||
// 查询字典
|
||||
queryDictDataCache().then((res) => {
|
||||
uni.setStorageSync(cacheKey.dictData, res.data)
|
||||
resolve(res.data.filter((item) => item.code === key)[0]?.children || [])
|
||||
}).catch(err=>{
|
||||
reject(err)
|
||||
})
|
||||
queryDictDataCache()
|
||||
.then((res) => {
|
||||
uni.setStorageSync(cacheKey.dictData, res.data)
|
||||
resolve(res.data.filter((item) => item.code === key)[0]?.children || [])
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -333,5 +357,6 @@ export default {
|
||||
getDictData,
|
||||
getToday,
|
||||
getBeforeDays,
|
||||
getThreeMonthsAgo
|
||||
getThreeMonthsAgo,
|
||||
getMonthFirstAndLastDay,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user