JLBA202505130001_关于吉林银行新建AI智能培训系统的需求_0120开发完成
This commit is contained in:
+44
-37
@@ -284,38 +284,38 @@ function isLogin() {
|
||||
* @returns {string} 最终的额外高度值(带单位)
|
||||
*/
|
||||
export const getExtraHeight = () => {
|
||||
// 所有常量移入函数内部定义,TARGET_DEVICE_MODEL 改为数组类型
|
||||
const TARGET_DEVICE_MODEL = ['XT2321-2']; // 目标设备型号数组(摩托罗拉razr 40 Ultra)
|
||||
const EXTRA_HEIGHT_TARGET = '15rpx'; // 目标设备额外高度
|
||||
const EXTRA_HEIGHT_DEFAULT = '2rpx'; // 默认额外高度
|
||||
try {
|
||||
// 1. 优先读取缓存
|
||||
const cachedHeight = getValue('extra_height', '');
|
||||
if (cachedHeight) {
|
||||
console.log('缓存有值直接返回', cachedHeight);
|
||||
return cachedHeight; // 缓存有值直接返回
|
||||
}
|
||||
// 2. 缓存无值时,获取设备信息
|
||||
const deviceInfo = uni.getDeviceInfo();
|
||||
// 校验设备信息有效性
|
||||
if (!deviceInfo || !deviceInfo.deviceModel) {
|
||||
throw new Error('设备信息获取失败');
|
||||
}
|
||||
|
||||
// 3. 判断设备型号(数组包含判断,适配多型号)
|
||||
const isTargetDevice = TARGET_DEVICE_MODEL.includes(deviceInfo.deviceModel);
|
||||
const finalHeight = isTargetDevice ? EXTRA_HEIGHT_TARGET : EXTRA_HEIGHT_DEFAULT;
|
||||
// 所有常量移入函数内部定义,TARGET_DEVICE_MODEL 改为数组类型
|
||||
const TARGET_DEVICE_MODEL = ['XT2321-2']; // 目标设备型号数组(摩托罗拉razr 40 Ultra)
|
||||
const EXTRA_HEIGHT_TARGET = '15rpx'; // 目标设备额外高度
|
||||
const EXTRA_HEIGHT_DEFAULT = '2rpx'; // 默认额外高度
|
||||
try {
|
||||
// 1. 优先读取缓存
|
||||
const cachedHeight = getValue('extra_height', '');
|
||||
if (cachedHeight) {
|
||||
console.log('缓存有值直接返回', cachedHeight);
|
||||
return cachedHeight; // 缓存有值直接返回
|
||||
}
|
||||
// 2. 缓存无值时,获取设备信息
|
||||
const deviceInfo = uni.getDeviceInfo();
|
||||
// 校验设备信息有效性
|
||||
if (!deviceInfo || !deviceInfo.deviceModel) {
|
||||
throw new Error('设备信息获取失败');
|
||||
}
|
||||
|
||||
// 4. 缓存结果(后续复用)
|
||||
setValue('extra_height', finalHeight);
|
||||
return finalHeight; // 返回计算后的高度
|
||||
// 3. 判断设备型号(数组包含判断,适配多型号)
|
||||
const isTargetDevice = TARGET_DEVICE_MODEL.includes(deviceInfo.deviceModel);
|
||||
const finalHeight = isTargetDevice ? EXTRA_HEIGHT_TARGET : EXTRA_HEIGHT_DEFAULT;
|
||||
|
||||
} catch (error) {
|
||||
// 5. 异常兜底:返回默认值并缓存
|
||||
console.warn('获取/设置额外高度失败:', error.message);
|
||||
setValue('extra_height', EXTRA_HEIGHT_DEFAULT);
|
||||
return EXTRA_HEIGHT_DEFAULT;
|
||||
}
|
||||
// 4. 缓存结果(后续复用)
|
||||
setValue('extra_height', finalHeight);
|
||||
return finalHeight; // 返回计算后的高度
|
||||
|
||||
} catch (error) {
|
||||
// 5. 异常兜底:返回默认值并缓存
|
||||
console.warn('获取/设置额外高度失败:', error.message);
|
||||
setValue('extra_height', EXTRA_HEIGHT_DEFAULT);
|
||||
return EXTRA_HEIGHT_DEFAULT;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -327,20 +327,27 @@ export function setupKeyboardHeightListener(updateCallback) {
|
||||
return () => {};
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
// 获取系统信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
// 计算安全区域底部高度
|
||||
const safeAreaBottomHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom;
|
||||
// 校验回调函数类型,避免非函数传入导致报错
|
||||
if (typeof updateCallback !== 'function') {
|
||||
console.error('setupKeyboardHeightListener: updateCallback 必须是函数');
|
||||
return () => {};
|
||||
}
|
||||
|
||||
// 定义处理函数
|
||||
const handleKeyboardHeightChange = (res) => {
|
||||
// 获取系统信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
console.log('systemInfo', systemInfo);
|
||||
// 计算安全区域底部高度
|
||||
const safeAreaBottomHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom;
|
||||
console.log('计算安全区域底部高度', safeAreaBottomHeight);
|
||||
let keyboardHeight = res.height;
|
||||
|
||||
console.log('软键盘高度', keyboardHeight);
|
||||
// 仅在iOS端补偿安全区域高度
|
||||
if (systemInfo.platform === 'ios') {
|
||||
keyboardHeight = Math.max(0, keyboardHeight - safeAreaBottomHeight); // 避免负数
|
||||
keyboardHeight = Math.max(0, keyboardHeight); // 避免负数
|
||||
}
|
||||
|
||||
console.log('keyboardHeight', keyboardHeight);
|
||||
// 通过回调函数更新外部的响应式变量
|
||||
updateCallback(keyboardHeight);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user