Commit 4abc56ab by luyt

Merge remote-tracking branch 'remotes/origin/kyq-province' into dev_v1.0.0

# Conflicts:
#	src/App.vue
#	src/plugins/element.js
2 parents 4e4ece00 dbbbf07f
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@amap/amap-jsapi-loader": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/@amap/amap-jsapi-loader/-/amap-jsapi-loader-1.0.1.tgz",
"integrity": "sha512-nPyLKt7Ow/ThHLkSvn2etQlUzqxmTVgK7bIgwdBRTg2HK5668oN7xVxkaiRe3YZEzGzfV2XgH5Jmu2T73ljejw=="
},
"@babel/code-frame": { "@babel/code-frame": {
"version": "7.14.5", "version": "7.14.5",
"resolved": "https://registry.nlark.com/@babel/code-frame/download/@babel/code-frame-7.14.5.tgz?cache=0&sync_timestamp=1623280394200&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fcode-frame%2Fdownload%2F%40babel%2Fcode-frame-7.14.5.tgz", "resolved": "https://registry.nlark.com/@babel/code-frame/download/@babel/code-frame-7.14.5.tgz?cache=0&sync_timestamp=1623280394200&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fcode-frame%2Fdownload%2F%40babel%2Fcode-frame-7.14.5.tgz",
...@@ -7393,7 +7398,7 @@ ...@@ -7393,7 +7398,7 @@
}, },
"gulp": { "gulp": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/gulp/-/gulp-4.0.2.tgz", "resolved": "https://registry.npmmirror.com/gulp/-/gulp-4.0.2.tgz",
"integrity": "sha512-dvEs27SCZt2ibF29xYgmnwwCYZxdxhQ/+LFWlbAW8y7jt68L/65402Lz3+CKy0Ov4rOs+NERmDq7YlZaDqUIfA==", "integrity": "sha512-dvEs27SCZt2ibF29xYgmnwwCYZxdxhQ/+LFWlbAW8y7jt68L/65402Lz3+CKy0Ov4rOs+NERmDq7YlZaDqUIfA==",
"dev": true, "dev": true,
"requires": { "requires": {
...@@ -15411,6 +15416,21 @@ ...@@ -15411,6 +15416,21 @@
"integrity": "sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg=", "integrity": "sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg=",
"dev": true "dev": true
}, },
"uppercamelcase": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/uppercamelcase/-/uppercamelcase-1.1.0.tgz",
"integrity": "sha512-C7YEMvhgrvTEKEEVqA7LXNID/1TvvIwYZqNIKLquS6y/MGSkRQAav9LnTTILlC1RqUM8eTVBOe1U/fnB652PRA==",
"requires": {
"camelcase": "^1.2.1"
},
"dependencies": {
"camelcase": {
"version": "1.2.1",
"resolved": "https://registry.npmmirror.com/camelcase/-/camelcase-1.2.1.tgz",
"integrity": "sha512-wzLkDa4K/mzI1OSITC+DUyjgIl/ETNHE9QvYgy6J6Jvqyyz4C0Xfd+lQhb19sX2jMpZV4IssUn0VDVmglV+s4g=="
}
}
},
"uri-js": { "uri-js": {
"version": "4.4.1", "version": "4.4.1",
"resolved": "https://registry.npm.taobao.org/uri-js/download/uri-js-4.4.1.tgz?cache=0&sync_timestamp=1610237624359&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Furi-js%2Fdownload%2Furi-js-4.4.1.tgz", "resolved": "https://registry.npm.taobao.org/uri-js/download/uri-js-4.4.1.tgz?cache=0&sync_timestamp=1610237624359&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Furi-js%2Fdownload%2Furi-js-4.4.1.tgz",
...@@ -15689,6 +15709,14 @@ ...@@ -15689,6 +15709,14 @@
"resolved": "https://registry.nlark.com/vue/download/vue-2.6.14.tgz?cache=0&sync_timestamp=1631890705744&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fvue%2Fdownload%2Fvue-2.6.14.tgz", "resolved": "https://registry.nlark.com/vue/download/vue-2.6.14.tgz?cache=0&sync_timestamp=1631890705744&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fvue%2Fdownload%2Fvue-2.6.14.tgz",
"integrity": "sha1-5RqlJQJQ1Wmj+606ilpofWA24jU=" "integrity": "sha1-5RqlJQJQ1Wmj+606ilpofWA24jU="
}, },
"vue-amap": {
"version": "0.5.10",
"resolved": "https://registry.npmmirror.com/vue-amap/-/vue-amap-0.5.10.tgz",
"integrity": "sha512-9ViNCev1vx32+zZ5RvF/TmUZNbwL9QrdA2/OnD2GlXMfQBkJy7D08Vb7379t6guqnopDPtWJ8K6gg72h9+4GUg==",
"requires": {
"uppercamelcase": "^1.1.0"
}
},
"vue-hot-reload-api": { "vue-hot-reload-api": {
"version": "2.3.4", "version": "2.3.4",
"resolved": "https://registry.nlark.com/vue-hot-reload-api/download/vue-hot-reload-api-2.3.4.tgz", "resolved": "https://registry.nlark.com/vue-hot-reload-api/download/vue-hot-reload-api-2.3.4.tgz",
...@@ -15716,6 +15744,87 @@ ...@@ -15716,6 +15744,87 @@
} }
} }
}, },
"vue-loader-v16": {
"version": "npm:vue-loader-v16@16.8.3",
"resolved": "https://registry.npmmirror.com/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmmirror.com/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-style-loader": { "vue-style-loader": {
"version": "4.1.3", "version": "4.1.3",
"resolved": "https://registry.nlark.com/vue-style-loader/download/vue-style-loader-4.1.3.tgz", "resolved": "https://registry.nlark.com/vue-style-loader/download/vue-style-loader-4.1.3.tgz",
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
"document": "concurrently \"npm run gulp\" \"npm run live\"" "document": "concurrently \"npm run gulp\" \"npm run live\""
}, },
"dependencies": { "dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"element-ui": "^2.15.6", "element-ui": "^2.15.6",
"glsx-common": "^1.4.9", "glsx-common": "^1.3.2",
"gulp": "^4.0.2",
"vue": "^2.6.11", "vue": "^2.6.11",
"vuedraggable": "^2.24.3" "vue-amap": "^0.5.10"
}, },
"devDependencies": { "devDependencies": {
"@vue/babel-helper-vue-jsx-merge-props": "^1.2.1", "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
......
...@@ -6,6 +6,7 @@ import Vue from 'vue' ...@@ -6,6 +6,7 @@ import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
// 一次性注册所有的过滤器 本地测试 // 一次性注册所有的过滤器 本地测试
import filters from '@/filters' import filters from '@/filters'
import VueAMap from 'vue-amap'
// 一次性注册所有的自定义指令 // 一次性注册所有的自定义指令
// import directives from '@/directives' // import directives from '@/directives'
// 注册全局过滤器(一次性注册) // 注册全局过滤器(一次性注册)
...@@ -30,6 +31,14 @@ import './index' ...@@ -30,6 +31,14 @@ import './index'
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.use(VueAMap)
// 初始化vue-amap
VueAMap.initAMapApiLoader({
key: 'bd290dc27d0945959280753215ddda71', // 这里写你申请的高德地图的key
plugin: ['AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.Geolocation'],
v: '1.4.15'
})
new Vue({ new Vue({
render: h => h(App) render: h => h(App)
}).$mount('#app') }).$mount('#app')
<template> <template>
<div v-if="provinceView"> <div v-if="provinceView">
<el-form ref="provinceForm" :model="provinceForm" :inline="true" class="province"> <el-form ref="provinceForm" :model="provinceForm" :inline="inline" class="province" label-width="154px">
<el-select size="small" v-model="provinceForm.provinceName" clearable placeholder="选择省份" :style="{ width: defaultWidth }" @clear="selectProvince" class="select-padding"> <el-form-item :label="provinceLabel">
<el-select size="small" v-model="provinceForm.provinceName" clearable placeholder="选择省份" @clear="selectProvince" class="select-padding" :style="{ width: subdistrict == 2 ? '52%' : '33.33%' }">
<el-option v-for="(item, index) in AllData" :key="'province' + index" :label="item.name" :value="item.name" @click.native="selectProvince(item)"></el-option> <el-option v-for="(item, index) in AllData" :key="'province' + index" :label="item.name" :value="item.name" @click.native="selectProvince(item)"></el-option>
</el-select> </el-select>
<el-select size="small" v-model="provinceForm.cityName" clearable placeholder="选择市" :style="{ width: defaultWidth }" @clear="selectCity" class="select-padding"> <el-select size="small" v-model="provinceForm.cityName" clearable placeholder="选择市" @clear="selectCity" class="select-padding" :style="{ width: subdistrict == 2 ? '52%' : '33.33%' }">
<el-option v-for="(item, index) in cityList" :key="'city' + index" :label="item.name" :value="item.name" @click.native="selectCity(item)"></el-option> <el-option v-for="(item, index) in cityList" :key="'city' + index" :label="item.name" :value="item.name" @click.native="selectCity(item)"></el-option>
</el-select> </el-select>
<el-select v-if="subdistrict == 3" size="small" v-model="provinceForm.townName" clearable placeholder="选择区" :style="{ width: defaultWidth }" @clear="selectTown" class="select-padding"> <el-select v-if="subdistrict == 3" size="small" v-model="provinceForm.townName" clearable placeholder="选择区" @clear="selectTown" class="select-padding" :style="{ width: subdistrict == 2 ? '52%' : '33.33%' }">
<el-option v-for="(item, index) in townList" :key="'town' + index" :label="item.name" :value="item.name" @click.native="selectTown(item)"></el-option> <el-option v-for="(item, index) in townList" :key="'town' + index" :label="item.name" :value="item.name" @click.native="selectTown(item)"></el-option>
</el-select> </el-select>
</el-form-item>
<el-form-item :label="detailAddressLabel">
<el-input size="small" v-if="mapView" readonly placeholder="请选择详细地址" v-model="provinceForm.fullAddress">
<el-button size="small" slot="append" @click="hanleSelectMap">
<img src="@/assets/map.png" alt="" class="map-icon" />
</el-button>
</el-input>
</el-form-item>
</el-form> </el-form>
<GLDialog :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址">
<map-view ref="mapForm" :mapHeight="mapHeight"></map-view>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogMapVisible = false">取 消</el-button>
<el-button size="small" type="primary" @click="getAddress">确 定</el-button>
</span>
</GLDialog>
</div> </div>
</template> </template>
<script> <script>
import mapView from './mapView.vue'
import GLDialog from '@/packages/GLDialog/src/GLDialog'
export default { export default {
name: 'GLProvince', name: 'GLProvince',
components: {
mapView,
GLDialog
},
props: { props: {
// 是否一行展示
inline: {
type: Boolean,
default: false
},
// 省市级别,2--只显示省市,3--显示省市区 // 省市级别,2--只显示省市,3--显示省市区
subdistrict: { subdistrict: {
type: Number, type: Number,
// `2-只显示省市` // `2-只显示省市`
default: 2 default: 2
}, },
// 省市下拉组件宽度
defaultWidth: {
type: String,
default: '150px'
},
// 组件是否展示,默认展示 // 组件是否展示,默认展示
provinceView: { provinceView: {
type: Boolean, type: Boolean,
default: true default: true
},
// 地图组件是否展示,默认展示
// 如果需要展示地图组件,需要下载vue-amap包,并且在main.js中引入
// import VueAMap from "vue-amap"
// Vue.use(VueAMap)
// 初始化vue-amap
// VueAMap.initAMapApiLoader({
// key: "bd290dc27d0945959280753215ddda71", // 这里写你申请的高德地图的key
// plugin: ["AMap.PlaceSearch", "AMap.Geocoder", "AMap.Geolocation"],
// v: "1.4.15"
// });
mapView: {
type: Boolean,
default: true
},
// 省份标签值
provinceLabel: {
type: String,
default: '省市地址:'
},
// 详细地址标签值
detailAddressLabel: {
type: String,
default: '详细地址:'
} }
}, },
data() { data() {
...@@ -55,8 +101,16 @@ export default { ...@@ -55,8 +101,16 @@ export default {
// 城市代码 // 城市代码
cityCode: '', cityCode: '',
// 地区代码 // 地区代码
townCode: '' townCode: '',
} lat: '',
lng: '',
// 全部地址
fullAddress: ''
},
mapHeight: 380,
dialogMapVisible: false,
// 暂存地址表单
addressData: {}
} }
}, },
mounted() { mounted() {
...@@ -93,7 +147,6 @@ export default { ...@@ -93,7 +147,6 @@ export default {
provinceList() { provinceList() {
var params = {} var params = {}
params.subdistrict = this.subdistrict params.subdistrict = this.subdistrict
// params ? (params.subdistrict ? '' : (params.subdistrict = this.subdistrict)) : (params.subdistrict = this.subdistrict)
let data = '' let data = ''
for (let key in params) { for (let key in params) {
data += '&' + key + '=' + params[key] data += '&' + key + '=' + params[key]
...@@ -111,12 +164,14 @@ export default { ...@@ -111,12 +164,14 @@ export default {
return pro return pro
}, },
// 省市回显 // 省市回显
init(province, city, town) { init(provinceData) {
this.provinceForm = { const { province, city, townName, fullAddress, lng, lat } = provinceData
provinceName: province, this.provinceForm.provinceName = province
cityName: city, this.provinceForm.cityName = city
townName: town this.provinceForm.townName = townName
} this.provinceForm.fullAddress = fullAddress
this.provinceForm.lng = lng
this.provinceForm.lat = lat
if (province) { if (province) {
this.AllData.map(item => { this.AllData.map(item => {
if (item.name.indexOf(province) != -1) { if (item.name.indexOf(province) != -1) {
...@@ -129,9 +184,9 @@ export default { ...@@ -129,9 +184,9 @@ export default {
this.provinceForm.cityCode = itm.adcode this.provinceForm.cityCode = itm.adcode
this.provinceForm.cityName = itm.name this.provinceForm.cityName = itm.name
this.townList = itm.districts this.townList = itm.districts
if (town) { if (townName) {
this.townList.map(itmx => { this.townList.map(itmx => {
if (itmx.name.indexOf(town) != -1) { if (itmx.name.indexOf(townName) != -1) {
this.provinceForm.townCode = itmx.adcode this.provinceForm.townCode = itmx.adcode
this.provinceForm.townName = itmx.name this.provinceForm.townName = itmx.name
} }
...@@ -145,6 +200,8 @@ export default { ...@@ -145,6 +200,8 @@ export default {
} }
}, },
selectProvince(val) { selectProvince(val) {
this.provinceForm.provinceName = val ? val.name : ''
this.provinceForm.fullAddress = ''
this.provinceForm.cityName = '' this.provinceForm.cityName = ''
this.provinceForm.townName = '' this.provinceForm.townName = ''
if (val) { if (val) {
...@@ -157,6 +214,8 @@ export default { ...@@ -157,6 +214,8 @@ export default {
}, },
selectCity(val) { selectCity(val) {
this.provinceForm.cityName = val ? val.name : ''
this.provinceForm.fullAddress = ''
this.provinceForm.townName = '' this.provinceForm.townName = ''
if (val) { if (val) {
this.townList = val.districts this.townList = val.districts
...@@ -168,18 +227,121 @@ export default { ...@@ -168,18 +227,121 @@ export default {
}, },
selectTown(val) { selectTown(val) {
this.provinceForm.townName = val ? val.name : ''
this.provinceForm.fullAddress = ''
// 选择区 // 选择区
this.$emit('selectTown', val) this.$emit('selectTown', val)
},
// 打开地图弹框
hanleSelectMap() {
console.log(this.provinceForm)
this.dialogMapVisible = true
this.$nextTick(() => {
if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) {
this.$refs.mapForm.address = this.provinceForm.fullAddress
this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat])
}
})
},
// 选择地图地址
getAddress() {
if (!this.$refs.mapForm.address) {
this.$message.success('请选择地址')
return
}
this.provinceForm.fullAddress = this.$refs.mapForm.address
// 获取选择经纬度
let lnglat = this.$refs.mapForm.lnglat
this.provinceForm.lat = lnglat.lat
this.provinceForm.lng = lnglat.lng
var mapData = this.$refs.mapForm.geocoderAddress
// 赋值省市区名称和code
const { city, citycode, province, district, towncode } = mapData.addressComponent
this.provinceForm.provinceName = province
this.provinceForm.cityName = city
this.provinceForm.townName = district
this.provinceForm.provincecode = mapData.adcode
this.provinceForm.citycode = citycode
this.provinceForm.towncode = towncode
var fullAddress = ''
var provincecode = ''
// 为防止打开地图弹框不选择地址点确定按钮无法正确判断地址选择是否正确产生的报错,设置this.addressData.fullAddress来保存上次选择的地址
if (mapData.addressComponent) {
fullAddress = mapData.addressComponent
provincecode = mapData.adcode
this.addressData.fullAddress = fullAddress
this.addressData.provincecode = provincecode
} else {
fullAddress = this.addressData.fullAddress
provincecode = this.addressData.provincecode
}
// 获取省市
var provincename = ''
var cityname = ''
var town = ''
provincename = fullAddress.province
cityname = fullAddress.city ? fullAddress.city : fullAddress.district
town = fullAddress.district
// 直辖市需额外判断
const municipalities = ['北京市', '天津市', '上海市', '重庆市']
var municipality = municipalities.find(item => item == provincename)
if (municipality) {
cityname = cityname.slice(0, 2) + '城区'
if (municipality === '重庆市') {
provincecode = provincecode.slice(0, 4)
provincecode == 5001 ? (cityname = cityname.slice(0, 2) + '城区') : (cityname = cityname.slice(0, 2) + '郊县')
// 重新赋值城市名
this.provinceForm.cityName = cityname
}
}
// 判断省市是否匹配
// 如果只展示省市
if (this.provinceForm.provinceName && !this.provinceForm.townName) {
if (this.provinceForm.provinceName !== provincename || this.provinceForm.cityName !== cityname) {
this.$message.error('您选择的地址错误,请重新选择')
return
}
}
// 如果展示省市区
if (this.provinceForm.provinceName && this.provinceForm.townName) {
if (this.provinceForm.provinceName !== provincename || this.provinceForm.cityName !== cityname || this.provinceForm.townName !== town) {
this.$message.error('您选择的地址错误,请重新选择')
return
}
}
this.dialogMapVisible = false
// this.subdistrict == 2 ? this.init(province, city) : this.init(province, city, town)
// console.log(this.provinceForm.lat, 'provinceForm')
// 通过地图选择省市区
this.$emit('selectAddressByMap', this.provinceForm)
} }
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.province { // .province {
display: inline-flex; // display: inline-flex;
} // }
.select-padding { .select-padding {
margin-right: 10px; &:nth-child(1) {
margin-left: 0;
}
margin-left: 10px;
}
.map-icon {
vertical-align: middle;
}
/deep/ {
.el-input-group__append {
background-color: #fff;
padding: 0 11px;
}
.el-form-item__content {
width: 474px;
display: flex;
}
} }
</style> </style>
<template>
<div class="map-box" :style="{ height: mapHeight + 'px' }">
<div id="container" style="width: 100%; height: 100%"></div>
<div class="map-address">{{ address }}</div>
<div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
<el-input placeholder="请输入关键字" v-model="input" class="input-with-select">
<el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button>
</el-input>
</div>
</div>
</template>
<script>
let map, marker, placeSearch
export default {
name: 'map',
props: {
mapHeight: {
type: Number,
default: 300
}
},
data() {
return {
input: '',
address: '',
lnglat: [],
geocoderAddress: {}
}
},
methods: {
mapInit() {
map = new AMap.Map('container', {
resizeEnable: true,
zoom: 20
})
AMap.plugin(['AMap.PlaceSearch'], function() {
//构造地点查询类
placeSearch = new AMap.PlaceSearch({
pageSize: 8, // 单页显示结果条数
pageIndex: 1, // 页码
citylimit: false, //是否强制限制在设置的城市内搜索
// panel: "panel", // 结果列表将在此容器中进行展示。
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
renderStyle: 'default'
})
})
// 添加列表点选监听事件
map.on('click', this.getAddress)
},
searchAddress() {
let _this = this
placeSearch.search(this.input, function(status, result) {
if (status === 'complete' && result.poiList.pois.length) {
let lnglat = result.poiList.pois[0].location
_this.getAddress(lnglat)
}
})
},
addMarker(lnglat) {
let position
if (lnglat.lng) {
position = [lnglat.lng, lnglat.lat]
} else {
position = lnglat
}
marker = new AMap.Marker({
icon: new AMap.Icon({
image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
size: new AMap.Size(27, 34), //图标大小
imageSize: new AMap.Size(27, 34)
}),
position: position,
offset: new AMap.Pixel(-10, -10)
})
map.add(marker)
map.setFitView()
},
getAddress(e) {
let self = this
let lnglat
if (e.type == 'click') {
lnglat = e.lnglat
} else {
let { lng, lat } = e
lnglat = [lng, lat]
}
if (marker) {
marker.setMap(null)
marker = null
}
self.addMarker(lnglat)
AMap.plugin('AMap.Geocoder', () => {
const geocoder = new AMap.Geocoder()
geocoder.getAddress(lnglat, (status, result) => {
self.lnglat = lnglat
self.address = result.regeocode.formattedAddress
geocoder.getLocation(self.address, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.geocoderAddress = result.geocodes[0]
}
})
})
})
},
selectAddress(e) {
//这里获得点选地点的经纬度
this.getAddress()
}
},
mounted() {
this.mapInit()
}
}
</script>
<style scoped lang="scss">
.map-box {
position: relative;
width: 100%;
}
#container {
position: absolute;
height: 100%;
}
#panel {
position: absolute;
max-height: 90%;
overflow-y: auto;
top: 80px;
right: 10px;
width: 280px;
}
.map-address {
position: absolute;
line-height: 20px;
bottom: -30px;
}
</style>
...@@ -22,6 +22,7 @@ import GLSearchItem from './GlSearchItem' ...@@ -22,6 +22,7 @@ import GLSearchItem from './GlSearchItem'
import GLCombiForm from './GlCombiForm' import GLCombiForm from './GlCombiForm'
import GLTableButton from './GlTableButton' import GLTableButton from './GlTableButton'
import GLTabs from './GLTabs' import GLTabs from './GLTabs'
import GLTableOption from './GLTableOption'
// 导入业务组件 // 导入业务组件
import GLProvince from './GLProvince' import GLProvince from './GLProvince'
...@@ -37,7 +38,7 @@ const ElComponent = [Table, TableColumn, Popover, Button, ButtonGroup, Loading, ...@@ -37,7 +38,7 @@ const ElComponent = [Table, TableColumn, Popover, Button, ButtonGroup, Loading,
const BcComponent = [GLBcTest] const BcComponent = [GLBcTest]
// 存储组件列表 // 存储组件列表
const components = [TestComp, GLExternal, GLButton, GLDialog, GLTable, GLFooter, GLSearch, GLSearchItem, GLCombiForm, GLTableButton, GLProvince, GLFull, GLEditor, GLTabs].concat(ElComponent).concat(BcComponent) const components = [TestComp, GLExternal, GLButton, GLDialog, GLTable, GLFooter, GLSearch, GLSearchItem, GLCombiForm, GLTableButton, GLProvince, GLFull, GLEditor, GLTabs,GLTableOption].concat(ElComponent).concat(BcComponent)
// console.log('components: ', components); // console.log('components: ', components);
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册 // 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
...@@ -89,6 +90,7 @@ export default { ...@@ -89,6 +90,7 @@ export default {
GLSearchItem, GLSearchItem,
GLCombiForm, GLCombiForm,
GLTableButton, GLTableButton,
GLTableOption,
//业务组件 //业务组件
GLProvince, GLProvince,
GLBcTest, GLBcTest,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!