UNPKG

@vuemap/vue-amap

Version:

高德地图vue3版本封装

95 lines (92 loc) 2.87 kB
import { defineComponent, ref, withDirectives, openBlock, createElementBlock, createCommentVNode, vShow } from 'vue'; import '../../../mixins/index.mjs'; import '../../../utils/index.mjs'; import { propsTypes } from './props.mjs'; import guid from '../../../utils/guid.mjs'; import { useRegister } from '../../../mixins/useRegister.mjs'; const _hoisted_1 = { class: "el-vue-search-box-container" }; const _hoisted_2 = ["id", "placeholder"]; var script = /* @__PURE__ */ defineComponent({ ...{ name: "ElAmapSearchBox", inheritAttrs: false }, __name: "SearchBox", props: propsTypes, emits: ["init"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const saveInputId = ref(guid()); const saveVisible = ref(true); let $amapComponent; let preInput; const { $$getInstance } = useRegister((options, parentComponent) => { if (options.inputId) { saveInputId.value = options.inputId; delete options.inputId; } if (options.visible) { saveVisible.value = options.visible; } options.input = saveInputId.value; if (options.outputId) { options.output = options.outputId; delete options.outputId; } let _inputTimer; return new Promise((resolve) => { parentComponent.plugin(["AMap.AutoComplete"], () => { const debounce = props.debounce; preInput = AMap.Autocomplete.prototype.onInPut; AMap.Autocomplete.prototype.onInPut = function() { clearTimeout(_inputTimer); _inputTimer = setTimeout(() => { this.output && this.autoSearch(); }, debounce); }; $amapComponent = new AMap.AutoComplete(options); resolve($amapComponent); }); }); }, { emits, watchRedirectFn: { __visible(flag) { saveVisible.value = flag; }, __citylimit(flag) { $amapComponent.setCityLimit(flag); } }, destroyComponent() { if (preInput && AMap.Autocomplete) { AMap.Autocomplete.prototype.onInPut = preInput; } } }); __expose({ $$getInstance }); return (_ctx, _cache) => { return withDirectives((openBlock(), createElementBlock( "div", _hoisted_1, [ !_ctx.inputCustom ? (openBlock(), createElementBlock("input", { key: 0, id: saveInputId.value, type: "text", placeholder: _ctx.placeholder }, null, 8, _hoisted_2)) : createCommentVNode("v-if", true) ], 512 /* NEED_PATCH */ )), [ [vShow, _ctx.visible && !_ctx.inputCustom] ]); }; } }); export { script as default }; //# sourceMappingURL=SearchBox.vue2.mjs.map