PickerLonlat.vue 989 B

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