t20-common-lib 0.11.2 → 0.11.4

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
@@ -0,0 +1,10 @@
1
+ # 登录 npm 账号(需先在 npm 官网注册)
2
+ npm login
3
+
4
+ # 自动更新版本号(语义化版本,选其一)
5
+ npm version patch # 小补丁(1.0.0 → 1.0.1)
6
+ npm version minor # 次版本(1.0.0 → 1.1.0)
7
+ npm version major # 主版本(1.0.0 → 2.0.0)
8
+
9
+ # 发布到 npm 仓库(更新和首次发布命令一致)
10
+ npm publish
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "t20-common-lib",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -132,7 +132,20 @@ export default {
132
132
  }
133
133
 
134
134
  try {
135
- const { data = [] } = await this.requestFn(params);
135
+ const res = await this.requestFn(params);
136
+
137
+ // 仅兼容常见两种返回:{ list: [] } 与 { data: [] },同时支持直接返回数组
138
+ let data = [];
139
+ if (Array.isArray(res)) {
140
+ data = res;
141
+ } else if (res && Array.isArray(res.list)) {
142
+ data = res.list;
143
+ } else if (res && Array.isArray(res.data)) {
144
+ data = res.data;
145
+ } else {
146
+ data = [];
147
+ }
148
+
136
149
  if (isInitial) {
137
150
  this.branchBankList = data;
138
151
  } else {
@@ -141,7 +154,7 @@ export default {
141
154
  this.page.hasMore = data.length === this.page.size;
142
155
  } catch (error) {
143
156
  console.error("Failed to fetch branch data:", error);
144
- }
157
+ }
145
158
  },
146
159
  handleFilter(val) {
147
160
  this.page.key = val;
@@ -158,8 +171,29 @@ export default {
158
171
  this.fetchBranchData(true);
159
172
  },
160
173
  handleBranchChange(val) {
174
+ // 保持 v-model 行为
161
175
  this.$emit('input', val);
162
- this.$emit("canGetData", val);
176
+
177
+ // 尝试从已加载的列表中找到完整的 item 对象
178
+ const findByValueKey = (v) => {
179
+ if (v === undefined || v === null) return null;
180
+ return this.branchBankList.find(item => item[this.valueKey] == v) || null;
181
+ };
182
+
183
+ let option = null;
184
+ if (this.multiple) {
185
+ // 多选时 val 应为数组,映射回对应的对象数组,过滤掉未找到的项
186
+ if (Array.isArray(val)) {
187
+ option = val.map(v => findByValueKey(v)).filter(i => i != null);
188
+ } else {
189
+ option = [];
190
+ }
191
+ } else {
192
+ // 单选时返回对应对象或 null
193
+ option = findByValueKey(val) || null;
194
+ }
195
+
196
+ this.$emit('canGetData', val, option);
163
197
  },
164
198
  handleFocus() {
165
199
  if (!this.page.key && this.branchBankList.length === 0) {