VUE 模塊化彈框 獲取地圖中心位置坐標(biāo)地址

模塊文件VUE

<template>

? <div v-if="showDialog" class="dialog" @touchmove.prevent>

? ? <div v-if="showDialog" class="back-drop"></div>

? ? <div class="alert" :class="{'alert-active':showDialogActive,'alert-big':big,'alert-middle':middle}" :style="'width:'+width+'px'">

? ? ? <div class="title">

? ? ? ? {{title}}

? ? ? ? <div class="iconfont close" @click="close">&#xe608;</div>

? ? ? </div>

? ? ? <div class="dialog-content">

? ? ? ? <slot></slot>

? ? ? </div>

? ? </div>

? </div>

</template>

<script>

import { setTimeout } from "timers";

export default {

? name: "v-templateCreat",

? props: {

? ? title: {

? ? ? type: String,

? ? ? default: "溫馨提示"

? ? },

? ? cancelText: {

? ? ? type: String,

? ? ? default: "取消"

? ? },

? ? doneText: {

? ? ? type: String,

? ? ? default: "確定"

? ? },

? ? middle:{

? ? ? type:Boolean,

? ? ? default:false

? ? },

? ? big:{

? ? ? type:Boolean,

? ? ? default:false

? ? },

? ? show: {

? ? ? type: Boolean,

? ? ? default: false

? ? },

? ? dismiss: {

? ? ? type: Boolean,

? ? ? default: false

? ? },

? ? width: {

? ? ? default: 498

? ? },

? ? open:Boolean

? },

? data() {

? ? return {

? ? ? showDialog: false,

? ? ? message: "",

? ? ? cancel: false,

? ? ? value: "",

? ? ? templateCreat: false,

? ? ? showDialogActive: false

? ? };

? },

? methods: {

? ? close() {

? ? ? this.showDialogActive = false;

? ? ? this.$emit('update:open', false);

? ? ? setTimeout(() => (this.showDialog = false), 320);

? ? },

? ? openFn(){

? ? ? this.showDialog = true;

? ? ? setTimeout(() => (this.showDialogActive = true));

? ? }

? },

? watch: {

? ? open:function(data){

? ? ? if(data) this.openFn();

? ? ? if(!data) this.close();

? ? },

? ? show: function(data) {

? ? ? this.openFn();

? ? },

? ? dismiss: function() {

? ? ? this.close();

? ? },

? },

? mounted(){


? }

};

</script>

<style lang="scss">

@import "../filters/css/all.css";

.dialog {

? position: fixed;

? top: 0;

? bottom: 0;

? left: 0;

? right: 0;

? width: 100%;

? height: 100%;

? background: rgba(0, 0, 0, 0);

? z-index: 106;

? .iconfont {

? ? float: right;

? ? cursor: pointer;

? ? color: #9b9b9b;

? }

? .back-drop {

? ? position: fixed;

? ? top: 0;

? ? bottom: 0;

? ? left: 0;

? ? right: 0;

? ? width: 100%;

? ? height: 100%;

? ? background: rgba(0, 0, 0, 0.4);

? ? z-index: 106;

? }

? .alert {

? ? width: 498px;

? ? min-height: 260px;

? ? // overflow-y: scroll;

? ? background: #fff;

? ? left: calc(50% - 249px);

? ? top: calc(50% - 280px);

? ? position: fixed;

? ? z-index: -1;

? ? transform: scale(1.23);

? ? opacity: 0;

? ? transition: all 0.32s;

? ? position: relative;

? ? .title {

? ? ? height: 44px;

? ? ? width: 100%;

? ? ? padding: 0 20px;

? ? ? -webkit-box-sizing: border-box;

? ? ? box-sizing: border-box;

? ? ? line-height: 44px;

? ? ? background: #f2f2f2;

? ? ? -webkit-box-align: center;

? ? ? -ms-flex-align: center;

? ? ? align-items: center;

? ? ? font-size: 16px;

? ? }

? ? .message {

? ? ? padding: 18px;

? ? ? min-height: 100px;

? ? ? overflow: auto;

? ? }

? }

? .alert-middle{

? ? width:614px !important;

? ? left:calc(50% - 307px);

? }

? .alert-big{

? ? width:748px !important;

? ? left:calc(50% - 374px);

? }

? .alert-active {

? ? z-index: 9999;

? ? transform: scale(1);

? ? opacity: 1;

? }

}

</style>

////////////////////////////////


使用

import templateCreat from "@/components/templateCreat";

components: {

? ? templateCreat

? },

<!-- 店鋪地址 -->

? ? <templateCreat

? ? ? :open.sync="creatShowTemplate"

? ? ? title="店鋪地址"

? ? ? :width="450"

? ? >

? ? ? <div class="exampleCenten">

? ? ? ? <div class="flex">

? ? ? ? ? <div class="leftTxt">所在地區(qū)</div>

? ? ? ? ? <div class="rightViewImg">

? ? ? ? ? ? <el-cascader

? ? ? ? ? ? ? style="width:310px;height:40px;"

? ? ? ? ? ? ? size="large"

? ? ? ? ? ? ? :options="regionOptions"

? ? ? ? ? ? ? v-model="form.selectedOptions"

? ? ? ? ? ? ? @change="addressChange"

? ? ? ? ? ? ></el-cascader>

? ? ? ? ? </div>

? ? ? ? </div>

? ? ? ? <div class="flex">

? ? ? ? ? <div class="leftTxt"></div>

? ? ? ? ? <div class="rightViewImg">

? ? ? ? ? ? <div class="amapsView">

? ? ? ? ? ? ? <div style="padding:0 0 10px;">確認坐標(biāo),方便到店消費</div>

? ? ? ? ? ? ? <div class="amaps" :style="events?'width:300px;height:240px;':''">

? ? ? ? ? ? ? ? <el-amap

? ? ? ? ? ? ? ? ? ref="map"

? ? ? ? ? ? ? ? ? vid="amapDemo"

? ? ? ? ? ? ? ? ? :amap-manager="amapManager"

? ? ? ? ? ? ? ? ? :center="center"

? ? ? ? ? ? ? ? ? :zoom="zoom"

? ? ? ? ? ? ? ? ? :plugin="plugin"

? ? ? ? ? ? ? ? ? :events="events"

? ? ? ? ? ? ? ? ? class="amap-demo"

? ? ? ? ? ? ? ? ></el-amap>

? ? ? ? ? ? ? ? <div class="amapsSon"></div>

? ? ? ? ? ? ? </div>

? ? ? ? ? ? ? <div style="padding:10px 0;width:300px;">{{form.address}}</div>

? ? ? ? ? ? </div>

? ? ? ? ? </div>

? ? ? ? </div>

? ? ? </div>

? ? ? <div class="flex msgboxBtns">

? ? ? ? <el-button type="primary" style="width:100px;border-radius:0;" @click="shopSiteClick">保存</el-button>

? ? ? </div>

? ? </templateCreat>

import VueAMap from "vue-amap";

VueAMap.initAMapApiLoader({

? key: "e1dedc6bdd765d46693986ff7ff969f4",

? plugin: [

? ? "AMap.Autocomplete", //輸入提示插件

? ? "AMap.PlaceSearch", //POI搜索插件

? ? "AMap.Scale", //右下角縮略圖插件 比例尺

? ? "AMap.OverView", //地圖鷹眼插件

? ? "AMap.ToolBar", //地圖工具條

? ? "AMap.MapType", //類別切換控件芬骄,實現(xiàn)默認圖層與衛(wèi)星圖账阻、實施交通圖層之間切換的控制

? ? "AMap.PolyEditor", //編輯 折線多淘太,邊形

? ? "AMap.CircleEditor", //圓形編輯器插件

? ? "AMap.Geolocation" //定位控件,用來獲取和展示用戶主機所在的經(jīng)緯度位置

? ],

? uiVersion: "1.0"

});

let amapManager = new VueAMap.AMapManager();

data() {

? ? let self = this;

? ? return {

amapManager, //地圖

? ? ? regionOptions: regionData,

? ? ? zoom: 12,

? ? ? center: [],

? ? ? getCertificationData: "",

? ? ? uploadActions: "",

? ? ? uploadType: "",

? ? ? initShow: false,

? ? ? ?form:{

address:‘’} //地址

? ? ? plugin: [

? ? ? ? {

? ? ? ? ? pName: "Geolocation",

? ? ? ? ? events: {

? ? ? ? ? ? init(o) {

? ? ? ? ? ? ? if (!self.initShow) {

? ? ? ? ? ? ? ? self.initShow = true;

? ? ? ? ? ? ? ? // o 是高德地圖定位插件實例

? ? ? ? ? ? ? ? o.getCurrentPosition((status, result) => {

? ? ? ? ? ? ? ? ? if (result && result.position) {

? ? ? ? ? ? ? ? ? ? console.log(result);

? ? ? ? ? ? ? ? ? ? self.form.longitude = result.position.lng;

? ? ? ? ? ? ? ? ? ? self.form.latitude = result.position.lat;

? ? ? ? ? ? ? ? ? ? self.center = [self.form.longitude, self.form.latitude];

? ? ? ? ? ? ? ? ? ? self.form.address = result.formattedAddress;

? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? }

? ? ? ? }

? ? ? ],

? ? ? events: {

? ? ? ? init: o => {

? ? ? ? ? o.getCity(result => {});

? ? ? ? },

? ? ? ? moveend: () => {},

? ? ? ? zoomchange: () => {},

? ? ? ? dragend: e => {

? ? ? ? ? var lgt = this.$refs.map.$$getCenter();

? ? ? ? ? self.form.latitude = lgt[1];

? ? ? ? ? self.form.longitude = lgt[0];

? ? ? ? ? self.asdasdashowswxcasd = false;

? ? ? ? ? self.center = [self.form.longitude, self.form.latitude];

? ? ? ? ? // 這里通過高德 SDK 完成。

? ? ? ? ? var geocoder = new AMap.Geocoder({

? ? ? ? ? ? radius: 1000,

? ? ? ? ? ? extensions: "all"

? ? ? ? ? });

? ? ? ? ? geocoder.getAddress(this.$refs.map.$$getCenter(), function(

? ? ? ? ? ? status,

? ? ? ? ? ? result

? ? ? ? ? ) {

? ? ? ? ? ? if (status === "complete" && result.info === "OK") {

? ? ? ? ? ? ? if (result && result.regeocode) {

? ? ? ? ? ? ? ? self.center = [self.form.longitude, self.form.latitude];

? ? ? ? ? ? ? ? self.form.address = result.regeocode.formattedAddress;

? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? });

? ? ? ? }

? ? ? },

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末松嘶,一起剝皮案震驚了整個濱河市翠订,隨后出現(xiàn)的幾起案子遵倦,更是在濱河造成了極大的恐慌,老刑警劉巖橙弱,帶你破解...
    沈念sama閱讀 216,651評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件棘脐,死亡現(xiàn)場離奇詭異蛀缝,居然都是意外死亡目代,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,468評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來霜大,“玉大人,你說我怎么就攤上這事曙强⊥久#” “怎么了囊卜?”我有些...
    開封第一講書人閱讀 162,931評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長雀瓢。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么排截? 我笑而不...
    開封第一講書人閱讀 58,218評論 1 292
  • 正文 為了忘掉前任断傲,我火速辦了婚禮,結(jié)果婚禮上箱蝠,老公的妹妹穿的比我還像新娘垦垂。我一直安慰自己,他們只是感情好间校,可當(dāng)我...
    茶點故事閱讀 67,234評論 6 388
  • 文/花漫 我一把揭開白布憔足。 她就那樣靜靜地躺著滓彰,像睡著了一般州袒。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上洗做,一...
    開封第一講書人閱讀 51,198評論 1 299
  • 那天诚纸,我揣著相機與錄音畦徘,去河邊找鬼。 笑死井辆,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的杯缺。 我是一名探鬼主播萍肆,決...
    沈念sama閱讀 40,084評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼塘揣,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了才写?” 一聲冷哼從身側(cè)響起奖蔓,我...
    開封第一講書人閱讀 38,926評論 0 274
  • 序言:老撾萬榮一對情侶失蹤吆鹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后轰异,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體搭独,經(jīng)...
    沈念sama閱讀 45,341評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡牙肝,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,563評論 2 333
  • 正文 我和宋清朗相戀三年配椭,在試婚紗的時候發(fā)現(xiàn)自己被綠了雹姊。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,731評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡敦姻,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出镰惦,到底是詐尸還是另有隱情,我是刑警寧澤兑凿,帶...
    沈念sama閱讀 35,430評論 5 343
  • 正文 年R本政府宣布礼华,位于F島的核電站,受9級特大地震影響慷暂,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜奸腺,卻給世界環(huán)境...
    茶點故事閱讀 41,036評論 3 326
  • 文/蒙蒙 一突照、第九天 我趴在偏房一處隱蔽的房頂上張望氧吐。 院中可真熱鬧,春花似錦座慰、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,676評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽谜慌。三九已至,卻和暖如春又沾,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背杖刷。 一陣腳步聲響...
    開封第一講書人閱讀 32,829評論 1 269
  • 我被黑心中介騙來泰國打工滑燃, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人典予。 一個月前我還...
    沈念sama閱讀 47,743評論 2 368
  • 正文 我出身青樓瘤袖,卻偏偏與公主長得像昂验,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子既琴,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,629評論 2 354

推薦閱讀更多精彩內(nèi)容