UNPKG

@wfrog/vc

Version:

vue3 组件库 vc

184 lines (178 loc) 6.14 kB
import './index.css' import '../../chunk/E_WRn0OP.mjs'; import { E as ElInput } from '../../chunk/D19ZZ4OA.mjs'; import { E as ElButton } from '../../chunk/BT7IBuxS.mjs'; import { defineComponent, useTemplateRef, ref, computed, watch, nextTick, onMounted, createBlock, openBlock, unref, isRef, withCtx, createElementVNode, normalizeStyle, normalizeClass, createVNode, withKeys, createTextVNode } from 'vue'; import { Search } from '@element-plus/icons-vue'; import { d as defaultWindow, i as index } from '../../chunk/BdDihk0t.mjs'; import { C as Component$1 } from '../dialog/dialog.mjs'; import { _ as _export_sfc } from '../../chunk/pcqpp-6-.mjs'; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "dialog-map-point", props: { modelValue: {}, visible: { type: Boolean, default: false }, city: { default: "上海" }, ak: {} }, emits: ["update:visible", "update:modelValue", "close"], setup(__props, { emit: __emit }) { const props = __props; const emits = __emit; const containerRef = useTemplateRef("containerRef"); const keywords = ref(""); const dialogWidth = computed(() => { if (!defaultWindow) { return "500px"; } const width = document.body.clientWidth * 0.8; const maxWidth = 1e3; return `${width > maxWidth ? maxWidth : width}px`; }); const containerStyle = computed(() => { const height = document.body.clientHeight * 0.8; const maxHeight = 600; return { height: `${height > maxHeight ? maxHeight : height}px` }; }); const dialogVisible = computed({ get: () => props.visible, set: (val) => { emits("update:visible", val); if (!val) { emits("close"); } } }); let map; let local; const point = ref({ lng: 0, lat: 0 }); function init() { if (!defaultWindow) { return ""; } const { BMapGL } = defaultWindow; map = new BMapGL.Map(containerRef.value, { enableMapClick: false }); map.setDefaultCursor("default"); let marker = null; const { lng, lat } = props.modelValue; if (lng) { const myPoint = new BMapGL.Point(lng, lat); marker = new BMapGL.Marker(myPoint); map.addOverlay(marker); map.centerAndZoom(myPoint, 14); } else { map.centerAndZoom(props.city, 14); } map.enableScrollWheelZoom(); map.addControl(new BMapGL.NavigationControl()); setTimeout(() => { map.addControl(new BMapGL.ScaleControl()); }, 1e3); local = new BMapGL.LocalSearch(map, { renderOptions: { map } }); map.addEventListener("click", (e) => { point.value = e.latlng; marker && map.removeOverlay(marker); marker = new BMapGL.Marker(point.value); map.addOverlay(marker); }); } function handleClose() { dialogVisible.value = false; } function handleSearch() { local.search(keywords.value); } function handleClear() { local.clearResults(); } function destroy() { map = null; } watch(dialogVisible, (val) => { val && nextTick(() => init()); !val && destroy(); }); function handleConfirm() { emits("update:modelValue", point.value); handleClose(); } onMounted(() => { index.loadScriptSingle(`//api.map.baidu.com/getscript?type=webgl&v=1.0&ak=${props.ak}`); }); return (_ctx, _cache) => { const _component_ElButton = ElButton; const _component_ElInput = ElInput; return openBlock(), createBlock(Component$1, { modelValue: unref(dialogVisible), "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(dialogVisible) ? dialogVisible.value = $event : null), title: "选择地点", "close-on-click-modal": false, width: unref(dialogWidth), "show-close": false, "append-to-body": "", "show-fullscreen": false }, { footer: withCtx(() => [ createVNode(_component_ElButton, { onClick: handleClose }, { default: withCtx(() => [..._cache[2] || (_cache[2] = [ createTextVNode("取 消", -1) ])]), _: 1 }), createVNode(_component_ElButton, { type: "primary", onClick: handleConfirm }, { default: withCtx(() => [..._cache[3] || (_cache[3] = [ createTextVNode("确 定", -1) ])]), _: 1 }) ]), default: withCtx(() => [ createElementVNode("div", { ref_key: "containerRef", ref: containerRef, style: normalizeStyle(unref(containerStyle)) }, null, 4), createElementVNode("div", { class: normalizeClass(_ctx.$style.search) }, [ createVNode(_component_ElInput, { modelValue: unref(keywords), "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(keywords) ? keywords.value = $event : null), placeholder: "请输入查询地址", clearable: "", onKeyup: withKeys(handleSearch, ["enter"]), onClear: handleClear }, { append: withCtx(() => [ createVNode(_component_ElButton, { icon: unref(Search), onClick: handleSearch }, null, 8, ["icon"]) ]), _: 1 }, 8, ["modelValue"]) ], 2) ]), _: 1 }, 8, ["modelValue", "width"]); }; } }); /* unplugin-vue-components disabled */const search = "_search_56edn_1"; const style0 = { search: search }; const cssModules = { "$style": style0 }; const Component = /* @__PURE__ */ _export_sfc(_sfc_main, [["__cssModules", cssModules]]); const __vite_glob_0_11 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ __proto__: null, default: Component }, Symbol.toStringTag, { value: 'Module' })); export { Component as C, __vite_glob_0_11 as _ };