| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- <template>
- <div class="canvas-design-panel">
- <div class="mb-10">
- <b>客户可编辑项</b>
- </div>
- <div class="mb-10">
- <el-checkbox-group v-model="backgroundPerms" size="small">
- <el-checkbox v-for="perm in selectablePerms" :key="perm.code" :value="perm.code"
- @change="backgroundPermChange">
- {{ perm.name }}
- </el-checkbox>
- </el-checkbox-group>
- </div>
- <el-divider style="margin: 12px 0"/>
- <div class="mb-10">
- <b>{{ t("style.canvasSize") }}</b>
- </div>
- <div class="mb-10">
- <el-row class="size-row">
- <el-col :span="11">
- <el-input
- v-model="canvasWidth"
- :value="pageSizeWidth"
- @change="changeTemplateWidth"
- oninput="value=value.replace(/[^\d.]/g,'')"
- >
- <template #prepend>{{ t("style.w") }}</template>
- </el-input>
- </el-col>
- <el-col :span="2" class="fixed-ratio">
- <el-tooltip
- effect="dark"
- placement="top"
- :content="t('style.unlockAspectRatio')"
- v-if="isFixed"
- >
- <IconLock class="icon-btn" @click="changeFixedRatio(false)"/>
- </el-tooltip>
- <el-tooltip
- effect="dark"
- placement="top"
- :content="t('style.lockAspectRatio')"
- v-else
- >
- <IconUnlock class="icon-btn" @click="changeFixedRatio(true)"/>
- </el-tooltip>
- </el-col>
- <el-col :span="11">
- <el-input
- v-model="canvasHeight"
- :value="pageSizeHeight"
- @change="changeTemplateHeight"
- oninput="value=value.replace(/[^\d.]/g,'')"
- >
- <template #prepend>{{ t("style.h") }}</template>
- </el-input>
- </el-col>
- </el-row>
- </div>
- <!-- <div class="mb-10">-->
- <!-- <el-row>-->
- <!-- <el-col :span="11">-->
- <!-- <el-input-->
- <!-- v-model="clip"-->
- <!-- @change="changeTemplateClip"-->
- <!-- oninput="value=value.replace(/[^\d]/g,'')"-->
- <!-- :disabled="unitMode === 1"-->
- <!-- >-->
- <!-- <template #prepend>-->
- <!-- <el-tooltip-->
- <!-- placement="top"-->
- <!-- :hide-after="0"-->
- <!-- :content="t('style.bleedingLine')"-->
- <!-- >-->
- <!-- <IconCuttingOne/>-->
- <!-- </el-tooltip>-->
- <!-- </template>-->
- <!-- </el-input>-->
- <!-- </el-col>-->
- <!-- <el-col :span="2" class="fixed-ratio">-->
- <!-- <el-tooltip-->
- <!-- effect="dark"-->
- <!-- placement="top"-->
- <!-- :content="t('style.fillet')"-->
- <!-- v-if="isRound"-->
- <!-- >-->
- <!-- <IconRound class="icon-btn" @click="changeWorkRound(false)"/>-->
- <!-- </el-tooltip>-->
- <!-- <el-tooltip-->
- <!-- effect="dark"-->
- <!-- placement="top"-->
- <!-- :content="t('style.rightAngle')"-->
- <!-- v-else-->
- <!-- >-->
- <!-- <IconRightAngle class="icon-btn" @click="changeWorkRound(true)"/>-->
- <!-- </el-tooltip>-->
- <!-- </el-col>-->
- <!-- <el-col :span="11">-->
- <!-- <el-input-->
- <!-- v-model="safe"-->
- <!-- @change="changeTemplateSafe"-->
- <!-- oninput="value=value.replace(/[^\d]/g,'')"-->
- <!-- :disabled="unitMode === 1"-->
- <!-- >-->
- <!-- <template #prepend>-->
- <!-- <el-tooltip-->
- <!-- placement="top"-->
- <!-- :hide-after="0"-->
- <!-- :content="t('style.safetyLine')"-->
- <!-- >-->
- <!-- <IconShield/>-->
- <!-- </el-tooltip>-->
- <!-- </template>-->
- <!-- </el-input>-->
- <!-- </el-col>-->
- <!-- </el-row>-->
- <!-- </div>-->
- <!-- <div class="mt-10">-->
- <!-- <el-row>-->
- <!-- <el-col :span="11">-->
- <!-- <el-select v-model="unitMode" @change="changeUnitMode">-->
- <!-- <template #prefix>-->
- <!-- <el-tooltip-->
- <!-- placement="top"-->
- <!-- :hide-after="0"-->
- <!-- :content="t('style.unit')"-->
- <!-- >-->
- <!-- <IconRuler/>-->
- <!-- </el-tooltip>-->
- <!-- </template>-->
- <!-- <el-option-->
- <!-- v-for="item in DesignUnitMode"-->
- <!-- :key="item.id"-->
- <!-- :label="item.name"-->
- <!-- :value="item.id"-->
- <!-- ></el-option>-->
- <!-- </el-select>-->
- <!-- </el-col>-->
- <!-- <el-col :span="2"></el-col>-->
- <!-- <!– <el-col :span="11">–>-->
- <!-- <!– <el-select v-model="sizeMode">–>-->
- <!-- <!– <template #prefix>–>-->
- <!-- <!– <el-tooltip–>-->
- <!-- <!– placement="top"–>-->
- <!-- <!– :hide-after="0"–>-->
- <!-- <!– :content="t('style.template')"–>-->
- <!-- <!– >–>-->
- <!-- <!– <IconIdCard />–>-->
- <!-- <!– </el-tooltip>–>-->
- <!-- <!– </template>–>-->
- <!-- <!– <el-option–>-->
- <!-- <!– v-for="item in DesignSizeMode"–>-->
- <!-- <!– :key="item.id"–>-->
- <!-- <!– :label="item.name"–>-->
- <!-- <!– :value="item.id"–>-->
- <!-- <!– :disabled="item.disabled"–>-->
- <!-- <!– ></el-option>–>-->
- <!-- <!– </el-select>–>-->
- <!-- <!– </el-col>–>-->
- <!-- </el-row>-->
- <!-- </div>-->
- <el-divider style="margin: 12px 0"/>
- <div class="title">
- <b>{{ t("style.canvasFill") }}</b>
- </div>
- <!-- <div class="row">-->
- <!-- <el-button class="full-row" @click="changeAllBackgroud">{{ t("style.applyCanvasToAll") }}</el-button>-->
- <!-- </div>-->
- <Backgrounds/>
- <el-divider style="margin: 12px 0"/>
- <!-- <Watermark/>-->
- <!-- <el-divider style="margin: 12px 0"/>-->
- <!-- <div class="title">-->
- <!-- <b>{{ t("style.canvasMask") }}</b>-->
- <!-- </div>-->
- <!-- <el-row>-->
- <!-- <el-col :span="7" class="slider-name">{{ t("style.opacity") }}:</el-col>-->
- <!-- <el-col :span="13">-->
- <!-- <el-slider :min="0.1" :max="1" :step="0.01" v-model="opacity" @change="changeMaskOpacity"></el-slider>-->
- <!-- </el-col>-->
- <!-- <el-col :span="4" class="slider-num">{{ opacity }}</el-col>-->
- <!-- </el-row>-->
- </div>
- </template>
- <script lang="ts" setup>
- import {Rect} from "fabric";
- import {storeToRefs} from "pinia";
- import {ElMessage} from "element-plus";
- import {ref, watch, onMounted, computed, nextTick} from "vue";
- import {mm2px, px2mm} from "@/utils/image";
- import useI18n from "@/hooks/useI18n";
- import {useFabricStore, useMainStore, useTemplatesStore} from "@/store";
- import {
- WorkSpaceClipType,
- WorkSpaceDrawType,
- WorkSpaceMaskType,
- } from "@/configs/canvas";
- import {
- DesignUnitMode,
- DesignSizeMode,
- MinSize,
- MaxSize,
- } from "@/configs/background";
- import useCanvas from "@/views/Canvas/useCanvas";
- import Backgrounds from "../Backgrounds/index.vue";
- import Watermark from "./Watermark/index.vue";
- import useHistorySnapshot from "@/hooks/useHistorySnapshot";
- import useCanvasScale from '@/hooks/useCanvasScale'
- import {WorkSpaceElement} from "@/types/canvas";
- import {GradientColorLibs} from "@/configs/colorGradient";
- const {t} = useI18n();
- const mainStore = useMainStore();
- const templatesStore = useTemplatesStore();
- const fabricStore = useFabricStore();
- const {addHistorySnapshot} = useHistorySnapshot();
- const {sizeMode, unitMode} = storeToRefs(mainStore);
- const {currentTemplate} = storeToRefs(templatesStore);
- const {clip, safe, zoom, opacity} = storeToRefs(fabricStore);
- const {setCanvasSize, resetCanvas} = useCanvasScale()
- const pageSizeWidth = computed(() => {
- return Math.round(templateWidth.value * 100) / 100
- })
- const pageSizeHeight = computed(() => {
- return Math.round(templateHeight.value * 100) / 100
- })
- const templateWidth = computed(() => {
- // const [ canvas ] = useCanvas()
- // if (!canvas) return 0
- const workWidth = currentTemplate.value.width / currentTemplate.value.zoom;
- return unitMode.value === 0 ? px2mm(workWidth) : workWidth;
- });
- const templateHeight = computed(() => {
- // const [ canvas ] = useCanvas()
- // if (!canvas) return 0
- const workHeight = currentTemplate.value.height / currentTemplate.value.zoom;
- return unitMode.value === 0 ? px2mm(workHeight) : workHeight;
- });
- // const canvasWidth = ref<number>(px2mm(currentTemplate.value.width / currentTemplate.value.zoom))
- const canvasWidth = ref<number>(templateWidth.value);
- const canvasHeight = ref<number>(templateHeight.value);
- const backgroundPerms = ref([]);
- const selectablePerms = [
- {
- "name": "背景颜色",
- "code": "0"
- },
- {
- "name": "背景尺寸",
- "code": "1"
- },
- // {
- // "name": "上传背景",
- // "code": "2"
- // }
- ]
- // 固定宽高
- const isFixed = ref(false);
- // 直角圆角
- const isRound = ref(false);
- // 网格 预定义 参数
- const RECENT_GRIDS = "RECENT_GRIDS";
- const gridColorRecent = ref<[string[]]>([[]]);
- //修改背景的可编辑参数
- const backgroundPermChange = () => {
- const [canvas] = useCanvas();
- canvas.getObjects()
- .filter((item) => item.id === WorkSpaceDrawType).forEach(workSpaceDraw => {
- workSpaceDraw.set({permissionsConfig: backgroundPerms.value})
- })
- }
- // 获取画布尺寸
- const getCanvasSize = () => {
- let width =
- unitMode.value === 0 ? mm2px(canvasWidth.value) : canvasWidth.value;
- let height =
- unitMode.value === 0 ? mm2px(canvasHeight.value) : canvasHeight.value;
- width = width * zoom.value;
- height = height * zoom.value;
- return {width, height};
- };
- // 修改画布宽度
- const changeTemplateWidth = () => {
- const [canvas] = useCanvas();
- const workSpaceDraw = canvas
- .getObjects()
- .filter((item) => item.id === WorkSpaceDrawType)[0];
- if (!workSpaceDraw) return;
- const ratio = currentTemplate.value.height / currentTemplate.value.width;
- let {width, height} = getCanvasSize();
- if (width / zoom.value < mm2px(MinSize)) {
- ElMessage({
- message: t("style.minimumSizeLimit") + MinSize,
- type: "warning",
- });
- width = mm2px(MinSize) * zoom.value;
- }
- if (width / zoom.value > mm2px(MaxSize)) {
- ElMessage({
- message: t("style.maximumSizeLimit") + MaxSize,
- type: "warning",
- });
- width = mm2px(MaxSize) * zoom.value;
- }
- height = isFixed.value ? width * ratio : height;
- workSpaceDraw.set({width: width / zoom.value, height: height / zoom.value});
- templatesStore.setSize(width, height, zoom.value);
- sizeMode.value = 2;
- canvas.renderAll();
- // resetCanvas()
- addHistorySnapshot();
- };
- // 修改画布高度
- const changeTemplateHeight = () => {
- const [canvas] = useCanvas();
- const workSpaceDraw = canvas
- .getObjects()
- .filter((item) => item.id === WorkSpaceDrawType)[0];
- if (!workSpaceDraw) return;
- const ratio = currentTemplate.value.height / currentTemplate.value.width;
- let {width, height} = getCanvasSize();
- if (height / zoom.value < mm2px(MinSize)) {
- ElMessage({
- message: t("style.minimumSizeLimit") + MinSize,
- type: "warning",
- });
- height = mm2px(MinSize) * zoom.value;
- }
- if (height / zoom.value > mm2px(MaxSize)) {
- ElMessage({
- message: t("style.maximumSizeLimit") + MaxSize,
- type: "warning",
- });
- height = mm2px(MaxSize) * zoom.value;
- }
- width = isFixed.value ? height / ratio : width;
- workSpaceDraw.set({width: width / zoom.value, height: height / zoom.value});
- templatesStore.setSize(width, height, zoom.value);
- sizeMode.value = 2;
- canvas.renderAll();
- // resetCanvas()
- addHistorySnapshot();
- };
- // 修改出血尺寸
- const changeTemplateClip = async () => {
- templatesStore.setClip(clip.value);
- await templatesStore.renderTemplate();
- };
- // 修改安全尺寸
- const changeTemplateSafe = async () => {
- safe.value = Number(safe.value);
- await templatesStore.renderTemplate();
- };
- // 修改固定宽高比
- const changeFixedRatio = (fixedStatus: boolean) => {
- isFixed.value = fixedStatus;
- };
- // 修改直角圆角
- const changeWorkRound = (roundStatus: boolean) => {
- const [canvas] = useCanvas();
- const workSpaceclip = canvas
- .getObjects()
- .filter(
- (item) => WorkSpaceClipType === item.id && item.isType("Rect")
- )[0] as Rect;
- let rx = 0,
- ry = 0;
- isRound.value = roundStatus;
- if (isRound.value) rx = ry = 10;
- workSpaceclip.set({rx, ry});
- canvas.renderAll();
- };
- // 修改尺寸单位
- const changeUnitMode = async () => {
- const width = currentTemplate.value.width / currentTemplate.value.zoom;
- const heigth = currentTemplate.value.height / currentTemplate.value.zoom;
- if (unitMode.value === 0) {
- canvasWidth.value = px2mm(width);
- canvasHeight.value = px2mm(heigth);
- clip.value = 2;
- safe.value = 3;
- } else {
- canvasWidth.value = width;
- canvasHeight.value = heigth;
- clip.value = safe.value = 0;
- }
- await changeTemplateClip();
- await changeTemplateSafe();
- };
- // 应用背景到所有页面
- const changeAllBackgroud = () => {
- templatesStore.templates.forEach((item) => {
- item.workSpace = currentTemplate.value.workSpace;
- const currentWorkSpace = currentTemplate.value.objects.filter(
- (ele) => ele.id === WorkSpaceDrawType
- )[0];
- item.objects = item.objects.map((ele) =>
- ele.id === WorkSpaceDrawType ? currentWorkSpace : ele
- ) as any;
- });
- };
- // 加载缓存最近添加的网格
- onMounted(() => {
- const recentGridCache = localStorage.getItem(RECENT_GRIDS);
- if (recentGridCache) gridColorRecent.value = JSON.parse(recentGridCache);
- const [canvas] = useCanvas();
- const workSpaceDraw = canvas
- .getObjects()
- .filter((item) => item.id === WorkSpaceDrawType)[0];
- if (!workSpaceDraw) return;
- if (workSpaceDraw.get('permissionsConfig'))
- backgroundPerms.value = workSpaceDraw.get('permissionsConfig')
- });
- // 保存缓存最近添加的网格
- watch(
- gridColorRecent,
- () => {
- const recentGridCache = JSON.stringify(gridColorRecent.value);
- localStorage.setItem(RECENT_GRIDS, recentGridCache);
- },
- {deep: true}
- );
- const changeMaskOpacity = () => {
- const [canvas] = useCanvas();
- const workMask = canvas
- .getObjects()
- .filter((ele) => ele.id === WorkSpaceMaskType)[0];
- if (!workMask) return;
- workMask.set("opacity", opacity.value);
- canvas.renderAll();
- };
- </script>
- <style lang="scss" scoped>
- .icon-btn {
- cursor: pointer;
- }
- .canvas-design-panel {
- user-select: none;
- }
- .row {
- width: 100%;
- display: flex;
- align-items: center;
- margin-bottom: 10px;
- }
- .title {
- margin-bottom: 10px;
- }
- .fixed-ratio {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .slider-name {
- display: flex;
- align-items: center;
- }
- .mb-10 {
- margin-bottom: 10px;
- }
- .full-row {
- flex: 1;
- width: 100%;
- }
- .full-group {
- display: flex;
- flex: 1;
- .el-button {
- width: 50%;
- }
- }
- .full-ratio {
- display: flex;
- flex: 1;
- .el-radio-button {
- width: 50%;
- }
- .el-radio-button__inner {
- width: 100%;
- }
- }
- .background-image {
- height: 0;
- padding-bottom: 56.25%;
- border: 1px dashed var(--el-border-color);
- border-radius: $borderRadius;
- position: relative;
- transition: all $transitionDelay;
- &:hover {
- border-color: var(--el-color-primary);
- color: var(--el-color-primary);
- }
- .content {
- @include absolute-0();
- display: flex;
- justify-content: center;
- align-items: center;
- background-position: center;
- background-size: contain;
- background-repeat: no-repeat;
- cursor: pointer;
- }
- }
- .theme-list {
- @include flex-grid-layout();
- }
- .theme-item {
- @include flex-grid-layout-children(2, 48%);
- padding-bottom: 30%;
- border-radius: $borderRadius;
- position: relative;
- cursor: pointer;
- .theme-item-content {
- @include absolute-0();
- display: flex;
- flex-direction: column;
- justify-content: center;
- padding: 8px;
- border: 1px solid $borderColor;
- }
- .text {
- font-size: 16px;
- }
- .colors {
- display: flex;
- }
- .color-block {
- margin-top: 8px;
- width: 12px;
- height: 12px;
- margin-right: 2px;
- }
- &:hover .btns {
- display: flex;
- }
- .btns {
- @include absolute-0();
- flex-direction: column;
- justify-content: center;
- align-items: center;
- display: none;
- background-color: rgba($color: #000, $alpha: 0.25);
- }
- .btn {
- width: 72px;
- padding: 5px 0;
- text-align: center;
- background-color: $themeColor;
- color: #fff;
- font-size: 12px;
- border-radius: $borderRadius;
- &:hover {
- background-color: #c42f19;
- }
- & + .btn {
- margin-top: 5px;
- }
- }
- }
- .mt-10 {
- margin-top: 10px;
- }
- .slider-num {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- </style>
- <style scoped>
- :deep(.el-input .el-input-group__prepend) {
- padding: 0 5px;
- }
- :deep(.el-input .el-input-group__append) {
- padding: 0 5px;
- }
- :deep(.full-ratio .el-radio-button__inner) {
- width: 100%;
- }
- :deep(.size-row .el-input-group__prepend) {
- min-width: 24px;
- }
- </style>
|