BUG 139
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
import request from "./request";
|
/**
|
||||||
|
* Area类,用于处理地区相关信息
|
||||||
|
*/
|
||||||
export default class Area {
|
export default class Area {
|
||||||
|
/**
|
||||||
|
* 构造函数
|
||||||
|
* @param {string} code 地区编码
|
||||||
|
* @param {Object} hash 哈希表
|
||||||
|
*/
|
||||||
constructor(code, hash = {}) {
|
constructor(code, hash = {}) {
|
||||||
this.id = code
|
this.id = code
|
||||||
this.level = Area.getLevelByAreaId(code)
|
this.level = Area.getLevelByAreaId(code)
|
||||||
@@ -13,7 +18,7 @@ export default class Area {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取地区的行政等级
|
* 获取地区的行政等级
|
||||||
* @param code 地区编码
|
* @param {string} code 地区编码
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
static getLevelByAreaId(code) {
|
static getLevelByAreaId(code) {
|
||||||
@@ -28,8 +33,8 @@ export default class Area {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据地区编码获取指定等级的地区编码
|
* 根据地区编码获取指定等级的地区编码
|
||||||
* @param value 地区编码
|
* @param {string} value 地区编码
|
||||||
* @param level 指定等级
|
* @param {number} level 指定等级
|
||||||
* @returns {string|null|*}
|
* @returns {string|null|*}
|
||||||
*/
|
*/
|
||||||
static getAreaCodeByLevel(value, level) {
|
static getAreaCodeByLevel(value, level) {
|
||||||
@@ -50,10 +55,22 @@ export default class Area {
|
|||||||
} else return null
|
} else return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据地区id获取所有父级地区id
|
||||||
|
* @param {string} areaId 地区id
|
||||||
|
* @param {Object} ins 请求实例
|
||||||
|
* @param {string} action 请求地址
|
||||||
|
* @returns {Promise<Array>} 所有父级地区id
|
||||||
|
*/
|
||||||
static createByAction(areaId, ins = request, action = "/admin/area/getAllParentAreaId") {
|
static createByAction(areaId, ins = request, action = "/admin/area/getAllParentAreaId") {
|
||||||
return ins.post(action, null, {params: {areaId}, withoutToken: 1}).then(res => res?.data?.reverse() || [])
|
return ins.post(action, null, {params: {areaId}, withoutToken: 1}).then(res => res?.data?.reverse() || [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取地区信息
|
||||||
|
* @param {string} id 地区id
|
||||||
|
* @returns {Object} 地区信息
|
||||||
|
*/
|
||||||
getAreaInfo(id) {
|
getAreaInfo(id) {
|
||||||
let info = {}
|
let info = {}
|
||||||
const currentLevel = Area.getLevelByAreaId(id);
|
const currentLevel = Area.getLevelByAreaId(id);
|
||||||
@@ -63,21 +80,30 @@ export default class Area {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步获取地区名称
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async getAreaName() {
|
async getAreaName() {
|
||||||
const names = await Area.createByAction(this.id);
|
const names = await Area.createByAction(this.id);
|
||||||
this.getName(names)
|
this.getName(names)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取地区名称
|
||||||
|
* @param {Array} names 地区名称数组
|
||||||
|
*/
|
||||||
getName(names) {
|
getName(names) {
|
||||||
this.meta = 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.name = names?.slice(-1)?.[0]?.name
|
||||||
this.fullname = this.nameMap.join('')
|
this.fullname = this.nameMap.join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步从数据库中获取地区信息
|
* 异步从数据库中获取地区信息
|
||||||
* @returns {Promise<void>}
|
* @param {string} code 地区编码
|
||||||
|
* @returns {Promise<Area>} Area实例
|
||||||
*/
|
*/
|
||||||
static async init(code) {
|
static async init(code) {
|
||||||
const names = await Area.createByAction(code),
|
const names = await Area.createByAction(code),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
{{ btnShowArea ? selectedName : "切换地区" }}
|
{{ btnShowArea ? selectedName : "切换地区" }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<a class="custom-clicker" v-else @click="chooseArea">
|
<a class="custom-clicker" v-else @click="chooseArea">
|
||||||
<slot :areaname="selectedName" :fullname="fullName" :id="selected" :areatype="selectedAreaType"/>
|
<slot :areaname="selectedName" :fullname="fullName" :id="selected"/>
|
||||||
</a>
|
</a>
|
||||||
<ai-dialog :visible.sync="dialog" title="选择地区" width="60%" @onConfirm="confirmArea" @open="selected=(value||'')">
|
<ai-dialog :visible.sync="dialog" title="选择地区" width="60%" @onConfirm="confirmArea" @open="selected=(value||'')">
|
||||||
<ai-highlight content="您当前选择 @v" :value="selectedName" color="#333" bold/>
|
<ai-highlight content="您当前选择 @v" :value="selectedName" color="#333" bold/>
|
||||||
@@ -101,7 +101,10 @@ export default {
|
|||||||
header: levelLabels[i], list
|
header: levelLabels[i], list
|
||||||
})).slice(Math.max(0, this.startLevel), this.endLevel)
|
})).slice(Math.max(0, this.startLevel), this.endLevel)
|
||||||
if (this.startLevel > 0 && ops.length > 0) {
|
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
|
return ops
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user