提交app

This commit is contained in:
guanj
2026-03-17 14:00:55 +08:00
parent b71200cb97
commit 00e34c168f
82 changed files with 13202 additions and 4602 deletions

View File

@@ -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,
}