PickerLonlat.vue 962 B

123456789101112131415161718192021222324252627282930313233343536
  1. <template>
  2. <Button
  3. type="primary"
  4. size="small"
  5. :text="props.modelValue ? `${FormatUtils.formatCoordinates(props.modelValue[0], props.modelValue[1])}` : '请选择经纬度'"
  6. @click="openPicker"
  7. />
  8. </template>
  9. <script setup lang="ts">
  10. import { FormatUtils } from '@imengyu/imengyu-utils';
  11. import type { PickerLonlatProps } from './PickerLonlat';
  12. import Button from '@/components/basic/Button.vue';
  13. const props = defineProps<PickerLonlatProps & {
  14. modelValue: number[],
  15. }>()
  16. const emit = defineEmits(['update:modelValue', 'change']);
  17. function openPicker() {
  18. if (props.disabled)
  19. return;
  20. uni.chooseLocation({
  21. latitude: props.modelValue?.[0] || props.defaultLongLat?.[0],
  22. longitude: props.modelValue?.[1] || props.defaultLongLat?.[1],
  23. success: (res) => {
  24. console.log(res);
  25. emit('change', [res.latitude, res.longitude]);
  26. emit('update:modelValue', [res.latitude, res.longitude]);
  27. },
  28. });
  29. }
  30. </script>