t20-common-lib 0.15.4 → 0.15.5

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.5",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -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"
@@ -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') {