Files
aida_front/src/component/HomePage/ExportModel.vue

1607 lines
54 KiB
Vue
Raw Normal View History

2024-02-23 14:32:33 +08:00
<template>
2024-02-29 17:16:51 +08:00
<a-modal
class="modal_component Export"
v-model:visible="showUpgradePlan"
:footer="null"
width="78%"
:maskClosable="false"
:centered="true"
:closable="false"
:keyboard="false"
>
2024-02-23 14:32:33 +08:00
<div class="UpgradePlan_closeIcon">
2024-02-29 17:16:51 +08:00
<i class="fi fi-rr-cross-small" @click.stop="cancelDsign()"></i>
</div>
<div class="UpgradePlan_content">
2024-03-20 13:34:07 +08:00
<div>Edit & Export</div>
2024-02-29 17:16:51 +08:00
</div>
<!-- <div>
2024-02-23 14:32:33 +08:00
<canvas ref="exportCanvas"></canvas>
</div> -->
2024-02-29 17:16:51 +08:00
<div class="exportCanvasBox">
<div class="exportCanvasBox_left">
2024-03-04 09:57:46 +08:00
<div class="exportCanvasBox_title">Canvas Size</div>
2024-03-22 12:01:11 +08:00
<label>
<div>Width:</div>
<input type="number" @input="setMaxInput('width', 500)" v-model="canvasWH.width"/>
</label>
<label>
<div>Height:</div>
<input type="number" @input="setMaxInput('height', 10000)" v-model="canvasWH.height" />
</label>
<div class="exportCanvasBox_title" @click.stop="setCloseNav('nav')">
2024-02-29 17:16:51 +08:00
Canvas Nav
<div
:class="[
'icon',
'iconfont',
'icon-xiala',
closeNav.nav?'icon-rotate':''
2024-02-29 17:16:51 +08:00
]"
>
</div>
2024-02-27 15:15:38 +08:00
</div>
<div class="exportCanvasBox_img exportCanvasBox_left_item" :class="{'closeNav' :closeNav.nav}">
2024-02-29 17:16:51 +08:00
<div
class="exportCanvasBox_allItem"
v-for="(item,key) in allBoardData"
>
<div v-if="item[0]" class="exportCanvasBox_intro">{{ key }}</div>
2024-03-04 09:57:46 +08:00
<div class="exportCanvasBox_item_color" v-if="key == 'colorBoards'" v-for="colorItem in item" draggable="true" @dragstart="onDragstart(key,colorItem)">
<img src="" alt="">
2024-02-29 17:16:51 +08:00
<div class="exportCanvasBox_item_BGcolor" :style="{'background-color': 'rgb('+colorItem.rgbValue.r+','+colorItem.rgbValue.g+','+colorItem.rgbValue.b+')'}"></div>
<div>{{colorItem.tcx}}</div>
<div>{{colorItem.name}}</div>
</div>
<div
class="exportCanvasBox_item"
:class="[key == 'disposeMoodboard'?'exportCanvasBox_item_dispose':'']"
v-for="imgItem in item"
draggable
2024-03-04 09:57:46 +08:00
@dragstart="onDragstart(key,imgItem)"
2024-02-29 17:16:51 +08:00
>
<img :src="key == 'likeDesignCollectionList'?imgItem.designOutfitUrl:imgItem.imgUrl" alt="" />
</div>
</div>
</div>
<div class="exportCanvasBox_title" @click.stop="setCloseNav('tool')">
2024-03-04 09:57:46 +08:00
Canvas Tool
<div
:class="[
'icon',
'iconfont',
'icon-xiala',
closeNav.tool?'icon-rotate':''
2024-03-04 09:57:46 +08:00
]"
>
</div>
</div>
<div class="exportCanvasBox_left_tool exportCanvasBox_left_item" :class="{'closeNav' :closeNav.tool}">
<div class="exportCanvasBox_left_tool_item">
<i class="icon iconfont icon-chehui" @click="historyState('')"></i>
<i class="icon iconfont icon-fanchehui" @click="historyState('reverse')"></i>
<i class="icon iconfont icon-bianji" @click="setOperation('pencil')" :class="{active:operation == 'pencil'}"></i>
2024-03-20 13:34:07 +08:00
<i class="icon iconfont icon-caizhi" @click="setOperation('texture')" :class="{active:operation == 'texture'}"></i>
<i class="icon iconfont icon-move" @click="setOperation('move')" :class="{active:operation == 'move'}"></i>
<i class="icon iconfont icon-xiangpi_huaban1" @click="setOperation('eraser')" :class="{active:operation == 'eraser'}"></i>
</div>
2024-03-20 13:34:07 +08:00
<div class="exportCanvasBox_left_tool_item">
2024-03-20 13:34:07 +08:00
<label v-show="operation != 'move' && operation != 'eraser' && operation != 'texture'">
<div >Color</div>
<input type="color" @input="setPencilColor" v-model="canvasPencilColor">
</label>
2024-03-15 17:23:25 +08:00
<label v-show="operation != 'move'">
<div >Size:</div>
<input type="range" @input="setPencilWidth" min="1" max="50" v-model="canvasPencilWidth">
</label>
2024-03-15 09:21:17 +08:00
<label v-show="operation == 'pencil'">
<div >Brushwork:</div>
2024-03-20 13:34:07 +08:00
<a-select ref="select" class="label_select" size="small" v-model:value="brushworkValue"
2024-03-15 09:21:17 +08:00
style="flex: 1"
@change="brushworkChange"
>
<!-- v-model:value="brushwork" -->
<a-select-option class="label_select_item" v-for="item in brushList" :value="item.value">
<img :src="item.url" alt="">
</a-select-option>
</a-select>
</label>
2024-03-20 13:34:07 +08:00
<label v-show="operation == 'texture'" class="texture">
<div >Texture:</div>
<a-select ref="select" class="label_select" size="small" v-model:value="textureValue"
style="flex: 1"
@change="textureValueChange"
>
<!-- v-model:value="brushwork" -->
<a-select-option class="label_select_item" v-for="item in textureList" :value="item.value">
<img :src="item.url" alt="">
</a-select-option>
</a-select>
</label>
<label v-show="operation != 'pencil' && operation != 'eraser'&&operation != 'move'&&operation != 'texture'">
<div >FillBack:</div>
<div class="exportCanvasBox_left_tool_item leftAlign">
<i class="icon iconfont icon-tuceng1" @click="setOperationMode('fill')" :class="{active:operationMode == 'fill'}"></i>
<i class="icon iconfont icon-tuceng" @click="setOperationMode('border')" :class="{active:operationMode == 'border'}"></i>
</div>
</label>
<label v-show="operation === 'move'">
<div >Layer:</div>
<div class="exportCanvasBox_left_tool_item">
<i class="icon iconfont icon-shangyiceng" @click="setLayerIndex('Front')"></i>
<i class="icon iconfont icon-shangyiceng2" @click="setLayerIndex('Forward')"></i>
<i class="icon iconfont icon-xiayiceng" @click="setLayerIndex('Backwards')"></i>
<i class="icon iconfont icon-shangyiceng1" @click="setLayerIndex('Back')"></i>
</div>
</label>
</div>
</div>
<div class="exportCanvasBox_title" @click.stop="setCloseNav('move')">
More
<div
:class="[
'icon',
'iconfont',
'icon-xiala',
closeNav.move?'icon-rotate':''
]"
>
</div>
</div>
<div class="exportCanvasBox_left_tool exportCanvasBox_left_item" :class="{'closeNav' :closeNav.move}">
<div class="exportCanvasBox_left_tool_item">
2024-03-20 13:34:07 +08:00
<i class="icon iconfont icon-xian" @click="setOperation('fold')" :class="{active:operation == 'fold'}"></i>
<i class="icon iconfont icon-checkbox-full" @click="setOperation('rect')" :class="{active:operation == 'rect'}"></i>
2024-03-20 13:34:07 +08:00
<!-- <i class="icon iconfont icon-zhixian" @click="setOperation('line')" :class="{active:operation == 'line'}"></i> -->
<!-- <i class="icon iconfont icon-circle" @click="setOperation('circle')" :class="{active:operation == 'circle'}"></i> -->
<i class="icon iconfont icon-sanjiaoxing" @click="setOperation('triangle')" :class="{active:operation == 'triangle'}"></i>
<i class="icon iconfont icon-tx-fill-tuoyuanxing" @click="setOperation('ellipse')" :class="{active:operation == 'ellipse'}"></i>
2024-03-04 09:57:46 +08:00
</div>
2024-03-20 13:34:07 +08:00
2024-03-04 09:57:46 +08:00
</div>
2024-02-29 17:16:51 +08:00
</div>
<div class="exportCanvasBox_center">
<!-- <canvas ref="canvasDom" id="exportCanvas"></canvas> -->
</div>
<!-- <ExportNewCoolection ref="ExportNewCoolection"></ExportNewCoolection> -->
<div class="exportCanvasBox_right">
2024-03-04 09:57:46 +08:00
<div class="exportCanvasBox_title">
High-definition Download
</div>
<div class="exportCanvasBox_right_definition">
<label>
2024-03-22 12:01:11 +08:00
<div>Scale:</div>
<input type="number" @input="setMaxInput('scale', 500)" v-model="scaleSR"/>
2024-03-04 09:57:46 +08:00
</label>
</div>
2024-03-08 16:51:24 +08:00
<!-- <div class="" @click="multiselect">all</div> -->
<div class="exportCanvasBox_right_credits" v-show="credits<1">
<div><span class="icon iconfont icon-zhuyi"></span>Your points balance is insufficient, if you need to use this feature, please click the top left corner to recharge</div>
</div>
2024-03-04 09:57:46 +08:00
<div class="exportCanvasBox_right_btn">
2024-03-08 16:51:24 +08:00
<div class="subitOkPreviewBtn" :class="{active:credits<1}" @click="setHDExport">HD Export</div>
2024-03-21 10:49:21 +08:00
<div class="subitOkPreviewBtn Guide_1_32" @click="setExport">Export</div>
2024-03-04 09:57:46 +08:00
</div>
2024-02-29 17:16:51 +08:00
</div>
<div class="mark_loading" v-show="isShowMark">
<a-spin size="large" />
</div>
</div>
</a-modal>
2024-02-23 14:32:33 +08:00
</template>
2024-02-27 15:15:38 +08:00
<script>
2024-03-22 12:01:11 +08:00
import {defineComponent, computed, h, ref, nextTick, createVNode, reactive, onMounted,
2024-02-29 17:16:51 +08:00
} from "vue";
2024-02-23 14:32:33 +08:00
import { Https } from "@/tool/https";
2024-03-22 12:01:11 +08:00
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
2024-02-23 14:32:33 +08:00
import scaleImage from "@/component/HomePage/scaleImage.vue";
import ExportNewCoolection from "@/component/HomePage/ExportNewCoolection.vue";
2024-02-27 15:15:38 +08:00
import { useStore } from "vuex";
2024-02-29 17:16:51 +08:00
import JSZip, { forEach } from "jszip";
2024-03-21 10:49:21 +08:00
// import fabric from 'fabric';
2024-02-29 17:16:51 +08:00
import { message, Modal } from "ant-design-vue";
2024-03-21 10:49:21 +08:00
import { openGuide,driverObj__ } from "@/tool/guide";
2024-02-29 17:16:51 +08:00
const FileSaver = require("file-saver");
2024-03-20 13:34:07 +08:00
import { exportSele,JSRectUpdata,JSchangeType,JScanvasMouseDown,JScanvasMouseMove,JScreateCheck,JSSetTexture } from "@/tool/canvasDrawing";
2024-02-23 14:32:33 +08:00
export default defineComponent({
2024-02-29 17:16:51 +08:00
components: {
scaleImage,
ExportNewCoolection,
},
props: ["msg", "sketchCatecoryList"],
2024-03-22 12:01:11 +08:00
setup(props,{emit}) {
2024-03-21 10:49:21 +08:00
let driver__ = computed(()=>{
return store.state.Guide.guide
})
2024-02-27 15:15:38 +08:00
const store = useStore();
2024-02-29 17:16:51 +08:00
let showUpgradePlan = ref(false);
let canvas = reactive({});
// let canvasDom = ref()
let canvasWH = ref({
width: 400,
height: 1200,
});
canvasWH.value.width = [window.innerWidth/2.4]
canvasWH.value.width = canvasWH.value.width.map(num => Math.round(num / 100) * 100)[0];
2024-03-08 16:51:24 +08:00
let credits = computed(() => {
return store.state.UserHabit.credits.value;
2024-02-29 17:16:51 +08:00
});
2024-03-08 16:51:24 +08:00
2024-02-29 17:16:51 +08:00
let allBoardData = computed(() => {
return store.state.UploadFilesModule.allBoardData;
});
let likeDesignCollectionList = computed(() => {
return store.state.HomeStoreModule.likeDesignCollectionList;
});
let isShowMark = false;
// let allImage = Object.assign(allBoardData.value,{likeDesignCollectionList:likeDesignCollectionList.value})
let position = {
//设置每个图形位置的初始值
x: 0,
y: 0,
height: 0,
};
2024-03-04 09:57:46 +08:00
let sketchGrouping = 3; //sketch分组
let likeDesign = 4; //整体图分组
let disposeMoodboardShow = true;
let canvasState = ref()//存放canvas操作
let reverseCanvasState = ref([])//存放canvas操作
let normalCanvasState = ref([])//存放canvas操作
2024-03-04 09:57:46 +08:00
let isLoadCanvas = false//撤回或者反撤回false为撤回
2024-02-29 17:16:51 +08:00
let init = () => {
normalCanvasState.value = []
reverseCanvasState.value = []
2024-02-29 17:16:51 +08:00
showUpgradePlan.value = true;
nextTick().then(async () => {
allBoardData.value.likeDesignCollectionList =
likeDesignCollectionList;
let canvasBox = document.querySelector(
".Export .exportCanvasBox_center"
);
canvasBox.innerHTML = ""; // 清空原有内容
var canvasDom = document.createElement("canvas");
canvasBox.appendChild(canvasDom);
canvas = new fabric.Canvas(canvasDom, {
backgroundColor: "rgba(255, 255, 255)",
width: canvasWH.value.width,
height: canvasWH.value.height,
isDrawingMode: false, // 开启绘图模式
});
2024-03-21 10:49:21 +08:00
brushIndicator = clearBrushIndicator()
JSchangeType(canvas,'init')
2024-03-04 09:57:46 +08:00
canvasOnDrop()//开启鼠标到画布事件
setRemoveImage()//设置元素删除
canvas.on("object:modified", ()=>{
updateCanvasState()
});
2024-03-20 13:34:07 +08:00
canvas.preserveObjectStacking = true;
//鼠标移动
2024-03-22 12:01:11 +08:00
setCanvasKeyDown()//document上添加按下和抬起事件
canvas.on("mouse:over", event =>console.log(123123123123));
canvas.on("mouse:move", event =>setCanvasMove(event));
canvas.on("mouse:out", event=>setCanvasOut(event));
canvas.on("mouse:down", event=>setCanvasDown(event));
canvas.on("mouse:up", event=>setCanvasUp(event));
// canvas.on('path:created', (event)=>{updateCanvasState()});
// canvas.on("selection:created", (event)=>{setZIndex(event)});
// canvas.on('object:removed', function() {
// });
// canvas.on("object:added", (obj)=>{
// obj.target.cornerSize = 10
// obj.target.transparentCorners = false
// });
fabric.Object.prototype.cornerSize = 10
fabric.Object.prototype.transparentCorners = false
2024-03-04 09:57:46 +08:00
// setCanvasOperation()//设置监听添加修改画布元素,用来做撤回功能
2024-02-29 17:16:51 +08:00
let arr = [
"disposeMoodboard",
"moodboardFiles",
"printboardFiles",
"colorBoards",
"sketchboardFiles",
"likeDesignCollectionList",
];
2024-03-04 09:57:46 +08:00
2024-02-29 17:16:51 +08:00
let oldKey = "";
let margin = 20; //每个图形边距
2024-03-20 13:34:07 +08:00
let maxHeight = 0
let sketchXy = {x:0,y:0}
2024-02-29 17:16:51 +08:00
// arr.forEach((item,index)=>{
for (const item of arr) {
for (const key in allBoardData.value) {
if (item == key) {
//循环渲染顺序
2024-03-04 09:57:46 +08:00
let imgWidth = setImageWidth(key); //这是设置画布等宽
2024-02-29 17:16:51 +08:00
let sketchGroupingItem = [];
2024-03-04 09:57:46 +08:00
if (
2024-02-29 17:16:51 +08:00
item == "moodboardFiles" &&
!disposeMoodboardShow
) {
continue;
}
for (const [allItemIndex, allItem,] of allBoardData.value[key].entries()) {
await new Promise((resolve, reject) => {
2024-03-20 13:34:07 +08:00
maxHeight = position.y + position.height>maxHeight?position.y +position.height:maxHeight
2024-02-29 17:16:51 +08:00
if (key == "colorBoards") {
2024-03-04 09:57:46 +08:00
let rect = setGroup(allItem)
if (position.x + rect.width > canvasWH.value.width || oldKey != key) {
position.x = 0;
2024-03-20 13:34:07 +08:00
position.y = maxHeight;
2024-03-04 09:57:46 +08:00
}
let group = setCanvasColor(position.y,position.x,rect)
2024-02-29 17:16:51 +08:00
oldKey = key;
2024-03-04 09:57:46 +08:00
position.x += rect.width + margin;
2024-02-29 17:16:51 +08:00
position.height = group.height + margin;
resolve();
} else {
let itemCanvasImg = allItem.imgUrl;
if (key == "likeDesignCollectionList") {
itemCanvasImg =
allItem.designOutfitUrl;
}
2024-03-04 09:57:46 +08:00
fabric.Image.fromURL(itemCanvasImg,(img) => {
let scaleWH = imgWidth / img.width; //计算放到画布上缩小倍率
2024-03-20 13:34:07 +08:00
if(key == "sketchboardFiles"){
if(allItemIndex == 0){
position.x = 0;
position.y = maxHeight;
}
}else{
if (position.x + img.width * scaleWH > canvasWH.value.width || oldKey != key) {
position.x = 0;
position.y = maxHeight;
}
2024-03-04 09:57:46 +08:00
}
setCanvasImage(img,key,position.x,position.y)//设置图片
position.height = img.height * scaleWH + margin;
if (key == "sketchboardFiles") {
2024-03-20 13:34:07 +08:00
if (sketchGroupingItem.length <3) {
2024-03-04 09:57:46 +08:00
sketchGroupingItem.push(JSON.parse(JSON.stringify(position)));
}
2024-03-20 13:34:07 +08:00
if (sketchGroupingItem.length >2) {
2024-03-04 09:57:46 +08:00
let sketchXyIndex = {
maxIndex: 0,
2024-03-20 13:34:07 +08:00
maxNum: 0,
minNum: 999999,
2024-03-04 09:57:46 +08:00
minIndex: 0,
};
sketchGroupingItem.forEach(
(sketchItem,sketchIndex) => {
2024-03-20 13:34:07 +08:00
if (sketchItem.y + sketchItem.height < sketchXyIndex.minNum) {
// console.log(sketchItem.x,sketchItem.y);
sketchXyIndex.minNum = sketchItem.y + sketchItem.height
2024-03-04 09:57:46 +08:00
sketchXyIndex.minIndex = sketchIndex;
}
2024-03-20 13:34:07 +08:00
if (sketchItem.y + sketchItem.height > sketchXyIndex.maxNum) {
sketchXyIndex.maxNum = sketchItem.y + sketchItem.height
sketchXyIndex.maxIndex = sketchIndex;
}
2024-03-04 09:57:46 +08:00
}
);
2024-03-20 13:34:07 +08:00
sketchGroupingItem[sketchXyIndex.minIndex].y = sketchXyIndex.minNum
// sketchGroupingItem[sketchXyIndex.maxIndex].y = sketchXyIndex.maxNum
2024-03-04 09:57:46 +08:00
if (allBoardData.value[key].length == allItemIndex + 1) {
2024-03-20 13:34:07 +08:00
maxHeight = sketchXyIndex.maxNum
2024-03-04 09:57:46 +08:00
} else {
2024-03-20 13:34:07 +08:00
position = sketchGroupingItem[sketchXyIndex.minIndex];
2024-03-04 09:57:46 +08:00
}
}
2024-03-20 13:34:07 +08:00
}
if(key == "sketchboardFiles" && sketchGroupingItem.length >2){
}else{
position.x += img.width * scaleWH + margin;
2024-03-04 09:57:46 +08:00
}
img.lock_rotation = true;
canvas.add(img);
oldKey = key;
2024-03-20 13:34:07 +08:00
// setTimeout(() => {
resolve()
// }, 1000);
2024-03-04 09:57:46 +08:00
},{ crossOrigin: "Anonymous" });
2024-02-29 17:16:51 +08:00
}
});
}
}
}
2024-03-04 09:57:46 +08:00
if(position.y+position.height>canvasWH.value.height){
canvasWH.value.height = Math.floor(position.y+position.height)
canvas.setHeight(canvasWH.value.height);
}
2024-02-29 17:16:51 +08:00
}
updateCanvasState('')//加载完成后记录一下
2024-03-21 10:49:21 +08:00
if(driver__.value.driver){
driverObj__.moveNext()
}
2024-02-29 17:16:51 +08:00
});
2024-03-21 10:49:21 +08:00
2024-02-29 17:16:51 +08:00
};
2024-03-22 12:01:11 +08:00
let deleteObject = ()=> {
// var target = [transform.target];
2024-03-22 12:01:11 +08:00
if(!canvas.getActiveObjects()){
2024-03-20 13:34:07 +08:00
return
}
2024-03-22 12:01:11 +08:00
let target = canvas.getActiveObjects()
2024-03-04 09:57:46 +08:00
target.forEach((item)=>{
// var canvas = item.canvas;
// canvas.remove(item);
canvas.fxRemove(item, {
onComplete(){
canvas.discardActiveObject(); // 丢弃当前选中的对象
canvas.renderAll(); // 重新渲染 Canvas
}
})
canvas.FX_DURATION = 300
2024-03-04 09:57:46 +08:00
})
// canvas.requestRenderAll();
// canvas.discardActiveObject() // 丢弃当前活动的对象和触发事件。 如果fabric作为鼠标事件的结果调用该函数则将该事件作为参数传递给自定义事件的fire函数。 当作为一个方法使用时,参数没有任何应用。
// canvas.discardActiveObject(); // 丢弃当前选中的对象
// canvas.renderAll(); // 重新渲染 Canvas
updateCanvasState('remove')
2024-03-04 09:57:46 +08:00
}
2024-03-20 13:34:07 +08:00
let setRemoveImage = ()=>{
2024-03-04 09:57:46 +08:00
const deleteIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAACxAAAAsQHGLUmNAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAdBJREFUSImt1r1uU0EQBeDPFh1pgBQEEwFVAg9BROhCAh1FAg1gkMA8DA0oKOEB3IEIRQgF4SEQBIUC6ENSGgPFXaPx+udeSxxppPXOzJnZ8e7MrRmPWdzANZxPv+EbvmILL/G9hGcADayjgz8l0kUb56qSX8dhBeJcDrFSRv44ZRQdt3EPczieZB5NvB1ymta4zCP5J1yucOIFfM6CDJykob8s73GiAnkPJ7Eb/H9iJhpsZJlPQh6D7AWe9Z5iFr+CIpalhjWspnXZ/pXA01FURkv/HxpxK+g2UE+yGfZXM5+doHt4DEtB2R5dAXdD9nfG2LVxNa2XKGreiziXGefZ5rKZbCLmg/4jHIWNqSEZ1fC0IrnE0bM5qqdFGWoV92RBf/P/S3RRVqI3YaOZGd8eQpgHXMt8HgTd67qi5fZwMzOO5XuREmim9ShEji04q78tLwSDSR/aYuD599DgeVDsY3pMhqOQt4pnUXlGf7PbTQ5VcQofgv8BTudGK/rb9Z6it5RhEV+CX1cxYoeiZXDg7OC+4vpNJbmkuC3vMtsuHpVltKzo55OOzINxmeeYxhPVhn5H0ftnhhGNeu49NBSjdBkX9H+27Cvu+Sv8GEXwF9+O3b1zwZqdAAAAAElFTkSuQmCC"
// 创建删除图片元素
let deleteImg = document.createElement('img')
deleteImg.src = deleteIcon
function renderIcon(icon) {
return function (ctx, left, top, styleOverride, fabricObject) {
var size = this.cornerSize;
ctx.save();
ctx.translate(left, top);
ctx.rotate(fabric.util.degreesToRadians(fabricObject.angle));
ctx.drawImage(icon, -size/3, -size/3, size/1.5, size/1.5);
ctx.restore();
}
}
// 删除按钮控件
fabric.Object.prototype.controls.deleteControl = new fabric.Control({
x: 0.5,
y: -0.5,
offsetY: -16,
offsetX: 16,
cursorStyle: 'pointer',
mouseUpHandler: deleteObject,
render: renderIcon(deleteImg),
cornerSize: 24
})
}
2024-03-04 09:57:46 +08:00
let setImageWidth = (key)=>{
let imgWidth = canvasWH.value.width; //这是设置画布等宽
if (
disposeMoodboardShow &&
key == "disposeMoodboard" &&
allBoardData.value[key].length != 0 &&
allBoardData.value[key][0] != null
) {
//如果是mood 需要判断用户是否点击layout
disposeMoodboardShow = false;
}
if (key == "printboardFiles") {
imgWidth = canvasWH.value.width / 8;
}
if (key == "sketchboardFiles"||key == 'moodboardFiles') {
imgWidth =
(canvasWH.value.width -
(sketchGrouping - 1) * 20) /
sketchGrouping;
}
if (key == "likeDesignCollectionList") {
imgWidth =
(canvasWH.value.width -
(likeDesign - 1) * 20) /
likeDesign;
}
return imgWidth
}
let setCanvasImage = (img,key,left,top)=>{
let proportion = img.height / img.width; //计算图形宽高比例
let imgWidth = setImageWidth(key)
let scaleWH = imgWidth / img.width; //计算放到画布上缩小倍率
img.set({
// width: imgWidth/img.width,
// height: canvasWH.value.height/img.height,
left,
top,
scaleX:
imgWidth / img.width,
scaleY:(img.width * proportion * scaleWH) / img.height,
// cornerSize: 10, // 选中时角的大小为20
// transparentCorners: false, // 选中时角是被填充了。true 空心false 实心
2024-03-04 09:57:46 +08:00
lockRotation: true,
});
}
2024-02-29 17:16:51 +08:00
//设置导出
let setExport = async () => {
var imageDataURL = canvas.toDataURL({
format: "png", // 导出格式为 PNG
quality: 1, // 图片质量为 1最高质量
});
let a = document.createElement("a");
let img = [];
let index = 0;
img.push({
imgUrl: imageDataURL,
name: "collection.png",
});
let num = 0;
for (let key in allBoardData.value) {
if (key !== "colorBoards" && key !== "moodTemplateId") {
for (let item of allBoardData.value[key]) {
if (
key == "disposeMoodboard" &&
allBoardData.value[key][0] == undefined
) {
break;
}
2024-02-27 15:15:38 +08:00
2024-03-20 13:34:07 +08:00
let nameTail = item?.imgUrl?.split(".").pop().split("?").shift();
2024-02-29 17:16:51 +08:00
let data = {
imgUrl: item.imgUrl,
name: item?.resData?.name + index + "." + nameTail,
};
if (key == "likeDesignCollectionList") {
data.imgUrl = item.designOutfitUrl;
2024-03-20 13:34:07 +08:00
data.name = "result" + index + "." + data.imgUrl.split(".").pop().split("?").shift();;
2024-02-29 17:16:51 +08:00
}
img.push(data);
index++;
}
num++;
}
}
let dataList = [];
likeDesignCollectionList.value.forEach((item) => {
dataList.push(item.designItemId);
index++;
});
let mannequinList = [];
await Https.axiosPost(Https.httpUrls.designGetModel, dataList)
.then((rv) => {
mannequinList = rv;
})
.catch((rv) => {});
mannequinList.forEach((item) => {
let nameTail = item?.split(".").pop().split("?").shift();
let data = {
imgUrl: item,
name: "mannequin" + index + "." + nameTail,
};
img.push(data);
index++;
});
downImg(img);
};
let getImgArrayBuffer = (url) => {
return new Promise((resolve, reject) => {
//通过请求获取文件blob格式
let xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.responseType = "blob";
xmlhttp.onload = function () {
if (this.status == 200) {
resolve(this.response);
} else {
reject(this.status);
}
};
xmlhttp.send();
});
};
let downImg = (imagesParams) => {
let zip = new JSZip();
let cache = {};
let promises = [];
for (let item of imagesParams) {
const promise = getImgArrayBuffer(item.imgUrl).then((data) => {
// 下载文件, 并存成ArrayBuffer对象(blob)
zip.file(item.name, data, { binary: true }); // 逐个添加文件
cache[item.title] = data;
});
promises.push(promise);
}
Promise.all(promises)
.then(() => {
zip.generateAsync({ type: "blob" }).then((content) => {
// 生成二进制流
FileSaver.saveAs(content, "DesignFiles"); // 利用file-saver保存文件 自定义文件名
isShowMark = false;
});
2024-03-21 10:49:21 +08:00
if(driver__.value.driver){
driverObj__.moveNext()
}
2024-02-29 17:16:51 +08:00
})
.catch((res) => {
// message.warning(t('HomeView.jsContent3'));
isShowMark = false;
});
};
//关闭画布
let cancelDsign = () => {
showUpgradePlan.value = false;
position = {
//设置每个图形位置的初始值
x: 0,
y: 0,
height: 0,
};
2024-03-15 09:21:17 +08:00
operation.value = 'move'
operation.value = 'fill'
2024-02-29 17:16:51 +08:00
};
//设置画布宽高
let setMaxInput = (str, maxNum) => {
if (str == "width") {
// maxNum = window.innerWidth < 1100 ? 400 : maxNum;
maxNum = [window.innerWidth/2.4]
maxNum = maxNum.map(num => Math.round(num / 10) * 10)[0];
2024-03-04 09:57:46 +08:00
}else if(str == 'height'){
if(position.y+position.height>maxNum){
maxNum = Math.floor(position.y+position.height)
}
}
2024-02-29 17:16:51 +08:00
if (str == "width" && canvasWH.value.width >= maxNum) {
canvasWH.value.width = maxNum;
} else if (str == "height" && canvasWH.value.height >= maxNum) {
canvasWH.value.height = maxNum;
2024-03-22 12:01:11 +08:00
}else if(str == 'scale'){
scaleSR.value = scaleSR.value < 1 ? 1:scaleSR.value>4? 4:scaleSR.value
}
2024-02-29 17:16:51 +08:00
canvas.setHeight(canvasWH.value.height);
canvas.setWidth(canvasWH.value.width);
};
let closeNav = ref({
nav:true,
tool:false,
move:false,
})
let setCloseNav = (key)=>{
closeNav.value[key] = !closeNav.value[key]
2024-02-27 15:15:38 +08:00
}
2024-03-04 09:57:46 +08:00
function multiselect() {//获取整体宽高
2024-02-29 17:16:51 +08:00
canvas.discardActiveObject() // 丢弃当前活动的对象和触发事件。 如果fabric作为鼠标事件的结果调用该函数则将该事件作为参数传递给自定义事件的fire函数。 当作为一个方法使用时,参数没有任何应用。
const sel = new fabric.ActiveSelection(canvas.getObjects(), {
canvas
})
canvas.setActiveObject(sel)
canvas.requestRenderAll()
const activeObject = canvas.getActiveObject(); // 获取当前选中的整体对象
if (activeObject && activeObject.type === 'activeSelection') {
const totalWidth = activeObject.width * activeObject.scaleX;
const totalHeight = activeObject.height * activeObject.scaleY;
console.log('Total Width:', totalWidth);
console.log('Total Height:', totalHeight);
}
2024-02-27 15:15:38 +08:00
}
2024-03-04 09:57:46 +08:00
let currentType = ref({
type:'',
data:'',
})
let onDragstart = (type,imgItem)=>{
currentType.value.type = type
currentType.value.data = imgItem
2024-02-27 15:15:38 +08:00
}
2024-02-29 17:16:51 +08:00
let canvasOnDrop = ()=>{
2024-03-04 09:57:46 +08:00
canvas.on('drop', (opt)=> {
let offset = {
left: canvas.getSelectionElement().getBoundingClientRect().left,
top: canvas.getSelectionElement().getBoundingClientRect().top
}
let point = {
x: opt.e.x - offset.left,
y: opt.e.y - offset.top,
}
let pointerVpt = canvas.restorePointerVpt(point)
switch (currentType.value.type) {
case 'colorBoards':
let rect = setGroup(currentType.value.data)
setCanvasColor(pointerVpt.y, pointerVpt.x,rect)
break
case 'moodboardFiles':
createImage(pointerVpt.y, pointerVpt.x,currentType.value.type)
break
default :
createImage(pointerVpt.y, pointerVpt.x,currentType.value.type)
break
}
// 创建完元素,把当前操作的元素类型设置回 null
2024-03-04 09:57:46 +08:00
currentType.value.type = null
currentType.value.data = null
2024-03-04 09:57:46 +08:00
})
}
let setGroup = (data)=>{
var text = new fabric.Text(data.tcx,{
left: 0,
top: 60,
fontSize: 14,
fontFamily: "Arial",
textAlign: "left",
fill: "black",
});
let text1 = new fabric.Text(data.name,{
left: 0,
top: 80,
width: 20,
fontSize: 14,
fontFamily: "Arial",
textAlign: "left",
});
let width = 110 > text1.width ? 110 : text1.width;
var color = new fabric.Rect({
width: width,
height: 60,
textAlign: "left",
fill: `rgb(${data.rgbValue.r},${data.rgbValue.g},${data.rgbValue.b})`,
});
let rect = {text,text1,color,width}
return rect
}
let setCanvasColor = (top,left,rect)=>{
var group = new fabric.Group([rect.color, rect.text, rect.text1],{
left,
top,
width: rect.width,
fill: "rgb(255,255,255)",
stroke: "#212121",
strokeWidth: 1,
});
canvas.add(group);
return group
}
// 创建矩形
let createImage = async (top, left,key)=> {
2024-03-04 09:57:46 +08:00
let itemCanvasImg = currentType.value.data.imgUrl
if(key == 'likeDesignCollectionList'){
itemCanvasImg = currentType.value.data.designOutfitUrl;
2024-02-27 15:15:38 +08:00
}
await new Promise((resolve,reject)=>{
fabric.Image.fromURL(itemCanvasImg,(img) => {
setCanvasImage(img,key,left,top)//设置图片
canvas.add(img);
resolve()
},{ crossOrigin: "Anonymous" });
})
updateCanvasState()
}
//设置画布监听修改添加事件,用来做撤回功能
let updateCanvasState = (str) =>{
const canvasAsJson = JSON.stringify(canvas.toJSON());
if(str == 'loadingCompleted'){
// reverseCanvasState.value.push(canvasAsJson);
}
normalCanvasState.value.push(canvasAsJson);
if (isLoadCanvas) {
reverseCanvasState.value = []
isLoadCanvas = false;
canvasState.value = canvasAsJson
}
2024-03-04 09:57:46 +08:00
}
//撤回
let historyState = (str)=> {
if(str == 'reverse' && reverseCanvasState.value.length > 0){
canvasState.value = reverseCanvasState.value[reverseCanvasState.value.length-1]
let obj = reverseCanvasState.value.pop()
normalCanvasState.value.push(obj);
}else if(str == '' && normalCanvasState.value.length > 1){
let obj = normalCanvasState.value.pop()
reverseCanvasState.value.push(obj);
canvasState.value = normalCanvasState.value[normalCanvasState.value.length-1]
isLoadCanvas = true;
}else{
return
}
canvas.loadFromJSON(canvasState.value, () => {});
}
//在画布进行画画
let operation = ref('move')
let operationMode = ref('fill')
2024-03-20 13:34:07 +08:00
let textureValue = ref(0)//材质信息
let textureValueChange = (value)=>{
textureValue.value = value
setTexture()
}
//铅笔颜色 大小
2024-03-15 09:21:17 +08:00
let brushworkValue = ref('PencilBrush')
let brushworkChange = (value)=>{
brushworkValue.value = value
setPencil()
}
// let brushwork = ref('')
2024-03-20 13:34:07 +08:00
// 监听键盘的 keydown 和 keyup 事件
let keyDown = []
2024-03-22 12:01:11 +08:00
let canvasKeyDown = (event) => {
console.log(123123123);
2024-03-20 13:34:07 +08:00
if(keyDown.indexOf(event.key)>-1){
}else{
keyDown.push(event.code)
if(event.key === 'Enter' && operation.value == 'fold'){
foldEnd('Enter')
}else if(event.key === 'Delete'){
deleteObject()
}else if(keyDown.indexOf('ControlLeft') > -1 && keyDown.indexOf('KeyZ') > -1 && keyDown.indexOf('ShiftLeft') > -1){
historyState('reverse')
}else if(keyDown.indexOf('ControlLeft') > -1 && keyDown.indexOf('KeyZ') > -1){
historyState('')
}else if(keyDown.indexOf('ControlLeft') > -1 && keyDown.indexOf('KeyC') > -1){
copy()
}else if(keyDown.indexOf('ControlLeft') > -1 && keyDown.indexOf('KeyV') > -1){
paste()
}
}
2024-03-22 12:01:11 +08:00
}
let canvasKeyUp = (event) =>{
keyDown = keyDown.filter(function(item) {
return event.code !== item;
})
}
let setCanvasKeyDown = ()=>{
document.addEventListener('keydown',canvasKeyDown );
document.addEventListener('keyup', canvasKeyUp);
}
let clearCanvasKeyDown = ()=>{
document.removeEventListener('keydown',canvasKeyDown );
document.removeEventListener('keyup', canvasKeyUp);
}
let canvasPencilColor = ref('#000000')
let canvasPencilWidth = ref(20)
let setOperation = (str)=>{
operation.value = str
2024-03-15 09:21:17 +08:00
//折线图的时候切换其他形状或者笔触需要把未完成的折线图删掉
canvas.discardActiveObject();//取消所有选中边框
2024-03-15 09:21:17 +08:00
if(createPatterningIs){
canvas.remove(currentPatterning)
}
canvas.remove(polyLineBtn)
if(str == 'pencil'){
setPencil()
}else if(str == 'move'){
setMove()
canvas.forEachObject((obj) =>obj.selectable = true);
JSchangeType(canvas,'init')
2024-03-20 13:34:07 +08:00
}else if(str == 'texture'){
setTexture()
}else if(str == 'eraser'){
setEraser()
}else{
canvas.forEachObject((obj) =>obj.selectable = false);
canvas.isDrawingMode = false
}
}
2024-03-20 13:34:07 +08:00
let _clipboard = null // 复制到的内容
let copy = () => {//复制
var activeObject = canvas.getActiveObject();
if(!activeObject){
return
}
activeObject.clone(function(cloned) {
_clipboard = cloned;
})
}
let paste = () => {//粘贴
if(!_clipboard){
return
}
_clipboard.clone(clonedObj => {
canvas.discardActiveObject() // 取消选择
// 设置新内容的坐标位置
clonedObj.set({
left: clonedObj.left + 10,
top: clonedObj.top + 10,
evented: true
})
if (clonedObj.type === 'activeSelection') {
// 活动选择需要一个对画布的引用
clonedObj.canvas = canvas;
clonedObj.forEachObject(function(obj) {
canvas.add(obj)
})
clonedObj.setCoords()
} else {
canvas.add(clonedObj)
}
_clipboard.top += 10
_clipboard.left += 10
canvas.setActiveObject(clonedObj)
canvas.requestRenderAll()
})
updateCanvasState()
}
let textureList = ref([])
for (let index = 0; index < 20; index++) {
2024-03-21 10:49:21 +08:00
textureList.value.push({value:index,url:`/image/texture/texture${index}.webp`})
2024-03-20 13:34:07 +08:00
}
let setTexture = async ()=>{
canvas.isDrawingMode = true//开启绘画模式
let img = await JSSetTexture(textureList.value[textureValue.value].url)
let patternBrush = new fabric.PatternBrush(canvas)
patternBrush.source = img
patternBrush.width = canvasPencilWidth.value; // 设置画笔大小
canvas.freeDrawingBrush = patternBrush
}
let setOperationMode = (str) =>{
operationMode.value = str
}
2024-03-20 13:34:07 +08:00
let setLayerIndex = (str) =>{//设置优先级
var activeObject = canvas.getActiveObject();
switch (str) {
case 'Front':
canvas.bringToFront(activeObject)//顶层
break
case 'Back':
canvas.sendToBack(activeObject)//底层
break
case 'Forward':
canvas.bringForward(activeObject)
break
case 'Backwards':
canvas.sendBackwards(activeObject)
break
}
}
2024-03-21 10:49:21 +08:00
let clearBrushIndicator = ()=>{
let cator = new fabric.Circle({
radius:canvasPencilWidth.value/2,
fill: '#fff',
stroke: '#000',
strokeWidth: 0,
originX: 'center',
originY: 'center',
visible :true,
erasable: false,
});
return cator
}
let brushIndicator
2024-03-15 09:21:17 +08:00
let hexToRgba=(hex, alpha)=> {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
let brushList = ref([
{
value:'PencilBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/PencilBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'Marking',
2024-03-21 10:49:21 +08:00
url:'/image/brush/PencilBrush-2.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'InkBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/InkBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'CrayonBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/CrayonBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'RibbonBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/RibbonBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'MarkerBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/MarkerBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'WritingBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/WritingBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'LongfurBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/LongfurBrush.jpg'
2024-03-15 09:21:17 +08:00
},{
value:'SpraypaintBrush',
2024-03-21 10:49:21 +08:00
url:'/image/brush/SpraypaintBrush.jpg'
2024-03-15 09:21:17 +08:00
},
])
let setPencil =()=>{
2024-03-15 09:21:17 +08:00
let pencil
canvas.isDrawingMode = true//开启绘画模式
2024-03-15 09:21:17 +08:00
if(brushworkValue.value == 'PencilBrush'){
pencil = new fabric.PencilBrush(canvas,{}); //普通笔
}else if(brushworkValue.value == 'Marking'){
pencil = new fabric.PencilBrush(canvas,); //记号笔
}else if(brushworkValue.value == 'InkBrush'){
pencil = new fabric.InkBrush(canvas,{}); //油画笔
}else if(brushworkValue.value=='CrayonBrush'){
pencil = new fabric.CrayonBrush(canvas,{}); //蜡笔
}else if(brushworkValue.value == 'RibbonBrush'){
pencil = new fabric.RibbonBrush(canvas,{width: 1,}); //色带
}else if(brushworkValue.value == 'MarkerBrush'){
pencil = new fabric.MarkerBrush(canvas,{}); //书写笔
2024-03-20 13:34:07 +08:00
// pencil = new fabric.PenBrush(canvas,{}); //书写笔
2024-03-15 09:21:17 +08:00
}else if(brushworkValue.value == 'WritingBrush'){
pencil = new fabric.WritingBrush(canvas,{}); //毛笔
}else if(brushworkValue.value == 'LongfurBrush'){
pencil = new fabric.LongfurBrush(canvas,{width: 1,}); //色带
}else if(brushworkValue.value == 'SpraypaintBrush'){
pencil = new fabric.SpraypaintBrush(canvas,{}); //长毛刷
}
canvas.freeDrawingBrush = pencil
2024-03-15 09:21:17 +08:00
canvas.freeDrawingBrush.width = canvasPencilWidth.value;
if(brushworkValue.value == 'RibbonBrush' || brushworkValue.value == 'LongfurBrush'){
canvas.freeDrawingBrush.width = 1;
}
if(brushworkValue.value == 'Marking'){
canvas.freeDrawingBrush.color = hexToRgba(canvasPencilColor.value,.5);
2024-03-20 13:34:07 +08:00
// }else if(brushworkValue.value == 'InkBrush'){
// canvas.freeDrawingBrush.color = hexToRgba(canvasPencilColor.value,.2);
2024-03-15 09:21:17 +08:00
}else{
canvas.freeDrawingBrush.color = hexToRgba(canvasPencilColor.value,1);
}
brushIndicator.set('fill',canvasPencilColor.value)
canvas.freeDrawingBrush.isEraser = false
2024-03-15 09:21:17 +08:00
}
let setMove = () =>{
canvas.isDrawingMode = false
canvas.forEachObject((obj) =>obj.selectable = true);
}
let setEraser = ()=>{
canvas.isDrawingMode = true
let eraser = new fabric.EraserBrush(canvas)
canvas.freeDrawingBrush = eraser
brushIndicator.set({fill: '#FFF'});
canvas.requestRenderAll();
canvas.freeDrawingBrush.isEraser = true
canvas.freeDrawingBrush.width = canvasPencilWidth.value;
}
let setTimeOut = {
color:null,
width:null,
}//给切换颜色设置防抖
let setPencilColor = ()=>{//切换颜色给铅笔设置颜色
clearTimeout(setTimeOut.color)
setTimeOut.color = setTimeout(()=>{
// brushIndicator.fill = canvasPencilColor.value;
2024-03-15 09:21:17 +08:00
if(canvas.freeDrawingBrush.isEraser){
}else{
brushIndicator.set({fill: canvasPencilColor.value});
}
2024-03-15 09:21:17 +08:00
if(brushworkValue.value == 'Marking'){
canvas.freeDrawingBrush.color = hexToRgba(canvasPencilColor.value,.5);
}else if(brushworkValue.value == 'InkBrush'){
canvas.freeDrawingBrush.color = hexToRgba(canvasPencilColor.value,.2);
}else{
canvas.freeDrawingBrush.color = hexToRgba(canvasPencilColor.value,1);
}
2024-03-15 09:21:17 +08:00
},100)
}
let setPencilWidth = ()=>{//切换颜色给铅笔设置颜色
clearTimeout(setTimeOut.width)
canvasPencilWidth.value = Number(canvasPencilWidth.value)
setTimeOut.width = setTimeout(()=>{
2024-03-15 09:21:17 +08:00
if(brushworkValue.value == 'LongfurBrush' || brushworkValue.value == 'RibbonBrush'){
canvas.freeDrawingBrush.width = 1;
}else{
canvas.freeDrawingBrush.width = canvasPencilWidth.value;
}
// setPencil()
},300)
}
let downPoint = null;//鼠标按下位置
let upPoint = null;//鼠标抬起位置
let currentPatterning = null//临时图形
let polyLineBtn = null
let createPatterningIs = false
let clearPatterning = () =>{
if(createPatterningIs){
canvas.remove(currentPatterning)
}
currentPatterning = null
canvas.remove(polyLineBtn)
updateCanvasState()
}
//设置再画布上移动
let setCanvasMove = (event)=>{
var pointer = canvas.getPointer(event.e);
if(canvas.isDrawingMode){
canvas.setCursor('none');
if(!canvas.contains(brushIndicator)){
canvas.add(brushIndicator)
canvas.bringToFront(brushIndicator);//设置优先级最高
}
// brushIndicator.fill = canvasPencilColor.value
brushIndicator.set({ left: pointer.x, top: pointer.y, visible: true,radius:canvasPencilWidth.value/2 });
}else{
if(createPatterningIs){
2024-03-20 13:34:07 +08:00
JScanvasMouseMove(operation.value,event,currentPatterning,downPoint,keyDown)
}
}
canvas.requestRenderAll()
}
let setCanvasOut = (event)=>{
canvas.remove(brushIndicator)//鼠标移出删除绘画范围的圆形
2024-03-22 12:01:11 +08:00
clearCanvasKeyDown()//鼠标移出关闭键盘事件
}
//设置再画布上按下
let setCanvasDown = (event)=>{
downPoint = event.absolutePointer
let arr = ['rect','line','circle','triangle','ellipse','fold']
if(arr.indexOf(operation.value) > -1){
JSchangeType(canvas,operation.value)
createPatterningIs = true
if(currentPatterning && operation.value == 'fold'){
canvas.skipTargetFind = false
currentPatterning.points.push({
x: downPoint.x,
y: downPoint.y
})
// currentPatterning = JScanvasMouseDown(operation.value,event,canvasPencilWidth.value,currentPatterning)
}else{
2024-03-20 13:34:07 +08:00
currentPatterning = JScanvasMouseDown(operation.value,event,canvasPencilWidth.value,currentPatterning)
canvas.add(currentPatterning)
canvas.bringToFront(currentPatterning);//设置优先级最高
if(operation.value == 'fold'){
polyLineBtn = JScreateCheck(event)
2024-03-20 13:34:07 +08:00
polyLineBtn.on('mousedown',foldEnd)
canvas.add(polyLineBtn)
}
}
}else{
createPatterningIs = false
}
}
2024-03-20 13:34:07 +08:00
let foldEnd = (key)=>{
canvas.skipTargetFind = true
let points = currentPatterning.points
if(key == 'Enter'){
}else{
points.pop()
}
points.pop()
canvas.remove(currentPatterning)
let polyline = new fabric.Polyline(points, {
fill: operationMode.value == 'fill'? canvasPencilColor.value : 'transparent',
stroke: canvasPencilColor.value,
strokeWidth:canvasPencilWidth.value,
selection:false,
})
canvas.add(polyline)
// currentPatterning.set({stroke: canvasPencilColor.value})
createPatterningIs = false
clearPatterning()//临时图形置为空并且添加撤回对象里面
}
//设置再画布上抬起
let setCanvasUp = (event)=>{
upPoint = event.absolutePointer
if(canvas.isDrawingMode){
2024-03-15 09:21:17 +08:00
setTimeout(() => {
canvas.remove(brushIndicator)
updateCanvasState()
}, 100);
}else{
// event.target && (event.target.bringToFront())//设置优先级
}
if(createPatterningIs){
switch (operation.value) {
case 'line':
currentPatterning.set({stroke: canvasPencilColor.value})
break
case 'fold':
// currentPatterning.set({stroke: canvasPencilColor.value})
break
default :
if(operationMode.value == 'fill'){
currentPatterning.set({fill: canvasPencilColor.value})
}else if (operationMode.value == 'border'){
currentPatterning.set({fill: 'transparent',stroke: canvasPencilColor.value,strokeWidth: canvasPencilWidth.value})
}
if(JSON.stringify(downPoint) == JSON.stringify(upPoint)){
canvas.remove(currentPatterning)
}
break
}
if(operation.value == 'fold'){
canvas.forEachObject((obj) =>obj.selectable = false);
canvas.bringToFront(polyLineBtn);//设置优先级最高
}else{
createPatterningIs = false
clearPatterning()//临时图形置为空并且添加撤回对象里面
}
}
}
2024-03-15 17:23:25 +08:00
let setHDExport = async ()=>{//获取选中内容的位置信息
2024-03-22 12:01:11 +08:00
let {url,imageType} = await exportSele(canvas,'jpg')
if(!imageType){
message.info('Please select the region of SR')
return
}
2024-03-20 13:34:07 +08:00
let img = new Image
2024-03-22 12:01:11 +08:00
img.src = url
let imgStyle = {
'width': '80%',
'max-height': '30rem',
'object-fit': 'contain',
'position': 'relative',
'left': '50%',
'transform': 'translateX(-50%)',
}
let imgElement = createVNode('img',{src:url,style:imgStyle})
2024-03-20 13:34:07 +08:00
img.onload = ()=>{
2024-03-22 12:01:11 +08:00
Modal.confirm({
title: 'SR needs 300 points, whether to continue',
icon: false,
okText: 'Yes',
cancelText: 'No',
content: imgElement,
mask:false,
centered:true,
onOk() {
if(img.width*scaleSR.value>4069 || img.height*scaleSR.value>4069){
message.info('Your selected area and SR magnification are more than 4096 pixels,Please re-select.')
return
}
let data = {
images: url,
scale: scaleSR.value,
uniqueId: "",
imageType:imageType,
}
Https.axiosPost(Https.httpUrls.prepareForSR, data).then((rv) => {
console.log(rv);
emit('setTask')
});
},
// onCancel(){
// _this.isShowMark = false
// resolve(false)
// }
});
2024-03-20 13:34:07 +08:00
}
2024-02-27 15:15:38 +08:00
}
2024-03-22 12:01:11 +08:00
let scaleSR = ref(2);
2024-02-29 17:16:51 +08:00
onMounted(() => {});
2024-02-27 15:15:38 +08:00
2024-02-23 14:32:33 +08:00
return {
2024-03-15 09:21:17 +08:00
showUpgradePlan,//当前弹窗是否打开
canvasWH,//画布初始宽高
credits,//积分 用来判断HD导出积分是否够用
init,//首页点击导出后初始化
setExport,//导出所有内容
cancelDsign,//关闭画布
setMaxInput,//设置画布宽高
isShowMark,//加载遮罩
allBoardData,//选择画布所有内容
closeNav,//导航展开或者收起来状态
setCloseNav,//给图片导航或者工具收起来或者展开
multiselect,//获取整体高度
onDragstart,//拖拽函数
historyState,//执行撤回或者反撤回
operation,//设置当前鼠标状态绘画或者矩形或者移动
operationMode,//设置矩形是边框还是填充
setOperation,//设置当前鼠标状态绘画或者矩形或者移动方法
setOperationMode,//设置矩形是边框还是填充方法
2024-03-20 13:34:07 +08:00
setLayerIndex,//设置选中元素的层级
2024-03-15 09:21:17 +08:00
brushList,//笔触列表
2024-03-20 13:34:07 +08:00
textureList,//材质列表
2024-03-15 09:21:17 +08:00
canvasPencilColor,//input选择颜色
canvasPencilWidth,//input选择宽度
setPencilColor,//切换颜色执行函数 给当前矩形或者笔触设置颜色
setPencilWidth,//切换宽度执行函数 给当前矩形或者笔触设置宽度
setHDExport,//高清导出选择的图片
brushworkChange,//切换笔触的回调
2024-03-20 13:34:07 +08:00
textureValueChange,//切换材质信息
2024-03-15 09:21:17 +08:00
brushworkValue,//当前笔触
2024-03-20 13:34:07 +08:00
textureValue,//当前材质
2024-03-22 12:01:11 +08:00
scaleSR,
2024-02-23 14:32:33 +08:00
};
},
data(prop) {
2024-02-29 17:16:51 +08:00
return {};
2024-02-23 14:32:33 +08:00
},
2024-02-29 17:16:51 +08:00
mounted() {},
watch: {
// driver__:{
// handler(newVal,oldVal){
// if(this.type_.type2 == 'Printboard'){
// if(newVal.index >= 14 && newVal.index < 15){
// this.setKeyword(newVal.index-14)
// }else{
// }
// }else if(this.type_.type2 == 'Sketchboard'){
// }
// }
// },
2024-02-23 14:32:33 +08:00
},
2024-03-04 09:57:46 +08:00
methods: {
},
2024-02-23 14:32:33 +08:00
});
</script>
<style lang="less" scoped>
.Export {
2024-02-29 17:16:51 +08:00
flex: 1;
2024-02-23 14:32:33 +08:00
// height: 30rem;
// overflow-x: hidden;
2024-02-29 17:16:51 +08:00
display: flex;
2024-02-23 14:32:33 +08:00
flex-direction: column;
border-right: 1px solid #e5e5e5;
2024-02-29 17:16:51 +08:00
position: relative;
.UpgradePlan_content {
font-size: var(--aida-fsize2);
font-weight: 900;
color: rgba(0, 0, 0, 0.65);
}
.UpgradePlan_closeIcon {
top: calc(2rem * 1.2);
right: calc(2rem * 1.2);
2024-02-23 14:32:33 +08:00
cursor: pointer;
2024-02-29 17:16:51 +08:00
width: calc(4rem * 1.2);
height: calc(4rem * 1.2);
display: flex;
align-items: center;
justify-content: center;
position: absolute;
.fi-rr-cross-small::before {
padding: calc(0.2rem * 1.2);
border-radius: 5px;
border: solid 2px rgba(0, 0, 0, 0.25);
transition: 1s all;
color: rgba(0, 0, 0, 0.55);
}
&.UpgradePlan_closeIcon:hover .fi-rr-cross-small::before {
border: solid 2px rgba(0, 0, 0, 0.55);
color: rgba(0, 0, 0, 1);
}
}
.exportCanvasBox {
flex: 1;
overflow-x: hidden;
display: flex;
margin-top: 2rem;
justify-content: space-between;
.exportCanvasBox_title {
margin-bottom: .5rem;
font-size: 1.8rem;
font-weight: 600;
2024-03-08 16:51:24 +08:00
// margin-top: 2rem;
padding-top: 2rem;
2024-02-29 17:16:51 +08:00
display: flex;
2024-03-08 16:54:04 +08:00
top: -1rem;
2024-02-29 17:16:51 +08:00
justify-content: space-between;
cursor: pointer;
position: sticky;
background: #f9fafb;
z-index: 2;
2024-02-29 17:16:51 +08:00
.icon{
transition: all .3s;
2024-02-27 15:15:38 +08:00
}
2024-03-04 09:57:46 +08:00
.icon-rotate{
transform: rotate(-180deg);
2024-02-29 17:16:51 +08:00
}
}
.exportCanvasBox_intro{
margin-bottom: 1rem;
font-size: 1.6rem;
font-weight: 600;
width: 100%;
2024-02-27 15:15:38 +08:00
}
2024-02-29 17:16:51 +08:00
.exportCanvasBox_right,
.exportCanvasBox_left {
width: 25rem;
2024-02-27 15:15:38 +08:00
height: 100%;
overflow-x: hidden;
2024-03-04 09:57:46 +08:00
label {
2024-02-29 17:16:51 +08:00
display: flex;
2024-03-04 09:57:46 +08:00
align-items: center;
margin-bottom: 1rem;
2024-03-15 09:21:17 +08:00
width: 100%;
2024-02-29 17:16:51 +08:00
div {
2024-03-15 09:21:17 +08:00
width: 8rem;
2024-02-29 17:16:51 +08:00
}
input {
2024-03-15 09:21:17 +08:00
// width: 10em;
flex: 1;
overflow: hidden;
2024-02-29 17:16:51 +08:00
}
2024-03-15 09:21:17 +08:00
.label_select{
img{
width: 100%;
2024-03-15 17:23:25 +08:00
max-height: 100%;
object-fit: contain;
2024-03-15 09:21:17 +08:00
}
}
2024-02-29 17:16:51 +08:00
}
2024-03-20 13:34:07 +08:00
.texture{
.label_select{
img{
max-height: none;
}
}
}
.exportCanvasBox_left_item.closeNav{
// max-height: 1000rem;
height: auto;
2024-03-04 09:57:46 +08:00
}
}
.exportCanvasBox_left::-webkit-scrollbar,
.exportCanvasBox_right::-webkit-scrollbar{display: none;}
.exportCanvasBox_left {
padding-right: 1rem;
.exportCanvasBox_title {
padding-right: 2rem;
}
.exportCanvasBox_left_item{
2024-02-29 17:16:51 +08:00
overflow: hidden;
transition: all .3s;
// max-height: 0;
height: 0;
2024-03-04 09:57:46 +08:00
transform: translate3d(0, 0, 0);
}
.exportCanvasBox_img {
// height: auto;
2024-03-04 09:57:46 +08:00
2024-02-29 17:16:51 +08:00
.exportCanvasBox_allItem {
display: flex;
flex-wrap: wrap;
.exportCanvasBox_item {
text-align: center;
img {
max-width: 7rem;
max-height: 7rem;
object-fit: contain;
margin-right: 2rem;
margin-bottom: 2rem;
}
}
.exportCanvasBox_item_color{
width: 8rem;
margin-right: 2rem;
margin-bottom: 2rem;
.exportCanvasBox_item_BGcolor{
height: 5rem;
}
2024-03-04 09:57:46 +08:00
div{
// -webkit-user-select:none; /* Safari */
// -moz-user-select:none; /* Firefox */
// -ms-user-select:none; /* IE10+/Edge */
// user-select:none; /* Standard syntax */
}
2024-02-29 17:16:51 +08:00
}
.exportCanvasBox_item_dispose{
img{
max-width: 100%;
max-height: 100%;
}
}
}
}
.exportCanvasBox_left_tool{
.exportCanvasBox_left_tool_item{
display: flex;
2024-03-20 13:34:07 +08:00
flex: 1;
flex-wrap: wrap;
justify-content: space-between;
margin-bottom: 1rem;
&.leftAlign{
justify-content: flex-start;
}
2024-03-15 09:21:17 +08:00
i{
font-size: 2.5rem;
cursor: pointer;
width: 4rem;
height: 4rem;
display: flex;
align-items: center;
justify-content: center;
&.active{
border: 1px solid;
border-radius: .4rem;
}
}
}
}
2024-02-29 17:16:51 +08:00
}
2024-03-04 09:57:46 +08:00
.exportCanvasBox_right{
display: flex;
flex-direction: column;
padding-left: 1rem;
2024-03-04 09:57:46 +08:00
position: relative;
.exportCanvasBox_right_definition{
// display: flex;
flex: 1;
}
2024-03-08 16:51:24 +08:00
.exportCanvasBox_right_credits{
margin-bottom: 2rem;
}
2024-03-04 09:57:46 +08:00
.exportCanvasBox_right_btn{
display: flex;
justify-content: space-between;
.subitOkPreviewBtn{
position: initial;
transform: none;
2024-03-08 16:51:24 +08:00
&.active{
opacity: .7;
cursor: not-allowed;
}
2024-03-04 09:57:46 +08:00
}
2024-03-08 16:51:24 +08:00
2024-03-04 09:57:46 +08:00
}
}
2024-02-29 17:16:51 +08:00
.exportCanvasBox_center {
height: 100%;
overflow-x: hidden;
}
.export_new_collection_review {
position: initial;
margin: 10rem auto;
margin-bottom: 0;
}
}
2024-02-23 14:32:33 +08:00
}
</style>
<style lang="less">
2024-02-29 17:16:51 +08:00
.Export {
.ant-modal-content {
border-radius: calc(1rem * 1.2);
overflow: hidden;
.ant-modal-header {
background-color: #fff;
border-bottom: none;
}
.ant-modal-body {
display: flex;
flex-direction: column;
padding: calc(5rem * 1.2) calc(5rem * 1.2) !important;
// height: calc(65vh - 6.4rem);
height: calc(65rem * 1.2);
background: #f9fafb;
}
//进度完成字体颜色
.ant-progress-circle.ant-progress-status-success .ant-progress-text {
color: #000;
}
.ant-progress-circle .ant-progress-text {
color: rgba(0, 0, 0, 0.55);
font-size: calc(1.6rem * 1.2);
}
}
2024-03-15 09:21:17 +08:00
.ant-select-focused:not(.ant-select-disabled).ant-select:not(.ant-select-customize-input) .ant-select-selector{
border-color: #d9d9d9;
box-shadow: none;
}
.ant-select:hover .ant-select-selector{
border-color: #d9d9d9;
}
}
.label_select_item{
img{
width: 100%;
2024-03-15 17:23:25 +08:00
max-height: 100%;
object-fit: contain;
2024-03-15 09:21:17 +08:00
}
2024-02-23 14:32:33 +08:00
}
</style>