fix: 修复类型定义及多处逻辑缺陷

- 补充字典项备注字段及部门排序必填约束
- 使用 Ref/ComputedRef 替代 ReturnType 简化类型
- 兜底胶囊按钮默认尺寸,避免获取失败时导航栏异常
- 移除不可靠的新版 API 降级调用,统一使用 getSystemInfoSync
- 修复防抖函数定时器未清空及类型不严谨问题
This commit is contained in:
Mickey wu
2026-05-25 21:55:04 +08:00
parent 7761370f36
commit 325316d0b0
5 changed files with 22 additions and 17 deletions

View File

@@ -124,7 +124,7 @@ export interface DeptForm {
/** 父部门ID */
parentId: number;
/** 排序 */
sort?: number;
sort: number;
/** 状态(1:启用0禁用) */
status?: number;
}

View File

@@ -112,8 +112,9 @@ export interface DictItemForm {
dictCode?: string;
label?: string;
value?: string;
sort?: number;
sort: number;
status?: number;
remark?: string;
}
export interface DictDataItem {
@@ -123,4 +124,5 @@ export interface DictDataItem {
value?: string;
sort?: number;
status?: number;
}
remark?: string;
}

View File

@@ -1,4 +1,4 @@
import { ref, computed } from "vue";
import { type Ref, type ComputedRef } from "vue";
/**
* 加载状态管理
@@ -35,11 +35,11 @@ export interface UseLoadingOptions {
export interface UseLoadingReturn {
/** 是否处于加载状态 */
isLoading: ReturnType<typeof computed<boolean>>;
isLoading: ComputedRef<boolean>;
/** 加载计数(支持并发) */
loadingCount: ReturnType<typeof ref<number>>;
loadingCount: Ref<number>;
/** 当前加载消息 */
message: ReturnType<typeof ref<string>>;
message: Ref<string>;
/** 开始加载 */
start: (msg?: string) => void;
/** 结束加载 */

View File

@@ -187,6 +187,15 @@ export function useNavbar(options: UseNavbarOptions = {}): UseNavbarReturn {
}
} catch (e) {
console.warn("获取胶囊按钮位置失败,使用默认值", e);
// 兜底:设置合理的默认胶囊按钮尺寸
menuButton.value = {
width: 87,
height: 32,
top: statusBarHeight.value + 6,
right: windowWidth.value - 10,
bottom: statusBarHeight.value + 38,
left: windowWidth.value - 97,
};
}
};
// #endif
@@ -194,14 +203,7 @@ export function useNavbar(options: UseNavbarOptions = {}): UseNavbarReturn {
// 初始化
const init = () => {
try {
// 优先使用新版 APIuni.getWindowInfo降级到 uni.getSystemInfoSync
let systemInfo: UniApp.GetSystemInfoSyncSuccess;
try {
// @ts-expect-error uni.getWindowInfo 是新版 API
systemInfo = uni.getWindowInfo?.() || uni.getSystemInfoSync();
} catch {
systemInfo = uni.getSystemInfoSync();
}
const systemInfo = uni.getSystemInfoSync();
statusBarHeight.value = systemInfo.statusBarHeight || 0;
safeAreaBottom.value = systemInfo.safeAreaInsets?.bottom || 0;

View File

@@ -5,11 +5,12 @@
* @returns
*/
const debounce = <T extends (...args: any[]) => any>(fn: T, delay: number) => {
let timer: number | null = null;
let timer: ReturnType<typeof setTimeout> | null = null;
return function (this: any, ...args: Parameters<T>) {
if (timer) clearTimeout(timer);
if (timer !== null) clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
timer = null;
}, delay);
};
};