导出图片添加配置

This commit is contained in:
李志鹏
2026-01-15 14:10:05 +08:00
parent 7a4fc0736d
commit 28b6153ab0
5 changed files with 38 additions and 17 deletions

View File

@@ -1018,9 +1018,10 @@ defineExpose({
exportImage: ({ exportImage: ({
isContainBg = false, // 是否包含背景图层 isContainBg = false, // 是否包含背景图层
isContainFixed = false, // 是否包含固定图层 isContainFixed = false, // 是否包含固定图层
isContainFixedOther = false, // 是否包含其他固定图层 isContainFixedOther = true, // 是否包含其他固定图层--颜色图层
isPrintTrimsNoRepeat = true, // 是否包含印花图层的不平铺 isPrintTrimsNoRepeat = true, // 是否包含印花图层的不平铺
isPrintTrimsRepeat = true, // 是否包含印花图层的平铺 isPrintTrimsRepeat = true, // 是否包含印花图层的平铺
isContainNormalLayer = true, // 是否包含普通图层
isCropByBg = false, // 是否使用背景大小裁剪 // 如果为true则导出时裁剪到背景图层大小 isCropByBg = false, // 是否使用背景大小裁剪 // 如果为true则导出时裁剪到背景图层大小
layerId = "", // 导出具体图层ID layerId = "", // 导出具体图层ID
layerIdArray = [], // 导出多个图层ID数组 layerIdArray = [], // 导出多个图层ID数组
@@ -1033,6 +1034,7 @@ defineExpose({
isContainFixedOther, isContainFixedOther,
isPrintTrimsNoRepeat, isPrintTrimsNoRepeat,
isPrintTrimsRepeat, isPrintTrimsRepeat,
isContainNormalLayer,
isCropByBg, isCropByBg,
layerId, layerId,
layerIdArray, layerIdArray,

View File

@@ -938,6 +938,7 @@ export class CanvasManager {
* @param {Boolean} options.isContainFixedOther 是否包含其他固定图层 * @param {Boolean} options.isContainFixedOther 是否包含其他固定图层
* @param {Boolean} options.isPrintTrimsNoRepeat 是否包含印花图层的不平铺 * @param {Boolean} options.isPrintTrimsNoRepeat 是否包含印花图层的不平铺
* @param {Boolean} options.isPrintTrimsRepeat 是否包含印花图层的平铺 * @param {Boolean} options.isPrintTrimsRepeat 是否包含印花图层的平铺
* @param {Boolean} options.isContainNormalLayer 是否包含普通图层
* @param {String} options.layerId 导出具体图层ID * @param {String} options.layerId 导出具体图层ID
* @param {Array} options.layerIdArray 导出多个图层ID数组 * @param {Array} options.layerIdArray 导出多个图层ID数组
* @param {String} options.expPicType 导出图片类型 (png/jpg/svg) * @param {String} options.expPicType 导出图片类型 (png/jpg/svg)
@@ -960,6 +961,7 @@ export class CanvasManager {
const enhancedOptions = { const enhancedOptions = {
isPrintTrimsNoRepeat: true, isPrintTrimsNoRepeat: true,
isPrintTrimsRepeat: true, isPrintTrimsRepeat: true,
isContainNormalLayer: true,
...options, ...options,
// 如果没有明确指定,则根据当前模式自动设置 // 如果没有明确指定,则根据当前模式自动设置
restoreOpacityInRedGreen: restoreOpacityInRedGreen:

View File

@@ -20,6 +20,7 @@ export class ExportManager {
* @param {Boolean} options.isContainBg 是否包含背景图层 * @param {Boolean} options.isContainBg 是否包含背景图层
* @param {Boolean} options.isContainFixed 是否包含固定图层 * @param {Boolean} options.isContainFixed 是否包含固定图层
* @param {Boolean} options.isContainFixedOther 是否包含其他固定图层 * @param {Boolean} options.isContainFixedOther 是否包含其他固定图层
* @param {Boolean} options.isContainNormalLayer 是否包含普通图层
* @param {Boolean} options.isCropByBg 是否使用背景大小裁剪 * @param {Boolean} options.isCropByBg 是否使用背景大小裁剪
* @param {String} options.layerId 导出具体图层ID * @param {String} options.layerId 导出具体图层ID
* @param {Array} options.layerIdArray 导出多个图层ID数组 * @param {Array} options.layerIdArray 导出多个图层ID数组
@@ -35,6 +36,7 @@ export class ExportManager {
isContainBg = false, isContainBg = false,
isContainFixed = false, isContainFixed = false,
isContainFixedOther = false, // 是否包含其他固定图层 isContainFixedOther = false, // 是否包含其他固定图层
isContainNormalLayer = true, // 是否包含普通图层
isCropByBg = false, // 是否使用背景大小裁剪 isCropByBg = false, // 是否使用背景大小裁剪
layerId = "", layerId = "",
layerIdArray = [], layerIdArray = [],
@@ -68,6 +70,7 @@ export class ExportManager {
isContainBg, isContainBg,
isContainFixed, isContainFixed,
isContainFixedOther, // 是否包含其他固定图层 isContainFixedOther, // 是否包含其他固定图层
isContainNormalLayer, // 是否包含普通图层
isRedGreenMode, isRedGreenMode,
restoreOpacityInRedGreen, restoreOpacityInRedGreen,
isCropByBg, isCropByBg,
@@ -81,6 +84,7 @@ export class ExportManager {
isContainBg, isContainBg,
isContainFixed, isContainFixed,
isContainFixedOther, // 是否包含其他固定图层 isContainFixedOther, // 是否包含其他固定图层
isContainNormalLayer, // 是否包含普通图层
isRedGreenMode, isRedGreenMode,
restoreOpacityInRedGreen, restoreOpacityInRedGreen,
isCropByBg, isCropByBg,
@@ -160,6 +164,7 @@ export class ExportManager {
* @param {Boolean} isContainBg 是否包含背景图层 * @param {Boolean} isContainBg 是否包含背景图层
* @param {Boolean} isContainFixed 是否包含固定图层 * @param {Boolean} isContainFixed 是否包含固定图层
* @param {Boolean} isContainFixedOther 是否包含其他固定图层 * @param {Boolean} isContainFixedOther 是否包含其他固定图层
* @param {Boolean} isContainNormalLayer 是否包含普通图层
* @param {Boolean} isRedGreenMode 是否为红绿图模式 * @param {Boolean} isRedGreenMode 是否为红绿图模式
* @param {Boolean} restoreOpacityInRedGreen 红绿图模式下是否恢复透明度为1 * @param {Boolean} restoreOpacityInRedGreen 红绿图模式下是否恢复透明度为1
* @param {Boolean} isCropByBg 是否使用背景大小裁剪 * @param {Boolean} isCropByBg 是否使用背景大小裁剪
@@ -173,6 +178,7 @@ export class ExportManager {
isContainBg, isContainBg,
isContainFixed, isContainFixed,
isContainFixedOther, // 是否包含其他固定图层 isContainFixedOther, // 是否包含其他固定图层
isContainNormalLayer = true, // 是否包含普通图层
isRedGreenMode, isRedGreenMode,
restoreOpacityInRedGreen, restoreOpacityInRedGreen,
isCropByBg, // 是否使用背景大小裁剪 isCropByBg, // 是否使用背景大小裁剪
@@ -188,6 +194,7 @@ export class ExportManager {
isContainBg, isContainBg,
isContainFixed, isContainFixed,
isContainFixedOther, // 是否包含其他固定图层 isContainFixedOther, // 是否包含其他固定图层
isContainNormalLayer, // 是否包含普通图层
); );
if (objectsToExport.length === 0) { if (objectsToExport.length === 0) {
@@ -220,6 +227,7 @@ export class ExportManager {
* @param {Boolean} isContainBg 是否包含背景图层 * @param {Boolean} isContainBg 是否包含背景图层
* @param {Boolean} isContainFixed 是否包含固定图层 * @param {Boolean} isContainFixed 是否包含固定图层
* @param {Boolean} isContainFixedOther 是否包含其他固定图层 * @param {Boolean} isContainFixedOther 是否包含其他固定图层
* @param {Boolean} isContainNormalLayer 是否包含普通图层
* @param {Boolean} isRedGreenMode 是否为红绿图模式 * @param {Boolean} isRedGreenMode 是否为红绿图模式
* @param {Boolean} restoreOpacityInRedGreen 红绿图模式下是否恢复透明度为1 * @param {Boolean} restoreOpacityInRedGreen 红绿图模式下是否恢复透明度为1
* @param {Boolean} isCropByBg 是否使用背景大小裁剪 * @param {Boolean} isCropByBg 是否使用背景大小裁剪
@@ -233,6 +241,7 @@ export class ExportManager {
isContainBg, isContainBg,
isContainFixed, isContainFixed,
isContainFixedOther, // 是否包含其他固定图层 isContainFixedOther, // 是否包含其他固定图层
isContainNormalLayer, // 是否包含普通图层
isRedGreenMode, isRedGreenMode,
restoreOpacityInRedGreen, restoreOpacityInRedGreen,
isCropByBg, // 是否使用背景大小裁剪 isCropByBg, // 是否使用背景大小裁剪
@@ -246,6 +255,7 @@ export class ExportManager {
isContainBg, isContainBg,
isContainFixed, isContainFixed,
isContainFixedOther, // 是否包含其他固定图层 isContainFixedOther, // 是否包含其他固定图层
isContainNormalLayer, // 是否包含普通图层
excludedLayers, excludedLayers,
); );
@@ -405,11 +415,12 @@ export class ExportManager {
* @param {Boolean} isContainBg 是否包含背景图层 * @param {Boolean} isContainBg 是否包含背景图层
* @param {Boolean} isContainFixed 是否包含固定图层 * @param {Boolean} isContainFixed 是否包含固定图层
* @param {Boolean} isContainFixedOther 是否包含其他固定图层 * @param {Boolean} isContainFixedOther 是否包含其他固定图层
* @param {Boolean} isContainNormalLayer 是否包含普通图层
* @param {Array} excludedLayers 排除的图层ID数组 * @param {Array} excludedLayers 排除的图层ID数组
* @returns {Array} 按正确顺序排列的真实对象数组 * @returns {Array} 按正确顺序排列的真实对象数组
* @private * @private
*/ */
_collectObjectsByLayerOrder(layerIdArray, isContainBg, isContainFixed, isContainFixedOther, excludedLayers) { _collectObjectsByLayerOrder(layerIdArray, isContainBg, isContainFixed, isContainFixedOther, isContainNormalLayer, excludedLayers) {
const objectsToExport = []; const objectsToExport = [];
const allLayers = this._getAllLayersFlattened(excludedLayers); // 获取扁平化的图层列表 const allLayers = this._getAllLayersFlattened(excludedLayers); // 获取扁平化的图层列表
@@ -421,7 +432,7 @@ export class ExportManager {
if (layerIdArray && !layerIdArray.includes(layer.id)) continue; if (layerIdArray && !layerIdArray.includes(layer.id)) continue;
// 检查图层类型过滤条件 // 检查图层类型过滤条件
if (!this._shouldIncludeLayer(layer, isContainBg, isContainFixed, isContainFixedOther)) if (!this._shouldIncludeLayer(layer, isContainBg, isContainFixed, isContainFixedOther, isContainNormalLayer))
continue; continue;
if (layer.visible) { if (layer.visible) {
@@ -1040,10 +1051,11 @@ export class ExportManager {
* @param {Boolean} isContainBg 是否包含背景图层 * @param {Boolean} isContainBg 是否包含背景图层
* @param {Boolean} isContainFixed 是否包含固定图层 * @param {Boolean} isContainFixed 是否包含固定图层
* @param {Boolean} isContainFixedOther 是否包含其他固定图层 * @param {Boolean} isContainFixedOther 是否包含其他固定图层
* @param {Boolean} isContainNormalLayer 是否包含普通图层
* @returns {Boolean} 是否应该包含 * @returns {Boolean} 是否应该包含
* @private * @private
*/ */
_shouldIncludeLayer(layer, isContainBg, isContainFixed, isContainFixedOther) { _shouldIncludeLayer(layer, isContainBg, isContainFixed, isContainFixedOther, isContainNormalLayer) {
if (!layer) return false; if (!layer) return false;
// 检查背景图层 // 检查背景图层
@@ -1061,7 +1073,12 @@ export class ExportManager {
return isContainFixedOther; return isContainFixedOther;
} }
// 普通图层总是包含 // 印花图层始终导出
return true; if (layer.isPrintTrims || layer.isPrintTrimsGroup) {
return true;
}
// 普通图层
return isContainNormalLayer;
} }
} }

View File

@@ -30,7 +30,7 @@
DELETE: "delete", DELETE: "delete",
SORT: "sort", SORT: "sort",
}; };
const emit = defineEmits(["change-canvas"]); const emit = defineEmits(["change-canvas", "init-canvas"]);
const props = defineProps({ const props = defineProps({
list: { type: Array, default: () => [] }, list: { type: Array, default: () => [] },
}); });
@@ -41,7 +41,6 @@
onMounted(async () => { onMounted(async () => {
initCanvas(); initCanvas();
await setCanvasData(); await setCanvasData();
let throttleTimeout = null; let throttleTimeout = null;
let lastRunTime = 0; let lastRunTime = 0;
let trailingTimeout = null; let trailingTimeout = null;
@@ -63,6 +62,7 @@
} }
}); });
observer.value.observe(el.value); observer.value.observe(el.value);
emit("init-canvas", props.list);
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
observer.value.disconnect(); observer.value.disconnect();

View File

@@ -335,15 +335,15 @@ const otherData = {
color: {rgba: {r:255,g:0,b:0,a:1}}, color: {rgba: {r:255,g:0,b:0,a:1}},
printObject: { printObject: {
prints: [ prints: [
// { {
// ifSingle: false, ifSingle: false,
// level2Type: "Pattern", level2Type: "Pattern",
// designType: "Library", designType: "Library",
// path: "/src/assets/images/canvas/yinhua1.jpg", path: "/src/assets/images/canvas/yinhua1.jpg",
// location: [250, 780], location: [250, 780],
// scale: [0.3, 0.4], scale: [0.3, 0.4],
// angle: 0, angle: 0,
// }, },
{ {
ifSingle: true, ifSingle: true,
level2Type: "Pattern", level2Type: "Pattern",