From 94335d8dc20d9612906380e374941504d44ddcf5 Mon Sep 17 00:00:00 2001 From: Terry Zeng Date: Sun, 26 Feb 2023 20:18:42 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=A0=B8=E5=BF=83=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RegionCityPicker.js | 8 +- src/RegionColumns.js | 6 +- src/RegionGroup.js | 6 +- src/RegionSelects.js | 3 +- src/RegionText.js | 10 +- src/__tests__/Component.js | 26 +++ src/__tests__/{city.spec.js => city.js} | 0 src/__tests__/{column.spec.js => column.js} | 0 src/__tests__/core-data.spec.js | 5 + src/__tests__/core.spec.js | 175 ++++++++++++++++++++ src/__tests__/{group.spec.js => group.js} | 0 src/__tests__/select.spec.js | 123 +++++++------- src/components/Columns.js | 6 +- src/components/Group.js | 6 +- src/components/Select.js | 14 +- src/formatted.js | 29 ++-- src/utils/helper.js | 16 -- src/utils/parse.js | 2 +- 18 files changed, 319 insertions(+), 116 deletions(-) create mode 100644 src/__tests__/Component.js rename src/__tests__/{city.spec.js => city.js} (100%) rename src/__tests__/{column.spec.js => column.js} (100%) create mode 100644 src/__tests__/core-data.spec.js create mode 100644 src/__tests__/core.spec.js rename src/__tests__/{group.spec.js => group.js} (100%) diff --git a/src/RegionCityPicker.js b/src/RegionCityPicker.js index 6db53b3..a5ef63c 100644 --- a/src/RegionCityPicker.js +++ b/src/RegionCityPicker.js @@ -1,6 +1,6 @@ import './styles/city.sass' -import { ref, computed, watch, nextTick, h } from 'vue' +import { ref, computed, watch, nextTick, h, defineComponent } from 'vue' import { CN } from './language' import { regionProvinces, regionCities } from './formatted' import { PLACEHOLDER_OTHER_CITIES } from './constants' @@ -12,10 +12,10 @@ const maxDisplayCities = 2 // 完整的城市列表(基于省份进行分组) const fullCityDirectory = cityDirectory() -export default { +export default defineComponent({ name: 'RegionCityPicker', props: { - modelValue: { type: Array, default: [] }, + modelValue: { type: Array, default: () => [] }, /** * 按钮中显示选中城市模式 * true: 显示所有选中城市名称 @@ -186,4 +186,4 @@ export default { return generateDropdown(dropdownOption, trigger, contents) } } -} +}) diff --git a/src/RegionColumns.js b/src/RegionColumns.js index d58f9e6..28bb4b3 100644 --- a/src/RegionColumns.js +++ b/src/RegionColumns.js @@ -1,10 +1,10 @@ -import { ref, h, useAttrs, mergeProps } from 'vue' +import { ref, h, useAttrs, mergeProps, defineComponent } from 'vue' import RegionColumnsCore from './components/Columns' import { CN } from './language' import { useDropdown } from './utils/selector' -export default { +export default defineComponent({ name: 'RegionColumns', inheritAttrs: false, props: { @@ -50,4 +50,4 @@ export default { return generateDropdown(dropdownOption, trigger, contents) } } -} +}) diff --git a/src/RegionGroup.js b/src/RegionGroup.js index c32230d..eac6cc9 100644 --- a/src/RegionGroup.js +++ b/src/RegionGroup.js @@ -1,10 +1,10 @@ -import { ref, h, useAttrs, mergeProps } from 'vue' +import { ref, h, useAttrs, mergeProps, defineComponent } from 'vue' import RegionGroupCore from './components/Group' import { CN } from './language' import { useDropdown } from './utils/selector' -export default { +export default defineComponent({ name: 'RegionGroup', inheritAttrs: false, props: { @@ -52,4 +52,4 @@ export default { return generateDropdown(dropdownOption, trigger, contents) } } -} +}) diff --git a/src/RegionSelects.js b/src/RegionSelects.js index 8de8138..46a3add 100644 --- a/src/RegionSelects.js +++ b/src/RegionSelects.js @@ -26,8 +26,9 @@ export default defineComponent({ provide('disabled', toRef(props, 'disabled')) provide('blank', props.blank) - function generateLevel (list, model, callback) { + function generateLevel (list, model, callback, refObject) { return h(RegionSelect, { + ref: refObject, list, blankText: lang.pleaseSelect, modelValue: model, diff --git a/src/RegionText.js b/src/RegionText.js index 8181c7b..8db167b 100644 --- a/src/RegionText.js +++ b/src/RegionText.js @@ -1,8 +1,8 @@ -import { h, ref } from 'vue' +import { h, ref, defineComponent } from 'vue' import { validModel } from './utils/helper' -import { modelToRegion, parseRegionToText } from './utils/parse' +import { modelToRegion, regionToText } from './utils/parse' -export default { +export default defineComponent({ name: 'RegionText', props: { modelValue: { type: Object, default: undefined }, @@ -14,9 +14,9 @@ export default { const text = ref('') modelToRegion(props.modelValue).then(resp => { - text.value = parseRegionToText(resp).join(props.separator) + text.value = regionToText(resp).join(props.separator) }) return () => h('span', text.value) } -} +}) diff --git a/src/__tests__/Component.js b/src/__tests__/Component.js new file mode 100644 index 0000000..7695141 --- /dev/null +++ b/src/__tests__/Component.js @@ -0,0 +1,26 @@ +import { h } from 'vue' +import { useState, availableLevels } from '../utils/helper' + +export default { + props: { + city: Boolean, + area: Boolean, + town: Boolean + }, + setup (props, { expose }) { + const { haveCity, haveArea, haveTown } = useState(props) + + function getAvailableLevels () { + return availableLevels(props) + } + + expose({ + haveCity, + haveArea, + haveTown, + getAvailableLevels + }) + + return () => h('div') + } +} diff --git a/src/__tests__/city.spec.js b/src/__tests__/city.js similarity index 100% rename from src/__tests__/city.spec.js rename to src/__tests__/city.js diff --git a/src/__tests__/column.spec.js b/src/__tests__/column.js similarity index 100% rename from src/__tests__/column.spec.js rename to src/__tests__/column.js diff --git a/src/__tests__/core-data.spec.js b/src/__tests__/core-data.spec.js new file mode 100644 index 0000000..dfc8268 --- /dev/null +++ b/src/__tests__/core-data.spec.js @@ -0,0 +1,5 @@ +import { describe, it, expect } from 'vitest' + +describe('v-region 核心数据模块', () => { + +}) diff --git a/src/__tests__/core.spec.js b/src/__tests__/core.spec.js new file mode 100644 index 0000000..90bd1fe --- /dev/null +++ b/src/__tests__/core.spec.js @@ -0,0 +1,175 @@ +import { describe, it, expect } from 'vitest' +import { mount } from '@vue/test-utils' + +import Component from './Component' +import { + getCities, + getAreas, + getTowns, + getLevels, + useLanguage +} from '../utils/helper' +import { modelToRegion, regionToModel, regionToText } from '../utils/parse' + +describe('v-region 核心工具模块', () => { + const data = { + province: { + key: '350000', + value: '福建省' + }, + city: { + key: '350100', + value: '福州市' + }, + area: { + key: '350103', + value: '台江区' + }, + town: { + key: '350103001', + value: '瀛洲街道' + } + } + const model = { + province: '350000', + city: '350100', + area: '350103', + town: '350103001' + } + describe('行政级别开关状态模块(state)', () => { + const wrapper = mount(Component, { + props: { + city: true, + area: true, + town: true + } + }) + + it('默认的行政级别状态应均为启用', () => { + expect(wrapper.vm.haveCity).equal(true) + expect(wrapper.vm.haveArea).equal(true) + expect(wrapper.vm.haveTown).equal(true) + expect(wrapper.vm.getAvailableLevels()).toEqual( + ['province', 'city', 'area', 'town'] + ) + }) + it('关闭 town prop,town 级别应为关闭状态', async () => { + await wrapper.setProps({ town: false }) + expect(wrapper.vm.haveTown).equal(false) + expect(wrapper.vm.getAvailableLevels()).toEqual( + ['province', 'city', 'area'] + ) + }) + it('关闭 area prop,area 与 town 级别应均为关闭状态', async () => { + await wrapper.setProps({ area: false }) + expect(wrapper.vm.haveArea).equal(false) + expect(wrapper.vm.haveTown).equal(false) + expect(wrapper.vm.getAvailableLevels()).toEqual( + ['province', 'city'] + ) + }) + it('关闭 city prop,city、area 与 town 级别应均为关闭状态', async () => { + await wrapper.setProps({ city: false }) + expect(wrapper.vm.haveCity).equal(false) + expect(wrapper.vm.haveArea).equal(false) + expect(wrapper.vm.haveTown).equal(false) + expect(wrapper.vm.getAvailableLevels()).toEqual( + ['province'] + ) + }) + it('默认全启用状态下,关闭 city prop,city、area 与 town 级别应均为关闭状态', async () => { + await wrapper.setProps({ city: true, area: true, town: true }) + await wrapper.setProps({ city: false }) + expect(wrapper.vm.haveCity).equal(false) + expect(wrapper.vm.haveArea).equal(false) + expect(wrapper.vm.haveTown).equal(false) + expect(wrapper.vm.getAvailableLevels()).toEqual( + ['province'] + ) + }) + }) + + describe('数据加载模块(loader)', () => { + it('提供福建省编码,该省的城市数量应为 9 个', () => { + const list = getCities({ key: '350000' }) + expect(list.length).equal(9) + }) + it('提供福州市编码,该市的区/县数量应为 13 个', () => { + const list = getAreas({ key: '350100' }) + expect(list.length).equal(13) + }) + it('提供台江区编码,该区的乡/镇数量应为 10 个', async () => { + const list = await getTowns({ key: '350103' }) + expect(list.length).equal(10) + }) + }) + + describe('根据指定级别获得下级行政级别(getLevels)', () => { + it('指定省级,应得到市、区、乡', () => { + expect(getLevels('province')).toEqual(['city', 'area', 'town']) + }) + it('指定市级,应得到区、乡', () => { + expect(getLevels('city')).toEqual(['area', 'town']) + }) + it('指定区/县级,应得到乡', () => { + expect(getLevels('area')).toEqual(['town']) + }) + it('指定乡/镇级,应无内容返回', () => { + expect(getLevels('town')).toEqual([]) + }) + }) + + describe('多语言(useLanguage)', () => { + it('不指定语言,则使用中文', () => { + const lang = useLanguage() + expect(lang.pleaseSelect).equal('请选择') + }) + it('指定中文', () => { + const lang = useLanguage('cn') + expect(lang.pleaseSelect).equal('请选择') + }) + it('指定英文', () => { + const lang = useLanguage('en') + expect(lang.pleaseSelect).equal('Please select') + }) + it('指定非预设语言,则使用中文', () => { + const lang = useLanguage('de') + expect(lang.pleaseSelect).equal('请选择') + }) + }) + + describe('提取行政区划数据文本内容(regionToText)', () => { + it('使用完整行政区划数据,关闭区/县级别,获得的文本应为`福建省福州市`', () => { + expect(regionToText(data, ['province', 'city'])).toEqual(['福建省', '福州市']) + }) + it('不限制区域级别,获得的文本应为`福建省福州市台江区瀛洲街道`', () => { + expect(regionToText(data)).toEqual(['福建省', '福州市', '台江区', '瀛洲街道']) + }) + }) + + describe('行政区划数据模型转换为参数数据模型(仅编码)(regionToModel)', () => { + it('获得用于 `v-model` 输入输出数据模型', () => { + expect(regionToModel(data)).toEqual(model) + }) + }) + + describe('参数数据模型转换为行政区划数据模型(modelToRegion)', () => { + it('获得完整行政区划数据', async () => { + const value = await modelToRegion(model) + expect(value).toEqual(data) + }) + it('设置有效区域级别仅为省、市时,仅返回有效级别的数据内容', async () => { + const value = await modelToRegion(model, ['province', 'city']) + expect(value).toEqual({ + province: { + key: '350000', + value: '福建省' + }, + city: { + key: '350100', + value: '福州市' + } + }) + }) + }) +}) diff --git a/src/__tests__/group.spec.js b/src/__tests__/group.js similarity index 100% rename from src/__tests__/group.spec.js rename to src/__tests__/group.js diff --git a/src/__tests__/select.spec.js b/src/__tests__/select.spec.js index 96fa60b..d198d66 100644 --- a/src/__tests__/select.spec.js +++ b/src/__tests__/select.spec.js @@ -34,6 +34,13 @@ describe('v-region Select 表单元素下拉列表模式', function () { const wb = await mount(RegionSelects, { props: { blank: false + }, + global: { + renderStubDefaultSlot: false, + stubs: { + // transition: false, + RegionSelect: true + } } }) await nextTick() @@ -41,8 +48,12 @@ describe('v-region Select 表单元素下拉列表模式', function () { await wb.findAllComponents(RegionSelect)[0].trigger('click') await nextTick() + console.log( - wb.findAllComponents(RegionSelect)[0] + wb.findAllComponents(Dropdown) + // wb.findAllComponents(RegionSelect)[0].html() + // wb.findComponent({ ref: 'provinceRef' }) + // document.body.outerHTML ) // console.log(wb.vm) @@ -59,61 +70,61 @@ describe('v-region Select 表单元素下拉列表模式', function () { expect(wd.findAll('.rg-select__el--disabled').length).to.equal(4) }) - describe('功能操作', () => { - const wrapperOperate = mount(RegionSelects, { - propsData: { - type: 'select', - town: true - } - }) + // describe('功能操作', () => { + // const wrapperOperate = mount(RegionSelects, { + // propsData: { + // type: 'select', + // town: true + // } + // }) - it('省级列表中选中 “河北省”,选择元素显示的文本应为 “河北省”', async () => { - await wrapperOperate.findAll('.rg-select').at(0).trigger('click') - await wrapperOperate.findAll('.rg-select__list').at(0).findAll('li').at(3).trigger('click') - expect(wrapperOperate.findAll('.rg-select__content').at(0).text()).to.equal('河北省') - expect(wrapperOperate.emitted('input')[0][0].province).to.equal('130000') - }) + // it('省级列表中选中 “河北省”,选择元素显示的文本应为 “河北省”', async () => { + // await wrapperOperate.findAll('.rg-select').at(0).trigger('click') + // await wrapperOperate.findAll('.rg-select__list').at(0).findAll('li').at(3).trigger('click') + // expect(wrapperOperate.findAll('.rg-select__content').at(0).text()).to.equal('河北省') + // expect(wrapperOperate.emitted('input')[0][0].province).to.equal('130000') + // }) - it('当前省级选中的数据应为 "130000" (河北省)', () => { - expect(wrapperOperate.vm.region.province.key).to.equal('130000') - }) - it('城市列表中选中 “唐山市”,选择元素显示的文本应为 “唐山市”', async () => { - await wrapperOperate.findAll('.rg-select').at(1).trigger('click') - await wrapperOperate.findAll('.rg-select__list').at(1).findAll('li').at(2).trigger('click') - expect(wrapperOperate.findAll('.rg-select__content').at(1).text()).to.equal('唐山市') - expect(wrapperOperate.vm.region.city.key).to.equal('130200') - }) - it('区/县列表中选中 “路南区”,选择元素显示的文本应为 “路南区”', async () => { - await wrapperOperate.findAll('.rg-select').at(2).trigger('click') - await wrapperOperate.findAll('.rg-select__list').at(2).findAll('li').at(1).trigger('click') - expect(wrapperOperate.findAll('.rg-select__content').at(2).text()).to.equal('路南区') - expect(wrapperOperate.vm.region.area.key).to.equal('130202') - }) - it('乡/镇/街道列表中选中 “友谊街道”,选择元素显示的文本应为 “友谊街道”', async () => { - await wrapperOperate.findAll('.rg-select').at(3).trigger('click') - await wrapperOperate.findAll('.rg-select__list').at(3).findAll('li').at(2).trigger('click') - expect(wrapperOperate.findAll('.rg-select__content').at(3).text()).to.equal('友谊街道') - expect(wrapperOperate.vm.region.town.key).to.equal('130202002') - }) - it('省级修改为 “北京市”,选择元素显示的文本应当变更为 “北京市”', async () => { - await wrapperOperate.findAll('.rg-select').at(0).trigger('click') - await wrapperOperate.findAll('.rg-select__list').at(0).findAll('li').at(1).trigger('click') - expect(wrapperOperate.findAll('.rg-select__content').at(0).text()).to.equal('北京市') - expect(wrapperOperate.vm.region.province.key).to.equal('110000') - }) - it('城市元素显示的文本应为 “请选择”,且城市列表中只有 2 个项目', async () => { - await wrapperOperate.findAll('.rg-select').at(1).trigger('click') - expect(wrapperOperate.findAll('.rg-select__list').at(1).findAll('li').length).to.equal(2) - expect(wrapperOperate.findAll('.rg-select__content').at(1).text()).to.equal('请选择') - expect(wrapperOperate.vm.region.city).to.equal(undefined) - }) - it('区/县元素显示的文本应为 “请选择”,且区/县列表中只有 1 个项目(“请选择”)', () => { - expect(wrapperOperate.findAll('.rg-select__content').at(2).text()).to.equal('请选择') - expect(wrapperOperate.vm.region.area).to.equal(undefined) - }) - it('乡/镇/街道元素显示的文本应为 “请选择”,且乡/镇/街道列表中只有 1 个项目(“请选择”)', () => { - expect(wrapperOperate.findAll('.rg-select__content').at(3).text()).to.equal('请选择') - expect(wrapperOperate.vm.region.town).to.equal(undefined) - }) - }) + // it('当前省级选中的数据应为 "130000" (河北省)', () => { + // expect(wrapperOperate.vm.region.province.key).to.equal('130000') + // }) + // it('城市列表中选中 “唐山市”,选择元素显示的文本应为 “唐山市”', async () => { + // await wrapperOperate.findAll('.rg-select').at(1).trigger('click') + // await wrapperOperate.findAll('.rg-select__list').at(1).findAll('li').at(2).trigger('click') + // expect(wrapperOperate.findAll('.rg-select__content').at(1).text()).to.equal('唐山市') + // expect(wrapperOperate.vm.region.city.key).to.equal('130200') + // }) + // it('区/县列表中选中 “路南区”,选择元素显示的文本应为 “路南区”', async () => { + // await wrapperOperate.findAll('.rg-select').at(2).trigger('click') + // await wrapperOperate.findAll('.rg-select__list').at(2).findAll('li').at(1).trigger('click') + // expect(wrapperOperate.findAll('.rg-select__content').at(2).text()).to.equal('路南区') + // expect(wrapperOperate.vm.region.area.key).to.equal('130202') + // }) + // it('乡/镇/街道列表中选中 “友谊街道”,选择元素显示的文本应为 “友谊街道”', async () => { + // await wrapperOperate.findAll('.rg-select').at(3).trigger('click') + // await wrapperOperate.findAll('.rg-select__list').at(3).findAll('li').at(2).trigger('click') + // expect(wrapperOperate.findAll('.rg-select__content').at(3).text()).to.equal('友谊街道') + // expect(wrapperOperate.vm.region.town.key).to.equal('130202002') + // }) + // it('省级修改为 “北京市”,选择元素显示的文本应当变更为 “北京市”', async () => { + // await wrapperOperate.findAll('.rg-select').at(0).trigger('click') + // await wrapperOperate.findAll('.rg-select__list').at(0).findAll('li').at(1).trigger('click') + // expect(wrapperOperate.findAll('.rg-select__content').at(0).text()).to.equal('北京市') + // expect(wrapperOperate.vm.region.province.key).to.equal('110000') + // }) + // it('城市元素显示的文本应为 “请选择”,且城市列表中只有 2 个项目', async () => { + // await wrapperOperate.findAll('.rg-select').at(1).trigger('click') + // expect(wrapperOperate.findAll('.rg-select__list').at(1).findAll('li').length).to.equal(2) + // expect(wrapperOperate.findAll('.rg-select__content').at(1).text()).to.equal('请选择') + // expect(wrapperOperate.vm.region.city).to.equal(undefined) + // }) + // it('区/县元素显示的文本应为 “请选择”,且区/县列表中只有 1 个项目(“请选择”)', () => { + // expect(wrapperOperate.findAll('.rg-select__content').at(2).text()).to.equal('请选择') + // expect(wrapperOperate.vm.region.area).to.equal(undefined) + // }) + // it('乡/镇/街道元素显示的文本应为 “请选择”,且乡/镇/街道列表中只有 1 个项目(“请选择”)', () => { + // expect(wrapperOperate.findAll('.rg-select__content').at(3).text()).to.equal('请选择') + // expect(wrapperOperate.vm.region.town).to.equal(undefined) + // }) + // }) }) diff --git a/src/components/Columns.js b/src/components/Columns.js index 30dc55a..3454988 100644 --- a/src/components/Columns.js +++ b/src/components/Columns.js @@ -1,13 +1,13 @@ import '../styles/column.sass' -import { h, ref } from 'vue' +import { h, ref, defineComponent } from 'vue' import RegionColumn from './Column' import { PROVINCE_KEY, CITY_KEY, AREA_KEY, TOWN_KEY } from '../constants' import { useState } from '../utils/helper' import { commonProps, useData } from '../utils/data' -export default { +export default defineComponent({ name: 'RegionColumnsCore', props: { ...commonProps @@ -69,4 +69,4 @@ export default { return h('div', { class: 'rg-column-container' }, columns) } } -} +}) diff --git a/src/components/Group.js b/src/components/Group.js index b9f94be..496bab2 100644 --- a/src/components/Group.js +++ b/src/components/Group.js @@ -1,6 +1,6 @@ import '../styles/group.sass' -import { ref, h, nextTick, onBeforeMount } from 'vue' +import { ref, h, nextTick, onBeforeMount, defineComponent } from 'vue' import IconTrash from '../icons/IconTrash.vue' @@ -9,7 +9,7 @@ import { useLanguage, availableLevels } from '../utils/helper' import { LEVELS, PROVINCE_KEY } from '../constants' -export default { +export default defineComponent({ name: 'RegionGroupCore', props: { ...commonProps @@ -122,4 +122,4 @@ export default { generateContent() ]) } -} +}) diff --git a/src/components/Select.js b/src/components/Select.js index c6745c8..4de37e7 100644 --- a/src/components/Select.js +++ b/src/components/Select.js @@ -9,13 +9,8 @@ export default defineComponent({ modelValue: { type: Object, default: undefined } }, emits: ['update:modelValue'], - setup (props, { emit, expose }) { - const { - visible, - dropdown, - closeDropdown, - generateDropdown - } = useDropdown(props) + setup (props, { emit }) { + const { visible, closeDropdown, generateDropdown } = useDropdown(props) const disabled = inject('disabled') const blank = inject('blank') @@ -34,11 +29,8 @@ export default defineComponent({ closeDropdown() } - expose({ dropdown }) - return () => { - // dropdown trigger object - const trigger = h( + const trigger = h( // dropdown trigger object 'div', { class: triggerClasses }, [ diff --git a/src/formatted.js b/src/formatted.js index 6ca8e3d..df5a295 100644 --- a/src/formatted.js +++ b/src/formatted.js @@ -1,22 +1,31 @@ import data from './data.json' -import { isProvince, isCity } from './utils/helper' + +// xx0000 为省级编码格式 +function isProvince (key) { + return !(window.Number(key) % 1e4) +} +// xxxx00 为市级编码格式 +function isCity (key) { + if (!(window.Number(key) % 100)) { + return true + } + // 后四位数处理 + if (window.Number(key.substring(2)) > 9000) { + return true + } + return false +} /** * json 数据转换为模型列表 * 模型格式:{ key: string, value: string } */ const list = [] -/** - * 省/直辖市模型列表 - */ +// 省/直辖市模型列表 const provinces = [] -/** - * 市模型列表 - */ +// 市模型列表 const cities = [] -/** - * 区/县模型列表 - */ +// 区/县模型列表 const areas = [] Object.entries(data).forEach(val => { diff --git a/src/utils/helper.js b/src/utils/helper.js index fb9fe59..72f35e1 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -3,22 +3,6 @@ import { regionFull, regionCities, regionAreas } from '../formatted' import { LEVEL_KEYS, PROVINCE_KEY } from '../constants' import languages, { CN } from '../language' -// xx0000 为省级编码格式 -export function isProvince (key) { - return !(window.Number(key) % 1e4) -} -// xxxx00 为市级编码格式 -export function isCity (key) { - if (!(window.Number(key) % 100)) { - return true - } - // 后四位数处理 - if (window.Number(key.substring(2)) > 9000) { - return true - } - return false -} - /** * 根据省读取城市列表 * diff --git a/src/utils/parse.js b/src/utils/parse.js index 4183580..61f871c 100644 --- a/src/utils/parse.js +++ b/src/utils/parse.js @@ -92,7 +92,7 @@ export function regionToModel (region) { * * @returns {object} 区域原始数据模型 */ -export function parseRegionToText (region, levels = LEVEL_KEYS) { +export function regionToText (region, levels = LEVEL_KEYS) { return levels .map(val => region[val] && region[val].value) .filter(val => val)