index.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <el-input v-model="appLink" placeholder="输入或选择链接">
  3. <template #append>
  4. <el-button @click="handleOpenDialog">选择</el-button>
  5. </template>
  6. </el-input>
  7. <AppLinkSelectDialog ref="dialogRef" @change="handleLinkSelected" />
  8. </template>
  9. <script lang="ts" setup>
  10. import { propTypes } from '@/utils/propTypes'
  11. // APP 链接输入框
  12. defineOptions({ name: 'AppLinkInput' })
  13. // 定义属性
  14. const props = defineProps({
  15. // 当前选中的链接
  16. modelValue: propTypes.string.def('')
  17. })
  18. // 当前的链接
  19. const appLink = ref('')
  20. // 选择对话框
  21. const dialogRef = ref()
  22. // 处理打开对话框
  23. const handleOpenDialog = () => dialogRef.value?.open(appLink.value)
  24. // 处理 APP 链接选中
  25. const handleLinkSelected = (link: string) => (appLink.value = link)
  26. // getter
  27. watch(
  28. () => props.modelValue,
  29. () => (appLink.value = props.modelValue),
  30. { immediate: true }
  31. )
  32. // setter
  33. const emit = defineEmits<{
  34. 'update:modelValue': [link: string]
  35. }>()
  36. watch(
  37. () => appLink,
  38. () => emit('update:modelValue', appLink.value)
  39. )
  40. </script>