From 3a01fa9011732d3cbd18679ee04ffca53ca12c5c Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 23 Mar 2023 18:19:52 +0800 Subject: [PATCH] BUG 139 --- ui/lib/js/area.js | 42 ++++++++++++++++++++++++++++------- ui/packages/common/AiArea.vue | 7 ++++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/ui/lib/js/area.js b/ui/lib/js/area.js index 7c910efc..6d5c22de 100644 --- a/ui/lib/js/area.js +++ b/ui/lib/js/area.js @@ -1,7 +1,12 @@ -import request from "./request"; - - +/** + * Area类,用于处理地区相关信息 + */ export default class Area { + /** + * 构造函数 + * @param {string} code 地区编码 + * @param {Object} hash 哈希表 + */ constructor(code, hash = {}) { this.id = code this.level = Area.getLevelByAreaId(code) @@ -13,7 +18,7 @@ export default class Area { /** * 获取地区的行政等级 - * @param code 地区编码 + * @param {string} code 地区编码 * @returns {number} */ static getLevelByAreaId(code) { @@ -28,8 +33,8 @@ export default class Area { /** * 根据地区编码获取指定等级的地区编码 - * @param value 地区编码 - * @param level 指定等级 + * @param {string} value 地区编码 + * @param {number} level 指定等级 * @returns {string|null|*} */ static getAreaCodeByLevel(value, level) { @@ -50,10 +55,22 @@ export default class Area { } else return null } + /** + * 根据地区id获取所有父级地区id + * @param {string} areaId 地区id + * @param {Object} ins 请求实例 + * @param {string} action 请求地址 + * @returns {Promise} 所有父级地区id + */ static createByAction(areaId, ins = request, action = "/admin/area/getAllParentAreaId") { return ins.post(action, null, {params: {areaId}, withoutToken: 1}).then(res => res?.data?.reverse() || []) } + /** + * 获取地区信息 + * @param {string} id 地区id + * @returns {Object} 地区信息 + */ getAreaInfo(id) { let info = {} const currentLevel = Area.getLevelByAreaId(id); @@ -63,21 +80,30 @@ export default class Area { return info } + /** + * 异步获取地区名称 + * @returns {Promise} + */ async getAreaName() { const names = await Area.createByAction(this.id); this.getName(names) } + /** + * 获取地区名称 + * @param {Array} names 地区名称数组 + */ getName(names) { this.meta = names - this.nameMap = names?.map(e => e.name) || [] + this.nameMap = names?.map(e => e?.name) || [] this.name = names?.slice(-1)?.[0]?.name this.fullname = this.nameMap.join('') } /** * 异步从数据库中获取地区信息 - * @returns {Promise} + * @param {string} code 地区编码 + * @returns {Promise} Area实例 */ static async init(code) { const names = await Area.createByAction(code), diff --git a/ui/packages/common/AiArea.vue b/ui/packages/common/AiArea.vue index dc9cf9d6..eb093091 100644 --- a/ui/packages/common/AiArea.vue +++ b/ui/packages/common/AiArea.vue @@ -14,7 +14,7 @@ {{ btnShowArea ? selectedName : "切换地区" }} - + @@ -101,7 +101,10 @@ export default { header: levelLabels[i], list })).slice(Math.max(0, this.startLevel), this.endLevel) if (this.startLevel > 0 && ops.length > 0) { - ops[0].list = ops[0].list.filter(e => e.id == this.selectedMap[this.startLevel]) + const tmp = this.$copy(ops[0]?.list?.[0] || {}) + const prev = +tmp.type - 1 + const prevId = tmp.parentId + prev > -1 && ops.unshift({header: levelLabels[prev], list: [this.hashMap[prevId]]}) } return ops }