From 38fe9befb99472587cf8c43231ca67f899b478a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Thu, 24 Oct 2019 19:03:35 +0800 Subject: [PATCH] build: compile 0.5.22 --- dist/area/index.js | 61 +++++++++++++++++++++++++++++++++++++++++++--- lib/area/index.js | 61 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 114 insertions(+), 8 deletions(-) diff --git a/dist/area/index.js b/dist/area/index.js index 03aa598d..17392c9a 100644 --- a/dist/area/index.js +++ b/dist/area/index.js @@ -1,5 +1,6 @@ import { VantComponent } from '../common/component'; import { pickerProps } from '../picker/shared'; +const COLUMNSPLACEHOLDERCODE = '000000'; VantComponent({ classes: ['active-class', 'toolbar-class', 'column-class'], props: Object.assign({}, pickerProps, { value: String, areaList: { @@ -8,10 +9,22 @@ VantComponent({ }, columnsNum: { type: [String, Number], value: 3 + }, columnsPlaceholder: { + type: Array, + observer(val) { + this.setData({ + typeToColumnsPlaceholder: { + province: val[0] || '', + city: val[1] || '', + county: val[2] || '', + } + }); + } } }), data: { columns: [{ values: [] }, { values: [] }, { values: [] }], - displayColumns: [{ values: [] }, { values: [] }, { values: [] }] + displayColumns: [{ values: [] }, { values: [] }, { values: [] }], + typeToColumnsPlaceholder: {} }, watch: { value(value) { @@ -41,20 +54,40 @@ VantComponent({ this.emit('cancel', event.detail); }, onConfirm(event) { - this.emit('confirm', event.detail); + const { index } = event.detail; + let { value } = event.detail; + value = this.parseOutputValues(value); + this.emit('confirm', { value, index }); }, emit(type, detail) { detail.values = detail.value; delete detail.value; this.$emit(type, detail); }, + // parse output columns data + parseOutputValues(values) { + const { columnsPlaceholder } = this.data; + return values.map((value, index) => { + // save undefined value + if (!value) + return value; + value = JSON.parse(JSON.stringify(value)); + if (!value.code || value.name === columnsPlaceholder[index]) { + value.code = ''; + value.name = ''; + } + return value; + }); + }, onChange(event) { const { index, picker, value } = event.detail; this.code = value[index].code; + let getValues = picker.getValues(); + getValues = this.parseOutputValues(getValues); this.setValues().then(() => { this.$emit('change', { picker, - values: picker.getValues(), + values: getValues, index }); }); @@ -64,6 +97,7 @@ VantComponent({ return (areaList && areaList[`${type}_list`]) || {}; }, getList(type, code) { + const { typeToColumnsPlaceholder } = this.data; let result = []; if (type !== 'province' && !code) { return result; @@ -80,6 +114,14 @@ VantComponent({ } result = result.filter(item => item.code.indexOf(code) === 0); } + if (typeToColumnsPlaceholder[type] && result.length) { + // set columns placeholder + const codeFill = type === 'province' ? '' : type === 'city' ? COLUMNSPLACEHOLDERCODE.slice(2, 4) : COLUMNSPLACEHOLDERCODE.slice(4, 6); + result.unshift({ + code: `${code}${codeFill}`, + name: typeToColumnsPlaceholder[type] + }); + } return result; }, getIndex(type, code) { @@ -99,7 +141,18 @@ VantComponent({ }, setValues() { const county = this.getConfig('county'); - let code = this.code || Object.keys(county)[0] || ''; + let { code } = this; + if (!code) { + if (this.data.columnsPlaceholder.length) { + code = COLUMNSPLACEHOLDERCODE; + } + else if (Object.keys(county)[0]) { + code = Object.keys(county)[0]; + } + else { + code = ''; + } + } const province = this.getList('province'); const city = this.getList('city', code.slice(0, 2)); const picker = this.getPicker(); diff --git a/lib/area/index.js b/lib/area/index.js index 3c7bb95e..f4c2fa5b 100644 --- a/lib/area/index.js +++ b/lib/area/index.js @@ -13,6 +13,7 @@ var __assign = (this && this.__assign) || function () { Object.defineProperty(exports, "__esModule", { value: true }); var component_1 = require("../common/component"); var shared_1 = require("../picker/shared"); +var COLUMNSPLACEHOLDERCODE = '000000'; component_1.VantComponent({ classes: ['active-class', 'toolbar-class', 'column-class'], props: __assign({}, shared_1.pickerProps, { value: String, areaList: { @@ -21,10 +22,22 @@ component_1.VantComponent({ }, columnsNum: { type: [String, Number], value: 3 + }, columnsPlaceholder: { + type: Array, + observer: function (val) { + this.setData({ + typeToColumnsPlaceholder: { + province: val[0] || '', + city: val[1] || '', + county: val[2] || '', + } + }); + } } }), data: { columns: [{ values: [] }, { values: [] }, { values: [] }], - displayColumns: [{ values: [] }, { values: [] }, { values: [] }] + displayColumns: [{ values: [] }, { values: [] }, { values: [] }], + typeToColumnsPlaceholder: {} }, watch: { value: function (value) { @@ -55,21 +68,41 @@ component_1.VantComponent({ this.emit('cancel', event.detail); }, onConfirm: function (event) { - this.emit('confirm', event.detail); + var index = event.detail.index; + var value = event.detail.value; + value = this.parseOutputValues(value); + this.emit('confirm', { value: value, index: index }); }, emit: function (type, detail) { detail.values = detail.value; delete detail.value; this.$emit(type, detail); }, + // parse output columns data + parseOutputValues: function (values) { + var columnsPlaceholder = this.data.columnsPlaceholder; + return values.map(function (value, index) { + // save undefined value + if (!value) + return value; + value = JSON.parse(JSON.stringify(value)); + if (!value.code || value.name === columnsPlaceholder[index]) { + value.code = ''; + value.name = ''; + } + return value; + }); + }, onChange: function (event) { var _this = this; var _a = event.detail, index = _a.index, picker = _a.picker, value = _a.value; this.code = value[index].code; + var getValues = picker.getValues(); + getValues = this.parseOutputValues(getValues); this.setValues().then(function () { _this.$emit('change', { picker: picker, - values: picker.getValues(), + values: getValues, index: index }); }); @@ -79,6 +112,7 @@ component_1.VantComponent({ return (areaList && areaList[type + "_list"]) || {}; }, getList: function (type, code) { + var typeToColumnsPlaceholder = this.data.typeToColumnsPlaceholder; var result = []; if (type !== 'province' && !code) { return result; @@ -95,6 +129,14 @@ component_1.VantComponent({ } result = result.filter(function (item) { return item.code.indexOf(code) === 0; }); } + if (typeToColumnsPlaceholder[type] && result.length) { + // set columns placeholder + var codeFill = type === 'province' ? '' : type === 'city' ? COLUMNSPLACEHOLDERCODE.slice(2, 4) : COLUMNSPLACEHOLDERCODE.slice(4, 6); + result.unshift({ + code: "" + code + codeFill, + name: typeToColumnsPlaceholder[type] + }); + } return result; }, getIndex: function (type, code) { @@ -115,7 +157,18 @@ component_1.VantComponent({ setValues: function () { var _this = this; var county = this.getConfig('county'); - var code = this.code || Object.keys(county)[0] || ''; + var code = this.code; + if (!code) { + if (this.data.columnsPlaceholder.length) { + code = COLUMNSPLACEHOLDERCODE; + } + else if (Object.keys(county)[0]) { + code = Object.keys(county)[0]; + } + else { + code = ''; + } + } var province = this.getList('province'); var city = this.getList('city', code.slice(0, 2)); var picker = this.getPicker();