搜索页等
This commit is contained in:
+66
-32
@@ -21,7 +21,6 @@ function show(title, msg, showCancel = true, cancelText = '取消', confirmText
|
||||
confirmText,
|
||||
success: (res) => {
|
||||
// 统一处理成功回调,解析为布尔值
|
||||
console.log('res.confirm', res.confirm);
|
||||
resolve(!!res.confirm);
|
||||
}
|
||||
};
|
||||
@@ -65,23 +64,23 @@ const hideLoading = () => uni.hideLoading()
|
||||
|
||||
// 防抖工具函数
|
||||
function debounce(fn, wait = 300) {
|
||||
let isLocked = false; // 锁定状态标记
|
||||
return function(...args) {
|
||||
// 如果处于锁定状态,直接返回不执行
|
||||
if (isLocked) {
|
||||
return;
|
||||
}
|
||||
// 执行函数
|
||||
fn.apply(this, args);
|
||||
|
||||
// 锁定,防止再次执行
|
||||
isLocked = true;
|
||||
|
||||
// 等待指定时间后解锁
|
||||
setTimeout(() => {
|
||||
isLocked = false;
|
||||
}, wait);
|
||||
};
|
||||
let isLocked = false; // 锁定状态标记
|
||||
return function(...args) {
|
||||
// 如果处于锁定状态,直接返回不执行
|
||||
if (isLocked) {
|
||||
return;
|
||||
}
|
||||
// 执行函数
|
||||
fn.apply(this, args);
|
||||
|
||||
// 锁定,防止再次执行
|
||||
isLocked = true;
|
||||
|
||||
// 等待指定时间后解锁
|
||||
setTimeout(() => {
|
||||
isLocked = false;
|
||||
}, wait);
|
||||
};
|
||||
}
|
||||
|
||||
// 保留当前页面,跳转到应用内的某个页面,使用uni.navigateBack可以返回到原页面。
|
||||
@@ -174,23 +173,23 @@ export const getUserInfo = (key = '') => {
|
||||
}
|
||||
// 数字转换,把传入的秒转换为HH:mm:ss格式
|
||||
export const formatSeconds = (seconds) => {
|
||||
// 处理非数字或负数情况
|
||||
if (typeof seconds !== 'number' || isNaN(seconds) || seconds < 0) {
|
||||
return '00:00:00';
|
||||
}
|
||||
// 处理非数字或负数情况
|
||||
if (typeof seconds !== 'number' || isNaN(seconds) || seconds < 0) {
|
||||
return '00:00:00';
|
||||
}
|
||||
|
||||
// 计算小时、分钟和剩余秒数
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
// 计算小时、分钟和剩余秒数
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
|
||||
// 补零函数:将数字转为两位数字符串
|
||||
const padZero = (num) => num.toString().padStart(2, '0');
|
||||
// 补零函数:将数字转为两位数字符串
|
||||
const padZero = (num) => num.toString().padStart(2, '0');
|
||||
|
||||
// 拼接成00:00:00格式
|
||||
return `${padZero(hours)}:${padZero(minutes)}:${padZero(remainingSeconds)}`;
|
||||
};
|
||||
|
||||
// 拼接成00:00:00格式
|
||||
return `${padZero(hours)}:${padZero(minutes)}:${padZero(remainingSeconds)}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断当前运行平台是否匹配指定标识
|
||||
* @param {string} flag - 平台标识:'IOS' 表示苹果iOS平台,'AND' 表示安卓平台
|
||||
@@ -242,6 +241,41 @@ function isLogin() {
|
||||
return !!getToken();
|
||||
}
|
||||
|
||||
// 封装键盘高度变化处理
|
||||
export function setupKeyboardHeightListener(updateCallback) {
|
||||
// #ifndef APP-PLUS
|
||||
return () => {};
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
// 获取系统信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
// 计算安全区域底部高度
|
||||
const safeAreaBottomHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom;
|
||||
|
||||
// 定义处理函数
|
||||
const handleKeyboardHeightChange = (res) => {
|
||||
let keyboardHeight = res.height;
|
||||
|
||||
// 仅在iOS端补偿安全区域高度
|
||||
if (systemInfo.platform === 'ios') {
|
||||
keyboardHeight = Math.max(0, keyboardHeight - safeAreaBottomHeight); // 避免负数
|
||||
}
|
||||
|
||||
// 通过回调函数更新外部的响应式变量
|
||||
updateCallback(keyboardHeight);
|
||||
};
|
||||
|
||||
// 监听键盘高度变化
|
||||
uni.onKeyboardHeightChange(handleKeyboardHeightChange);
|
||||
|
||||
// 返回取消监听的函数,方便组件卸载时清理
|
||||
return () => {
|
||||
uni.offKeyboardHeightChange(handleKeyboardHeightChange);
|
||||
};
|
||||
// #endif
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
getPageCache,
|
||||
setPageCache,
|
||||
|
||||
Reference in New Issue
Block a user