@xjw_/vue2-npm-system 1.0.65 → 1.0.66

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 CHANGED
@@ -41,6 +41,56 @@ Vue.component('JcInput', JcInput)
41
41
  Vue.component('JcTable', JcTable)
42
42
  ```
43
43
 
44
+ ## 工具函数
45
+
46
+ ### createRequest 请求封装
47
+
48
+ 基于 axios 的通用请求封装,支持统一的错误处理和 token 管理。
49
+
50
+ ```javascript
51
+ import { createRequest } from '@xjw_/vue2-npm-system'
52
+
53
+ // 创建请求实例
54
+ const request = createRequest({
55
+ baseURL: 'http://api.example.com',
56
+ timeout: 30000,
57
+ // 获取 token 的方法
58
+ getToken: () => {
59
+ return localStorage.getItem('token')
60
+ },
61
+ // Token 过期回调
62
+ onTokenExpired: () => {
63
+ // 清除 token,跳转登录页等
64
+ localStorage.removeItem('token')
65
+ window.location.href = '/login'
66
+ },
67
+ // 自定义成功状态码
68
+ successCodes: [200, 2000, 3000]
69
+ })
70
+
71
+ // 使用请求实例
72
+ export function getUserList(params, pageSize, pageNum) {
73
+ return request({
74
+ url: '/api/user/list',
75
+ method: 'post',
76
+ data: {
77
+ ...params,
78
+ pageSize,
79
+ pageNum
80
+ }
81
+ })
82
+ }
83
+ ```
84
+
85
+ **配置项:**
86
+ - `baseURL`: API 基础地址
87
+ - `timeout`: 超时时间(毫秒)
88
+ - `getToken`: 获取 token 的函数
89
+ - `onTokenExpired`: Token 过期时的回调
90
+ - `successCodes`: 成功的状态码数组 (默认: [200, 2000, 3000])
91
+ - `errorHandler`: 自定义错误处理函数
92
+ - `headers`: 额外的请求头
93
+
44
94
  ## 组件列表
45
95
 
46
96
  ### JcButton 按钮
@@ -178,6 +228,77 @@ export default {
178
228
  - `change`: 改变事件
179
229
  - `visible-change`: 显示/隐藏事件
180
230
 
231
+ ### XBusinessLog 业务日志查询
232
+
233
+ 集成的业务日志查询组件,包含搜索栏和数据表格。
234
+
235
+ ```vue
236
+ <template>
237
+ <div class="app-container">
238
+ <x-business-log
239
+ ref="businessLog"
240
+ :api-method="selectSysBusinessLogList"
241
+ :page-size="10"
242
+ :parse-time-method="parseTime"
243
+ />
244
+ </div>
245
+ </template>
246
+
247
+ <script>
248
+ import { selectSysBusinessLogList } from "@/api/system/log"
249
+
250
+ export default {
251
+ name: "BusinessLog",
252
+ methods: {
253
+ // 自定义时间格式化(可选)
254
+ parseTime(time) {
255
+ if (!time) return ''
256
+ const date = new Date(time)
257
+ // 你的格式化逻辑
258
+ return formattedTime
259
+ }
260
+ }
261
+ }
262
+ </script>
263
+ ```
264
+
265
+ **Props:**
266
+ - `apiMethod`: API 请求方法 (必需),接收 `(params, pageSize, pageNum)` 参数
267
+ - `pageSize`: 每页条数 (默认: 10)
268
+ - `parseTimeMethod`: 自定义时间格式化函数 (可选)
269
+
270
+ **Methods:**
271
+ - `resetForm()`: 重置表单并重新查询
272
+ - `refresh()`: 刷新列表
273
+ - `getList()`: 获取数据列表
274
+
275
+ **API 方法要求:**
276
+
277
+ 传入的 `apiMethod` 应该返回 Promise,响应格式为:
278
+ ```javascript
279
+ {
280
+ rows: [], // 数据列表
281
+ total: 0 // 总条数
282
+ }
283
+ ```
284
+
285
+ 示例 API 封装:
286
+ ```javascript
287
+ import request from '@/utils/request'
288
+
289
+ export function selectSysBusinessLogList(params, pageSize, pageNum) {
290
+ return request({
291
+ url: '/system/business-log/list',
292
+ method: 'post',
293
+ data: {
294
+ ...params,
295
+ pageSize,
296
+ pageNum
297
+ }
298
+ })
299
+ }
300
+ ```
301
+
181
302
  ### JcTable 表格
182
303
 
183
304
  增强的表格组件,支持动态列配置和分页。