WebpageLinkEditDialog.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="webpage-link-edit-dialog">
  3. <div class="title">{{ lang.ssEditWebLink }}</div>
  4. <Input
  5. class="input"
  6. ref="inputRef"
  7. v-model:value="url"
  8. :placeholder="lang.ssWebUrlPh"
  9. @enter="save()"
  10. />
  11. <div class="btns">
  12. <Button @click="emit('close')" style="margin-right: 10px;">{{ lang.ssCancel }}</Button>
  13. <Button type="primary" @click="save()">{{ lang.ssConfirm }}</Button>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import { onMounted, ref, nextTick } from 'vue'
  19. import { useSlidesStore } from '@/store'
  20. import useHistorySnapshot from '@/hooks/useHistorySnapshot'
  21. import message from '@/utils/message'
  22. import { lang } from '@/main'
  23. import Input from '@/components/Input.vue'
  24. import Button from '@/components/Button.vue'
  25. const emit = defineEmits<{
  26. (event: 'close'): void
  27. }>()
  28. const props = defineProps<{
  29. elementId: string
  30. currentUrl: string
  31. }>()
  32. const slidesStore = useSlidesStore()
  33. const { addHistorySnapshot } = useHistorySnapshot()
  34. const url = ref(props.currentUrl)
  35. const inputRef = ref<InstanceType<typeof Input>>()
  36. onMounted(() => {
  37. nextTick(() => {
  38. inputRef.value?.focus()
  39. })
  40. })
  41. const save = () => {
  42. if (!url.value) {
  43. message.error(lang.ssWebUrlReq)
  44. return
  45. }
  46. // 验证URL格式
  47. try {
  48. new URL(url.value)
  49. }
  50. catch {
  51. message.error(lang.ssWebUrlInvalid)
  52. return
  53. }
  54. // 更新元素链接
  55. slidesStore.updateElement({
  56. id: props.elementId,
  57. props: { url: url.value }
  58. })
  59. // 添加历史记录
  60. addHistorySnapshot()
  61. emit('close')
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .webpage-link-edit-dialog {
  66. font-size: 13px;
  67. line-height: 1.675;
  68. }
  69. .title {
  70. font-size: 16px;
  71. font-weight: 600;
  72. margin-bottom: 20px;
  73. color: #333;
  74. }
  75. .input {
  76. width: 100%;
  77. height: 32px;
  78. }
  79. .btns {
  80. margin-top: 20px;
  81. text-align: right;
  82. }
  83. </style>