@hhfenpm/utils 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # @hhfenpm/utils
2
+
3
+ 通用工具函数库,从 ma-management 和 medical-anget 两个项目中抽离的公共工具函数。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @hhfenpm/utils
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```javascript
14
+ // 按需导入
15
+ import { format_date, validatePhone, getSession } from "@hhfenpm/utils";
16
+
17
+ // 或导入整个模块
18
+ import * as utils from "@hhfenpm/utils";
19
+ ```
20
+
21
+ ## 功能模块
22
+
23
+ ### 格式化 (format)
24
+
25
+ - `format_date(timestamp, str)` - 日期格式化
26
+ - `formatDateMinute(timestamp)` - 日期时间格式化(精确到分钟)
27
+ - `format_decimal(number, num, scale)` - 小数转百分比(数字)
28
+ - `format_decimal_string(number, num, scale)` - 小数转百分比(字符串)
29
+ - `format_money(number, num, scale)` - 金额格式化
30
+ - `format_number(num)` - 数字格式化(千分位)
31
+ - `create_guid()` - 创建唯一 ID
32
+ - `arr_label(arr, props)` - 数组转标签对象
33
+ - `arr_obj(arr, props)` - 数组转对象
34
+ - `copy_content(content)` - 复制到剪贴板
35
+ - `calculate_height(item, container)` - 计算高度
36
+ - `formatTxt(text)` - 文字截断
37
+ - `set_cursor(dom, start, end)` - 设置光标位置
38
+ - `sleep(time)` - 同步 setTimeout
39
+ - `detectZoom()` - 检测浏览器缩放比例
40
+ - `findNodeOfTree(tree, id, keyMap)` - 递归查找树节点
41
+ - `copyToClip(content, type)` - 复制到剪贴板(兼容版)
42
+ - `hidePhone(phone)` - 手机号脱敏
43
+ - `escapeRegExp(string)` - 转义正则表达式特殊字符
44
+
45
+ ### 验证 (validate)
46
+
47
+ - `validateFieldAsync(prop, form)` - 基于 Promise 的表单字段验证
48
+ - `validatePhone(rule, value, callback)` - 手机号验证
49
+ - `isEmptyObj(obj)` - 判断对象是否为空
50
+ - `isEqual(a, b)` - 深度相等比较
51
+ - `isEmpty(value)` - 判断值是否为空
52
+ - `getBrowserInfo()` - 获取浏览器信息
53
+ - `isSupported()` - 检测是否支持媒体设备
54
+ - `validateMeaninglessConsecutiveSymbols(input)` - 校验无意义连续符号
55
+
56
+ ### 缓存 (cache)
57
+
58
+ - `cache` - 内存缓存对象
59
+ - `cache.set(key, data)` - 设置缓存
60
+ - `cache.get(key)` - 获取缓存
61
+ - `cache.clear(key)` - 清除缓存
62
+ - `buildUniqueUrl(url, method, params, data)` - 构建唯一的 URL 键值
63
+
64
+ ### Session 管理 (session)
65
+
66
+ - `set_system_key(key)` - 设置系统标识
67
+ - `get_system_key(key)` - 获取带系统标识的 key
68
+ - `setSession(session, key)` - 设置 localStorage 中的 session
69
+ - `getSession(key)` - 获取 localStorage 中的 session
70
+ - `removeSession(key)` - 移除 localStorage 中的 session
71
+ - `extentSession(patch, key)` - 扩展 session 中的部分属性
72
+ - `setSessionStorage(session, key)` - 设置 sessionStorage
73
+ - `getSessionStorage(key)` - 获取 sessionStorage
74
+ - `removeSessionStorage(key)` - 移除 sessionStorage
75
+
76
+ ### 图片 URL 处理 (imgUrl)
77
+
78
+ - `getImgURL(url)` - 获取图片 URL
79
+ - `getGaugeImgUrl(url)` - 获取量表图片 URL
80
+ - `doctor_head_img(url)` - 获取医生头像 URL
81
+
82
+ ### 设备检测 (device)
83
+
84
+ - `isTablet()` - 检测是否为平板
85
+ - `getDeviceType()` - 获取设备类型
86
+ - `isTouchDevice()` - 检测是否为触摸设备
87
+ - `getDeviceInfo()` - 获取设备信息
88
+
89
+ ### URL 处理 (url)
90
+
91
+ - `queryToObj(str)` - 查询字符串转对象
92
+ - `toQueryString(obj)` - 对象转查询字符串
93
+ - `urlToJson(selfUrl)` - URL 转 JSON 对象
94
+ - `getQueryString(name, url)` - 获取 URL 中的指定参数
95
+ - `setUrl(json, originUrl)` - 设置 URL 参数
96
+ - `get_url_params(url)` - 获取 URL 参数(兼容旧 API)
97
+
98
+ ### 通用工具 (tools)
99
+
100
+ - `convertMilliseconds(ms, secondsTo2decimal)` - 毫秒转时分秒
101
+ - `myDebounce(fn, time)` - 防抖函数
102
+ - `debounce(fn, delay)` - 防抖函数(兼容版)
103
+ - `throttle(fn, delay)` - 节流函数
104
+ - `mapStringifyReplacer(key, value)` - Map 序列化替换器
105
+ - `mapParseReviver(key, value)` - Map 反序列化恢复器
106
+ - `getHalfYearAgoToday(reduce)` - 获取 N 个月前的日期
107
+ - `fileDownloadHelper` - 文件下载助手
108
+ - `copyText(text)` - 复制文本到剪贴板
109
+
110
+ ### UUID 生成 (uuid)
111
+
112
+ - `uuid()` - 生成短 UUID
113
+ - `uuidLong()` - 生成长 UUID
114
+
115
+ ### 对象属性获取 (get)
116
+
117
+ - `get(object, path, defaultValue)` - 安全获取对象属性(类似 lodash.get)
118
+
119
+ ### Axios 适配器 (defaultAdapter)
120
+
121
+ - `defaultAdapter(options)` - 防止重复请求的适配器
122
+
123
+ ## 注意事项
124
+
125
+ 1. **API 兼容性**:所有导出的函数名都保持与原业务代码中的命名一致(使用下划线命名),确保兼容旧 API。
126
+ 2. **依赖要求**:需要安装 `date-fns` 作为 peerDependency。
127
+ 3. **浏览器环境**:部分函数需要在浏览器环境中使用,在 Node.js 环境中会返回默认值或警告。
128
+
129
+ ## 开发
130
+
131
+ ```bash
132
+ # 安装依赖
133
+ npm install
134
+
135
+ # 构建
136
+ npm run build
137
+
138
+ # 开发模式(监听文件变化)
139
+ npm run dev
140
+ ```
141
+
142
+ ## License
143
+
144
+ MIT