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,144 @@
1
+ ---
2
+ lang: zh-CN
3
+ title: pit-business-utils 工具函数文档
4
+ ---
5
+
6
+ # pit-business-utils
7
+
8
+ 创智艾泰克前端项目工具类库,提供认证管理、HTTP 请求封装、表单校验、文件操作、国际化、OSS 文件服务等前端常用工具函数。
9
+
10
+ ## 安装
11
+
12
+ ```bash
13
+ # 建议带上 --save-exact 参数,避免版本号不一致导致的依赖问题
14
+ npm install pit-business-utils --save-exact
15
+ ```
16
+
17
+ ---
18
+
19
+ ## 快速上手
20
+
21
+ ### 1. 请求初始化(必须在 main.js 中配置)
22
+
23
+ ```js
24
+ import { getToken, removeAll, locale, setI18nInstance } from 'pit-business-utils'
25
+ import i18n from './i18n'
26
+
27
+ // 初始化国际化
28
+ locale(i18n)
29
+ setI18nInstance(i18n)
30
+
31
+ // 挂载 Vue 根实例(剪贴板、消息提示依赖)
32
+ const vm = new Vue({ i18n, render: h => h(App) }).$mount('#app')
33
+ window.vm = vm
34
+
35
+ // 注入 Vuex store 和 Router(权限判断依赖)
36
+ window._store = store
37
+ window._router = router
38
+
39
+ // 配置请求拦截器
40
+ window.setConfigCallback = (config) => {
41
+ config.baseURL = process.env.VUE_APP_BASE_API
42
+ const token = getToken()
43
+ if (token) config.headers['Authorization'] = `Bearer ${token}`
44
+ return config
45
+ }
46
+ window.requestThen = (response) => {
47
+ const res = response.data
48
+ if (res.code !== 200) return Promise.reject(res)
49
+ return res
50
+ }
51
+ window.requestCatch = (error) => {
52
+ if (error.response?.status === 401) { removeAll(); router.push('/login') }
53
+ return Promise.reject(error)
54
+ }
55
+ ```
56
+
57
+ ### 2. 表单校验
58
+
59
+ ```js
60
+ import { formValidate } from 'pit-business-utils'
61
+
62
+ rules: {
63
+ phone: [{ required: true, message: '请输入手机号' }, { validator: formValidate('iphone', '手机号格式错误'), trigger: 'blur' }],
64
+ idCard: [{ validator: formValidate('idCard', '身份证号格式错误'), trigger: 'blur' }],
65
+ }
66
+ ```
67
+
68
+ ### 3. 日期格式化
69
+
70
+ ```js
71
+ import pit from 'pit-business-utils'
72
+
73
+ pit.toDate(1711036800000) // "2024-03-22 00:00"
74
+ pit.toDateText(Date.now() - 300000) // "5分钟前"
75
+ pit.getThatDay(-7) // 7天前的日期
76
+ ```
77
+
78
+ ### 4. 按钮权限判断
79
+
80
+ ```js
81
+ import pit from 'pit-business-utils'
82
+
83
+ if (pit.hasBtnP(pit.hasCode.btn_add)) {
84
+ // 显示新增按钮
85
+ }
86
+ ```
87
+
88
+ ### 5. 文件下载
89
+
90
+ ```js
91
+ import { downloadTemplate } from 'pit-business-utils'
92
+
93
+ const res = await exportApi()
94
+ downloadTemplate(res, '导出数据.xlsx')
95
+ ```
96
+
97
+ ---
98
+
99
+ ## 全局依赖汇总
100
+
101
+ 部分功能依赖宿主项目在全局注入变量,**所有全局变量均需在 `main.js` 初始化阶段配置**:
102
+
103
+ | 全局变量 | 使用该变量的模块 | 说明 |
104
+ |----------|-----------------|------|
105
+ | `window.vm` | clipboard | Vue 根实例,用于调用 `$message` |
106
+ | `window._store` | pit、utils、get-page-title | Vuex store 实例 |
107
+ | `window._router` | pit | Vue Router 实例 |
108
+ | `window.setConfigCallback` | request | 请求拦截配置(注入 token、baseURL 等) |
109
+ | `window.requestThen` | request | 响应成功处理回调 |
110
+ | `window.requestCatch` | request | 响应失败处理回调 |
111
+
112
+ ---
113
+
114
+ ## 环境变量
115
+
116
+ | 变量名 | 使用模块 | 说明 |
117
+ |--------|----------|------|
118
+ | `VUE_APP_BASE_API` | request | API 基础路径(在 `setConfigCallback` 中使用) |
119
+ | `VUE_APP_BASE_JWKS_KID` | jwks | JWKS 密钥集中目标公钥的 Key ID |
120
+
121
+ ---
122
+
123
+ ## 模块文档目录
124
+
125
+ | 模块 | 说明 | 文档 |
126
+ |------|------|------|
127
+ | `pit`(默认导出) | 核心工具对象:日期、树结构、存储、权限 | [./pit.md](/pit.md) |
128
+ | `utils` | 通用工具函数集合(约 30 个函数) | [./utils.md](utils.md) |
129
+ | `auth` | 认证令牌管理(localStorage 封装) | [./auth.md](/auth.md) |
130
+ | `request`(默认导出) | axios HTTP 请求封装 | [./request.md](/request.md) |
131
+ | `validate` | 基础格式验证函数 | [./validate.md](/validate.md) |
132
+ | `formValidate` | Element UI 表单正则校验器(含 16 条内置规则) | [./formValidate.md](/formValidate.md) |
133
+ | `passwordValidate` | 密码强度校验(企业级复杂度规则) | [./passwordValidate.md](/passwordValidate.md) |
134
+ | `i18n` / `locale` | 国际化集成(vue-i18n v8/v9+ 兼容) | [./i18n.md](/i18n.md) |
135
+ | `clipboard` | 一键复制文本到剪贴板 | [./clipboard.md](/clipboard.md) |
136
+ | `MyPrint` | 局部打印 Vue 插件 | [./print.md](/print.md) |
137
+ | `scrollTo` | 页面平滑滚动 | [./scroll-to.md](/scroll-to.md) |
138
+ | `jwks` | JWKS 公钥 RSA 加密(登录密码加密) | [./jwks.md](/jwks.md) |
139
+ | `getPageTitle` | 浏览器标签页标题生成 | [./get-page-title.md](/get-page-title.md) |
140
+ | `generateTitle` | 路由/菜单标题生成 | [./generateTitle.md](/generateTitle.md) |
141
+ | OSS 接口(19 个) | OSS 文件上传、下载、预览、删除等 | [./oss.md](/oss.md) |
142
+ | `filePreviewList` | 文件在线预览 URL 获取 | [./filePreview.md](/filePreview.md) |
143
+
144
+ ---
@@ -0,0 +1,170 @@
1
+ # auth — 认证令牌管理
2
+
3
+ 管理登录令牌及相关本地存储状态,所有键名统一加 `pit_` 前缀,底层通过 `pit.storageSet/Get/Remove/Clear` 操作 `localStorage`。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import { getToken, setToken, removeToken, removeAll } from 'pit-business-utils'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 函数列表
14
+
15
+ ### `getToken()`
16
+
17
+ 获取当前登录令牌。
18
+
19
+ | — | — |
20
+ |---|---|
21
+ | **参数** | 无 |
22
+ | **返回值** | `string \| null`,存储的 token 值,未设置时返回 `null` |
23
+
24
+ ```js
25
+ const token = getToken()
26
+ if (token) {
27
+ console.log('已登录,token:', token)
28
+ }
29
+ ```
30
+
31
+ ---
32
+
33
+ ### `setToken(token)`
34
+
35
+ 将令牌写入 `localStorage`。
36
+
37
+ | 参数 | 类型 | 必填 | 说明 |
38
+ |------|------|------|------|
39
+ | `token` | `string` | ✅ | 登录成功后服务端返回的认证令牌 |
40
+
41
+ | — | — |
42
+ |---|---|
43
+ | **返回值** | `void` |
44
+
45
+ ```js
46
+ setToken('eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...')
47
+ ```
48
+
49
+ ---
50
+
51
+ ### `removeToken()`
52
+
53
+ 删除 `localStorage` 中的令牌,通常在退出登录时调用。
54
+
55
+ | — | — |
56
+ |---|---|
57
+ | **参数** | 无 |
58
+ | **返回值** | `void` |
59
+
60
+ ```js
61
+ removeToken()
62
+ ```
63
+
64
+ ---
65
+
66
+ ### `getLock()`
67
+
68
+ 获取锁屏状态。
69
+
70
+ > ⚠️ 该功能现已较少使用,保留为兼容老版本。
71
+
72
+ | — | — |
73
+ |---|---|
74
+ | **参数** | 无 |
75
+ | **返回值** | `string \| null` |
76
+
77
+ ---
78
+
79
+ ### `setLock(lock)`
80
+
81
+ 设置锁屏状态。
82
+
83
+ | 参数 | 类型 | 必填 | 说明 |
84
+ |------|------|------|------|
85
+ | `lock` | `string` | ✅ | 锁屏状态标识值 |
86
+
87
+ | — | — |
88
+ |---|---|
89
+ | **返回值** | `void` |
90
+
91
+ ---
92
+
93
+ ### `removeLock()`
94
+
95
+ 清除锁屏状态。
96
+
97
+ | — | — |
98
+ |---|---|
99
+ | **参数** | 无 |
100
+ | **返回值** | `void` |
101
+
102
+ ---
103
+
104
+ ### `getPasswordLock()`
105
+
106
+ 获取弱密码锁定状态,用于首次登录强制修改密码的引导流程判断。
107
+
108
+ | — | — |
109
+ |---|---|
110
+ | **参数** | 无 |
111
+ | **返回值** | `string \| null` |
112
+
113
+ ```js
114
+ if (getPasswordLock()) {
115
+ // 跳转到修改密码页面
116
+ router.push('/change-password')
117
+ }
118
+ ```
119
+
120
+ ---
121
+
122
+ ### `setPasswordLock(passwordLock)`
123
+
124
+ 设置弱密码锁定标记。
125
+
126
+ | 参数 | 类型 | 必填 | 说明 |
127
+ |------|------|------|------|
128
+ | `passwordLock` | `string` | ✅ | 锁定标识,通常传 `"1"` 表示锁定 |
129
+
130
+ | — | — |
131
+ |---|---|
132
+ | **返回值** | `void` |
133
+
134
+ ---
135
+
136
+ ### `removePasswordLock()`
137
+
138
+ 清除弱密码锁定状态,通常在用户成功修改密码后调用。
139
+
140
+ | — | — |
141
+ |---|---|
142
+ | **参数** | 无 |
143
+ | **返回值** | `void` |
144
+
145
+ ---
146
+
147
+ ### `removeAll()`
148
+
149
+ 清空所有带 `pit_` 前缀的 `localStorage` 数据,通常在退出登录时调用,彻底清除用户相关缓存。
150
+
151
+ | — | — |
152
+ |---|---|
153
+ | **参数** | 无 |
154
+ | **返回值** | `void` |
155
+
156
+ ```js
157
+ // 退出登录
158
+ function logout() {
159
+ removeAll()
160
+ router.push('/login')
161
+ }
162
+ ```
163
+
164
+ ---
165
+
166
+ ## 注意事项
167
+
168
+ - 所有数据存储在 `localStorage`,浏览器关闭后数据依然保留,刷新页面不丢失。
169
+ - `removeAll()` 只清除以 `pit_` 为前缀的项,不会影响业务系统自行写入 `localStorage` 的其他数据。
170
+ - 令牌存储的实际 key 为 `pit_token`,不建议直接操作 `localStorage`,应通过本模块提供的函数访问。
@@ -0,0 +1,72 @@
1
+ # clipboard — 剪贴板复制
2
+
3
+ 提供一键复制文本到系统剪贴板的能力,复制成功/失败后自动弹出全局消息提示。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import { copyClipboard } from 'pit-business-utils'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 全局依赖
14
+
15
+ > ⚠️ **使用前必须在宿主项目中完成以下配置:**
16
+
17
+ | 全局变量 | 作用 |
18
+ |----------|------|
19
+ | `window.vm` | Vue 根实例,用于调用 `window.vm.$message` 弹出提示 |
20
+
21
+ ```js
22
+ // main.js
23
+ const vm = new Vue({ render: h => h(App) }).$mount('#app')
24
+ window.vm = vm
25
+ ```
26
+
27
+ ---
28
+
29
+ ## 函数
30
+
31
+ ### `copyClipboard(text, event)`
32
+
33
+ 将指定文本复制到系统剪贴板,复制结果通过全局 `$message` 提示用户。
34
+
35
+ | 参数 | 类型 | 必填 | 说明 |
36
+ |------|------|------|------|
37
+ | `text` | `string` | ✅ | 需要复制到剪贴板的文本内容 |
38
+ | `event` | `Event` | ✅ | 触发复制的 DOM 事件对象(如点击事件),用于定位目标元素 |
39
+
40
+ | — | — |
41
+ |---|---|
42
+ | **返回值** | `void` |
43
+ | **成功提示** | 弹出成功 `$message`,文本来自 i18n |
44
+ | **失败提示** | 弹出错误 `$message`,文本来自 i18n |
45
+
46
+ ### 使用示例
47
+
48
+ ```html
49
+ <!-- 在模板点击事件中直接传入 $event -->
50
+ <template>
51
+ <el-button @click="handleCopy(record.code, $event)">复制编号</el-button>
52
+ </template>
53
+ ```
54
+
55
+ ```js
56
+ import { copyClipboard } from 'pit-business-utils'
57
+
58
+ methods: {
59
+ handleCopy(text, event) {
60
+ copyClipboard(text, event)
61
+ }
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 注意事项
68
+
69
+ - `event` 参数**不可省略**,`clipboard.js` 底层需要绑定到触发元素上才能执行复制操作。
70
+ - 该函数依赖浏览器的 `execCommand('copy')` 或 Clipboard API(由 `clipboard` 库处理兼容性),在部分旧版或非 HTTPS 环境下可能失败。
71
+ - `window.vm` 必须在 `main.js` 中挂载,否则成功/失败提示无法显示(会报 `TypeError`)。
72
+ - 每次调用都会创建并立即销毁一个 `Clipboard` 实例,不会造成内存泄漏。
@@ -0,0 +1,60 @@
1
+ # filePreview — 文件预览 API
2
+
3
+ 封装文件在线预览 URL 的获取接口,通常与 `getPreviewUrl`(utils 模块)配合使用。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import { filePreviewList } from 'pit-business-utils'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 函数
14
+
15
+ ### `filePreviewList(data)`
16
+
17
+ 批量获取文件的在线预览 URL 列表。
18
+
19
+ | 参数 | 类型 | 必填 | 说明 |
20
+ |------|------|------|------|
21
+ | `data` | `Array` | ✅ | 预览参数数组,每项包含文件 ID 等信息(具体字段由后端接口定义) |
22
+
23
+ | — | — |
24
+ |---|---|
25
+ | **接口** | `POST /preview-url` |
26
+ | **返回值** | `Promise<Array>`,包含每个文件对应的预览 URL 信息 |
27
+
28
+ ---
29
+
30
+ ## 使用示例
31
+
32
+ ```js
33
+ import { filePreviewList } from 'pit-business-utils'
34
+
35
+ // 获取多个文件的预览链接
36
+ const files = [
37
+ { fileUploadRecordId: 'id-001' },
38
+ { fileUploadRecordId: 'id-002' }
39
+ ]
40
+
41
+ const previewUrls = await filePreviewList(files)
42
+ // previewUrls: [{ fileUploadRecordId: 'id-001', previewUrl: 'https://...' }, ...]
43
+ ```
44
+
45
+ ```js
46
+ // 与 utils 中的 getPreviewUrl 配合使用
47
+ import { getPreviewUrl, filePreviewList } from 'pit-business-utils'
48
+
49
+ // getPreviewUrl 内部会调用 filePreviewList 获取预览地址
50
+ const url = await getPreviewUrl({ fileId: 'file-id-xxx' }, 'fileId')
51
+ window.open(url)
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 注意事项
57
+
58
+ - 该接口通常不需要直接调用,`utils.getPreviewUrl()` 已将其封装,推荐通过 `getPreviewUrl` 获取预览链接。
59
+ - 接口地址为 `/preview-url`,实际 baseURL 来自宿主项目的 `window.setConfigCallback` 配置。
60
+ - 参数数组中每项的具体字段(如是否需要 `previewType`、`objectName` 等)取决于后端接口定义,请参考后端文档。
@@ -0,0 +1,75 @@
1
+ # formValidate — 表单正则校验
2
+
3
+ 为 Element UI 表单提供预定义规则校验器以及自定义正则校验能力,返回符合 el-form `rules` 规范的验证函数。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import { formValidate } from 'pit-business-utils'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 函数
14
+
15
+ ### `formValidate(type, msg)`
16
+
17
+ 生成适用于 Element UI `el-form` 的字段验证函数。
18
+
19
+ | 参数 | 类型 | 必填 | 说明 |
20
+ |------|------|------|------|
21
+ | `type` | `string` | ✅ | 预定义规则名(见下方规则表),或直接传入自定义正则表达式字符串 |
22
+ | `msg` | `string` | — | 校验失败时显示的提示文本;不传则使用 i18n 翻译提示,均无时显示空字符串 |
23
+
24
+ | — | — |
25
+ |---|---|
26
+ | **返回值** | `Function(rule, value, callback)`,Element UI 校验器回调函数 |
27
+
28
+ ### 使用示例
29
+
30
+ ```js
31
+ // 使用预定义规则
32
+ rules: {
33
+ phone: [{ validator: formValidate('iphone', '请输入正确的手机号'), trigger: 'blur' }],
34
+ email: [{ validator: formValidate('email'), trigger: 'blur' }],
35
+ idCard: [{ validator: formValidate('idCard', '身份证号格式错误'), trigger: 'blur' }],
36
+ }
37
+ ```
38
+
39
+ ```js
40
+ // 使用自定义正则字符串
41
+ rules: {
42
+ postCode: [{ validator: formValidate('^[0-9]{6}$', '邮政编码为6位数字'), trigger: 'blur' }]
43
+ }
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 内置校验规则表
49
+
50
+ | 规则名 | 说明 | 示例合法值 |
51
+ |--------|------|-----------|
52
+ | `iphone` | 手机号(1[3-9]开头,11位数字) | `13812345678` |
53
+ | `password` | 密码(6-16位,必须同时含字母和数字) | `abc12345` |
54
+ | `idCard` | 18位居民身份证号(含校验位X) | `110101199001011234` |
55
+ | `email` | 电子邮箱 | `user@example.com` |
56
+ | `plateNumber` | 车牌号(含新能源车牌) | `粤A12345`、`粤AD12345` |
57
+ | `chinese` | 纯汉字 | `张三` |
58
+ | `enCode` | 字母、数字、点的组合(编码格式) | `A.001`、`abc123` |
59
+ | `enCode2` | 同 `enCode`(字母数字及点) | `node.v1` |
60
+ | `userAccount` | 纯字母数字账号 | `admin123` |
61
+ | `userAccount1` | 字母数字及中文字符账号 | `张三001` |
62
+ | `english` | 纯英文字母(大小写均可) | `HelloWorld` |
63
+ | `fullName` | 字母、数字、汉字组合名称 | `张三A1` |
64
+ | `userCode` | 纯数字编号 | `00123` |
65
+ | `allDate` | 整数或 `.5` 结尾的小数(如工时) | `8`、`4.5` |
66
+ | `bigInt` | 正整数(不含 0 开头) | `100`、`99` |
67
+ | `netUrl` | HTTP / HTTPS / FTP URL | `https://www.example.com` |
68
+
69
+ ---
70
+
71
+ ## 注意事项
72
+
73
+ - `formValidate` 仅在值**不为空**时触发正则校验;空值不会报错,因此**必填验证需另加 `required: true` 规则**。
74
+ - 自定义正则传入的是正则字符串(如 `'^[0-9]{6}$'`),内部使用 `new RegExp(type)` 构造,注意转义规则。
75
+ - 若项目配置了 i18n,校验失败提示会自动走国际化翻译;如需统一中文提示,在 `msg` 参数中直接传入即可。
@@ -0,0 +1,49 @@
1
+ # generateTitle — 路由标题生成
2
+
3
+ 根据路由元信息中的标题字段,生成菜单或面包屑等处展示用的路由标题文本。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import { generateTitle } from 'pit-business-utils'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 函数
14
+
15
+ ### `generateTitle(title, fullName)`
16
+
17
+ 优先返回 `fullName`,若 `fullName` 为空则返回 `title`。常用于路由菜单渲染中国际化标题和默认标题的优先级切换。
18
+
19
+ | 参数 | 类型 | 必填 | 说明 |
20
+ |------|------|------|------|
21
+ | `title` | `string` | ✅ | 默认标题(备用值,通常为路由 `meta.title`) |
22
+ | `fullName` | `string` | — | 优先显示的完整标题(通常来自后端菜单接口返回的名称) |
23
+
24
+ | — | — |
25
+ |---|---|
26
+ | **返回值** | `string`,`fullName` 非空时返回 `fullName`,否则返回 `title` |
27
+
28
+ ---
29
+
30
+ ## 使用示例
31
+
32
+ ```js
33
+ generateTitle('项目列表', '工程项目管理') // "工程项目管理"(优先返回 fullName)
34
+ generateTitle('项目列表', '') // "项目列表"(fullName 为空,回退)
35
+ generateTitle('项目列表', undefined) // "项目列表"
36
+ ```
37
+
38
+ ```js
39
+ // 在侧边菜单组件中使用
40
+ // route.meta.title 为路由配置中的默认标题
41
+ // route.meta.fullName 为后端菜单接口返回的自定义名称
42
+ <span>{{ generateTitle(route.meta.title, route.meta.fullName) }}</span>
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 注意事项
48
+
49
+ - 逻辑等价于 `fullName || title`,当 `fullName` 为任意 falsy 值(`""`、`null`、`undefined`、`0`)时均返回 `title`。
@@ -0,0 +1,65 @@
1
+ # get-page-title — 页面标题生成
2
+
3
+ 根据当前路由页面名称和系统名称,生成浏览器标签页的完整标题字符串,格式为 `"页面名 - 系统名"`。
4
+
5
+ ## 引用方式
6
+
7
+ ```js
8
+ import { getPageTitle } from 'pit-business-utils'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 全局依赖
14
+
15
+ > ⚠️ **系统标题从 `window._store` 中读取,宿主项目需提前注入。**
16
+
17
+ | 全局变量 | 读取路径 | 说明 |
18
+ |----------|----------|------|
19
+ | `window._store` | `window._store.state.settings.title` | Vuex store 实例,用于读取系统名称配置 |
20
+
21
+ 若 `window._store` 未注入,则使用默认系统名称 `"工程项目建设管理系统"`。
22
+
23
+ ---
24
+
25
+ ## 函数
26
+
27
+ ### `getPageTitle(key, fullName)`
28
+
29
+ 生成页面标题字符串。
30
+
31
+ | 参数 | 类型 | 必填 | 说明 |
32
+ |------|------|------|------|
33
+ | `key` | `string` | — | 保留参数,当前版本未使用,传 `""` 或任意字符串即可 |
34
+ | `fullName` | `string` | — | 当前页面的名称;不传或为空时,仅返回系统名称 |
35
+
36
+ | — | — |
37
+ |---|---|
38
+ | **返回值** | `string`,格式为 `"页面名 - 系统名"` 或仅 `"系统名"` |
39
+
40
+ ---
41
+
42
+ ## 使用示例
43
+
44
+ ```js
45
+ // 在 Vue Router 的路由守卫中统一设置页面标题
46
+ import { getPageTitle } from 'pit-business-utils'
47
+
48
+ router.afterEach((to) => {
49
+ document.title = getPageTitle('', to.meta.title)
50
+ // to.meta.title = "项目列表" → document.title = "项目列表 - 工程项目建设管理系统"
51
+ })
52
+ ```
53
+
54
+ ```js
55
+ getPageTitle('', '项目列表') // "项目列表 - 工程项目建设管理系统"
56
+ getPageTitle('', '') // "工程项目建设管理系统"
57
+ getPageTitle('', undefined) // "工程项目建设管理系统"
58
+ ```
59
+
60
+ ---
61
+
62
+ ## 注意事项
63
+
64
+ - 第一个参数 `key` 为保留参数,当前不参与逻辑,传入任意值均不影响结果。
65
+ - 系统标题优先从 `window._store.state.settings.title` 读取,若 Vuex store 未注入,降级为硬编码的默认值 `"工程项目建设管理系统"`。