@indfnd/utils 0.1.0 → 0.1.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.
- package/CHANGELOG.md +25 -0
- package/dist/ind-utils.es.js +68 -17
- package/dist/ind-utils.umd.cjs +19 -19
- package/package.json +2 -2
- package/src/api/index-desc.ts +6 -6
- package/src/utils/request/index.ts +1 -1
- package/src/utils/table.ts +81 -11
- package/src/utils/validate.ts +2 -2
- package/types/api/index-desc.d.ts +1 -9
- package/types/api/index-desc.d.ts.map +1 -1
- package/types/utils/request/index.d.ts.map +1 -1
- package/types/utils/table.d.ts +8 -1
- package/types/utils/table.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indfnd/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "huxuetong",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"type-check": "vue-tsc --noEmit -p tsconfig.json --composite false",
|
|
28
28
|
"build-only": "vite build",
|
|
29
29
|
"dts": "rimraf types/ && vue-tsc -p tsconfig.types.json",
|
|
30
|
-
"release": "node build/auto-build.js && yarn release-
|
|
30
|
+
"release": "node build/auto-build.js && yarn release-patch && git push --follow-tags && yarn re-publish",
|
|
31
31
|
"release-major": "standard-version --release-as major",
|
|
32
32
|
"release-minor": "standard-version --release-as minor",
|
|
33
33
|
"release-patch": "standard-version --release-as patch",
|
package/src/api/index-desc.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { config } from '@/config'
|
|
|
4
4
|
const UC_CONTEXT = config.ucExtServerContext
|
|
5
5
|
|
|
6
6
|
export function listIndexDescApi(params) {
|
|
7
|
-
return Promise.resolve({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
7
|
+
// return Promise.resolve({
|
|
8
|
+
// data: [
|
|
9
|
+
// { indexCode: 'comName', indexName: '商业公司', indexDesc: '这个是商业公司的描述' },
|
|
10
|
+
// { indexCode: 'comSname', indexName: '商业公司简称', indexDesc: '这个是商业公司简称的描述' },
|
|
11
|
+
// ],
|
|
12
|
+
// })
|
|
13
13
|
return axios.get(`${UC_CONTEXT}/index-desc/list`, { params })
|
|
14
14
|
}
|
|
@@ -7,7 +7,7 @@ export * from './url-params'
|
|
|
7
7
|
export * from './content-type'
|
|
8
8
|
export { responseInterceptors }
|
|
9
9
|
|
|
10
|
-
const instance: AxiosExtendsInstance = axios.create({ timeout: 60 * 1000 })
|
|
10
|
+
const instance: AxiosExtendsInstance = axios.create({ timeout: 5 * 60 * 1000 })
|
|
11
11
|
instance.interceptors.request.use(requestInterceptors, inspectorError)
|
|
12
12
|
instance.interceptors.response.use(responseInterceptors, inspectorError)
|
|
13
13
|
|
package/src/utils/table.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @Author: huxuetong
|
|
3
3
|
* @Date: 2023-10-27 15:05:25
|
|
4
4
|
* @Last Modified by: huxuetong
|
|
5
|
-
* @Last Modified time: 2024-03-
|
|
5
|
+
* @Last Modified time: 2024-03-27 18:18:47
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import _ from 'lodash'
|
|
9
|
-
import { isFunction, isNil } from './is-type'
|
|
8
|
+
import _, { head } from 'lodash'
|
|
9
|
+
import { isFunction, isNil, isString } from './is-type'
|
|
10
10
|
|
|
11
11
|
const GROUP_SEP = '__'
|
|
12
12
|
const VALUE_SEP = '--'
|
|
@@ -42,6 +42,12 @@ interface row2columnOption {
|
|
|
42
42
|
keyPropName?: string
|
|
43
43
|
// 组织后表格列定义title对应属性名称
|
|
44
44
|
titlePropName?: string
|
|
45
|
+
// 合计列的扁平化定义
|
|
46
|
+
sumColumnDefs?: Array<{ key: string; title: string; [propName: string]: any }>
|
|
47
|
+
// 合计列的key
|
|
48
|
+
sumColKeyProp?: 'sumColCode'
|
|
49
|
+
// 合计列的title
|
|
50
|
+
sumColTitleProp?: 'sumColName'
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
interface Column {
|
|
@@ -112,7 +118,8 @@ function renderColumnTree(
|
|
|
112
118
|
|
|
113
119
|
// 动态列
|
|
114
120
|
if (keyProp) {
|
|
115
|
-
let columnUniqData =
|
|
121
|
+
let columnUniqData =
|
|
122
|
+
_.uniqBy(data, columnGroup.keyProp)?.filter((item) => !isNil(item[columnGroup.keyProp])) || []
|
|
116
123
|
if (sortProp) {
|
|
117
124
|
const unSortData = columnUniqData.filter((item) => isNil(item[sortProp]))
|
|
118
125
|
const sortData = columnUniqData.filter((item) => !isNil(item[sortProp]))
|
|
@@ -230,6 +237,49 @@ function renderRowData(data: Array<any>, keys: string[]) {
|
|
|
230
237
|
return value
|
|
231
238
|
}
|
|
232
239
|
|
|
240
|
+
function getRowKeyValue(item: any, rowKey: string | string[]): string {
|
|
241
|
+
if (!item) return ''
|
|
242
|
+
if (isString(rowKey)) return item[rowKey] || ''
|
|
243
|
+
for (const key of rowKey) {
|
|
244
|
+
if (item[key]) {
|
|
245
|
+
return item[key]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return ''
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function renderSumColumn(keys, titles, idx, columns, def) {
|
|
252
|
+
if (idx >= keys.length) return
|
|
253
|
+
|
|
254
|
+
const key = keys[idx]
|
|
255
|
+
let header = _.find(columns, { key })
|
|
256
|
+
if (!header) {
|
|
257
|
+
header = { key, title: titles[idx], children: [] }
|
|
258
|
+
columns.push(header)
|
|
259
|
+
|
|
260
|
+
if (idx === keys.length - 1) {
|
|
261
|
+
Object.assign(header, def, { title: titles[idx] })
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
renderSumColumn(keys, titles, idx + 1, header.children, def)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function renderSumColumns({ sumColumnDefs }: row2columnOption): Column[] {
|
|
270
|
+
const columns = []
|
|
271
|
+
|
|
272
|
+
for (const def of sumColumnDefs) {
|
|
273
|
+
const { key, title } = def
|
|
274
|
+
const keys = key.split(GROUP_SEP)
|
|
275
|
+
const titles = title.split(GROUP_SEP)
|
|
276
|
+
|
|
277
|
+
renderSumColumn(keys, titles, 0, columns, def)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return columns
|
|
281
|
+
}
|
|
282
|
+
|
|
233
283
|
/**
|
|
234
284
|
* 行转列公共方法
|
|
235
285
|
* ! 目前是根据非动态列下全是非动态列的分组来组织的,若动态列和非动态列相互穿插分组,那就糟糕了
|
|
@@ -243,22 +293,42 @@ function renderRowData(data: Array<any>, keys: string[]) {
|
|
|
243
293
|
export function row2column(
|
|
244
294
|
data: Array<any> = [],
|
|
245
295
|
columnGroups: ColumnGroup[] = [],
|
|
246
|
-
rowKey: string,
|
|
296
|
+
rowKey: string | string[],
|
|
247
297
|
option: row2columnOption = {},
|
|
248
298
|
): row2columnResult {
|
|
249
299
|
// 组织表头
|
|
250
|
-
const columns =
|
|
251
|
-
|
|
252
|
-
|
|
300
|
+
const columns = []
|
|
301
|
+
if (option.sumColumnDefs && option.sumColumnDefs.length) {
|
|
302
|
+
columns.push(...renderSumColumns(option))
|
|
303
|
+
}
|
|
304
|
+
const groupColumns =
|
|
305
|
+
_.flatten<Column>(columnGroups.map((group) => renderColumnTree(data, group, option))) || []
|
|
306
|
+
columns.push(...groupColumns)
|
|
253
307
|
const leafColumns = getLeafColumns(columns)
|
|
254
308
|
|
|
255
309
|
// 组织数据
|
|
256
|
-
const rowKeyUniqData =
|
|
257
|
-
|
|
310
|
+
const rowKeyUniqData =
|
|
311
|
+
_.uniqBy(data, (item) => getRowKeyValue(item, rowKey))?.filter(
|
|
312
|
+
(item) => !isNil(getRowKeyValue(item, rowKey)),
|
|
313
|
+
) || []
|
|
314
|
+
const groupData = _.groupBy(data, (item) => getRowKeyValue(item, rowKey))
|
|
258
315
|
const rltData = rowKeyUniqData.map((item) => {
|
|
259
|
-
const
|
|
316
|
+
const rowKeyValue = getRowKeyValue(item, rowKey)
|
|
317
|
+
const rowGroupData = groupData[rowKeyValue] || []
|
|
260
318
|
const newItem = { ...item }
|
|
261
319
|
|
|
320
|
+
if (option.sumColumnDefs && option.sumColumnDefs.length) {
|
|
321
|
+
option.sumColumnDefs.forEach((def) => {
|
|
322
|
+
const { key } = def
|
|
323
|
+
const keys = key.split(GROUP_SEP) || []
|
|
324
|
+
const code = keys?.[0] || ''
|
|
325
|
+
const indexCol = keys?.[keys.length - 1] || ''
|
|
326
|
+
const { sumColKeyProp = 'sumColCode' } = option
|
|
327
|
+
const itemData = _.find(rowGroupData, { [sumColKeyProp]: code }) || {}
|
|
328
|
+
newItem[key] = itemData[indexCol]
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
262
332
|
leafColumns.forEach((column) => {
|
|
263
333
|
const columnKey: string = column[option.keyPropName || 'key'] || ''
|
|
264
334
|
const keys = columnKey.split(GROUP_SEP) || []
|
package/src/utils/validate.ts
CHANGED
|
@@ -135,7 +135,7 @@ export function checkTel(val) {
|
|
|
135
135
|
export function checkVehicleNo(str: string): boolean {
|
|
136
136
|
// 新能源车
|
|
137
137
|
const newReg =
|
|
138
|
-
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z]-(([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))$/
|
|
138
|
+
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](-)?(([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))$/
|
|
139
139
|
|
|
140
140
|
if (newReg.test(str)) {
|
|
141
141
|
return true
|
|
@@ -143,7 +143,7 @@ export function checkVehicleNo(str: string): boolean {
|
|
|
143
143
|
|
|
144
144
|
// 非新能源车
|
|
145
145
|
const reg =
|
|
146
|
-
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z]-[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/
|
|
146
|
+
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](-)?[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/
|
|
147
147
|
|
|
148
148
|
return reg.test(str)
|
|
149
149
|
}
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
export declare function listIndexDescApi(params: any):
|
|
2
|
-
| Promise<import('axios').AxiosResponse<any>>
|
|
3
|
-
| Promise<{
|
|
4
|
-
data: {
|
|
5
|
-
indexCode: string
|
|
6
|
-
indexName: string
|
|
7
|
-
indexDesc: string
|
|
8
|
-
}[]
|
|
9
|
-
}>
|
|
1
|
+
export declare function listIndexDescApi(params: any): Promise<import('axios').AxiosResponse<any>>
|
|
10
2
|
//# sourceMappingURL=index-desc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-desc.d.ts","sourceRoot":"","sources":["../../src/api/index-desc.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,CAAC,MAAM,KAAA
|
|
1
|
+
{"version":3,"file":"index-desc.d.ts","sourceRoot":"","sources":["../../src/api/index-desc.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,CAAC,MAAM,KAAA,+CAQtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/request/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAuB,oBAAoB,EAAkB,MAAM,gBAAgB,CAAA;AAG1F,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAE/B,QAAA,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/request/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAuB,oBAAoB,EAAkB,MAAM,gBAAgB,CAAA;AAG1F,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAE/B,QAAA,MAAM,QAAQ,EAAE,oBAA+D,CAAA;AAU/E,OAAO,EAAE,QAAQ,IAAI,KAAK,EAAE,CAAA"}
|
package/types/utils/table.d.ts
CHANGED
|
@@ -15,6 +15,13 @@ interface ColumnGroup {
|
|
|
15
15
|
interface row2columnOption {
|
|
16
16
|
keyPropName?: string
|
|
17
17
|
titlePropName?: string
|
|
18
|
+
sumColumnDefs?: Array<{
|
|
19
|
+
key: string
|
|
20
|
+
title: string
|
|
21
|
+
[propName: string]: any
|
|
22
|
+
}>
|
|
23
|
+
sumColKeyProp?: 'sumColCode'
|
|
24
|
+
sumColTitleProp?: 'sumColName'
|
|
18
25
|
}
|
|
19
26
|
interface Column {
|
|
20
27
|
key?: string
|
|
@@ -39,7 +46,7 @@ interface row2columnResult {
|
|
|
39
46
|
export declare function row2column(
|
|
40
47
|
data: Array<any>,
|
|
41
48
|
columnGroups: ColumnGroup[],
|
|
42
|
-
rowKey: string,
|
|
49
|
+
rowKey: string | string[],
|
|
43
50
|
option?: row2columnOption,
|
|
44
51
|
): row2columnResult
|
|
45
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/ut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