migrate map sheet to composition API and typescript

This commit is contained in:
MaysWind
2025-01-05 17:56:58 +08:00
parent fb8fbbcf70
commit 4f51480af9
3 changed files with 44 additions and 35 deletions
+2 -2
View File
@@ -56,7 +56,7 @@ const finalMapStyle = computed<Record<string, unknown>>(() => {
return styles; return styles;
}); });
function init() { function initMapView() {
let isFirstInit = false; let isFirstInit = false;
let centerChanged = false; let centerChanged = false;
@@ -112,6 +112,6 @@ function init() {
} }
defineExpose({ defineExpose({
init initMapView
}); });
</script> </script>
+41 -32
View File
@@ -30,39 +30,48 @@
</f7-sheet> </f7-sheet>
</template> </template>
<script> <script setup lang="ts">
export default { import { computed, useTemplateRef } from 'vue';
props: [ import type MapView from '@/components/common/MapView.vue';
'modelValue',
'show' import type { MapPosition } from '@/lib/map/base.ts';
],
emits: [ const props = defineProps<{
'update:modelValue', modelValue?: MapPosition;
'update:show' show: boolean;
], }>();
computed: {
geoLocation: { const emit = defineEmits<{
get: function () { (e: 'update:modelValue', value: MapPosition | undefined): void,
return this.modelValue; (e: 'update:show', value: boolean): void
}, }>();
set: function (value) {
this.$emit('update:modelValue', value); const map = useTemplateRef<MapView>('map');
}
} const geoLocation = computed<MapPosition | undefined>({
get: () => {
return props.modelValue;
}, },
methods: { set: value => {
save() { emit('update:modelValue', value);
this.$emit('update:show', false); }
}, });
onSheetOpen() {
this.$refs.map.init(); function save() {
}, emit('update:show', false);
onSheetClosed() { }
this.close();
}, function close() {
close() { emit('update:show', false);
this.$emit('update:show', false); }
}
function onSheetOpen() {
if (map.value) {
map.value.initMapView();
} }
} }
function onSheetClosed() {
close();
}
</script> </script>
@@ -756,7 +756,7 @@ export default {
if (newValue === 'map') { if (newValue === 'map') {
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs.map) { if (this.$refs.map) {
this.$refs.map.init(); this.$refs.map.initMapView();
} }
}); });
} }