t20-common-lib 0.15.4 → 0.15.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "t20-common-lib",
3
- "version": "0.15.4",
3
+ "version": "0.15.6",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -36,7 +36,7 @@
36
36
  </template>
37
37
  <script>
38
38
  import dayjs from 'dayjs'
39
- import { getDataForPost, getDataForGet } from '../utils/request'
39
+ import { getDataForPost, getDataForGet } from '../../../../src/api/common'
40
40
  export default {
41
41
  name: 'Dialog',
42
42
  props: {
@@ -27,7 +27,7 @@
27
27
  <script>
28
28
  import dayjs from 'dayjs'
29
29
  /* 各属性,方法参考el-select */
30
- import { getDataForPost, getDataForGet } from '../utils/request'
30
+ import { getDataForPost, getDataForGet } from '../../../../src/api/common'
31
31
  export default {
32
32
  name: "SelectLazy",
33
33
  props: {
@@ -1,5 +1,7 @@
1
1
  <template>
2
2
  <T20-Scroll-Load-Select
3
+ ref="scrollLoadSelect"
4
+ class="input-w"
3
5
  v-model="_value"
4
6
  v-bind="passThroughProps"
5
7
  v-on="innerListeners"
@@ -8,7 +10,7 @@
8
10
  </template>
9
11
 
10
12
  <script>
11
- import { getDataForGet, getDataForPost } from '../utils/request'
13
+ import { getDataForGet, getDataForPost } from '../../../../src/api/common'
12
14
 
13
15
  export default {
14
16
  name: 'ScrollLoadSelect',
@@ -61,6 +63,10 @@ export default {
61
63
  }
62
64
  return this.$attrs.requestFn || this.$attrs['request-fn'] || this.fetchByStaticOptions
63
65
  },
66
+ // shouldAutoLoad() {
67
+ // const autoLoad = this.items?.props?.autoLoad ?? this.$attrs.autoLoad
68
+ // return autoLoad !== false
69
+ // },
64
70
  passThroughProps() {
65
71
  return {
66
72
  ...this.$attrs,
@@ -74,7 +80,19 @@ export default {
74
80
  }
75
81
  }
76
82
  },
83
+ mounted() {
84
+ // this.triggerInitialRequest()
85
+ },
77
86
  methods: {
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
+ // },
78
96
  resolvePath(data, path) {
79
97
  if (!path) return data
80
98
  return String(path)
@@ -93,14 +111,55 @@ export default {
93
111
  return item
94
112
  })
95
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
+ buildPagingParams(params, apiConfig) {
128
+ const pageConfig = apiConfig?.page || {}
129
+ const currentKey = pageConfig.current || 'current'
130
+ const sizeKey = pageConfig.size || 'size'
131
+ const currentVal = params.current
132
+ const sizeVal = params.size
133
+
134
+ // 场景1:page: { current, size }
135
+ if (pageConfig.reqKey) {
136
+ return {
137
+ [pageConfig.reqKey]: {
138
+ [currentKey]: currentVal,
139
+ [sizeKey]: sizeVal
140
+ }
141
+ }
142
+ }
143
+
144
+ // 场景2:page.current=xx&page.size=xx(支持点路径)
145
+ const pageParams = {}
146
+ this.setDeepValue(pageParams, currentKey, currentVal)
147
+ this.setDeepValue(pageParams, sizeKey, sizeVal)
148
+ return pageParams
149
+ },
96
150
  async fetchByApiConfig(params = {}) {
97
151
  const apiConfig = this.items?.api || {}
98
152
  const method = String(apiConfig.requestMethod || '').toUpperCase()
99
153
  const reqKeys = apiConfig.reqKeys || {}
100
154
  const headerConfig = apiConfig.headerConfig || {}
155
+ const searchValue = params[this.runtimeSearchKeyName]
156
+ const pagingParams = this.buildPagingParams(params, apiConfig)
101
157
  const requestData = {
102
158
  ...reqKeys,
103
- ...params
159
+ ...pagingParams
160
+ }
161
+ if (searchValue !== undefined) {
162
+ requestData[this.runtimeSearchKeyName] = searchValue
104
163
  }
105
164
  let res = null
106
165
  if (method === 'GET') {
@@ -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 '../utils/request'
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 '../utils/request'
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
  }
@@ -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
- }