From 6b59d4962ca710385a7355a33bcadbe95c3d6795 Mon Sep 17 00:00:00 2001 From: Vyacheslav Nagel Date: Mon, 10 Jul 2023 00:33:40 +0700 Subject: [PATCH] add pinia --- package.json | 1 + src/App.vue | 110 +++++++++++++------------------------- src/components/Canvas.vue | 59 ++++++++++---------- src/const.ts | 19 ++++++- src/main.ts | 7 ++- src/store.ts | 61 +++++++++++++++++++++ src/types.ts | 8 ++- yarn.lock | 18 +++++++ 8 files changed, 180 insertions(+), 103 deletions(-) create mode 100644 src/store.ts diff --git a/package.json b/package.json index 3b3fbdc..a754609 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "html2canvas": "^1.4.1", + "pinia": "^2.1.4", "vue": "3.3.4" }, "devDependencies": { diff --git a/src/App.vue b/src/App.vue index b08a5bf..f78cc5f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,31 +6,25 @@ import Button from "./components/Button.vue"; import Page from "./components/Page.vue"; import Input from "./components/Input.vue"; import Canvas from "./components/Canvas.vue"; -import { ref } from "vue"; -import { - DEFAULT_HORIZONTAL_MARGIN, - DEFAULT_IMAGE_HEIGHT, - DEFAULT_IMAGE_WIDTH, - DEFAULT_VERTICAL_MARGIN, - DEFAULT_IMAGE_BACKGROUND_COLOR, - DEFAULT_VERTICAL_ROTATION, - DEFAULT_MARGIN_ENABLE, - DEFAULT_MARGIN_BACKGROUND_COLOR, - DEFAULT_MARGIN_LEFT_MARGIN, -} from "./const"; import { ButtonSize, InputType } from "./types"; +import { useStore } from "./store"; +import { storeToRefs } from "pinia"; +import { VARIANTS_VERTICAL_ROTATION, VARIANTS_IMAGE_SIZE } from './const'; -const vMargin = ref(DEFAULT_VERTICAL_MARGIN); -const vRotation = ref(DEFAULT_VERTICAL_ROTATION); -const hMargin = ref(DEFAULT_HORIZONTAL_MARGIN); -const hMargin2 = ref(DEFAULT_HORIZONTAL_MARGIN); -const imageWidth = ref(DEFAULT_IMAGE_WIDTH); -const imageHeight = ref(DEFAULT_IMAGE_HEIGHT); -const imageBackgroundColor = ref(DEFAULT_IMAGE_BACKGROUND_COLOR); +const store = useStore(); -const marginEnable = ref(DEFAULT_MARGIN_ENABLE); -const marginColor = ref(DEFAULT_MARGIN_BACKGROUND_COLOR); -const marginLeftMargin = ref(DEFAULT_MARGIN_LEFT_MARGIN); +const { + imageBackgroundColor, + vMargin, + vRotation, + hMargin, + hMargin2, + marginEnable, + marginColor, + marginLeftMargin, + imageWidth, + imageHeight, +} = storeToRefs(store); const savePng = async () => { const canvas = document.getElementById("canvas") as HTMLCanvasElement; @@ -43,90 +37,60 @@ const savePng = async () => { link.click(); } }; - -const rotatePage = () => { - const tmp = imageHeight.value; - imageHeight.value = imageWidth.value; - imageWidth.value = tmp; -};