bx-865-apps #1

Merged
ksenia_mikhailova merged 140 commits from bx-865-apps into main 2024-06-27 15:03:27 +03:00
4 changed files with 76 additions and 34 deletions
Showing only changes of commit 870bdb7554 - Show all commits

View File

@ -5,12 +5,21 @@
@font-face { @font-face {
font-family: 'albertus'; font-family: 'albertus';
src: url( src: url('../font/Albertus\ Extra\ Bold\ Regular.ttf'
'../font/Albertus\ Extra\ Bold\ Regular.ttf' );
);
} }
@layer components {} @layer components {
.bg-primary {
@apply bg-pink-300
}
.bg-primary-hover {
@apply bg-pink-400
}
.border-primary {
@apply border-pink-500
}
}
.header { .header {
@apply col-span-12 p-2 font-extrabold text-2xl flex align-middle justify-center; @apply col-span-12 p-2 font-extrabold text-2xl flex align-middle justify-center;
@ -35,4 +44,5 @@
.router-link-active { .router-link-active {
@apply bg-slate-200 dark:bg-slate-700 @apply bg-slate-200 dark:bg-slate-700
} }

View File

@ -13,6 +13,12 @@ export default defineNuxtConfig({
css: ['~/assets/css/main.css'], css: ['~/assets/css/main.css'],
ssr: false, ssr: false,
devServer: { devServer: {
host: '0.0.0.0',
port: 3011 port: 3011
}, },
runtimeConfig: {
public: {
apiBase: '', // can be overridden by NUXT_PUBLIC_API_BASE environment variable
}
},
}) })

View File

@ -1,30 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
const testImg = '/_nuxt/assets/img/plan.svg'
const canvasElement: Ref<HTMLCanvasElement | undefined> = ref(); const canvasElement: Ref<HTMLCanvasElement | undefined> = ref();
const context: Ref<CanvasRenderingContext2D | undefined> = ref(); const context: Ref<CanvasRenderingContext2D | undefined> = ref();
console.log(testImg)
onMounted(async () => { onMounted(async () => {
const plan = useState('plan')
console.log(plan)
context.value = canvasElement.value?.getContext('2d') || undefined; context.value = canvasElement.value?.getContext('2d') || undefined;
if (context.value) { if (context.value) {
const img = await new Promise((resolve, reject) => { plan.value.paths.forEach(path => {
let img = new Image() context.value.stroke(new Path2D(path));
img.onload = () => resolve(img) });
img.onerror = reject
img.src = testImg
return img
})
const sourceWidth = img.width
const sourceHeight = img.height
const canvasHeight = canvasElement.value?.height || 1
const canvasWidth = canvasElement.value?.width
const imgHeight = (sourceHeight / sourceWidth) * canvasHeight
context.value.drawImage(img, 0, 0, canvasWidth, imgHeight)
// context.value.scale(2,2)
} }
}) })
</script> </script>
<template> <template>
<canvas ref="canvasElement" width="1300" height="1000"></canvas> <canvas ref="canvasElement" width="1200" height="1000"></canvas>
</template> </template>

View File

@ -1,15 +1,54 @@
<script setup lang="ts"> <script setup lang="ts">
const onAdvancedUpload = (event) => { import type { FileUploadUploadEvent } from '~/node_modules/primevue/fileupload/FileUpload.d.ts'
console.log(event) interface SvgContext {
paths: string[],
width: number,
height: number
}
const config = useRuntimeConfig()
const plan: Ref<SvgContext | {}> = useState('plan', () => ({}));
const loading = ref<boolean>(false)
const canvasElement: Ref<HTMLCanvasElement | undefined> = ref();
const context: Ref<CanvasRenderingContext2D | undefined> = ref();
const beforeUpload = () => {
loading.value = true
}
const onUpload = (event: FileUploadUploadEvent) => {
loading.value = false
try {
const data = JSON.parse(event.xhr.response)
plan.value = data.response
context.value = canvasElement.value?.getContext('2d') || undefined;
if (canvasElement.value && context.value) {
context.value.clearRect(0, 0, canvasElement.value.width, canvasElement.value.height);
if (!plan.value.hasOwnProperty('paths')) return
plan.value.paths.forEach((path: string) => {
if (!context.value) return
context.value.fillStyle = 'rgba(255, 0, 0, 0.25)'
context.value.fill(new Path2D(path));
context.value.strokeStyle = 'blue'
context.value.stroke(new Path2D(path));
});
}
} catch (error) {
console.error(error)
}
} }
</script> </script>
<template> <template>
<Panel> <div class="flex flex-col gap-4">
<FileUpload name="demo[]" url="/api/upload" @upload="onAdvancedUpload($event)" :multiple="true" accept="image/*" <Panel>
:maxFileSize="1000000"> <FileUpload mode="basic" name="demo" :url="`${config.public.apiBase}/api/prepare_image`" accept="image/*"
<template #empty> :maxFileSize="10000000" @upload="onUpload" @before-upload="beforeUpload" :auto="true"
<p>Перетащите сюда файлы для загрузки</p> chooseLabel="Выберите файл" :disabled="loading" />
</template> </Panel>
</FileUpload> <Panel v-if="plan && plan.paths">
</Panel> <canvas ref="canvasElement" width="1200" height="1000"></canvas>
</Panel>
</div>
</template> </template>