@@ -52,7 +52,10 @@ const svgUrl = ref<string | null>(null)
|
||||
|
||||
// Получение имени файла
|
||||
const sanitizedFileName = computed(() => {
|
||||
const sanitized = qrCodeData.value?.name.replace(/[^a-zA-Z0-9-_]/g, '').trim()
|
||||
const sanitized = qrCodeData.value?.name
|
||||
.replace(/[<>:"/\\|?*\x00-\x1F]/g, '') // Убираем запрещённые символы
|
||||
.replace(/\s+/g, '_') // Заменяем пробелы на подчёркивания
|
||||
.trim()
|
||||
return sanitized ? `${sanitized}_QR-Code_HereConnect` : 'QR-Code_HereConnect'
|
||||
})
|
||||
|
||||
|
||||
@@ -1,50 +1,16 @@
|
||||
<template>
|
||||
<div class="flex flex-col min-h-screen">
|
||||
<!-- Основной контент -->
|
||||
<main class="flex-grow flex items-center justify-center py-6 px-4 md:px-6">
|
||||
<section class="max-w-lg w-full">
|
||||
<p class="text-gray-600 mb-4 text-center">
|
||||
Выберите сообщение из списка или напишите своё:
|
||||
</p>
|
||||
|
||||
<!-- Предустановленные сообщения -->
|
||||
<div v-if="presetMessages.length" class="mb-6">
|
||||
<div class="flex flex-col gap-3">
|
||||
<Button
|
||||
v-for="(message, index) in presetMessages"
|
||||
:key="index"
|
||||
class="p-button-outlined w-full text-left"
|
||||
:disabled="loading"
|
||||
@click="sendPresetMessage(message)"
|
||||
>
|
||||
{{ message }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Текстовое поле ввода с кнопкой -->
|
||||
<form @submit.prevent="sendCustomMessage" class="flex gap-2 items-center">
|
||||
<InputText
|
||||
id="customMessage"
|
||||
v-model="customMessage"
|
||||
class="flex-1"
|
||||
placeholder="Напишите сообщение"
|
||||
:disabled="loading"
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
icon="pi pi-send"
|
||||
class="p-button-md"
|
||||
:disabled="!customMessage.trim() || loading"
|
||||
/>
|
||||
</form>
|
||||
|
||||
<p v-if="success" class="text-green-500 mt-4 text-center">Сообщение отправлено!</p>
|
||||
<p v-if="error" class="text-red-500 mt-4 text-center">Ошибка: {{ error }}</p>
|
||||
<section class="max-w-lg w-full flex flex-col gap-10">
|
||||
<ReadContactInfo v-if="actions.includes('viewContactInfo')" :contactInfo="contactInfo" />
|
||||
<ReadMessageSender
|
||||
v-if="actions.includes('sendMessage')"
|
||||
:qr_code_uri="qr_code_uri"
|
||||
:predefinedMessages="predefinedMessages"
|
||||
/>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<!-- Футер -->
|
||||
<footer class="bg-gray-100 text-center py-4 border-t text-sm text-gray-700">
|
||||
<p>
|
||||
Нужен такой же?
|
||||
@@ -62,55 +28,22 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { getQrCodeDocument } from '@/api/qrCode'
|
||||
import { type QRCodeDocument } from '@/types/DBDocumentTypes'
|
||||
|
||||
const { qr_code_uri } = defineProps<{ qr_code_uri: QRCodeDocument['uri'] }>()
|
||||
const { qr_code_uri } = defineProps<{ qr_code_uri: string }>()
|
||||
|
||||
// Локальные состояния
|
||||
const presetMessages = ref<string[]>([])
|
||||
const customMessage = ref('')
|
||||
const success = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
const loading = ref(false)
|
||||
const predefinedMessages = ref<string[]>([])
|
||||
const contactInfo = ref<{ name?: string; phone?: string; email?: string }>({})
|
||||
const actions = ref<string[]>([])
|
||||
|
||||
// Функция для отправки сообщения
|
||||
async function sendMessage(message: string) {
|
||||
try {
|
||||
loading.value = true
|
||||
console.log({
|
||||
qr_code_uri,
|
||||
message: message.trim(),
|
||||
})
|
||||
|
||||
success.value = true
|
||||
error.value = null
|
||||
customMessage.value = ''
|
||||
} catch {
|
||||
success.value = false
|
||||
error.value = 'Ошибка отправки сообщения'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Функция для отправки предустановленного сообщения
|
||||
async function sendPresetMessage(message: string) {
|
||||
await sendMessage(message)
|
||||
}
|
||||
|
||||
// Функция для отправки пользовательского сообщения
|
||||
async function sendCustomMessage() {
|
||||
await sendMessage(customMessage.value)
|
||||
}
|
||||
|
||||
// Загрузка данных QR‑кода
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const qrCodeDoc = await getQrCodeDocument(qr_code_uri)
|
||||
presetMessages.value = qrCodeDoc!.predefinedMessage || []
|
||||
predefinedMessages.value = qrCodeDoc!.predefinedMessage || []
|
||||
contactInfo.value = qrCodeDoc!.contactInfo || { name: 'waka', phone: '+123' }
|
||||
actions.value = qrCodeDoc!.actions || []
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
error.value = 'Ошибка загрузки данных QR‑кода'
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user