Commit 251d3f36 by liimin

feat(config): 添加iOS调试配置并优化组件工具栏功能

- 在launch.json中添加uni-app iOS设备调试配置
- 在FinishStep组件中添加onOpend事件发射器
- 优化ToolBox组件中的隐藏逻辑,完善代码注释
- 在common.uts中新增firstNonNull、asObject等实用工具函数
- 创建新的component.uts文件提供组件实例类型定义
- 导出新创建的component工具模块到主入口文件
1 parent d656ccf5
......@@ -5,6 +5,11 @@
"customPlaygroundType" : "local",
"playground" : "custom",
"type" : "uni-app:app-android"
},
{
"customPlaygroundType" : "device",
"playground" : "standard",
"type" : "uni-app:app-ios"
}
]
}
......@@ -160,10 +160,10 @@ type Props = {
const props = withDefaults(defineProps<Props>(), {
sceneType: 0,
customerType: 1,
titleTips: ""
titleTips: "",
});
const emit = defineEmits(["submit", "back"]);
const emit = defineEmits(["submit", "back", "onOpend"]);
// ============ 响应式数据 ============
const showPopup = ref<boolean>(false); // 控制弹窗显示(现在由 MessageBox 管理)
......@@ -284,6 +284,7 @@ onMounted(() => {
const info = uni.getWindowInfo();
windowWidth.value = info.windowWidth;
windowHeight.value = info.windowHeight;
emit("onOpend");
});
// 使用 uni.onWindowResize 需要确保它只在支持的平台上调用,但为了兼容性,
......
......@@ -501,30 +501,34 @@ const activeItemId = ref<string>('');
activeItemId.value = '';
};
/**
* 隐藏工具栏
*/
const hide = (): void => {
show.value = false;
};
const onActionClick = (action: ToolAction): void => {
activeItemId.value = '';
if (action.kind == "dynamic") {
if (action.item != null) {
selectItem(action.item);
}
// 关闭弹窗
return;
}
if (action.kind == "pay") {
toPay();
// 关闭弹窗
return;
}
if (action.kind == "finish") {
finish();
// 关闭弹窗
hide();
}
};
/**
* 隐藏工具栏
*/
const hide = (): void => {
show.value = false;
};
syncWindowMetrics();
......
......@@ -701,3 +701,80 @@ export function deepClone<T>(obj: any): null | T {
}
return obj as T;
}
/**
* 获取第一个非空值(类似 SQL 的 COALESCE)
* @param values 可变参数列表,按优先级传入多个值
* @returns 第一个非 null 且非空字符串的值,如果都为空则返回默认值
* @example firstNonNull(null, "", "hello", "world") // "hello"
* @example firstNonNull(null, undefined, "") // ""
*/
export function firstNonNull(...values: Array<any>): string {
for (const value of values) {
if (value != null && value !== "") {
return value as string;
}
}
return "";
}
/**
* 将任意值转换为 UTSJSONObject(安全类型断言)
* @param value 任意值
* @returns UTSJSONObject 或 null(如果值为 null/undefined)
* @example asObject(someValue)
*/
export function asObject(value: any | null): UTSJSONObject | null {
return value != null ? (value as UTSJSONObject) : null;
}
/**
* 安全获取字符串属性值(避免重复的类型断言)
* @param obj 对象(可为 null)
* @param key 属性名
* @returns 字符串或 null
* @example getStringProp(obj, 'name')
*/
export function getStringProp(obj: UTSJSONObject | null, key: string): string | null {
if (obj == null) return null;
const value = obj[key];
return value != null ? (value as string) : null;
}
/**
* 安全获取任意类型属性值(通用索引访问)
* @param obj 对象(可为 null)
* @param key 属性名
* @returns 属性值或 null
* @example getProp(obj, 'id')
*/
export function getProp(obj: UTSJSONObject | null, key: string): any | null {
if (obj == null) return null;
const value = obj[key];
return value != null ? value : null;
}
/**
* 创建空的 UTSJSONObject(避免重复的类型断言)
* @returns 空的 UTSJSONObject
* @example createObject()
*/
export function createObject(): UTSJSONObject {
return {} as UTSJSONObject;
}
/**
* 安全获取字符串属性值,如果值不是字符串则返回 null
* @param obj 对象(可为 null)
* @param key 属性名
* @returns 字符串或 null(如果值不是字符串类型)
* @example getStringPropSafe(obj, 'name')
*/
export function getStringPropSafe(obj: UTSJSONObject | null, key: string): string | null {
if (obj == null) return null;
const value = obj[key];
if (value != null && typeof value === "string") {
return value;
}
return null;
}
import type { ComponentPublicInstance, Ref } from "vue";
/**
* 组件实例 Ref 类型
* 用于简化组件 ref 的类型定义
*/
export type ComponentRef = ComponentPublicInstance | null;
/**
* 调用组件方法的辅助函数
* @param ref 组件 ref
* @param methodName 方法名
*/
export const callComponentMethod = (ref: Ref<ComponentRef>, methodName: string): void => {
if (ref.value != null) {
(ref.value as ComponentPublicInstance).$callMethod(methodName);
}
};
......@@ -3,3 +3,4 @@ export * from "./common.uts";
export * from "./parse.uts";
export * from "./error.uts";
export * from "./permission.uts";
export * from "./component.uts";
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!