|
|
@@ -12,6 +12,20 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
+ <el-row class="permRow" :gutter="20">
|
|
|
+ <el-col :span="10">
|
|
|
+ <span class="eleLabel">显示背景</span>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="14">
|
|
|
+ <el-switch
|
|
|
+ v-model="backGroundObject.visible"
|
|
|
+ :active-value="true"
|
|
|
+ :inactive-value="false"
|
|
|
+ @change="setBackGroudVisible"
|
|
|
+ />
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
<template v-for="(perm) in backGroundObject.permissionsConfig">
|
|
|
<el-row class="permRow" v-if="perm == '0'">
|
|
|
<el-row>
|
|
|
@@ -79,7 +93,7 @@
|
|
|
filterable
|
|
|
allow-create
|
|
|
default-first-option
|
|
|
- @change="eleTextChange(text.id, $event)">
|
|
|
+ @change="eleTextChange(text, $event)">
|
|
|
<el-option v-for="str in text.userPresetTexts"
|
|
|
:key="str.text"
|
|
|
:label="str.text"
|
|
|
@@ -93,22 +107,35 @@
|
|
|
<el-col :span="4">
|
|
|
<span class="eleLabel">字号</span>
|
|
|
</el-col>
|
|
|
- <el-col :span="20">
|
|
|
- <el-button-group class="full-group">
|
|
|
- <el-tooltip placement="top" content="增大字号" :hide-after="0">
|
|
|
- <el-button class="font-size" @click="handleElementFontsize(text.id,'+')">
|
|
|
- <IconFontSize/>
|
|
|
- +
|
|
|
- </el-button>
|
|
|
- </el-tooltip>
|
|
|
+ <!-- <el-col :span="20">-->
|
|
|
+ <!-- <el-button-group class="full-group">-->
|
|
|
+ <!-- <el-tooltip placement="top" content="增大字号" :hide-after="0">-->
|
|
|
+ <!-- <el-button class="font-size" @click="handleElementFontsize(text.id,'+')">-->
|
|
|
+ <!-- <IconFontSize/>-->
|
|
|
+ <!-- +-->
|
|
|
+ <!-- </el-button>-->
|
|
|
+ <!-- </el-tooltip>-->
|
|
|
+
|
|
|
+ <!-- <el-tooltip placement="top" content="减小字号" :hide-after="0">-->
|
|
|
+ <!-- <el-button @click="handleElementFontsize(text.id,'-')">-->
|
|
|
+ <!-- <IconFontSize/>-->
|
|
|
+ <!-- - -->
|
|
|
+ <!-- </el-button>-->
|
|
|
+ <!-- </el-tooltip>-->
|
|
|
+ <!-- </el-button-group>-->
|
|
|
+ <!-- </el-col>-->
|
|
|
|
|
|
- <el-tooltip placement="top" content="减小字号" :hide-after="0">
|
|
|
- <el-button @click="handleElementFontsize(text.id,'-')">
|
|
|
- <IconFontSize/>
|
|
|
- -
|
|
|
- </el-button>
|
|
|
- </el-tooltip>
|
|
|
- </el-button-group>
|
|
|
+ <el-col :span="20">
|
|
|
+ <el-select
|
|
|
+ v-model="text.fontSize"
|
|
|
+ filterable
|
|
|
+ allow-create
|
|
|
+ default-first-option
|
|
|
+ placement="left"
|
|
|
+ @change="handleElementFontSize(text.id,$event)"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in FontSizeLibs" :key="item" :label="item" :value="item"></el-option>
|
|
|
+ </el-select>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
@@ -136,6 +163,19 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
+ <!--曲线文字需要调整曲率-->
|
|
|
+ <el-row class="permRow" v-if="text.type.toLowerCase() === ElementNames.ARCTEXT && perm == '0'">
|
|
|
+ <el-col :span="4">
|
|
|
+ <span class="eleLabel">曲率</span>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1"></el-col>
|
|
|
+ <el-col :span="19" class="flex-align">
|
|
|
+ <el-slider :min="1" :max="1000" :step="1" v-model="text.radius"
|
|
|
+ @change="changeArcTextRadius(text.id, $event)" size="small"></el-slider>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+
|
|
|
<!-- 颜色-->
|
|
|
<el-row class="permRow" v-if="perm == '3'">
|
|
|
<el-row>
|
|
|
@@ -254,13 +294,14 @@ import {WorkSpaceElement} from "@/types/canvas";
|
|
|
import {storeToRefs} from "pinia";
|
|
|
import {useFabricStore, useMainStore, useTemplatesStore} from "@/store";
|
|
|
import {propertiesToInclude, WorkSpaceDrawType} from "@/configs/canvas";
|
|
|
-import {Gradient, Pattern, Image, util, Textbox} from "fabric";
|
|
|
+import {Image, Pattern, Textbox, util} from "fabric";
|
|
|
import useHandleBackground from "@/hooks/useHandleBackground";
|
|
|
import {mm2px, px2mm} from "@/utils/image";
|
|
|
import {ElMessage} from "element-plus";
|
|
|
import useI18n from "@/hooks/useI18n";
|
|
|
import {ArcText} from "@/extension/object/ArcText";
|
|
|
-import {FontGroupOption} from "@/types/elements";
|
|
|
+import {ElementNames, FontGroupOption} from "@/types/elements";
|
|
|
+import {FontSizeLibs} from "@/configs/texts";
|
|
|
|
|
|
const {t} = useI18n();
|
|
|
const mainStore = useMainStore();
|
|
|
@@ -294,8 +335,8 @@ const objects = canvas.getObjects().filter((object) => !["WorkSpaceMaskType", "W
|
|
|
// })
|
|
|
|
|
|
const backGroundObject = canvas.getObjects().filter((item) => item.id === WorkSpaceDrawType)[0];
|
|
|
-const textObjects = canvas.getObjects().filter((item) => item.name === 'textbox');
|
|
|
-const imgObjects = canvas.getObjects().filter((item) => item.name === 'image');
|
|
|
+const textObjects = currentTemplate.value.objects.filter((item) => item.name === 'textbox');
|
|
|
+const imgObjects = currentTemplate.value.objects.filter((item) => item.name === 'image');
|
|
|
|
|
|
const textPermDisplay = computed(() => {
|
|
|
let result = false;
|
|
|
@@ -390,6 +431,11 @@ const updateBackground = (props: Partial<WorkSpaceElement>) => {
|
|
|
canvas.renderAll();
|
|
|
};
|
|
|
|
|
|
+// 设置背景可见
|
|
|
+const setBackGroudVisible = (val) => {
|
|
|
+ templatesStore.modifedElement(backGroundObject, {visible: val})
|
|
|
+}
|
|
|
+
|
|
|
// 修改上传背景
|
|
|
const changeBackgroundImage = async (imageURL: string) => {
|
|
|
if (background.value.imageSize === "repeat") {
|
|
|
@@ -485,16 +531,99 @@ const findObject = (objId: string) => {
|
|
|
return objects.find((item) => item.id === objId);
|
|
|
}
|
|
|
|
|
|
+// 文字核心调整函数0-默认
|
|
|
+function adjustFontDefault(textbox, maxHeight, maxWidth) {
|
|
|
+ const textWidth = textbox.calcTextWidth();
|
|
|
+
|
|
|
+ const scaleWidth = textWidth > maxWidth ? textWidth : maxWidth
|
|
|
+
|
|
|
+ if (textbox.isEditing) {
|
|
|
+ textbox.setSelectionStyles({width: scaleWidth})
|
|
|
+ } else {
|
|
|
+ templatesStore.modifedElement(textbox, {width: scaleWidth})
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 文字核心调整函数1-尺寸
|
|
|
+function adjustFontSize(textbox, maxHeight, maxWidth) {
|
|
|
+ let currentSize = textbox.fontSize;
|
|
|
+ const maxFontSize = 80
|
|
|
+ const minFontSize = 6
|
|
|
+
|
|
|
+ console.log("宽" + maxWidth + "高" + maxHeight)
|
|
|
+ // 若空间有余,尝试恢复最大字号
|
|
|
+ while (/*textbox.width <= maxWidth*/ textbox.height < maxHeight && currentSize < maxFontSize) {
|
|
|
+ currentSize += 1;
|
|
|
+ const fontSize = currentSize
|
|
|
+ if (textbox.isEditing) {
|
|
|
+ textbox.setSelectionStyles({fontSize})
|
|
|
+ } else {
|
|
|
+ templatesStore.modifedElement(textbox, {fontSize})
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检测是否超出边界
|
|
|
+ while (/*(textbox.width > maxWidth ||*/ textbox.height > maxHeight && currentSize > minFontSize) {
|
|
|
+ currentSize -= 1;
|
|
|
+ const fontSize = currentSize
|
|
|
+ if (textbox.isEditing) {
|
|
|
+ textbox.setSelectionStyles({fontSize})
|
|
|
+ } else {
|
|
|
+ templatesStore.modifedElement(textbox, {fontSize})
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// 文字核心调整函数2-缩放
|
|
|
+function adjustFontScale(textbox, maxHeight, maxWidth, originScaleX) {
|
|
|
+ let scaleX = originScaleX;
|
|
|
+
|
|
|
+ // console.log('width ' + maxWidth);
|
|
|
+ const textWidth = textbox.calcTextWidth();
|
|
|
+
|
|
|
+ const scaleWidth = textWidth > maxWidth ? textWidth : maxWidth
|
|
|
+ // console.log('textWidth ' + textWidth);
|
|
|
+ scaleX *= maxWidth / scaleWidth;
|
|
|
+ // console.log('scaleX ' + scaleX);
|
|
|
+
|
|
|
+ if (textbox.isEditing) {
|
|
|
+ textbox.setSelectionStyles({scaleX})
|
|
|
+ textbox.setSelectionStyles({width: maxWidth})
|
|
|
+ // textbox.setSelectionStyles({height: maxHeight})
|
|
|
+ } else {
|
|
|
+ templatesStore.modifedElement(textbox, {scaleX})
|
|
|
+ templatesStore.modifedElement(textbox, {width: maxWidth})
|
|
|
+ // templatesStore.modifedElement(textbox, {height: maxHeight})
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//修改文字信息
|
|
|
-const eleTextChange = (objId: string, text) => {
|
|
|
- const handleElement = findObject(objId) as Textbox | ArcText;
|
|
|
+const eleTextChange = (obj, text) => {
|
|
|
+ const handleElement = findObject(obj.id) as Textbox | ArcText;
|
|
|
+
|
|
|
+ const maxHeight = obj.objOriginHeight
|
|
|
+ const maxWidth = obj.objOriginWidth
|
|
|
+ const originScaleX = obj.objOriginScaleX
|
|
|
|
|
|
if (handleElement.isEditing) {
|
|
|
handleElement.setSelectionStyles({text})
|
|
|
} else {
|
|
|
templatesStore.modifedElement(handleElement, {text})
|
|
|
}
|
|
|
- canvas.renderAll()
|
|
|
+ // canvas.renderAll()
|
|
|
+
|
|
|
+ // 读取预设的缩放行为
|
|
|
+ let scaleType = 0
|
|
|
+ if (obj.textScaleType >= 0)
|
|
|
+ scaleType = obj.textScaleType
|
|
|
+
|
|
|
+ if (scaleType == 0)
|
|
|
+ adjustFontDefault(handleElement, maxHeight, maxWidth)
|
|
|
+ else if (scaleType == 1)
|
|
|
+ adjustFontSize(handleElement, maxHeight, maxWidth)
|
|
|
+ else if (scaleType == 2)
|
|
|
+ adjustFontScale(handleElement, maxHeight, maxWidth, originScaleX)
|
|
|
}
|
|
|
|
|
|
// 修改字体大小
|
|
|
@@ -511,6 +640,20 @@ const handleElementFontsize = (objId: string, mode: string) => {
|
|
|
canvas.renderAll()
|
|
|
}
|
|
|
|
|
|
+// 修改字体大小-直接输入
|
|
|
+const handleElementFontSize = (objId: string, fontSize: string) => {
|
|
|
+ const handleElement = findObject(objId) as Textbox | ArcText;
|
|
|
+
|
|
|
+ fontSize = fontSize.replace(/[^\d]/g, '')
|
|
|
+ if (!fontSize) return
|
|
|
+ if (handleElement.isEditing) {
|
|
|
+ handleElement.setSelectionStyles({fontSize})
|
|
|
+ } else {
|
|
|
+ templatesStore.modifedElement(handleElement, {fontSize})
|
|
|
+ }
|
|
|
+ canvas.renderAll()
|
|
|
+}
|
|
|
+
|
|
|
// 修改字体族
|
|
|
const handleElementFontFamily = (objId: string, fontFamily: string) => {
|
|
|
const handleElement = findObject(objId) as Textbox | ArcText;
|
|
|
@@ -534,6 +677,14 @@ const updateFontColor = (objId: string, fill: string) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//修改字体曲率
|
|
|
+const changeArcTextRadius = (objId: string, val: number) => {
|
|
|
+ const handleElement = findObject(objId) as Textbox | ArcText;
|
|
|
+
|
|
|
+ (handleElement as ArcText).setRadius(val);
|
|
|
+ templatesStore.modifedElement(handleElement, {radius: val});
|
|
|
+}
|
|
|
+
|
|
|
// 修改缩进
|
|
|
const handleElementCharSpacing = (objId: string, mode: '+' | '-') => {
|
|
|
const handleElement = findObject(objId) as Textbox | ArcText;
|
|
|
@@ -553,7 +704,15 @@ const replaceImage = (objId: string, files: FileList) => {
|
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
|
- // console.log('aaaaaaaaaaaaassssssssssssssss' + JSON.stringify(canvasObject))
|
|
|
+ // console.log('aaaaaaaaaaaaassssssssssssssss' + JSON.stringify(textObjects))
|
|
|
+
|
|
|
+ //记录所有text的原始宽高,用于自动缩放字体
|
|
|
+ textObjects.forEach(x => {
|
|
|
+ const handleElement = findObject(x.id) as Textbox | ArcText;
|
|
|
+ x.objOriginHeight = handleElement.height
|
|
|
+ x.objOriginWidth = handleElement.width
|
|
|
+ x.objOriginScaleX = handleElement.scaleX
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
@@ -617,6 +776,7 @@ onMounted(() => {
|
|
|
font-size: 0.8rem;
|
|
|
font-weight: bold;
|
|
|
margin-bottom: 10px;
|
|
|
+ text-align: center;
|
|
|
}
|
|
|
|
|
|
.colorButton {
|