feat:初始提交uni-app项目

This commit is contained in:
2026-01-14 18:19:33 +08:00
commit 0dcbd340e6
515 changed files with 38560 additions and 0 deletions

36
utils/common.js Normal file
View File

@@ -0,0 +1,36 @@
export function compareTimestamp(timestamp) {
const currentTime = new Date().getTime();
const timeDiff = currentTime - timestamp;
if (timeDiff < 60000) {
return '1分钟内';
} else if (timeDiff < 3600000) {
return Math.floor(timeDiff / 60000) + '分钟';
} else if (timeDiff < 86400000) {
return Math.floor(timeDiff / 3600000) + '小时';
} else if (timeDiff < 2592000000) {
return Math.floor(timeDiff / 86400000) + '天';
} else if (timeDiff < 7776000000) {
return Math.floor(timeDiff / 2592000000) + '月';
} else {
return null;
}
}
export function gotoHome(){
uni.showModal({
title:"提示",
content:"页面有误将返回首页",
showCancel:false,
success: (res) => {
if(res.confirm){
uni.reLaunch({
url:"/pages/index/index"
})
}
}
})
}

52
utils/request.js Normal file
View File

@@ -0,0 +1,52 @@
const BASE_URL = "https://tea.qingnian8.com/api/bizhi";
// config是形参然后对其进行解构
export function request(config={}){
let {
url,
data={},
method="GET",
header={}
} = config
// 对url进行拼接
url = BASE_URL + url
//下面这种写法是针对header里面的属性进行赋值
header['access-key'] = "888888"
//你要加一个token的话就可以按下面的步骤进行
// header['token'] = '11212212'
return new Promise((resolve,reject)=>{
uni.request({
//url属性接收外面传入的url可以进行简写url:url, ==》 url
url,
data,
method,
header,
success:res =>{
if(res.data.errCode === 0){
//res返回是全部信息但是我们要的是res.data就可以了
// resolve(res)
resolve(res.data)
}else if(res.data.errCode === 400){
uni.showModal({
title:"错误提示",
content:res.data.errMsg,
// 不展示“取消”键
showCancel:false
})
reject(res.data)
}else{
uni.showToast({
title:res.data.errMsg,
icon:"none"
})
reject(res.data)
}
},
fail:err=>{
reject(err)
}
})
})
}

45
utils/system.js Normal file
View File

@@ -0,0 +1,45 @@
//获取状态栏高度
const SYSTEM_INFO = uni.getSystemInfoSync();
// 获取高度失败的话就返回默认值 0
// 获取状态栏高度
export const getStatusBarHeight = ()=> SYSTEM_INFO.statusBarHeight || 0
//获取预览页面的状态栏
export const getPreviewBarHeight = ()=>{
// 下面是获取胶囊按钮全部信息
// let MENU_BUTTON = uni.getMenuButtonBoundingClientRect();
//如果有胶囊按钮,我们才进行操作,否则返回一个固定的值
if(uni.getMenuButtonBoundingClientRect){
//我们使用解构的方法来选取所需的特定内容就可以了
let {top} = uni.getMenuButtonBoundingClientRect();
// 标题栏的高度
let PreviewBarHeight = top
return PreviewBarHeight
}
else{
return 40;
}
}
//获取标题栏高度
export const getTitleBarHeight = ()=>{
// 下面是获取胶囊按钮全部信息
// let MENU_BUTTON = uni.getMenuButtonBoundingClientRect();
//如果有胶囊按钮,我们才进行操作,否则返回一个固定的值
if(uni.getMenuButtonBoundingClientRect){
//我们使用解构的方法来选取所需的特定内容就可以了
let {top,height} = uni.getMenuButtonBoundingClientRect();
// 标题栏的高度
let titleBarHeight = (top - getStatusBarHeight())*2 + height
return titleBarHeight
}
else{
return 40;
}
}
//获取整个导航栏高度用于fill栏
export const getNavBarHeight = ()=> getTitleBarHeight() + getStatusBarHeight();