Files
2026-09-22 16:04:51 +08:00

228 lines
8.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { WidgetType, WidgetContainerProps } from './button';
/**
* 把任意值按目标类型做类型转换(json/array/number/integer/float/bool/string 互转)
* @param {*} data 待转换的值
* @param {string} type 目标类型
* @returns {*} 转换后的值,没有匹配的转换规则时原样返回
*/
declare function toPrimitive(data: any, type: string): any;
/**
* 判断值的基础类型,返回 'null'/'array'/'json'/'bool'/'string'/'integer'/'float' 之一
* @param {*} value 待判断的值
* @returns {string} 类型名
*/
declare function getPrimitiveType(value: any): string;
/**
* 按 registerProps 的字段配置(code/field/router/query/string)解析出实际的 props 数据;
* 配置里出现 type: 'code' 时走异步表达式求值,否则走同步解析
* @param {Object} [registerProps] props 的类型/来源配置,支持嵌套
* @param {Object} [data] 表达式求值、字段取值时使用的上下文数据
* @param {Object} [fns] 表达式求值时可调用的额外函数
* @param {*} [defaultValue] 字段没有取到值时的兜底默认值
* @returns {Object|Promise<Object>} 解析后的 props 数据;含 code 类型字段时返回 Promise
*/
declare function getWidgetPropsData(registerProps?: any, data?: any, fns?: any, defaultValue?: any): any | Promise<any>;
/**
* 递归遍历每个成员做条件判断,成员是 object 或 array 时继续深入遍历
* @param {*} items 待遍历的值(对象/数组/其他)
* @param {(value: *, key: string|number) => boolean} [func] 判断函数,返回 true 即命中
* @returns {boolean} 只要有一处命中就返回 true
*/
declare function deepSome(items: any, func?: (value: any, key: string | number) => boolean): boolean;
/**
* 递归替换对象(含嵌套对象/数组)里的 key,不在 keyMap 里的 key 保持不变
* @param {*} obj 待处理的对象/数组/其他值
* @param {Object<string, string>} keyMap 旧 key 到新 key 的映射
* @returns {*} 替换 key 后的新对象;非对象/数组的值原样返回
*/
declare function replaceKeys(obj: any, keyMap: {
[x: string]: string;
}): any;
/**
* 生成一个 UUID v4 格式的字符串(非加密安全,仅用于前端本地标识)
* @returns {string} UUID 字符串
*/
declare function uuid(): string;
/**
* 从 @pkg 风格的包路径里取出包名(路径第 4 段),如 @pkg/owner/category/name/... -> name
* @param {string} pkg 包路径字符串
* @returns {string} 包名,解析不出时返回空字符串
*/
declare function getPkgName(pkg: string): string;
/**
* 从 @pkg 风格的包路径里取出分类(路径第 3 段),如 @pkg/owner/category/... -> category
* @param {string} pkg 包路径字符串
* @returns {string} 分类名,解析不出时返回空字符串
*/
declare function getPkgCategory(pkg: string): string;
/**
* 从 @pkg 风格的包路径里取出所有者(路径第 2 段),如 @pkg/owner/... -> owner
* @param {string} pkg 包路径字符串
* @returns {string} 所有者名,解析不出时返回空字符串
*/
declare function getPkgOwner(pkg: string): string;
/**
* 生成 JSON 的 MurmurHash3
* @param {Object} obj - JSON 对象
* @param {number} bits - 输出位数 32 或 128,默认 32
* @param {"x86"|"x64"|"auto"} algo - 算法版本,默认 auto
* @returns {string} hash 字符串
*/
declare function hashJSON(obj: any, bits?: number, algo?: "x86" | "x64" | "auto"): string;
/**
* 创建一个 id 生成器;返回的函数把任意一组参数(对象/函数按引用、原始值按值)映射成
* 形如 "1::2::3" 的可读唯一 key,相同的参数组合总是得到相同的 id
* @returns {(...args: *[]) => string} getId 函数
*/
declare function makeUniqueIdGenerator(): (...args: any[]) => string;
/**
* 判断 URL 是否包含域名(包括域名、localhost 和 IP 地址)
* @param {string} url - 待检测的 URL 字符串
* @returns {boolean} 如果包含域名/主机名返回 true,否则返回 false
*
* @example
* hasUrlPrefix('https://www.example.com/path') // true
* hasUrlPrefix('http://example.com') // true
* hasUrlPrefix('//example.com/path') // true
* hasUrlPrefix('example.com/path') // true
* hasUrlPrefix('www.example.com') // true
* hasUrlPrefix('http://localhost:3000') // true
* hasUrlPrefix('http://127.0.0.1:8080') // true
* hasUrlPrefix('http://192.168.1.1') // true
* hasUrlPrefix('/path/to/resource') // false
* hasUrlPrefix('./relative/path') // false
* hasUrlPrefix('../relative/path') // false
*/
declare function hasUrlPrefix(url: string): boolean;
/**
* 为 URL 添加默认前缀(如果没有域名前缀)
* @param {string} url - 待处理的 URL 字符串
* @param {string} defaultPrefix - 默认前缀,默认为当前域名
* @returns {string} 处理后的 URL
*
* @example
* getUrlWithPrefix('/path/to/resource') // 'http://current-domain.com/path/to/resource'
* getUrlWithPrefix('/api/data', 'https://api.example.com') // 'https://api.example.com/api/data'
* getUrlWithPrefix('https://example.com/path') // 'https://example.com/path' (不变)
* getUrlWithPrefix('example.com/path') // 'example.com/path' (不变,已有域名)
*/
declare function getUrlWithPrefix(url: string, defaultPrefix?: string): string;
/**
* 生成 UUID v4 字符串,优先用 crypto.randomUUID/getRandomValues,都不支持时降级为 Math.random
* @returns {string} UUID 字符串
*/
declare function generateUUID(): string;
// ===== 用户数据结构(复用类型,JSDoc 无法跨文件引用,放 .d.ts) =====
interface UserRoleBinding {
user_uuid: string
role_uuid: string
created_at: string
updated_at: string
created_user: string
owned_user: string
}
interface UserInfo {
uuid: string
username: string
nickname: string
email: string
last_login_ip: string
is_active: 0 | 1
UserRole: UserRoleBinding[]
[key: string]: unknown
}
interface MenuItem {
/** 菜单唯一标识 */
uuid: string
/** 菜单显示名称 */
name: string
/** 图标 class 名 */
icon: string
/** 行为目标(组件标识 / 路由 uuid 等),含义随 widgetType 而定 */
widget: string
/** 行为类型 */
widgetType: WidgetType
/** 传给目标组件的 props 映射配置 */
widgetProps: Record<string, unknown>
/** 传给目标组件的 $setting 配置 */
widgetSetting: Record<string, unknown>
/** 弹窗容器配置 */
widgetContainerSetting: WidgetContainerProps
/** 子菜单 */
children?: MenuItem[]
}
interface RouteItem {
/** 路由唯一标识 */
uuid: string
/** 路由名称 */
name: string
/** react-router path,支持动态参数(如 /page/:id) */
uri: string
/** 是否为布局路由(外层 layout,不直接渲染页面内容) */
isLayout: boolean
/** 是否需要登录才能访问 */
isLogin: boolean
/** 是否为手机端专属路由 */
isPhone: boolean
/** 路由类型 */
type: Exclude<WidgetType, 'redirect'>
/** 是否精确匹配路径 */
exact: boolean
/** widget 标识(等同于 ButtonProps.widget),经 core.getWidgetComponent 加载 */
component: string
/** 传给页面组件的 props 映射配置 */
widgetProps: Record<string, unknown>
/** 传给页面组件的 $setting 配置 */
widgetSetting: Record<string, unknown>
/** 弹窗容器配置 */
widgetContainerSetting: WidgetContainerProps
/** 附加配置(如 layout 标识等) */
extra?: Record<string, unknown>
}
// ===== http — Proxy 模式产生交叉类型,JSDoc 无法表达 =====
/** 每次请求自动附加的请求头 */
interface HttpHeaders {
/** 客户端平台标识,固定为 'web' */
Platform: string
/** SaaS 租户标识,单租户时为 null */
SaaS: string | null
/** JWT Bearer token,未登录时为 undefined */
Authorization: string | undefined
}
// ===== func — ff-worker-pipe 无类型文件,显式声明 =====
/**
* 基于 Worker 的表达式执行引擎单例;
* exec 在独立 Worker 上下文中求值一段 JS 表达式/源码
*/
interface WorkerPipeInstance {
/**
* 在 Worker 上下文中执行一段 JS 表达式
* @param expression 要执行的表达式字符串
* @param args 传给表达式的参数(可在表达式内作为第一个参数使用)
* @param fns 注入到表达式执行作用域的额外可调用函数
* @param session 会话标识;相同 session 共享 Worker 侧工作区(this)
*/
exec: (
expression: string,
args?: Record<string, unknown>,
fns?: Record<string, Function>,
session?: string
) => Promise<unknown>
/** 清除指定 session 的 Worker 侧工作区 */
clear: (session: string) => void
}
export { deepSome, generateUUID, getPkgCategory, getPkgName, getPkgOwner, getPrimitiveType, getUrlWithPrefix, getWidgetPropsData, hasUrlPrefix, hashJSON, makeUniqueIdGenerator, replaceKeys, toPrimitive, uuid };
export type { HttpHeaders, MenuItem, RouteItem, UserInfo, UserRoleBinding, WorkerPipeInstance };