diff --git a/src/area/README.md b/src/area/README.md index e6d4d3e66..0927db334 100644 --- a/src/area/README.md +++ b/src/area/README.md @@ -55,6 +55,7 @@ Set `columns-num` with 2, you'll have a 2 level picker. | visible-item-count | Count of visible columns | `number` | `5` | | confirm-button-text | Text of confirm button | `string` | `Confirm` | | cancel-button-text | Text of cancel button | `string` | `Cancel` | +| is-oversea-code | The method to validate oversea code | `() => boolean` | - | ### Events diff --git a/src/area/README.zh-CN.md b/src/area/README.zh-CN.md index 7651299b7..88fd9b233 100644 --- a/src/area/README.zh-CN.md +++ b/src/area/README.zh-CN.md @@ -54,6 +54,7 @@ Vue.use(Area); | visible-item-count | 可见的选项个数 | `number` | `5` | - | | confirm-button-text | 确认按钮文字 | `string` | `确认` | 1.5.3 | | cancel-button-text | 取消按钮文字 | `string` | `取消` | 1.5.3 | +| is-oversea-code | 根据`code`校验海外地址,海外地址会划分至单独的分类 | `() => boolean` | - | 2.1.4 | ### Events diff --git a/src/area/index.js b/src/area/index.js index 7bf965c56..cab65f3fe 100644 --- a/src/area/index.js +++ b/src/area/index.js @@ -4,6 +4,10 @@ import { pickerProps } from '../picker/shared'; const [createComponent, bem] = createNamespace('area'); +function isOverseaCode(code) { + return code[0] === '9'; +} + export default createComponent({ props: { ...pickerProps, @@ -15,6 +19,10 @@ export default createComponent({ columnsNum: { type: [Number, String], default: 3 + }, + isOverseaCode: { + type: Function, + default: isOverseaCode } }, @@ -81,7 +89,7 @@ export default createComponent({ if (code) { // oversea code - if (code[0] === '9' && type === 'city') { + if (this.isOverseaCode(code) && type === 'city') { code = '9'; } @@ -97,7 +105,7 @@ export default createComponent({ const list = this.getList(type, code.slice(0, compareNum - 2)); // oversea code - if (code[0] === '9' && type === 'province') { + if (this.isOverseaCode(code) && type === 'province') { compareNum = 1; } @@ -163,7 +171,7 @@ export default createComponent({ const names = values.map(item => item.name); area.code = values[values.length - 1].code; - if (area.code[0] === '9') { + if (this.isOverseaCode(area.code)) { area.country = names[1] || ''; area.province = names[2] || ''; } else {