xianniu-ui 0.8.51 → 0.8.52

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": "xianniu-ui",
3
- "version": "0.8.51",
3
+ "version": "0.8.52",
4
4
  "private": false,
5
5
  "main": "lib/xianniu-ui.umd.min.js",
6
6
  "scripts": {
@@ -120,7 +120,6 @@ export default {
120
120
  const res = this.findParent(_value, this.flattenResult).map(
121
121
  (item) => item.cityCode
122
122
  );
123
- console.log("123", res);
124
123
  return res;
125
124
  }
126
125
  },
@@ -246,28 +245,26 @@ export default {
246
245
  // });
247
246
  // },
248
247
  handleChange(code) {
249
- const changeResults = Array.isArray(code)
250
- ? code.map((c) => this.getRes(c))
251
- : this.getRes(code);
248
+ // 判断是否是多选
249
+ const isMultiple = Array.isArray(code) && Array.isArray(code[0]);
252
250
 
253
- const value = changeResults.map(({ cityCodeLast }) =>
254
- this.valueKey ? code : cityCodeLast
255
- );
256
-
257
- this.$emit("on-change", value);
251
+ // 获取变更结果
252
+ const changeResults = (isMultiple ? code : [code]).map(this.getRes);
258
253
 
259
- const cityResults = changeResults.map((res) => {
260
- const { city, cityCode, cityName, cityCodeLast, cityNameLast } = res;
261
- return {
262
- city,
263
- cityCode,
264
- cityName,
265
- cityCodeLast,
266
- cityNameLast,
267
- };
268
- });
254
+ // 生成 value cityResults
255
+ const [value, cityResults] = changeResults.reduce(
256
+ (acc, res) => {
257
+ const { city, cityCode, cityName, cityCodeLast, cityNameLast } = res;
258
+ acc[0].push(this.valueKey ? code : cityCodeLast);
259
+ acc[1].push({ city, cityCode, cityName, cityCodeLast, cityNameLast });
260
+ return acc;
261
+ },
262
+ [[], []]
263
+ );
269
264
 
270
- this.$emit("on-city", cityResults);
265
+ // 触发事件
266
+ this.$emit("on-change", isMultiple ? value : value[0]);
267
+ this.$emit("on-city", isMultiple ? cityResults : cityResults[0]);
271
268
  },
272
269
  // 获取结果
273
270
  getRes(cityCode) {