添加 cl-form 组件
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
import { getCurrentInstance } from "vue";
|
||||
|
||||
/**
|
||||
* 获取父组件实例
|
||||
*
|
||||
* 用于在子组件中获取父组件实例,以便访问父组件的属性和方法
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // 在子组件中使用
|
||||
* const parent = useParent<ParentType>();
|
||||
* // 访问父组件属性
|
||||
* console.log(parent.someProperty);
|
||||
* ```
|
||||
*
|
||||
* @template T 父组件实例的类型
|
||||
* @returns {T} 返回父组件实例
|
||||
* 获取父组件
|
||||
* @param name 组件名称
|
||||
* @example useParent<ClFormComponentPublicInstance>("cl-form")
|
||||
* @returns 父组件
|
||||
*/
|
||||
export function useParent<T>(): T {
|
||||
export function useParent<T>(name: string): T | null {
|
||||
const { proxy } = getCurrentInstance()!;
|
||||
return proxy?.$parent as T;
|
||||
|
||||
let p = proxy?.$parent;
|
||||
|
||||
while (p != null) {
|
||||
if (p.$options.name == name) {
|
||||
return p as T | null;
|
||||
}
|
||||
p = p.$parent;
|
||||
}
|
||||
|
||||
return p as T | null;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ export function get(object: any, path: string, defaultValue: any | null = null):
|
||||
* 设置对象的属性值
|
||||
* @example set({a: 1}, 'b', 2) // {a: 1, b: 2}
|
||||
*/
|
||||
export function set(object: any, key: string, value: any): void {
|
||||
export function set(object: any, key: string, value: any | null): void {
|
||||
(object as UTSJSONObject)[key] = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ref, type Ref } from "vue";
|
||||
import { forEach, forInObject, isArray, isObject, isString } from "./comm";
|
||||
|
||||
/**
|
||||
@@ -104,6 +105,21 @@ export const parseClass = (data: any): string => {
|
||||
return names.join(" ");
|
||||
};
|
||||
|
||||
/**
|
||||
* 将自定义类型数据转换为UTSJSONObject对象
|
||||
* @param data 要转换的数据
|
||||
* @returns 转换后的UTSJSONObject对象
|
||||
*/
|
||||
export function parseToObject<T>(data: T): UTSJSONObject {
|
||||
// #ifdef APP
|
||||
return JSON.parseObject(JSON.stringify(data)!)!;
|
||||
// #endif
|
||||
|
||||
// #ifndef APP
|
||||
return JSON.parse(JSON.stringify(data)) as UTSJSONObject;
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数值或字符串转换为rpx单位的字符串
|
||||
* @param val 要转换的值,可以是数字或字符串
|
||||
|
||||
Reference in New Issue
Block a user