Browse Source

修改省市级联菜单

zhanghe 7 years ago
parent
commit
b7aa2941e1
3 changed files with 135 additions and 133 deletions
  1. 2 2
      src/routes/Campus/modal.js
  2. 132 129
      src/utils/city.js
  3. 1 2
      src/utils/config.js

+ 2 - 2
src/routes/Campus/modal.js

@@ -12,7 +12,7 @@ export default class CampusModalForm extends Component {
       const data = { ...getFieldsValue() };
 
       data.provinceCode = city.provNameToCode(data.cascader[0]);
-      data.cityName = data.cascader.slice(1, 3).join(' ');
+      data.cityName = data.cascader[1];
       delete data.cascader;
       if (item.id) {
         data.id = item.id;
@@ -44,7 +44,7 @@ export default class CampusModalForm extends Component {
                   message: '校区地址为必选项!',
                 },
               ],
-              initialValue: item.provinceCode && [city.provCodeToName(item.provinceCode), ...(item.cityName || '').split(' ')],
+              initialValue: item.provinceCode && [city.provCodeToName(item.provinceCode), item.cityName],
             })(<Cascader
               style={{ width: '100%' }}
               options={city.DICT_FIXED}

+ 132 - 129
src/utils/city.js

@@ -21,45 +21,45 @@
     JSON.stringify(map)
     ```
 */
-const DICT = {
+let DICT = {
+  //修改过
   110000: '北京',
-  110100: '北京市',
-  110101: '东城区',
-  110102: '西城区',
-  110105: '朝阳区',
-  110106: '丰台区',
-  110107: '石景山区',
-  110108: '海淀区',
-  110109: '门头沟区',
-  110111: '房山区',
-  110112: '通州区',
-  110113: '顺义区',
-  110114: '昌平区',
-  110115: '大兴区',
-  110116: '怀柔区',
-  110117: '平谷区',
-  110228: '密云县',
-  110229: '延庆县',
-  110230: '其它区',
+  110100: '东城区',
+  110200: '西城区',
+  110300: '朝阳区',
+  110400: '丰台区',
+  110500: '石景山区',
+  110600: '海淀区',
+  110700: '门头沟区',
+  110800: '房山区',
+  110900: '通州区',
+  111000: '顺义区',
+  111100: '昌平区',
+  111200: '大兴区',
+  111300: '怀柔区',
+  111400: '平谷区',
+  111500: '密云县',
+  111600: '延庆县',
+  111700: '其它区',
+  //修改过
   120000: '天津',
-  120100: '天津市',
-  120101: '和平区',
-  120102: '河东区',
-  120103: '河西区',
-  120104: '南开区',
-  120105: '河北区',
-  120106: '红桥区',
-  120110: '东丽区',
-  120111: '西青区',
-  120112: '津南区',
-  120113: '北辰区',
-  120114: '武清区',
-  120115: '宝坻区',
-  120116: '滨海新区',
-  120221: '宁河县',
-  120223: '静海县',
-  120225: '蓟县',
-  120226: '其它区',
+  120100: '和平区',
+  120200: '河东区',
+  120300: '河西区',
+  120400: '南开区',
+  120500: '河北区',
+  120600: '红桥区',
+  120700: '东丽区',
+  120800: '西青区',
+  120900: '津南区',
+  121000: '北辰区',
+  121100: '武清区',
+  121200: '宝坻区',
+  121300: '滨海新区',
+  121400: '宁河县',
+  121500: '静海县',
+  121600: '蓟县',
+  121700: '其它区',
   130000: '河北省',
   130100: '石家庄市',
   130102: '长安区',
@@ -892,26 +892,26 @@ const DICT = {
   232723: '漠河县',
   232724: '加格达奇区',
   232725: '其它区',
+  //上海属于直辖市,做了修改
   310000: '上海',
-  310100: '上海市',
-  310101: '黄浦区',
-  310104: '徐汇区',
-  310105: '长宁区',
-  310106: '静安区',
-  310107: '普陀区',
-  310108: '闸北区',
-  310109: '虹口区',
-  310110: '杨浦区',
-  310112: '闵行区',
-  310113: '宝山区',
-  310114: '嘉定区',
-  310115: '浦东新区',
-  310116: '金山区',
-  310117: '松江区',
-  310118: '青浦区',
-  310120: '奉贤区',
-  310230: '崇明县',
-  310231: '其它区',
+  310100: '黄浦区',
+  310200: '徐汇区',
+  310300: '长宁区',
+  310400: '静安区',
+  310500: '普陀区',
+  310600: '闸北区',
+  310700: '虹口区',
+  310800: '杨浦区',
+  310900: '闵行区',
+  311000: '宝山区',
+  311100: '嘉定区',
+  311200: '浦东新区',
+  311300: '金山区',
+  311400: '松江区',
+  311500: '青浦区',
+  311600: '奉贤区',
+  311700: '崇明县',
+  311900: '其它区',
   320000: '江苏省',
   320100: '南京市',
   320102: '玄武区',
@@ -2500,49 +2500,49 @@ const DICT = {
   469035: '保亭黎族苗族自治县',
   469036: '琼中黎族苗族自治县',
   471005: '其它区',
+  //重庆做了修改
   500000: '重庆',
-  500100: '重庆市',
-  500101: '万州区',
-  500102: '涪陵区',
-  500103: '渝中区',
-  500104: '大渡口区',
-  500105: '江北区',
-  500106: '沙坪坝区',
-  500107: '九龙坡区',
-  500108: '南岸区',
-  500109: '北碚区',
-  500110: '万盛区',
-  500111: '双桥区',
-  500112: '渝北区',
-  500113: '巴南区',
-  500114: '黔江区',
-  500115: '长寿区',
-  500222: '綦江区',
-  500223: '潼南县',
-  500224: '铜梁县',
-  500225: '大足区',
-  500226: '荣昌县',
-  500227: '璧山县',
-  500228: '梁平县',
-  500229: '城口县',
-  500230: '丰都县',
-  500231: '垫江县',
-  500232: '武隆县',
-  500233: '忠县',
-  500234: '开县',
-  500235: '云阳县',
-  500236: '奉节县',
-  500237: '巫山县',
-  500238: '巫溪县',
-  500240: '石柱土家族自治县',
-  500241: '秀山土家族苗族自治县',
-  500242: '酉阳土家族苗族自治县',
-  500243: '彭水苗族土家族自治县',
-  500381: '江津区',
-  500382: '合川区',
-  500383: '永川区',
-  500384: '南川区',
-  500385: '其它区',
+  500100: '万州区',
+  500200: '涪陵区',
+  500300: '渝中区',
+  500400: '大渡口区',
+  500500: '江北区',
+  500600: '沙坪坝区',
+  500700: '九龙坡区',
+  500800: '南岸区',
+  500900: '北碚区',
+  501000: '万盛区',
+  501100: '双桥区',
+  501200: '渝北区',
+  501300: '巴南区',
+  501400: '黔江区',
+  501500: '长寿区',
+  501600: '綦江区',
+  501700: '潼南县',
+  501800: '铜梁县',
+  501900: '大足区',
+  502000: '荣昌县',
+  502100: '璧山县',
+  502200: '梁平县',
+  502300: '城口县',
+  502400: '丰都县',
+  502500: '垫江县',
+  502600: '武隆县',
+  502700: '忠县',
+  502800: '开县',
+  502900: '云阳县',
+  503000: '奉节县',
+  503100: '巫山县',
+  503200: '巫溪县',
+  503300: '石柱土家族自治县',
+  503400: '秀山土家族苗族自治县',
+  503500: '酉阳土家族苗族自治县',
+  503600: '彭水苗族土家族自治县',
+  503700: '江津区',
+  503800: '合川区',
+  503900: '永川区',
+  504000: '南川区',
+  504100: '其它区',
   510000: '四川省',
   510100: '成都市',
   510104: '锦江区',
@@ -4018,44 +4018,47 @@ const DICT = {
   820200: '离岛',
   990000: '海外',
   990100: '海外',
-};
+}
 
 // id pid/parentId name children
 const tree = (list) => {
-  const mapped = {};
-  let item;
+  let mapped = {}
+  let item
   for (let i = 0; i < list.length; i += 1) {
-    item = list[i];
-    if (!item || !item.id) continue;
-    mapped[item.id] = item;
+    item = list[i]
+    if (!item || !item.id) continue
+    mapped[item.id] = item
   }
 
-  const result = [];
+  let result = []
   for (let ii = 0; ii < list.length; ii += 1) {
-    item = list[ii];
+    item = list[ii]
 
-    if (!item) continue;
+    if (!item) continue
     /* jshint -W041 */
     if (item.pid === undefined && item.parentId === undefined) {
-      result.push(item);
-      continue;
+      result.push(item)
+      continue
     }
-    const parent = mapped[item.pid] || mapped[item.parentId];
-    if (!parent) continue;
-    if (!parent.children) parent.children = [];
-    parent.children.push(item);
+    let parent = mapped[item.pid] || mapped[item.parentId]
+    if (!parent) continue
+    if (!parent.children) parent.children = []
+    parent.children.push(item)
   }
-  return result;
-};
+  return result
+}
 
-const DICT_FIXED = (function () {
-  const fixed = [];
-  for (const id in DICT) {
+let DICT_FIXED = (function () {
+  let fixed = []
+  for (let id in DICT) {
     if ({}.hasOwnProperty.call(DICT, id)) {
-      let pid;
+      let pid
       if (id.slice(2, 6) !== '0000') {
-        pid = id.slice(4, 6) === '00' ? (`${id.slice(0, 2)}0000`) :
-          `${id.slice(0, 4)}00`;
+        if (id.slice(4,6) === '00') {
+          pid = `${id.slice(0, 2)}0000`;
+        } else {
+          continue; //去掉三级市区
+        }
       }
       fixed.push({
         id,
@@ -4063,24 +4066,24 @@ const DICT_FIXED = (function () {
         name: DICT[id],
         value: DICT[id],
         label: DICT[id],
-      });
+      })
     }
   }
-  return tree(fixed);
-}());
+  return tree(fixed)
+}())
 
 function provCodeToName(provCode) {
-  for (const key in DICT) {
-    if (String(key).slice(0, 2) === provCode) {
+  for (let key in DICT) {
+    if (String(key).slice(0,2) === provCode) {
       return DICT[key];
     }
   }
 }
 
 function provNameToCode(provName) {
-  for (const key in DICT) {
+  for (let key in DICT) {
     if (provName === DICT[key]) {
-      return String(key).slice(0, 2);
+      return String(key).slice(0,2);
     }
   }
 }
@@ -4089,4 +4092,4 @@ module.exports = {
   DICT_FIXED,
   provCodeToName,
   provNameToCode,
-};
+}

+ 1 - 2
src/utils/config.js

@@ -44,8 +44,7 @@ Codes.CODE_SEASON = '季';
 Codes.CODE_ITEM = '件';
 
 module.exports = {
-  // apiHost: '/api/v1',
-  apiHost: 'http://tt-cms.api.ai160.com',
+  apiHost: '/api/v1',
   ossHost: 'http://efunimgs.oss-cn-beijing.aliyuncs.com',
   // apiHost: '/api',
   // 每页返回数据量