pit-docs-mcp 1.0.2

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.
Files changed (203) hide show
  1. package/README.md +180 -0
  2. package/dist/codegen.d.ts +5 -0
  3. package/dist/codegen.d.ts.map +1 -0
  4. package/dist/codegen.js +112 -0
  5. package/dist/constants.d.ts +6 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +10 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +115 -0
  11. package/dist/resources.d.ts +3 -0
  12. package/dist/resources.d.ts.map +1 -0
  13. package/dist/resources.js +80 -0
  14. package/dist/tools.d.ts +3 -0
  15. package/dist/tools.d.ts.map +1 -0
  16. package/dist/tools.js +258 -0
  17. package/dist/utils.d.ts +26 -0
  18. package/dist/utils.d.ts.map +1 -0
  19. package/dist/utils.js +198 -0
  20. package/docs/codegen/pit-simplify-web.md +686 -0
  21. package/docs/pitBusinessUi/README.md +102 -0
  22. package/docs/pitBusinessUi/add-date-picker.md +57 -0
  23. package/docs/pitBusinessUi/add-operation.md +64 -0
  24. package/docs/pitBusinessUi/batch-download.md +44 -0
  25. package/docs/pitBusinessUi/bill-tree-dialog.md +82 -0
  26. package/docs/pitBusinessUi/collapse.md +88 -0
  27. package/docs/pitBusinessUi/date-time-picker.md +74 -0
  28. package/docs/pitBusinessUi/design-report-explain.md +47 -0
  29. package/docs/pitBusinessUi/dialog.md +89 -0
  30. package/docs/pitBusinessUi/dic-radio.md +67 -0
  31. package/docs/pitBusinessUi/dic.md +78 -0
  32. package/docs/pitBusinessUi/document-preview.md +54 -0
  33. package/docs/pitBusinessUi/drawer.md +67 -0
  34. package/docs/pitBusinessUi/editor.md +63 -0
  35. package/docs/pitBusinessUi/expand-search-form.md +65 -0
  36. package/docs/pitBusinessUi/file-preview.md +56 -0
  37. package/docs/pitBusinessUi/flow-table-status.md +47 -0
  38. package/docs/pitBusinessUi/icon-box.md +74 -0
  39. package/docs/pitBusinessUi/image-preview.md +55 -0
  40. package/docs/pitBusinessUi/image.md +53 -0
  41. package/docs/pitBusinessUi/input-formatter.md +100 -0
  42. package/docs/pitBusinessUi/input-number.md +47 -0
  43. package/docs/pitBusinessUi/input-select.md +68 -0
  44. package/docs/pitBusinessUi/input.md +56 -0
  45. package/docs/pitBusinessUi/jm-preview.md +47 -0
  46. package/docs/pitBusinessUi/json-editor.md +71 -0
  47. package/docs/pitBusinessUi/loading-btn.md +64 -0
  48. package/docs/pitBusinessUi/monaco.md +82 -0
  49. package/docs/pitBusinessUi/money-input.md +59 -0
  50. package/docs/pitBusinessUi/pagination.md +70 -0
  51. package/docs/pitBusinessUi/password-strength.md +59 -0
  52. package/docs/pitBusinessUi/positive-number.md +63 -0
  53. package/docs/pitBusinessUi/preview-image.md +62 -0
  54. package/docs/pitBusinessUi/preview-office.md +50 -0
  55. package/docs/pitBusinessUi/preview.md +57 -0
  56. package/docs/pitBusinessUi/quill.md +52 -0
  57. package/docs/pitBusinessUi/runflow-btn.md +52 -0
  58. package/docs/pitBusinessUi/search-date-picker.md +60 -0
  59. package/docs/pitBusinessUi/select-bid-list.md +66 -0
  60. package/docs/pitBusinessUi/select-color.md +38 -0
  61. package/docs/pitBusinessUi/select-contract-tree.md +41 -0
  62. package/docs/pitBusinessUi/select-dept.md +38 -0
  63. package/docs/pitBusinessUi/select-project-unit.md +48 -0
  64. package/docs/pitBusinessUi/select-section-tree.md +45 -0
  65. package/docs/pitBusinessUi/select-section.md +66 -0
  66. package/docs/pitBusinessUi/select-string.md +60 -0
  67. package/docs/pitBusinessUi/select-system-unit.md +41 -0
  68. package/docs/pitBusinessUi/select-user-by-role.md +51 -0
  69. package/docs/pitBusinessUi/switch.md +43 -0
  70. package/docs/pitBusinessUi/table-contract.md +66 -0
  71. package/docs/pitBusinessUi/table-operation.md +81 -0
  72. package/docs/pitBusinessUi/table.md +75 -0
  73. package/docs/pitBusinessUi/tag.md +86 -0
  74. package/docs/pitBusinessUi/textarea.md +65 -0
  75. package/docs/pitBusinessUi/transfer-direct.md +57 -0
  76. package/docs/pitBusinessUi/transfer-user-project.md +78 -0
  77. package/docs/pitBusinessUi/transfer.md +68 -0
  78. package/docs/pitBusinessUi/tree-lazy.md +72 -0
  79. package/docs/pitBusinessUi/tree-select-name.md +59 -0
  80. package/docs/pitBusinessUi/tree-select-plus.md +106 -0
  81. package/docs/pitBusinessUi/tree-select.md +86 -0
  82. package/docs/pitBusinessUi/upload-avatar.md +60 -0
  83. package/docs/pitBusinessUi/upload-file-dialog.md +86 -0
  84. package/docs/pitBusinessUi/upload-file.md +77 -0
  85. package/docs/pitBusinessUi/upload-list-card.md +62 -0
  86. package/docs/pitBusinessUi/upload-table.md +77 -0
  87. package/docs/pitBusinessUi/user-transform.md +72 -0
  88. package/docs/pitBusinessUi/utils.md +272 -0
  89. package/docs/pitBusinessUtils/README.md +144 -0
  90. package/docs/pitBusinessUtils/auth.md +170 -0
  91. package/docs/pitBusinessUtils/clipboard.md +72 -0
  92. package/docs/pitBusinessUtils/filePreview.md +60 -0
  93. package/docs/pitBusinessUtils/formValidate.md +75 -0
  94. package/docs/pitBusinessUtils/generateTitle.md +49 -0
  95. package/docs/pitBusinessUtils/get-page-title.md +65 -0
  96. package/docs/pitBusinessUtils/i18n.md +130 -0
  97. package/docs/pitBusinessUtils/jwks.md +82 -0
  98. package/docs/pitBusinessUtils/oss.md +391 -0
  99. package/docs/pitBusinessUtils/passwordValidate.md +120 -0
  100. package/docs/pitBusinessUtils/pit.md +496 -0
  101. package/docs/pitBusinessUtils/print.md +126 -0
  102. package/docs/pitBusinessUtils/request.md +137 -0
  103. package/docs/pitBusinessUtils/scroll-to.md +68 -0
  104. package/docs/pitBusinessUtils/utils.md +762 -0
  105. package/docs/pitBusinessUtils/validate.md +224 -0
  106. package/docs/pitElementUi/alert.md +238 -0
  107. package/docs/pitElementUi/avatar.md +147 -0
  108. package/docs/pitElementUi/backtop.md +60 -0
  109. package/docs/pitElementUi/badge.md +120 -0
  110. package/docs/pitElementUi/base-tabs.md +73 -0
  111. package/docs/pitElementUi/border.md +135 -0
  112. package/docs/pitElementUi/breadcrumb.md +44 -0
  113. package/docs/pitElementUi/button.md +301 -0
  114. package/docs/pitElementUi/calendar.md +66 -0
  115. package/docs/pitElementUi/card.md +170 -0
  116. package/docs/pitElementUi/carousel.md +212 -0
  117. package/docs/pitElementUi/cascader.md +1966 -0
  118. package/docs/pitElementUi/checkbox.md +283 -0
  119. package/docs/pitElementUi/collapse.md +131 -0
  120. package/docs/pitElementUi/color-picker.md +123 -0
  121. package/docs/pitElementUi/color.md +244 -0
  122. package/docs/pitElementUi/container.md +240 -0
  123. package/docs/pitElementUi/custom-theme.md +131 -0
  124. package/docs/pitElementUi/date-picker.md +448 -0
  125. package/docs/pitElementUi/datetime-picker.md +254 -0
  126. package/docs/pitElementUi/descriptions.md +191 -0
  127. package/docs/pitElementUi/dialog-header.md +53 -0
  128. package/docs/pitElementUi/dialog.md +239 -0
  129. package/docs/pitElementUi/divider.md +61 -0
  130. package/docs/pitElementUi/drawer.md +307 -0
  131. package/docs/pitElementUi/dropdown.md +308 -0
  132. package/docs/pitElementUi/empty.md +61 -0
  133. package/docs/pitElementUi/font-family.md +90 -0
  134. package/docs/pitElementUi/form-base.md +1239 -0
  135. package/docs/pitElementUi/form-item-checkbox-group.md +48 -0
  136. package/docs/pitElementUi/form-item-date.md +60 -0
  137. package/docs/pitElementUi/form-item-dic.md +18 -0
  138. package/docs/pitElementUi/form-item-editor.md +16 -0
  139. package/docs/pitElementUi/form-item-input-money.md +19 -0
  140. package/docs/pitElementUi/form-item-input-number.md +20 -0
  141. package/docs/pitElementUi/form-item-input.md +18 -0
  142. package/docs/pitElementUi/form-item-radio-group.md +21 -0
  143. package/docs/pitElementUi/form-item-select.md +21 -0
  144. package/docs/pitElementUi/form-item-switch.md +15 -0
  145. package/docs/pitElementUi/form-item-textarea.md +20 -0
  146. package/docs/pitElementUi/form-item-tree-select.md +27 -0
  147. package/docs/pitElementUi/form-item-upload-card.md +18 -0
  148. package/docs/pitElementUi/form-item-upload.md +1 -0
  149. package/docs/pitElementUi/form-two.md +102 -0
  150. package/docs/pitElementUi/form.md +952 -0
  151. package/docs/pitElementUi/i18n.md +228 -0
  152. package/docs/pitElementUi/icon-custom.md +99 -0
  153. package/docs/pitElementUi/icon-line-custom.md +12 -0
  154. package/docs/pitElementUi/icon.md +28 -0
  155. package/docs/pitElementUi/image.md +178 -0
  156. package/docs/pitElementUi/infiniteScroll.md +87 -0
  157. package/docs/pitElementUi/input-number.md +197 -0
  158. package/docs/pitElementUi/input-select.md +1 -0
  159. package/docs/pitElementUi/input.md +800 -0
  160. package/docs/pitElementUi/installation.md +9 -0
  161. package/docs/pitElementUi/layout-column.md +376 -0
  162. package/docs/pitElementUi/layout-tree.md +715 -0
  163. package/docs/pitElementUi/layout.md +354 -0
  164. package/docs/pitElementUi/link.md +66 -0
  165. package/docs/pitElementUi/loading.md +208 -0
  166. package/docs/pitElementUi/menu.md +403 -0
  167. package/docs/pitElementUi/message-box.md +326 -0
  168. package/docs/pitElementUi/message.md +219 -0
  169. package/docs/pitElementUi/notification.md +311 -0
  170. package/docs/pitElementUi/page-header.md +40 -0
  171. package/docs/pitElementUi/pagination.md +200 -0
  172. package/docs/pitElementUi/popconfirm.md +60 -0
  173. package/docs/pitElementUi/popover.md +167 -0
  174. package/docs/pitElementUi/progress.md +178 -0
  175. package/docs/pitElementUi/quickstart.md +290 -0
  176. package/docs/pitElementUi/radio.md +211 -0
  177. package/docs/pitElementUi/rate.md +135 -0
  178. package/docs/pitElementUi/result.md +76 -0
  179. package/docs/pitElementUi/select-tree.md +661 -0
  180. package/docs/pitElementUi/select.md +586 -0
  181. package/docs/pitElementUi/skeleton.md +316 -0
  182. package/docs/pitElementUi/slider.md +237 -0
  183. package/docs/pitElementUi/steps.md +154 -0
  184. package/docs/pitElementUi/switch.md +142 -0
  185. package/docs/pitElementUi/table.md +4023 -0
  186. package/docs/pitElementUi/tabs.md +303 -0
  187. package/docs/pitElementUi/tag.md +203 -0
  188. package/docs/pitElementUi/time-picker.md +199 -0
  189. package/docs/pitElementUi/timeline.md +154 -0
  190. package/docs/pitElementUi/tooltip.md +177 -0
  191. package/docs/pitElementUi/transfer.md +249 -0
  192. package/docs/pitElementUi/transition.md +155 -0
  193. package/docs/pitElementUi/tree.md +1157 -0
  194. package/docs/pitElementUi/typography.md +151 -0
  195. package/docs/pitElementUi/upload-table.md +39 -0
  196. package/docs/pitElementUi/upload.md +392 -0
  197. package/docs/pitElementUi/virtual-list.md +154 -0
  198. package/docs/pitElementUi/virtual-select-tree.md +243 -0
  199. package/docs/pitElementUi/virtual-select.md +451 -0
  200. package/docs/pitElementUi/virtual-table-column.md +1 -0
  201. package/docs/pitElementUi/virtual-table.md +490 -0
  202. package/docs/pitElementUi/virtual-tree.md +119 -0
  203. package/package.json +33 -0
@@ -0,0 +1,496 @@
1
+ # pit — 核心工具对象
2
+
3
+ `pit` 是本库最核心的工具对象,涵盖日期时间处理、数据结构转换、数字格式化、LocalStorage 封装、权限判断等多类实用方法。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import pit from 'pit-business-utils'
9
+
10
+ // 或按需解构(pit 是 default export,需通过 pit.xxx 调用)
11
+ pit.dateDiff('2024-01-01', '2024-03-01')
12
+ ```
13
+
14
+ ---
15
+
16
+ ## 一、日期时间类
17
+
18
+ ### `pit.dateDiff(sDate1, sDate2)`
19
+
20
+ 计算两个日期之间的天数差(绝对值)。
21
+
22
+ | 参数 | 类型 | 必填 | 说明 |
23
+ |------|------|------|------|
24
+ | `sDate1` | `string` | ✅ | 日期字符串,格式 `yyyy-MM-dd` |
25
+ | `sDate2` | `string` | ✅ | 日期字符串,格式 `yyyy-MM-dd` |
26
+
27
+ | — | — |
28
+ |---|---|
29
+ | **返回值** | `number`,两日期相差的天数(始终为正整数) |
30
+
31
+ ```js
32
+ pit.dateDiff('2024-01-01', '2024-03-15') // 74
33
+ pit.dateDiff('2024-03-15', '2024-01-01') // 74(绝对值)
34
+ ```
35
+
36
+ ---
37
+
38
+ ### `pit.toDateText(dateTimeStamp)`
39
+
40
+ 将时间戳转换为人性化的相对时间描述。
41
+
42
+ | 参数 | 类型 | 必填 | 说明 |
43
+ |------|------|------|------|
44
+ | `dateTimeStamp` | `number` | ✅ | 毫秒级时间戳 |
45
+
46
+ | — | — |
47
+ |---|---|
48
+ | **返回值** | `string`,如 `"3分钟前"`、`"2小时前"`、`"3天前"`、`"2周前"`、`"1个月前"` 或 `"yyyy/MM/dd"` 日期 |
49
+
50
+ ```js
51
+ pit.toDateText(Date.now() - 5 * 60 * 1000) // "5分钟前"
52
+ pit.toDateText(Date.now() - 2 * 3600 * 1000) // "2小时前"
53
+ pit.toDateText(new Date('2023-01-01').getTime()) // "2023/01/01"
54
+ ```
55
+
56
+ ---
57
+
58
+ ### `pit.getDate(format, strInterval, number)`
59
+
60
+ 从当前时间增减指定单位后,返回格式化日期字符串。
61
+
62
+ | 参数 | 类型 | 必填 | 说明 |
63
+ |------|------|------|------|
64
+ | `format` | `string` | ✅ | 输出格式,如 `"yyyy-MM-dd"` |
65
+ | `strInterval` | `string` | ✅ | 时间单位:`s`=秒、`n`=分、`h`=时、`d`=天、`w`=周、`q`=季度、`m`=月、`y`=年 |
66
+ | `number` | `number` | ✅ | 偏移数量,正数为未来,负数为过去 |
67
+
68
+ | — | — |
69
+ |---|---|
70
+ | **返回值** | `string`,格式化后的日期字符串 |
71
+
72
+ ```js
73
+ pit.getDate('yyyy-MM-dd', 'd', 7) // 7天后的日期,如 "2024-03-22"
74
+ pit.getDate('yyyy-MM-dd', 'd', -30) // 30天前的日期
75
+ pit.getDate('yyyy-MM-dd', 'm', 1) // 1个月后
76
+ ```
77
+
78
+ ---
79
+
80
+ ### `pit.toDate(v, format)`
81
+
82
+ 将多种格式的时间值统一转为格式化日期字符串,兼容 `.NET` 的 `/Date(timestamp)/` 格式。
83
+
84
+ | 参数 | 类型 | 必填 | 说明 |
85
+ |------|------|------|------|
86
+ | `v` | `string \| number \| Date` | ✅ | 原始时间值,支持时间戳、日期字符串、Date 对象、`/Date(123456)/` 格式 |
87
+ | `format` | `string` | — | 输出格式,默认 `"yyyy-MM-dd HH:mm"` |
88
+
89
+ | — | — |
90
+ |---|---|
91
+ | **返回值** | `string`,格式化后的日期字符串 |
92
+
93
+ ```js
94
+ pit.toDate(1711036800000) // "2024-03-22 00:00"
95
+ pit.toDate('2024-03-22T08:30:00') // "2024-03-22 08:30"
96
+ pit.toDate('/Date(1711036800000)/', 'yyyy-MM-dd') // "2024-03-22"
97
+ ```
98
+
99
+ ---
100
+
101
+ ### `pit.getThatDay(space)`
102
+
103
+ 获取相对今天偏移 N 天的日期字符串。
104
+
105
+ | 参数 | 类型 | 必填 | 说明 |
106
+ |------|------|------|------|
107
+ | `space` | `number` | — | 偏移天数,`0` 或不传表示今天,正数为未来,负数为过去 |
108
+
109
+ | — | — |
110
+ |---|---|
111
+ | **返回值** | `string`,格式 `yyyy-MM-dd` |
112
+
113
+ ```js
114
+ pit.getThatDay(0) // 今天,如 "2024-03-15"
115
+ pit.getThatDay(-1) // 昨天
116
+ pit.getThatDay(7) // 7天后
117
+ ```
118
+
119
+ ---
120
+
121
+ ### `pit.assemblyDay(data)`
122
+
123
+ 将年、月、日对象组装为日期字符串,月份自动加 1 并补零。
124
+
125
+ | 参数 | 类型 | 必填 | 说明 |
126
+ |------|------|------|------|
127
+ | `data` | `Object` | ✅ | 含 `year`(年)、`month`(月,从 0 开始)、`date`(日)的对象 |
128
+
129
+ | — | — |
130
+ |---|---|
131
+ | **返回值** | `string`,格式 `yyyy-MM-dd` |
132
+
133
+ ```js
134
+ // new Date() 的 getMonth() 返回 0-11,传入时无需手动 +1
135
+ const d = new Date()
136
+ pit.assemblyDay({ year: d.getFullYear(), month: d.getMonth(), date: d.getDate() })
137
+ // "2024-03-15"
138
+ ```
139
+
140
+ ---
141
+
142
+ ### `pit.complement(value, digit)`
143
+
144
+ 数字补零至指定位数。
145
+
146
+ | 参数 | 类型 | 必填 | 说明 |
147
+ |------|------|------|------|
148
+ | `value` | `number \| string` | ✅ | 原始数字 |
149
+ | `digit` | `number` | — | 目标位数,默认 `2` |
150
+
151
+ | — | — |
152
+ |---|---|
153
+ | **返回值** | `string`,补零后的字符串 |
154
+
155
+ ```js
156
+ pit.complement(5) // "05"
157
+ pit.complement(5, 3) // "005"
158
+ pit.complement(12) // "12"
159
+ ```
160
+
161
+ ---
162
+
163
+ ### `pit.dateFormat(date, format)`
164
+
165
+ 基于 dayjs 将时间戳(毫秒)转为格式化日期字符串。
166
+
167
+ | 参数 | 类型 | 必填 | 说明 |
168
+ |------|------|------|------|
169
+ | `date` | `number \| string \| Date` | ✅ | 时间戳(毫秒)或可被 dayjs 解析的值 |
170
+ | `format` | `string` | — | dayjs 格式字符串,默认 `"YYYY-MM-DD HH:mm"` |
171
+
172
+ | — | — |
173
+ |---|---|
174
+ | **返回值** | `string`,格式化后的日期字符串 |
175
+
176
+ ```js
177
+ pit.dateFormat(1711036800000) // "2024-03-22 00:00"
178
+ pit.dateFormat(1711036800000, 'YYYY/MM/DD') // "2024/03/22"
179
+ ```
180
+
181
+ ---
182
+
183
+ ### `pit.timestamp(val)`
184
+
185
+ 将日期字符串或 Date 对象转为毫秒时间戳。
186
+
187
+ | 参数 | 类型 | 必填 | 说明 |
188
+ |------|------|------|------|
189
+ | `val` | `string \| Date` | ✅ | 日期字符串或 Date 对象 |
190
+
191
+ | — | — |
192
+ |---|---|
193
+ | **返回值** | `number`,毫秒时间戳 |
194
+
195
+ ```js
196
+ pit.timestamp('2024-03-22') // 1711036800000
197
+ pit.timestamp(new Date()) // 当前毫秒时间戳
198
+ ```
199
+
200
+ ---
201
+
202
+ ### `pit.tableDateFormat(row, column, cellValue)`
203
+
204
+ Element UI `el-table-column` 的 `:formatter` 专用日期格式化函数,接收表格内置参数。
205
+
206
+ | 参数 | 类型 | 必填 | 说明 |
207
+ |------|------|------|------|
208
+ | `row` | `Object` | ✅ | 行数据(el-table 内置) |
209
+ | `column` | `Object` | ✅ | 列配置(el-table 内置) |
210
+ | `cellValue` | `any` | ✅ | 单元格原始值,通常为时间戳 |
211
+
212
+ | — | — |
213
+ |---|---|
214
+ | **返回值** | `string`,格式化后的日期字符串 `"YYYY-MM-DD HH:mm"` |
215
+
216
+ ```html
217
+ <el-table-column label="创建时间" prop="createTime" :formatter="pit.tableDateFormat" />
218
+ ```
219
+
220
+ ---
221
+
222
+ ## 二、数据结构类
223
+
224
+ ### `pit.toTreeViewJson(data, id, parentIdText, idText)`
225
+
226
+ 将扁平数组转换为树形结构,常用于菜单、组织架构、部门树等场景。
227
+
228
+ | 参数 | 类型 | 必填 | 说明 |
229
+ |------|------|------|------|
230
+ | `data` | `Array` | ✅ | 扁平数组,每项含父级 ID 和自身 ID |
231
+ | `id` | `number` | — | 根节点的父级 ID 值,默认 `0` |
232
+ | `parentIdText` | `string` | — | 父级 ID 的属性名,默认 `"parentId"` |
233
+ | `idText` | `string` | — | 自身 ID 的属性名,默认 `"id"` |
234
+
235
+ | — | — |
236
+ |---|---|
237
+ | **返回值** | `Array`,树形结构数组,每个节点附加 `hasChildren`、`ChildNodes`、`isexpand`、`complete` 字段 |
238
+
239
+ ```js
240
+ const flat = [
241
+ { id: 1, parentId: 0, name: '总公司' },
242
+ { id: 2, parentId: 1, name: '技术部' },
243
+ { id: 3, parentId: 1, name: '市场部' },
244
+ ]
245
+ pit.toTreeViewJson(flat)
246
+ // [{ id: 1, name: '总公司', ChildNodes: [{ id: 2, ... }, { id: 3, ... }], ... }]
247
+ ```
248
+
249
+ ---
250
+
251
+ ## 三、数字 / 文件大小类
252
+
253
+ ### `pit.toFileSize(size)`
254
+
255
+ 将字节数转换为可读性友好的文件大小字符串。
256
+
257
+ | 参数 | 类型 | 必填 | 说明 |
258
+ |------|------|------|------|
259
+ | `size` | `number \| string` | ✅ | 文件大小(字节数) |
260
+
261
+ | — | — |
262
+ |---|---|
263
+ | **返回值** | `string`,如 `"1.50 MB"`、`"256 字节"`、`"3.20 GB"` |
264
+
265
+ ```js
266
+ pit.toFileSize(1536) // "1.50 KB"
267
+ pit.toFileSize(1572864) // "1.50 MB"
268
+ pit.toFileSize(0) // "0 字节"
269
+ ```
270
+
271
+ ---
272
+
273
+ ### `pit.toDecimal(num)`
274
+
275
+ 将数字格式化为千分位分隔 + 保留两位小数的字符串,支持负数。
276
+
277
+ | 参数 | 类型 | 必填 | 说明 |
278
+ |------|------|------|------|
279
+ | `num` | `number \| string` | ✅ | 原始数字 |
280
+
281
+ | — | — |
282
+ |---|---|
283
+ | **返回值** | `string`,如 `"1,234,567.89"`、`"-1,234.00"` |
284
+
285
+ ```js
286
+ pit.toDecimal(1234567.89) // "1,234,567.89"
287
+ pit.toDecimal(-1234) // "-1,234.00"
288
+ pit.toDecimal('99') // "99.00"
289
+ ```
290
+
291
+ ---
292
+
293
+ ## 四、LocalStorage 封装类
294
+
295
+ > 所有键名自动添加 `pit_` 前缀,存储时附加类型标记,`storageGet` 取出时自动还原原始类型。
296
+
297
+ ### 类型标记机制说明
298
+
299
+ | 存入类型 | localStorage 中实际存储 | `storageGet` 返回类型 |
300
+ |----------|-------------------------|----------------------|
301
+ | `string` | `"hello\|String"` | `string` |
302
+ | `number` | `"42\|Number"` | `number` |
303
+ | `boolean` | `"true\|Boolean"` | `boolean` |
304
+ | `object/array` | `"[...]\|Object"` | `object/array` |
305
+
306
+ ---
307
+
308
+ ### `pit.storageSet(obj)`
309
+
310
+ 批量将对象属性写入 `localStorage`。
311
+
312
+ | 参数 | 类型 | 必填 | 说明 |
313
+ |------|------|------|------|
314
+ | `obj` | `Object` | ✅ | 键值对对象,键名即 localStorage key(自动加 `pit_` 前缀) |
315
+
316
+ | — | — |
317
+ |---|---|
318
+ | **返回值** | `void` |
319
+
320
+ ```js
321
+ pit.storageSet({ userName: '张三', userAge: 28, isAdmin: false })
322
+ // localStorage 中:pit_userName="张三|String",pit_userAge="28|Number",pit_isAdmin="false|Boolean"
323
+ ```
324
+
325
+ ---
326
+
327
+ ### `pit.storageGet(key)`
328
+
329
+ 从 `localStorage` 读取指定 key 的值,自动还原存入时的原始类型。
330
+
331
+ | 参数 | 类型 | 必填 | 说明 |
332
+ |------|------|------|------|
333
+ | `key` | `string` | ✅ | key 名(不含 `pit_` 前缀) |
334
+
335
+ | — | — |
336
+ |---|---|
337
+ | **返回值** | 原始类型值(`string \| number \| boolean \| object \| null`);key 不存在时返回 `null` |
338
+
339
+ ```js
340
+ pit.storageGet('userAge') // 28(number,非字符串 "28")
341
+ pit.storageGet('isAdmin') // false(boolean)
342
+ pit.storageGet('notExist') // null
343
+ ```
344
+
345
+ ---
346
+
347
+ ### `pit.storageRemove(key)`
348
+
349
+ 删除指定 key 的 `localStorage` 数据。
350
+
351
+ | 参数 | 类型 | 必填 | 说明 |
352
+ |------|------|------|------|
353
+ | `key` | `string` | ✅ | key 名(不含 `pit_` 前缀) |
354
+
355
+ | — | — |
356
+ |---|---|
357
+ | **返回值** | `void` |
358
+
359
+ ```js
360
+ pit.storageRemove('userAge')
361
+ ```
362
+
363
+ ---
364
+
365
+ ### `pit.storageClear()`
366
+
367
+ 清除所有带 `pit_` 前缀的 `localStorage` 数据,不影响其他系统数据。
368
+
369
+ | — | — |
370
+ |---|---|
371
+ | **参数** | 无 |
372
+ | **返回值** | `void` |
373
+
374
+ ```js
375
+ pit.storageClear()
376
+ ```
377
+
378
+ ---
379
+
380
+ ## 五、权限类
381
+
382
+ ### `pit.hasBtnP(enCode)`
383
+
384
+ 判断当前用户在当前路由菜单下是否拥有指定的按钮权限。
385
+
386
+ > ⚠️ **全局依赖:** 需要 `window._router`(Vue Router 实例)和 `window._store`(Vuex store 实例)已在宿主项目中注入。
387
+
388
+ | 参数 | 类型 | 必填 | 说明 |
389
+ |------|------|------|------|
390
+ | `enCode` | `string` | ✅ | 按钮权限编码,可使用 `pit.hasCode` 常量 |
391
+
392
+ | — | — |
393
+ |---|---|
394
+ | **返回值** | `boolean`,`true` 表示有权限 |
395
+
396
+ ```js
397
+ // 使用预定义常量
398
+ if (pit.hasBtnP(pit.hasCode.btn_add)) {
399
+ // 显示新增按钮
400
+ }
401
+
402
+ // 使用自定义编码
403
+ if (pit.hasBtnP('btn_export')) {
404
+ // 显示导出按钮
405
+ }
406
+ ```
407
+
408
+ ---
409
+
410
+ ### `pit.hasFlow(params, hasFlow, enCode, key)`
411
+
412
+ 在启用审批流程的场景下,根据审批状态判断当前操作是否可执行(如编辑、删除)。
413
+
414
+ | 参数 | 类型 | 必填 | 说明 |
415
+ |------|------|------|------|
416
+ | `params` | `Object` | ✅ | 包含 `approvalStatus` 字段的业务数据对象 |
417
+ | `hasFlow` | `boolean` | ✅ | 当前功能是否启用了审批流程 |
418
+ | `enCode` | `string` | — | 保留参数,暂未使用 |
419
+ | `key` | `string` | — | 判断的权限字段名,默认 `"writeable"`(可写权限) |
420
+
421
+ | — | — |
422
+ |---|---|
423
+ | **返回值** | `boolean`,`true` 表示可操作 |
424
+
425
+ **可操作状态说明:** `approvalStatus` 为草稿、拒绝、撤回、终止或 `null` 时,返回 `true`。
426
+
427
+ ```js
428
+ // 判断当前记录在流程中是否可编辑
429
+ const canEdit = pit.hasFlow(row, true)
430
+ if (canEdit) {
431
+ // 显示编辑按钮
432
+ }
433
+ ```
434
+
435
+ ---
436
+
437
+ ### `pit.adminAuthority()`
438
+
439
+ 判断当前用户是否为管理员(读取 `localStorage.administrator`)。
440
+
441
+ | — | — |
442
+ |---|---|
443
+ | **参数** | 无 |
444
+ | **返回值** | `boolean` |
445
+
446
+ ```js
447
+ if (pit.adminAuthority()) {
448
+ // 显示管理员专属功能
449
+ }
450
+ ```
451
+
452
+ ---
453
+
454
+ ### `pit.isProjectManager()`
455
+
456
+ 判断当前用户是否为项目负责人(读取 `localStorage.isPermission`)。
457
+
458
+ | — | — |
459
+ |---|---|
460
+ | **参数** | 无 |
461
+ | **返回值** | `boolean` |
462
+
463
+ ```js
464
+ if (pit.isProjectManager()) {
465
+ // 显示项目负责人专属操作
466
+ }
467
+ ```
468
+
469
+ ---
470
+
471
+ ## 六、权限编码常量 `pit.hasCode`
472
+
473
+ 预定义的按钮权限编码常量,与 `pit.hasBtnP()` 配合使用。
474
+
475
+ | 常量名 | 编码值 | 说明 |
476
+ |--------|--------|------|
477
+ | `pit.hasCode.btn_add` | `"btn_add"` | 新增 |
478
+ | `pit.hasCode.btn_edit` | `"btn_edit"` | 编辑 |
479
+ | `pit.hasCode.btn_detail` | `"btn_detail"` | 查看详情 |
480
+ | `pit.hasCode.btn_remove` | `"btn_remove"` | 删除 |
481
+ | `pit.hasCode.btn_import` | `"btn_import"` | 导入 |
482
+ | `pit.hasCode.btn_export` | `"btn_export"` | 导出 |
483
+ | `pit.hasCode.btn_download` | `"btn_download"` | 下载 |
484
+ | `pit.hasCode.btn_upload` | `"btn_upload"` | 上传 |
485
+ | `pit.hasCode.btn_submit` | `"btn_submit"` | 提交 |
486
+ | `pit.hasCode.btn_withdraw` | `"btn_withdraw"` | 撤回 |
487
+ | `pit.hasCode.btn_print` | `"btn_print"` | 打印 |
488
+ | `pit.hasCode.btn_copy` | `"btn_copy"` | 复制 |
489
+
490
+ ---
491
+
492
+ ## 注意事项
493
+
494
+ - `pit.hasBtnP()` 和 `pit.hasFlow()` 依赖于 `window._router` 和 `window._store`,需在应用初始化时由宿主项目注入,否则会报错。
495
+ - `pit.storageSet()` 存入 `null` 或 `undefined` 值时,行为未定义,请避免传入。
496
+ - `pit.toTreeViewJson()` 生成的子节点存放在 `ChildNodes` 字段(非 `children`),使用时请注意字段名。
@@ -0,0 +1,126 @@
1
+ # print — 打印插件
2
+
3
+ 以 Vue 插件形式提供局部打印能力,通过 `Vue.use()` 注册后,在任意组件内使用 `this.$print(dom, options)` 触发指定区域的打印。
4
+
5
+ ## 安装与注册
6
+
7
+ ```js
8
+ // main.js
9
+ import Vue from 'vue'
10
+ import { MyPrint } from 'pit-business-utils'
11
+
12
+ Vue.use(MyPrint)
13
+ // 注册后所有组件实例可通过 this.$print() 调用
14
+ ```
15
+
16
+ ---
17
+
18
+ ## 使用方法
19
+
20
+ ### `this.$print(dom, options)`
21
+
22
+ 在组件内打印指定 DOM 区域或 Vue 组件。
23
+
24
+ | 参数 | 类型 | 必填 | 说明 |
25
+ |------|------|------|------|
26
+ | `dom` | `string \| HTMLElement \| VueComponent` | ✅ | 待打印的目标:CSS 选择器字符串(如 `"#print-area"`)、DOM 元素、或 Vue 组件实例(自动取 `.$el`) |
27
+ | `options` | `Object` | — | 配置项,详见下方配置说明 |
28
+
29
+ | — | — |
30
+ |---|---|
31
+ | **返回值** | `void`,内部创建 iframe 并触发系统打印对话框 |
32
+
33
+ ### options 配置项
34
+
35
+ | 属性 | 类型 | 默认值 | 说明 |
36
+ |------|------|--------|------|
37
+ | `noPrint` | `string` | `".no-print"` | 不需要打印的元素选择器,打印时这些元素会被隐藏 |
38
+
39
+ ---
40
+
41
+ ## 使用示例
42
+
43
+ ### 1. 通过 CSS 选择器打印
44
+
45
+ ```html
46
+ <template>
47
+ <div>
48
+ <div id="print-area">
49
+ <h1>合同详情</h1>
50
+ <p>合同编号:HT-2024-001</p>
51
+ <el-button class="no-print" @click="handlePrint">打印</el-button>
52
+ </div>
53
+ </div>
54
+ </template>
55
+
56
+ <script>
57
+ export default {
58
+ methods: {
59
+ handlePrint() {
60
+ this.$print('#print-area')
61
+ }
62
+ }
63
+ }
64
+ </script>
65
+ ```
66
+
67
+ ### 2. 通过 ref 获取 DOM 元素打印
68
+
69
+ ```html
70
+ <template>
71
+ <div ref="printContent">
72
+ <p>报表内容...</p>
73
+ <div class="no-print">
74
+ <el-button @click="handlePrint">打印报表</el-button>
75
+ </div>
76
+ </div>
77
+ </template>
78
+
79
+ <script>
80
+ export default {
81
+ methods: {
82
+ handlePrint() {
83
+ this.$print(this.$refs.printContent)
84
+ }
85
+ }
86
+ }
87
+ </script>
88
+ ```
89
+
90
+ ### 3. 自定义不打印元素
91
+
92
+ ```js
93
+ // 将 class 为 .action-bar 和 .footer 的元素排除在打印范围外
94
+ this.$print('#report-area', { noPrint: '.action-bar, .footer' })
95
+ ```
96
+
97
+ ### 4. 打印子组件
98
+
99
+ ```html
100
+ <my-report ref="reportComp" />
101
+
102
+ <script>
103
+ methods: {
104
+ handlePrint() {
105
+ this.$print(this.$refs.reportComp) // 自动使用 this.$refs.reportComp.$el
106
+ }
107
+ }
108
+ </script>
109
+ ```
110
+
111
+ ---
112
+
113
+ ## 工作原理
114
+
115
+ 1. 收集当前页面所有 `<style>` 和 `<link>` 样式
116
+ 2. 捕获打印区域内 `input`/`textarea`/`select` 的**当前值**(避免打印出空白表单)
117
+ 3. 创建一个隐藏的 `<iframe>`,将样式和 HTML 写入
118
+ 4. `iframe.onload` 触发后调用 `print()`,100ms 后自动移除 iframe
119
+
120
+ ---
121
+
122
+ ## 注意事项
123
+
124
+ - 打印样式继承自当前页面,**不需要额外编写打印专用 CSS**(`@media print`);但若原页面有大量布局样式,可能影响打印效果,建议搭配 `.no-print` 灵活控制。
125
+ - 打印后会自动清理 iframe,不影响页面 DOM。
126
+ - 在某些浏览器(如 Firefox 旧版)中,`execCommand('print')` 可能失效,此时会回退到 `contentWindow.print()`。