diff --git a/src/views/Card/Edit.vue b/src/views/Card/Edit.vue index 10657ef..001390e 100644 --- a/src/views/Card/Edit.vue +++ b/src/views/Card/Edit.vue @@ -2,7 +2,7 @@ import Footer from "@/components/Footer.vue"; import FlexView from "@/components/FlexView.vue"; -import { ref, reactive, watch } from "vue"; +import { ref, watch, computed } from "vue"; import { useCardStore } from '@/store/card' @@ -11,10 +11,8 @@ import { useRouter } from "vue-router"; import axios from "axios"; import _ from "lodash"; -import { showToast, showLoadingToast, showSuccessToast,showFailToast } from "vant"; +import { showToast, showLoadingToast, showSuccessToast, showFailToast } from "vant"; -import { Cropper } from "vue-advanced-cropper"; -import "vue-advanced-cropper/dist/style.css"; import { onMounted } from "vue"; const URL = window.URL || window.webkitURL; @@ -33,18 +31,9 @@ const showDescSizePicker = ref(false); let flexRef = ref(null); const showMvPopup = () => { - console.log("test"); showMovie.value = true; }; -const crop = ref({ - show: false, - img: null, - outputType: "jpeg", - autoCrop: true, - autoCropWidth: 200, - autoCropHeight: 200, -}); // let state = reactive({ // imagePath: "", @@ -79,6 +68,21 @@ const form = ref({ }, }); +const defaultTheme = { + bgColor: "#ffffff", + desc: "", + descColor: "#000000", + image: "", + // link: "", + title: "", + titleSize: "xl", + descSize: "sm", + titleColor: "#000000", + ratio: "4:3", + isShow: true +} + + onMounted(() => { if (cardStore.cusCard.cus_card && cardStore.cusCard.cus_card.length > 0) { form.value = JSON.parse(cardStore.cusCard.cus_card); @@ -191,9 +195,9 @@ const moveBtn = (type, index) => { form.value.json5.cards[form.value.page - 1].btns[index], form.value.json5.cards[form.value.page - 1].btns[index - 1], ] = [ - form.value.json5.cards[form.value.page - 1].btns[index - 1], - form.value.json5.cards[form.value.page - 1].btns[index], - ]; + form.value.json5.cards[form.value.page - 1].btns[index - 1], + form.value.json5.cards[form.value.page - 1].btns[index], + ]; } } else { if (index + 1 !== form.value.json5.cards[form.value.page - 1].btns.length) { @@ -201,45 +205,127 @@ const moveBtn = (type, index) => { form.value.json5.cards[form.value.page - 1].btns[index + 1], form.value.json5.cards[form.value.page - 1].btns[index], ] = [ - form.value.json5.cards[form.value.page - 1].btns[index], - form.value.json5.cards[form.value.page - 1].btns[index + 1], - ]; + form.value.json5.cards[form.value.page - 1].btns[index], + form.value.json5.cards[form.value.page - 1].btns[index + 1], + ]; } } }; const afterRead = async (file, name) => { - // crop.value.show = true - // const ofile = file.file - // crop.value.img = URL.createObjectURL(ofile); + crop.value.show = true + const ofile = file.file + crop.value.img = URL.createObjectURL(ofile); + + // const imgFile = new FormData(); + // imgFile.append("fileType", "IMAGE"); + // imgFile.append("file", file.file); + + // showLoadingToast({ + // duration: 0, + // message: "圖片上傳中...", + // forbidClick: true, + // }); + + // let res = await axios.post( + // `${import.meta.env.VITE_APP_API_URL}/card/uploadfile`, + // imgFile, + // {} + // ); + + // if (res.data.code == 200) { + // form.value.json5.cards[form.value.page - 1].image = res.data.data; + + // showSuccessToast("上傳成功"); + // } else { + // showToast.fail("上傳失敗"); + // } - const imgFile = new FormData(); - imgFile.append("fileType", "IMAGE"); - imgFile.append("file", file.file); + // return; +}; - showLoadingToast({ - duration: 0, - message: "圖片上傳中...", - forbidClick: true, - }); +// START: 圖片剪裁 +// Author: Wayne +import { Cropper } from "vue-advanced-cropper"; +import "vue-advanced-cropper/dist/style.css"; - let res = await axios.post( - `${import.meta.env.VITE_APP_API_URL}/card/uploadfile`, - imgFile, - {} - ); +const myCrop = ref(null); - if (res.data.code == 200) { - form.value.json5.cards[form.value.page - 1].image = res.data.data; +const crop = ref({ + show: false, + img: null, + outputType: "jpeg", + autoCrop: true, + autoCropWidth: 200, + autoCropHeight: 200, +}); - showSuccessToast("上傳成功"); - } else { - showToast.fail("上傳失敗"); +const onCrop = () => { + const { canvas } = myCrop.value.getResult(); + if (canvas) { + const imgFile = new FormData(); + canvas.toBlob(async (blob) => { + let ufile = new File([blob], "image.jpg"); + imgFile.append("fileType", "IMAGE"); + imgFile.append("file", ufile); + + crop.value.show = false; + + showLoadingToast({ + duration: 0, + message: "圖片上傳中...", + forbidClick: true, + }); + + let res = await axios.post( + `${import.meta.env.VITE_APP_API_URL}/card/uploadfile`, + imgFile, + {} + ); + + if (res.data.code == 200) { + form.value.json5.cards[form.value.page - 1].image = res.data.data; + + showSuccessToast("上傳成功"); + } else { + showFailToast("上傳失敗"); + } + }, "image/jpeg"); } return; }; +const onClose = () => { + crop.value.show = false; +}; + +const setRatio = (type) => { + switch (type) { + case 1: + form.value.json5.cards[form.value.page - 1].ratio = '4:3'; + defaultTheme.ratio = '4:3' + break; + case 2: + form.value.json5.cards[form.value.page - 1].ratio = '1:1'; + defaultTheme.ratio = '1:1' + break; + case 3: + form.value.json5.cards[form.value.page - 1].ratio = '4:5'; + defaultTheme.ratio = '4:5' + break; + default: + break; + } +} + +const ratioToNumber = computed(() => { + let ratioArr = form.value.json5.cards[form.value.page - 1].ratio.split(':') + return (parseInt(ratioArr[0]) / parseInt(ratioArr[1])) +}) + +// END: 圖片剪裁 + const handleDelete = () => { form.value.json5.cards[form.value.page - 1].image = ""; }; @@ -280,10 +366,10 @@ const handleSubmit = async () => { let res = cardStore.updateCusCard(cusCard); - if(res){ + if (res) { showSuccessToast("建立成功"); - }else{ - showFailToast("建立失敗"); + } else { + showFailToast("建立失敗"); } // let res = await updateCusCard(cusCard); @@ -300,24 +386,17 @@ const handleSubmit = async () => { - + allowfullscreen> - - + + @@ -390,25 +436,13 @@ const handleSubmit = async () => {
- 卡片設定 - - + 卡片設定 + + - + - 內容圖片設定 - - + 內容圖片設定 + +