This commit is contained in:
yf 2025-01-07 01:47:30 +08:00
parent 8dd5fb6519
commit b41184a5de
5 changed files with 426 additions and 6 deletions

View File

@ -310,7 +310,7 @@ import {reactive, watch} from 'vue'
import {useMessage} from "@/hooks/web/useMessage";
import {DraftDesignDataApi} from "@/api/oms/draftdesigndata";
import DraftDesign from "@/components/DraftDesign/index.vue";
import {ShapeType} from "@/components/DraftDesign/config";
import {getHtml, ShapeType} from "@/components/DraftDesign/config";
import {ProductCareItemApi} from "@/api/oms/productcareitem";
import {replaceDomain} from "@/utils";
import * as FileApi from "@/api/infra/file";
@ -632,8 +632,9 @@ const uploadFile = async (fileName) => {
}
const saveMaxSvg = (svgElement,fileName)=>{
const blob = new Blob([svgElement?.parentElement?.innerHTML], { type: 'text/html' });
const file = new File([blob], fileName+".html", {type: 'image/png'});
const htmlStr = getHtml(`${svgElement?.parentElement?.innerHTML}`);
const blob = new Blob([htmlStr], { type: 'text/html' });
const file = new File([blob], fileName+".html", {type: 'text/html'});
FileApi.updateFile({file: file})
.then((res) => {
console.log("res"+res)

View File

@ -0,0 +1,308 @@
<!-- eslint-disable vue/this-in-template -->
<template>
<div
:id="cellInfo.id"
class="node-content"
:class="{
'node-content-group' : cellInfo.editMode && cellInfo.propGroupId,
'node-content-tips' : cellInfo.editMode && !cellInfo.style.shape.href
}"
:title="cellInfo.propGroupName"
v-reSize="changSize">
<div v-html="svgContent" style=" width: 100%;height: 100%;"></div>
</div>
</template>
<script lang="ts">
//
import {defineComponent} from 'vue'
import {
filterUnsafeHtml,
mergeDeepObject,
nextId,
} from "@/components/DraftDesign/utils/FuncUtil";
import {
configInfo,
getBarCodeType,
getDraftDesignState,
VueCellShapeType
} from "@/components/DraftDesign/config";
import bwipjs from 'bwip-js';
export default defineComponent({
name: 'ShapeBarcodeNode',
computed: {
VueCellShapeType() {
return VueCellShapeType
},
minShapeSize() {
if (this.cellInfo.style.shape.strokeWidth) {
return this.minSize - this.toInt(this.cellInfo.style.shape.strokeWidth)
}
return this.minSize;
},
svgStyle() {
const res = {
borderRadius: '',
backgroundColor: this.cellInfo.style.shape.fillColor || "",
width: `1000px`,
height: `1000px`,
transform: ''
}
// const tmp = Math.min(this.sizeWInfo.width, this.sizeWInfo.height) - (this.cellInfo.style.shape.strokeWidth * 2)
const w = (Math.max(this.sizeWInfo.width, 0)) / 1000;
const h = (Math.max(this.sizeWInfo.height, 0)) / 1000;
res.transform = `scaleX(${w}) scaleY(${h})`
return res;
},
},
// eslint-disable-next-line vue/order-in-components
inject: ['getNode'],
// eslint-disable-next-line vue/order-in-components
data() {
return {
textElId: nextId(),
svgContent: '',
cellInfo: {
id: '',
label: '文字说明',
editMode: false,
showInput: false,
propGroupName: "",
propGroupId: null,
shape: VueCellShapeType.Rect,
style: {
shape: {
x: 0, // x
y: 0, // y
rx: 0, // x
ry: 0, // y
fillColor: '', //
fillOpacity: '', //
href: '',
opacity: '', //
strokeDashoffset: '', // 线
strokeLinecap: undefined, // 线"round" | "butt" | "square" | "inherit" | undefined
strokeLinejoin: undefined, // 线"round" | "inherit" | "miter" | "bevel" | undefined
strokeDasharray: '', // 线
bottom: 0, //
transform: '', //
clipPath: '', //
filter: '', //
},
text: {
minWidth: 'max-content',
fontSize: 12,
minHeight: 'max-content',
}
}
},
nodeInfo: {
store: {
data: {
data: {
label: ''
}
}
}
},
fontSize: 12,
hrefBase64: null,
targetElement: null,
minSize: 2,
sizeWInfo: {
width: 0,
height: 0,
},
}
},
mounted() {
const node = (this as any).getNode()
this.nodeInfo = node
if (node && node.data) {
this.setCellInfo(node.data)
}
node.on('change:data', ({current}) => {
this.setCellInfo(current)
})
},
unmounted() {
},
methods: {
toInt(val, defaultVal = 0) {
try {
return parseInt(val)
} catch (e) {
return defaultVal
}
},
safeHtml(val) {
if (val) {
val = val.replace(/[\n\r]/g, "<br/>")
}
return filterUnsafeHtml(val)
},
inputBlur() {
// this.cellInfo.showInput = false
},
inputChange() {
if (this.nodeInfo.store && this.nodeInfo.store.data) {
// this.nodeInfo.store.data.data.label = this.cellInfo.label
this.nodeInfo.store.data.data = {
...this.nodeInfo.store.data.data,
...this.cellInfo
}
}
},
// @ts-ignore
setInput(val: boolean) {
},
changSize(size: any) {
if (!size) {
return;
}
this.sizeWInfo.width = size.width;
this.sizeWInfo.height = size.height;
this.minSize = Math.min(size.height, size.width)
let s = size.height + 12;
if (s > 60) {
s = s + s / 3
}
if (s < 6) {
s = 6
} else if (s >= 1000) {
s = 1000
}
this.changeBarcode();
console.log("生成");
// this.nodeInfo.store.data.size.width = size.width;
this.fontSize = s;
this.changeFontSize();
},
changeBarcode(){
console.log(" this.minSize", this.minSize)
this.svgContent = bwipjs.toSVG(this.getBarCodeType("code128"));
},
getBarCodeType(type){
return getBarCodeType(type, this.sizeWInfo.height / (2+(this.minSize/30)))
},
changeFontSize() {
// @ts-ignore
this.cellInfo.style.text.fontSize = `${this.fontSize}px`
},
setCellInfo(info: any) {
if (!info) {
info = {
style: {
text: {}
}
}
}
// @ts-ignore
this.cellInfo = mergeDeepObject({
showInput: false,
id: nextId(),
label: '',
shape: VueCellShapeType.Barcode,
style: {
shape: {
x: 0, // x
y: 0, // y
rx: 0, // x
ry: 0, // y
fillColor: 'rgba(0,0,0,0)', //
href: '',
label: '图片',
fillOpacity: '', //
opacity: '', //
strokeDashoffset: '', // 线
strokeLinecap: undefined, // 线"round" | "butt" | "square" | "inherit" | undefined
strokeLinejoin: undefined, // 线"round" | "inherit" | "miter" | "bevel" | undefined
strokeDasharray: '', // 线
bottom: 0, //
transform: '', //
clipPath: '', //
filter: '', //
},
text: {}
}
}, info)
// if(!this.hrefBase64 && this.cellInfo.style.shape.href && this.cellInfo.style.shape.href.indexOf("data:image") < 0){
// // DataUri.imageToDataUri(this.cellInfo.style.shape.href,
// // function (nu, url) {
// // console.log("base64 ")
// // //
// // // @ts-ignore
// // this.hrefBase64 = url; //
// // }
//
// // );
// convertImageToBase64(this.cellInfo.style.shape.href).then((res)=>{
// // @ts-ignore
// this.hrefBase64 = res
// console.log("base64 ")
// // this.cellInfo.style.shape.href = res
// })
// }
setTimeout(() => {
if (this.nodeInfo.store && this.nodeInfo.store.data) {
this.nodeInfo.store.data.data = this.cellInfo
}
}, 300)
this.cellInfo.editMode = getDraftDesignState();
if (this.cellInfo.editMode && this.cellInfo.propGroupId) {
const showRandomGroupColor = configInfo.LK_SHOW_RANDOM_GROUP_COLOR()
if (!showRandomGroupColor) {
setTimeout(() => {
const [type, id] = this.cellInfo.propGroupId.split("_")
if (id) {
document.getElementById(this.cellInfo.id)?.style.setProperty(
"--lk-prop-group-color",
`#${id}`
);
}
}, 100)
}
}
this.changeFontSize();
// bwipjs.toSVG({
// bcid: 'code128', //
// text: 'Hello, World!', //
// width: 200, //
// height: 50, //
// }, function(err, svg) {
// if (err) throw err;
// console.log("",svg);
// this.svgContent = svg;
// });
}
}
})
</script>
<style scoped lang="scss">
.node-content {
width: 100%;
height: 100%;
position: relative;
display: flex;
}
</style>

View File

@ -521,3 +521,58 @@ export const configInfo = {
return localStorage.setItem('lk_show_random_group_color', show ? 'true' : '')
}
}
export const getHtml = (htmlStr:string)=>{
return `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>oms稿件预览源文件</title>
<style>
#printButton {
padding: 3px 8px;
background-color: #4caf505e;
color: white;
border: none;
cursor: pointer;
font-size: 14px;
position: fixed;
top: 10px;
z-index: 99999;
border-radius: 3px;
}
#printButton:hover {
background-color: #45a049;
}
.tips{
color: #ff0000;
font-size: 14px;
position: fixed;
top: 30px;
left: 30px;
z-index: 99999;
}
</style>
</head>
<body>
<div class="tips">
*
</div>
${htmlStr}
<button id="printButton">PDF</button>
<script>
document.getElementById('printButton').addEventListener('click', function() {
document.getElementById('printButton').style.top = '-10000px'
window.print();
});
window.onafterprint = function() {
document.getElementById('printButton').style.top = '10px'
};
</script>
</body>
</html>
`
}

View File

@ -310,7 +310,7 @@ import {reactive, watch} from 'vue'
import {useMessage} from "@/hooks/web/useMessage";
import {DraftDesignDataApi} from "@/api/oms/draftdesigndata";
import DraftDesign from "@/components/DraftDesign/index.vue";
import {ShapeType} from "@/components/DraftDesign/config";
import {getHtml, ShapeType} from "@/components/DraftDesign/config";
import {ProductCareItemApi} from "@/api/oms/productcareitem";
import {replaceDomain} from "@/utils";
import * as FileApi from "@/api/infra/file";
@ -632,8 +632,9 @@ const uploadFile = async (fileName) => {
}
const saveMaxSvg = (svgElement,fileName)=>{
const blob = new Blob([svgElement?.parentElement?.innerHTML], { type: 'text/html' });
const file = new File([blob], fileName+".html", {type: 'image/png'});
const htmlStr = getHtml(`${svgElement?.parentElement?.innerHTML}`);
const blob = new Blob([htmlStr], { type: 'text/html' });
const file = new File([blob], fileName+".html", {type: 'text/html'});
FileApi.updateFile({file: file})
.then((res) => {
console.log("res"+res)

View File

@ -521,3 +521,58 @@ export const configInfo = {
return localStorage.setItem('lk_show_random_group_color', show ? 'true' : '')
}
}
export const getHtml = (htmlStr:string)=>{
return `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>oms稿件预览源文件</title>
<style>
#printButton {
padding: 3px 8px;
background-color: #4caf505e;
color: white;
border: none;
cursor: pointer;
font-size: 14px;
position: fixed;
top: 10px;
z-index: 99999;
border-radius: 3px;
}
#printButton:hover {
background-color: #45a049;
}
.tips{
color: #ff0000;
font-size: 14px;
position: fixed;
top: 30px;
left: 30px;
z-index: 99999;
}
</style>
</head>
<body>
<div class="tips">
*
</div>
${htmlStr}
<button id="printButton">PDF</button>
<script>
document.getElementById('printButton').addEventListener('click', function() {
document.getElementById('printButton').style.top = '-10000px'
window.print();
});
window.onafterprint = function() {
document.getElementById('printButton').style.top = '10px'
};
</script>
</body>
</html>
`
}