t20-common-lib 0.15.5 → 0.15.7
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/package.json +1 -1
- package/packages/dynamic-form/src/components/Dialog.vue +1 -1
- package/packages/dynamic-form/src/components/LazySelect.vue +1 -1
- package/packages/dynamic-form/src/components/ScrollLoadSelect.vue +36 -38
- package/packages/dynamic-form/src/components/Select.vue +1 -1
- package/packages/dynamic-form/src/components/SelectTree.vue +1 -1
- package/src/api/common.js +28 -0
- package/src/utils/request.js +20 -0
- package/packages/dynamic-form/src/utils/request.js +0 -19
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
<script>
|
|
28
28
|
import dayjs from 'dayjs'
|
|
29
29
|
/* 各属性,方法参考el-select */
|
|
30
|
-
import { getDataForPost, getDataForGet } from '
|
|
30
|
+
import { getDataForPost, getDataForGet } from '../../../../src/api/common'
|
|
31
31
|
export default {
|
|
32
32
|
name: "SelectLazy",
|
|
33
33
|
props: {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</template>
|
|
11
11
|
|
|
12
12
|
<script>
|
|
13
|
-
import { getDataForGet, getDataForPost } from '
|
|
13
|
+
import { getDataForGet, getDataForPost } from '../../../../src/api/common'
|
|
14
14
|
|
|
15
15
|
export default {
|
|
16
16
|
name: 'ScrollLoadSelect',
|
|
@@ -63,10 +63,10 @@ export default {
|
|
|
63
63
|
}
|
|
64
64
|
return this.$attrs.requestFn || this.$attrs['request-fn'] || this.fetchByStaticOptions
|
|
65
65
|
},
|
|
66
|
-
shouldAutoLoad() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
66
|
+
// shouldAutoLoad() {
|
|
67
|
+
// const autoLoad = this.items?.props?.autoLoad ?? this.$attrs.autoLoad
|
|
68
|
+
// return autoLoad !== false
|
|
69
|
+
// },
|
|
70
70
|
passThroughProps() {
|
|
71
71
|
return {
|
|
72
72
|
...this.$attrs,
|
|
@@ -81,18 +81,18 @@ export default {
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
mounted() {
|
|
84
|
-
this.triggerInitialRequest()
|
|
84
|
+
// this.triggerInitialRequest()
|
|
85
85
|
},
|
|
86
86
|
methods: {
|
|
87
|
-
triggerInitialRequest() {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
87
|
+
// triggerInitialRequest() {
|
|
88
|
+
// if (!this.shouldAutoLoad) return
|
|
89
|
+
// this.$nextTick(() => {
|
|
90
|
+
// const instance = this.$refs.scrollLoadSelect
|
|
91
|
+
// if (instance && typeof instance.handleFilter === 'function') {
|
|
92
|
+
// instance.handleFilter('')
|
|
93
|
+
// }
|
|
94
|
+
// })
|
|
95
|
+
// },
|
|
96
96
|
resolvePath(data, path) {
|
|
97
97
|
if (!path) return data
|
|
98
98
|
return String(path)
|
|
@@ -111,41 +111,39 @@ export default {
|
|
|
111
111
|
return item
|
|
112
112
|
})
|
|
113
113
|
},
|
|
114
|
-
setDeepValue(target, path, value) {
|
|
115
|
-
const keys = String(path || '').split('.').filter(Boolean)
|
|
116
|
-
if (keys.length === 0) return
|
|
117
|
-
let cur = target
|
|
118
|
-
for (let i = 0; i < keys.length - 1; i += 1) {
|
|
119
|
-
const key = keys[i]
|
|
120
|
-
if (!cur[key] || typeof cur[key] !== 'object' || Array.isArray(cur[key])) {
|
|
121
|
-
cur[key] = {}
|
|
122
|
-
}
|
|
123
|
-
cur = cur[key]
|
|
124
|
-
}
|
|
125
|
-
cur[keys[keys.length - 1]] = value
|
|
126
|
-
},
|
|
127
114
|
buildPagingParams(params, apiConfig) {
|
|
128
115
|
const pageConfig = apiConfig?.page || {}
|
|
116
|
+
const method = String(apiConfig?.requestMethod || '').toUpperCase()
|
|
129
117
|
const currentKey = pageConfig.current || 'current'
|
|
130
118
|
const sizeKey = pageConfig.size || 'size'
|
|
131
119
|
const currentVal = params.current
|
|
132
120
|
const sizeVal = params.size
|
|
133
121
|
|
|
134
|
-
//
|
|
135
|
-
if (
|
|
122
|
+
// GET: 直接按配置 key 传查询参数(支持 page.current/page.size)
|
|
123
|
+
if (method === 'GET') {
|
|
136
124
|
return {
|
|
137
|
-
[
|
|
138
|
-
|
|
139
|
-
|
|
125
|
+
[currentKey]: currentVal,
|
|
126
|
+
[sizeKey]: sizeVal
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// POST: 如果配置是 page.current/page.size,则转为 { page: { current, size } }
|
|
131
|
+
const currentParts = String(currentKey).split('.')
|
|
132
|
+
const sizeParts = String(sizeKey).split('.')
|
|
133
|
+
if (currentParts.length === 2 && sizeParts.length === 2 && currentParts[0] === sizeParts[0]) {
|
|
134
|
+
return {
|
|
135
|
+
[currentParts[0]]: {
|
|
136
|
+
[currentParts[1]]: currentVal,
|
|
137
|
+
[sizeParts[1]]: sizeVal
|
|
140
138
|
}
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
141
|
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
// POST 兜底:平铺参数
|
|
143
|
+
return {
|
|
144
|
+
[currentKey]: currentVal,
|
|
145
|
+
[sizeKey]: sizeVal
|
|
146
|
+
}
|
|
149
147
|
},
|
|
150
148
|
async fetchByApiConfig(params = {}) {
|
|
151
149
|
const apiConfig = this.items?.api || {}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<script>
|
|
32
32
|
import dayjs from 'dayjs'
|
|
33
33
|
import clickoutside from 'element-ui/src/utils/clickoutside'
|
|
34
|
-
import { getDataForPost, getDataForGet } from '
|
|
34
|
+
import { getDataForPost, getDataForGet } from '../../../../src/api/common'
|
|
35
35
|
export default {
|
|
36
36
|
name: "Select",
|
|
37
37
|
props: {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script>
|
|
16
16
|
import clickoutside from 'element-ui/src/utils/clickoutside'
|
|
17
|
-
import { getDataForPost, getDataForGet } from '
|
|
17
|
+
import { getDataForPost, getDataForGet } from '../../../../src/api/common'
|
|
18
18
|
export default {
|
|
19
19
|
name: 'SelectTree',
|
|
20
20
|
props: {
|
package/src/api/common.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import request from '@/utils/request'
|
|
2
2
|
|
|
3
|
+
function normalizeHeaders(headers = {}) {
|
|
4
|
+
if (!headers || typeof headers !== 'object') return {}
|
|
5
|
+
if (headers.headers && typeof headers.headers === 'object') {
|
|
6
|
+
return headers.headers
|
|
7
|
+
}
|
|
8
|
+
return headers
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
// 单位本位币
|
|
4
12
|
export function getUnitCurrency(unitNo) {
|
|
5
13
|
// return request({
|
|
@@ -30,4 +38,24 @@ export function getCommonConfig(params = {}) {
|
|
|
30
38
|
cache:true,
|
|
31
39
|
params
|
|
32
40
|
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getDataForGet(url, params = {}, headers = {}) {
|
|
44
|
+
return request({
|
|
45
|
+
url,
|
|
46
|
+
method: 'get',
|
|
47
|
+
loading: false,
|
|
48
|
+
params,
|
|
49
|
+
headers: normalizeHeaders(headers)
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getDataForPost(url, data = {}, headers = {}) {
|
|
54
|
+
return request({
|
|
55
|
+
url,
|
|
56
|
+
method: 'post',
|
|
57
|
+
loading: false,
|
|
58
|
+
data,
|
|
59
|
+
headers: normalizeHeaders(headers)
|
|
60
|
+
})
|
|
33
61
|
}
|
package/src/utils/request.js
CHANGED
|
@@ -81,4 +81,24 @@ service.interceptors.response.use(
|
|
|
81
81
|
}
|
|
82
82
|
)
|
|
83
83
|
|
|
84
|
+
function normalizeConfig(headers = {}) {
|
|
85
|
+
if (!headers || typeof headers !== 'object') return {}
|
|
86
|
+
// 兼容调用方直接传 { headers: {...} } 或扁平对象两种方式
|
|
87
|
+
if (headers.headers && typeof headers.headers === 'object') {
|
|
88
|
+
return headers
|
|
89
|
+
}
|
|
90
|
+
return { headers }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getDataForGet(url, params = {}, headers = {}) {
|
|
94
|
+
return service.get(url, {
|
|
95
|
+
params,
|
|
96
|
+
...normalizeConfig(headers)
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getDataForPost(url, data = {}, headers = {}) {
|
|
101
|
+
return service.post(url, data, normalizeConfig(headers))
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
export default service
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Vue from 'vue'
|
|
2
|
-
|
|
3
|
-
function resolveAxios() {
|
|
4
|
-
const axios = Vue.prototype && Vue.prototype.$axios
|
|
5
|
-
if (!axios || typeof axios !== 'object') {
|
|
6
|
-
throw new Error('[DynamicForm] $axios is required in Vue prototype')
|
|
7
|
-
}
|
|
8
|
-
return axios
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getDataForGet(url, params = {}, headers = {}) {
|
|
12
|
-
const axios = resolveAxios()
|
|
13
|
-
return axios.get(url, params, headers)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getDataForPost(url, data = {}, headers = {}) {
|
|
17
|
-
const axios = resolveAxios()
|
|
18
|
-
return axios.post(url, data, headers)
|
|
19
|
-
}
|