Commit b0182596 by linjinhong

feat:添加本地储存功能

parent e0f5d9e8
...@@ -33,14 +33,19 @@ async function createWindow() { ...@@ -33,14 +33,19 @@ async function createWindow() {
width: 1500, width: 1500,
height: 1000, height: 1000,
icon: "./src/assets/logo.jpg", icon: "./src/assets/logo.jpg",
webPreferences: { webPreferences: {
webSecurity: false, webSecurity: false,
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false, // ^1.4.0 版本必须关闭 contextIsolation: false, // ^1.4.0 版本必须关闭
}, },
show: false,
}); });
win.once("ready-to-show", () => {
win.maximize(); win.maximize();
win.show();
});
const template = [ const template = [
{ {
label: "文件", label: "文件",
...@@ -430,13 +435,6 @@ async function createWindow() { ...@@ -430,13 +435,6 @@ async function createWindow() {
if (result.length) { if (result.length) {
event.reply("select-folder-result", result[0]); event.reply("select-folder-result", result[0]);
} }
// if (!result.canceled && result.filePaths.length > 0) {
// // event.reply:向发送消息的渲染进程返回结果
// event.reply("select-folder-result", result.filePaths[0]);
// } else {
// // 用户取消选择,返回 null
// event.reply("select-folder-result", null);
// }
}, },
); );
}); });
......
...@@ -21,12 +21,22 @@ const { app } = require("electron"); ...@@ -21,12 +21,22 @@ const { app } = require("electron");
let fileEnv, env, visionUrl; let fileEnv, env, visionUrl;
axios.defaults.timeout = 12600000; axios.defaults.timeout = 12600000;
const multiparty = require("multiparty"); const multiparty = require("multiparty");
const { getVersion, setApi, getHostApi } = require("@/server/utils/store"); const {
getVersion,
setApi,
getHostApi,
getDesktopDevice,
} = require("@/server/utils/store");
//获取当前驱动版本
function getCurrentVersion() { function getCurrentVersion() {
const version = getVersion(); const version = getVersion();
return version; return version;
} }
//获取当前设备类型
function getCurrentDesktopDevice() {
const version = getDesktopDevice();
return version;
}
async function readEnv() { async function readEnv() {
let exePath, configPath; let exePath, configPath;
...@@ -57,6 +67,10 @@ async function readEnv() { ...@@ -57,6 +67,10 @@ async function readEnv() {
readEnv(); readEnv();
export default { export default {
saveImgByUrl: async (req, res) => { saveImgByUrl: async (req, res) => {
const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
try { try {
const response = await axios({ const response = await axios({
url: req.body.url, url: req.body.url,
...@@ -66,7 +80,7 @@ export default { ...@@ -66,7 +80,7 @@ export default {
let fileName = uuid.v4() + ".png"; let fileName = uuid.v4() + ".png";
const filePath = path.join( const filePath = path.join(
process.cwd(), process.cwd(),
`./${getCurrentVersion()}/Input/` + fileName, `./${version}/Input/` + fileName,
); );
const writer = fs.createWriteStream(filePath); const writer = fs.createWriteStream(filePath);
...@@ -147,7 +161,7 @@ export default { ...@@ -147,7 +161,7 @@ export default {
files = files.map((el) => ({ url: `${fileEnv}${el}` })); files = files.map((el) => ({ url: `${fileEnv}${el}` }));
const downloadFunc = const downloadFunc =
params.device === 1 ? downloadImage : downloadOtherImage; params.device === 2 ? downloadOtherImage : downloadImage;
const result = await downloadFunc(files); const result = await downloadFunc(files);
res.setHeader("Request-URL", url); res.setHeader("Request-URL", url);
...@@ -257,13 +271,17 @@ export default { ...@@ -257,13 +271,17 @@ export default {
downloadByDesignId: async (req, res) => { downloadByDesignId: async (req, res) => {
let q = req.body; let q = req.body;
try { try {
const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
let dir = path.join(os.homedir(), "/Desktop/" + q.productionNo + ".zip"); let dir = path.join(os.homedir(), "/Desktop/" + q.productionNo + ".zip");
const zipStream = new compressing.zip.Stream(); const zipStream = new compressing.zip.Stream();
for (let k in q.imgList) { for (let k in q.imgList) {
const p = path.join( const p = path.join(
process.cwd(), process.cwd(),
`./${getCurrentVersion()}/Input/` + q.imgList[k].fileName, `./${version}/Input/` + q.imgList[k].fileName,
); );
zipStream.addEntry(p); zipStream.addEntry(p);
} }
...@@ -288,7 +306,11 @@ export default { ...@@ -288,7 +306,11 @@ export default {
}, },
uploadImage: async (req, res) => { uploadImage: async (req, res) => {
try { try {
const p = path.join(process.cwd(), `./${getCurrentVersion()}/Input/`); const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
const p = path.join(process.cwd(), `./${version}/Input/`);
let fileName = uuid.v4() + ".png"; let fileName = uuid.v4() + ".png";
// console.log(fileName); // console.log(fileName);
...@@ -303,10 +325,7 @@ export default { ...@@ -303,10 +325,7 @@ export default {
code: 200, code: 200,
data: { data: {
fileName, fileName,
url: path.join( url: path.join(process.cwd(), `./${version}/Input/` + fileName),
process.cwd(),
`./${getCurrentVersion()}/Input/` + fileName,
),
}, },
}); });
} }
...@@ -318,9 +337,13 @@ export default { ...@@ -318,9 +337,13 @@ export default {
}, },
getPngImg: async (req, res) => { getPngImg: async (req, res) => {
try { try {
const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
const filePath = path.join( const filePath = path.join(
process.cwd(), process.cwd(),
`./${getCurrentVersion()}/Input/${req.body.fileName}`, `./${version}/Input/${req.body.fileName}`,
); );
console.log(filePath); console.log(filePath);
// 给客户端返回一个文件流 type类型 // 给客户端返回一个文件流 type类型
...@@ -449,7 +472,11 @@ export default { ...@@ -449,7 +472,11 @@ export default {
}, },
//删除图片 //删除图片
cleanDirectorySync: async (req, res) => { cleanDirectorySync: async (req, res) => {
let dirPath = path.join(process.cwd(), `./${getCurrentVersion()}/Input`); const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
let dirPath = path.join(process.cwd(), `./${version}/Input`);
if (!fs.existsSync(dirPath)) { if (!fs.existsSync(dirPath)) {
console.log(`目录不存在: ${dirPath}`); console.log(`目录不存在: ${dirPath}`);
res.json({ code: 500, msg: `目录不存在: ${dirPath}` }); res.json({ code: 500, msg: `目录不存在: ${dirPath}` });
...@@ -481,7 +508,11 @@ export default { ...@@ -481,7 +508,11 @@ export default {
}, },
saveToPng: async (req, res) => { saveToPng: async (req, res) => {
try { try {
const p = path.join(process.cwd(), `./${getCurrentVersion()}/Input/`); const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
const p = path.join(process.cwd(), `./${version}/Input/`);
const form = new multiparty.Form({ uploadDir: p }); const form = new multiparty.Form({ uploadDir: p });
form.parse(req, function(err, fields, files) { form.parse(req, function(err, fields, files) {
// console.log(367, fields, files, err); // console.log(367, fields, files, err);
...@@ -494,10 +525,7 @@ export default { ...@@ -494,10 +525,7 @@ export default {
fs.renameSync(file.path, path.join(p, fileName)); fs.renameSync(file.path, path.join(p, fileName));
list.push({ list.push({
fileName, fileName,
url: path.join( url: path.join(process.cwd(), `./${version}/Input/` + fileName),
process.cwd(),
`./${getCurrentVersion()}/Input/` + fileName,
),
}); });
}); });
res.json({ res.json({
......
import { exec } from "child_process"; import { exec } from "child_process";
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var request = require("request"); var request = require("request");
var uuid = require("uuid"); var uuid = require("uuid");
const compressing = require("compressing"); const compressing = require("compressing");
const { PassThrough } = require("stream"); const { PassThrough } = require("stream");
const { getVersion, getLocation } = require("@/server/utils/store"); const {
getVersion,
getDesktopDevice,
} = require("@/server/utils/store");
//获取当前驱动版本
function getCurrentVersion() { function getCurrentVersion() {
const version = getVersion(); const version = getVersion();
// console.log("version", version); return version;
}
//获取当前设备类型
function getCurrentDesktopDevice() {
const version = getDesktopDevice();
return version; return version;
} }
...@@ -53,91 +62,14 @@ function zip(from, to) { ...@@ -53,91 +62,14 @@ function zip(from, to) {
}); });
} }
// // 下载素材
// export const downloadImage = (list) => {
// return new Promise((resolve, reject) => {
// try {
// // console.log("Formatted Folder Name:", folderName); // 检查替换结果
// let dirPath = path.join(process.cwd(), `./${getCurrentVersion()}/Input/`);
// console.log(62, dirPath);
// console.log("list", list);
// if (!fs.existsSync(dirPath)) {
// fs.mkdirSync(dirPath);
// }
// let count = 0;
// for (let i = 0; i < list.length; i++) {
// if (list[i].url && list[i].url.includes("http")) {
// let fileName = "";
// let type = 2;
// let flag =
// [
// ".zip",
// ".gzip",
// ".tar",
// ".taz",
// ".rar",
// ".7z",
// ".gz",
// ".bz2",
// ].filter((el) => list[i].url.toLowerCase().includes(el)).length > 0;
// if (flag) {
// fileName = list[i].url.split("/")[
// list[i].url.split("/").length - 1
// ];
// type = 1;
// } else {
// fileName = uuid.v4() + ".png";
// type = 2;
// }
// let p = path.join(
// process.cwd(),
// `./${getCurrentVersion()}/Input/` + fileName
// );
// let stream = fs.createWriteStream(p);
// request(list[i].url)
// .pipe(stream)
// .on("close", async function() {
// if (type === 1) {
// list[i].list = await zip(p, dirPath);
// if (count === list.length - 1) {
// resolve(list);
// }
// } else {
// if (!list[i].list) list[i].list = [];
// const filename = list[i].url.split("/")[
// list[i].url.split("/").length - 1
// ];
// console.log(filename);
// list[i].list.push({
// fileName,
// productionFile: p,
// designId: filename.split("_GCPS")[0],
// });
// }
// if (count === list.length - 1) {
// // console.log(list);
// resolve(list);
// }
// count++;
// });
// }
// }
// } catch (err) {
// console.log(err);
// reject(err);
// }
// });
// };
export const downloadImage = (list) => { export const downloadImage = (list) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const dirPath = path.join( const desktopDevice = getCurrentDesktopDevice();
process.cwd(), const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
`./${getCurrentVersion()}/Input/`, console.log("version", version);
);
const dirPath = path.join(process.cwd(), `./${version}/Input/`);
// 创建目录(如果不存在) // 创建目录(如果不存在)
if (!fs.existsSync(dirPath)) { if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true }); fs.mkdirSync(dirPath, { recursive: true });
...@@ -156,8 +88,6 @@ export const downloadImage = (list) => { ...@@ -156,8 +88,6 @@ export const downloadImage = (list) => {
// 并行处理所有下载 // 并行处理所有下载
const downloadPromises = downloadItems.map((item) => { const downloadPromises = downloadItems.map((item) => {
return new Promise(async (itemResolve) => { return new Promise(async (itemResolve) => {
const downloadPath = getLocation();
let downloadwriteStream = null;
// 创建分流 // 创建分流
const passThrough = new PassThrough(); const passThrough = new PassThrough();
try { try {
...@@ -185,10 +115,6 @@ export const downloadImage = (list) => { ...@@ -185,10 +115,6 @@ export const downloadImage = (list) => {
const writeStream = fs.createWriteStream(filePath); const writeStream = fs.createWriteStream(filePath);
const requestStream = request(item.url); const requestStream = request(item.url);
if (downloadPath) {
const downloadFile = path.join(downloadPath, fileName);
downloadwriteStream = fs.createWriteStream(downloadFile);
}
// 添加超时处理 // 添加超时处理
requestStream.on("response", (response) => { requestStream.on("response", (response) => {
...@@ -202,7 +128,6 @@ export const downloadImage = (list) => { ...@@ -202,7 +128,6 @@ export const downloadImage = (list) => {
// 使用管道连接请求流和写入流 // 使用管道连接请求流和写入流
requestStream.pipe(passThrough); requestStream.pipe(passThrough);
passThrough.pipe(writeStream); passThrough.pipe(writeStream);
downloadwriteStream && passThrough.pipe(downloadwriteStream);
// 等待下载完成 // 等待下载完成
await new Promise((resolveStream) => { await new Promise((resolveStream) => {
...@@ -211,13 +136,6 @@ export const downloadImage = (list) => { ...@@ -211,13 +136,6 @@ export const downloadImage = (list) => {
console.error(`下载失败: ${item.url}`, err); console.error(`下载失败: ${item.url}`, err);
resolveStream(); resolveStream();
}); });
if (downloadwriteStream) {
downloadwriteStream.on("finish", resolveStream);
downloadwriteStream.on("error", (err) => {
console.error(`下载失败: ${item.url}`, err);
resolveStream();
});
}
}); });
if (isArchive) { if (isArchive) {
...@@ -254,6 +172,9 @@ export const downloadImage = (list) => { ...@@ -254,6 +172,9 @@ export const downloadImage = (list) => {
export function downloadOtherImage(list) { export function downloadOtherImage(list) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
const currentDate = new Date(); const currentDate = new Date();
// 将 UTC 时间转换为中国时间 (UTC + 8小时) // 将 UTC 时间转换为中国时间 (UTC + 8小时)
...@@ -274,7 +195,7 @@ export function downloadOtherImage(list) { ...@@ -274,7 +195,7 @@ export function downloadOtherImage(list) {
.split(".")[0]; .split(".")[0];
let otherTypePath = path.join( let otherTypePath = path.join(
process.cwd(), process.cwd(),
`./${getCurrentVersion()}/Input/${folderName}`, `./${version}/Input/${folderName}`,
); );
if (!fs.existsSync(otherTypePath)) { if (!fs.existsSync(otherTypePath)) {
fs.mkdirSync(otherTypePath); fs.mkdirSync(otherTypePath);
...@@ -343,10 +264,10 @@ export function downloadOtherImage(list) { ...@@ -343,10 +264,10 @@ export function downloadOtherImage(list) {
// 传递素材给前端 // 传递素材给前端
export const sendImg = (filename = "sample.png") => { export const sendImg = (filename = "sample.png") => {
let filePath = path.join( const desktopDevice = getCurrentDesktopDevice();
process.cwd(), const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
`./${getCurrentVersion()}/Input/` + filename, console.log("version", version);
); let filePath = path.join(process.cwd(), `./${version}/Input/` + filename);
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
return false; return false;
} }
...@@ -356,12 +277,14 @@ export const sendImg = (filename = "sample.png") => { ...@@ -356,12 +277,14 @@ export const sendImg = (filename = "sample.png") => {
}; };
export const toSend = (body) => { export const toSend = (body) => {
console.log("999999999", path.join(process.cwd(), getCurrentVersion())); const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec( exec(
body.cmd, body.cmd,
{ cwd: path.join(process.cwd(), getCurrentVersion()), shell: true }, { cwd: path.join(process.cwd(), version), shell: true },
(err) => { (err) => {
// console.log(stdout, 1); // console.log(stdout, 1);
// console.log(stderr, 2); // console.log(stderr, 2);
...@@ -370,7 +293,7 @@ export const toSend = (body) => { ...@@ -370,7 +293,7 @@ export const toSend = (body) => {
if (!err) { if (!err) {
exec( exec(
body.print_cmd, body.print_cmd,
{ cwd: path.join(process.cwd(), getCurrentVersion()), shell: true }, { cwd: path.join(process.cwd(), version), shell: true },
(err2) => { (err2) => {
console.log(err2); console.log(err2);
if (!err2) { if (!err2) {
...@@ -379,7 +302,7 @@ export const toSend = (body) => { ...@@ -379,7 +302,7 @@ export const toSend = (body) => {
fs.unlinkSync( fs.unlinkSync(
path.join( path.join(
process.cwd(), process.cwd(),
`${getCurrentVersion()}/Profile/` + `${version}/Profile/` +
body.fileName.replace(".png", "") + body.fileName.replace(".png", "") +
".xml", ".xml",
), ),
...@@ -387,7 +310,7 @@ export const toSend = (body) => { ...@@ -387,7 +310,7 @@ export const toSend = (body) => {
fs.unlinkSync( fs.unlinkSync(
path.join( path.join(
process.cwd(), process.cwd(),
`${getCurrentVersion()}/Output/` + `${version}/Output/` +
body.fileName.replace(".png", "") + body.fileName.replace(".png", "") +
".arxp", ".arxp",
), ),
...@@ -417,12 +340,11 @@ export const toSend = (body) => { ...@@ -417,12 +340,11 @@ export const toSend = (body) => {
export const writeProfileXml = (b) => { export const writeProfileXml = (b) => {
// console.log(b); // console.log(b);
const desktopDevice = getCurrentDesktopDevice();
const version = desktopDevice == 3 ? "huiLiCaiImg" : getCurrentVersion();
console.log("version", version);
try { try {
let p = path.join( let p = path.join(process.cwd(), `./${version}/Profile/${b.byInk}.xml`);
process.cwd(),
`./${getCurrentVersion()}/Profile/${b.byInk}.xml`,
);
let file = fs.readFileSync(p, { encoding: "utf8" }); let file = fs.readFileSync(p, { encoding: "utf8" });
file = file.replace( file = file.replace(
/<uiCopies>(.*)<\/uiCopies>/i, /<uiCopies>(.*)<\/uiCopies>/i,
...@@ -520,10 +442,7 @@ export const writeProfileXml = (b) => { ...@@ -520,10 +442,7 @@ export const writeProfileXml = (b) => {
fs.writeFileSync( fs.writeFileSync(
path.join( path.join(
process.cwd(), process.cwd(),
`./${getCurrentVersion()}/Profile/${b.fileName.replace( `./${version}/Profile/${b.fileName.replace(".png", "")}.xml`,
".png",
"",
)}.xml`,
), ),
file, file,
); );
...@@ -531,3 +450,84 @@ export const writeProfileXml = (b) => { ...@@ -531,3 +450,84 @@ export const writeProfileXml = (b) => {
console.log(404, err); console.log(404, err);
} }
}; };
/**
* 复制单个图片文件到目标文件夹(已知图片完整路径)
* @param {string} sourceImagePath - 源图片的完整绝对路径
* @param {string} targetDir - 目标文件夹路径(只传文件夹,不用传文件名)
* @returns {Promise<void>}
*/
const fsPromises = fs.promises; // 明确获取 promises 异步 API
export async function copySingleImage(sourceImagePath, targetDir) {
// 先打印传入的原始路径(方便验证是否和预期一致)
// console.log(`传入参数验证:
// 源图片路径:${sourceImagePath}
// 目标文件夹路径:${targetDir}`);
try {
// 步骤1:路径规范化(修正潜在的分隔符/隐形字符问题)
const normalizedSourcePath = path.resolve(sourceImagePath);
const normalizedTargetDir = path.resolve(targetDir);
// console.log(`路径规范化后:
// 源图片路径:${normalizedSourcePath}
// 目标文件夹路径:${normalizedTargetDir}`);
// 步骤2:校验源文件是否为有效图片文件
let fileStat;
try {
fileStat = await fsPromises.stat(normalizedSourcePath);
} catch (err) {
throw new Error(
`获取源文件状态失败:${err.message}(错误码:${err.code})`,
);
}
// 2.1 校验是否为文件(非文件夹)
if (!fileStat.isFile()) {
throw new Error(`源路径不是有效文件,是文件夹:${normalizedSourcePath}`);
}
// console.log("校验通过:源路径是有效文件");
// 2.2 校验是否为图片格式(可选,过滤非图片文件)
const validImageExts = [".jpg", ".jpeg", ".png", ".gif", ".bmp"];
const fileExt = path.extname(normalizedSourcePath).toLowerCase();
if (!validImageExts.includes(fileExt)) {
throw new Error(
`源文件不是有效图片格式,后缀为:${fileExt}(支持格式:${validImageExts.join(
", ",
)})`,
);
}
// console.log(`校验通过:源文件是图片格式(${fileExt})`);
// 步骤3:获取文件名 + 拼接目标图片完整路径
const imageFileName = path.basename(normalizedSourcePath);
const targetImagePath = path.join(normalizedTargetDir, imageFileName);
// console.log(`拼接目标文件路径:${targetImagePath}`);
// 步骤4:创建目标文件夹(递归创建,已存在则不报错)
try {
await fsPromises.mkdir(normalizedTargetDir, { recursive: true });
// console.log(`目标文件夹创建成功(已存在则跳过):${normalizedTargetDir}`);
} catch (err) {
throw new Error(
`创建目标文件夹失败:${err.message}(错误码:${err.code})`,
);
}
// 步骤5:复制图片文件(核心操作)
try {
await fsPromises.copyFile(normalizedSourcePath, targetImagePath);
console.log(`✅ 图片复制成功!`);
} catch (err) {
throw new Error(
`复制文件操作失败:${err.message}(错误码:${err.code})`,
);
}
} catch (err) {
console.error("❌ 单个图片复制失败:", err.message);
throw err;
}
}
...@@ -2,6 +2,30 @@ const Store = require("electron-store"); ...@@ -2,6 +2,30 @@ const Store = require("electron-store");
const store = new Store({ watch: true }); const store = new Store({ watch: true });
// 导出 store 实例(新增:方便外部获取实例进行监听) // 导出 store 实例(新增:方便外部获取实例进行监听)
// ===== 新增:私有缓存 Map + 缓存刷新方法 =====
let orderCacheMap = new Map(); // 模块内私有缓存,避免重复转换
const DEFAULT_UNIQUE_KEY = "newId";
// 刷新缓存:从 electron-store 读取数组,转为 Map 存入缓存
function refreshOrderCache(uniqueKey = DEFAULT_UNIQUE_KEY) {
const currentArray = store.get("orderInfo") || [];
const newMap = new Map();
currentArray.forEach((item) => {
if (item && item[uniqueKey]) {
newMap.set(item[uniqueKey], item);
}
});
orderCacheMap = newMap; // 更新缓存 Map
}
// 初始化缓存(模块加载时执行一次)
refreshOrderCache();
// 辅助工具函数:将 Map 转回对象数组
function mapToArray(dataMap) {
return Array.from(dataMap.values());
}
module.exports = { module.exports = {
//存储当前打印驱动版本 //存储当前打印驱动版本
setVersion: (version) => { setVersion: (version) => {
...@@ -38,13 +62,109 @@ module.exports = { ...@@ -38,13 +62,109 @@ module.exports = {
}, },
getBoard: () => store.get("desktoBoard") || 3, getBoard: () => store.get("desktoBoard") || 3,
//下载位置 //下载位置
setLocation: (version) => { setLocation: (version, locationKey) => {
store.set("downloadLocation", version); store.set(locationKey, version);
}, },
getLocation: () => store.get("downloadLocation") || "", getLocation: (locationKey) => store.get(locationKey) || "",
//设备 //设备
setDesktopDevice: (version) => { setDesktopDevice: (version) => {
store.set("desktopDevice", version); store.set("desktopDevice", version);
}, },
getDesktopDevice: () => store.get("desktopDevice") || "1", getDesktopDevice: () => store.get("desktopDevice") || "1",
// ===== 基于缓存 Map 优化的 orderInfo 方法 =====
getOrderInfo: () => store.get("orderInfo") || [],
setOrderInfo: (newData, uniqueKey = DEFAULT_UNIQUE_KEY) => {
let newObjArray = [];
if (newData instanceof Map) {
newObjArray = mapToArray(newData);
} else if (Array.isArray(newData)) {
const isValidObjArray = newData.every(
(item) => typeof item === "object" && item !== null,
);
if (!isValidObjArray) {
console.warn("setOrderInfo 要求数组内所有元素都是对象类型");
return;
}
newObjArray = newData;
} else {
console.warn("setOrderInfo 要求传入数组或 Map 类型,当前传入值无效");
return;
}
store.set("orderInfo", newObjArray);
// 新增:更新缓存 Map(无需重新从 store 读取,直接转换新数组)
const newMap = new Map();
newObjArray.forEach((item) => {
if (item && item[uniqueKey]) {
newMap.set(item[uniqueKey], item);
}
});
orderCacheMap = newMap;
},
addToOrderInfo: (newOrderObj, uniqueKey = DEFAULT_UNIQUE_KEY) => {
if (
typeof newOrderObj !== "object" ||
newOrderObj === null ||
!newOrderObj[uniqueKey]
) {
console.warn("添加失败:请传入包含唯一标识(默认id)的有效对象");
return;
}
const uniqueValue = newOrderObj[uniqueKey];
// 直接操作缓存 Map(O(1),无需重新转换)
if (orderCacheMap.has(uniqueValue)) {
console.log(`该对象(${uniqueKey}=${uniqueValue})已存在,不重复添加`);
return;
}
orderCacheMap.set(uniqueValue, newOrderObj);
// 写入 store 时,仅转换缓存 Map(一次 O(n),而非每次操作都 O(n))
const newArray = mapToArray(orderCacheMap);
store.set("orderInfo", newArray);
},
removeFromOrderInfo: (uniqueValue, uniqueKey = DEFAULT_UNIQUE_KEY) => {
// 直接操作缓存 Map(O(1))
if (!orderCacheMap.has(uniqueValue)) {
console.log(`未找到 ${uniqueKey}=${uniqueValue} 的对象,删除失败`);
return;
}
orderCacheMap.delete(uniqueValue);
const newArray = mapToArray(orderCacheMap);
store.set("orderInfo", newArray);
},
// 其他方法(updateOrderInfoItem、getOrderInfoItem)同理,均直接操作 orderCacheMap
updateOrderInfoItem: (
uniqueValue,
newOrderObj,
uniqueKey = DEFAULT_UNIQUE_KEY,
) => {
if (typeof newOrderObj !== "object" || newOrderObj === null) {
console.warn("修改失败:请传入有效对象");
return;
}
// 直接操作缓存 Map(O(1) 查找)
const targetObj = orderCacheMap.get(uniqueValue);
if (!targetObj) {
console.log(`未找到 ${uniqueKey}=${uniqueValue} 的对象,修改失败`);
return;
}
const updatedObj = { ...targetObj, ...newOrderObj };
orderCacheMap.set(uniqueValue, updatedObj);
const newArray = mapToArray(orderCacheMap);
store.set("orderInfo", newArray);
},
getOrderInfoItem: (uniqueValue) => {
// 直接操作缓存 Map(O(1) 查找,无需任何转换)
const targetObj = orderCacheMap.get(uniqueValue);
return targetObj || null;
},
}; };
<script> <script>
import bus from "@/bus"; import bus from "@/bus";
// import PrintDialog from "./printDialog.vue"; // import PrintDialog from "./printDialog.vue";
import { getProductCnByFactorySubOrderNumberApi } from "../../../api/index.js"; // import { getProductCnByFactorySubOrderNumberApi } from "../../../api/index.js";
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
// import { grid } from "../data"; // import { grid } from "../data";
import pkg from "../../../../package.json"; import pkg from "../../../../package.json";
...@@ -16,10 +16,13 @@ const { ...@@ -16,10 +16,13 @@ const {
getVersion, getVersion,
getHostApi, getHostApi,
setApi, setApi,
getLocation,
setLocation,
setDesktopDevice, setDesktopDevice,
getDesktopDevice, getDesktopDevice,
getOrderInfo,
getOrderInfoItem,
addToOrderInfo,
updateOrderInfoItem,
removeFromOrderInfo,
} = require("@/server/utils/store"); } = require("@/server/utils/store");
export default { export default {
...@@ -74,11 +77,10 @@ export default { ...@@ -74,11 +77,10 @@ export default {
autoPrint: false, autoPrint: false,
gridSpacing: 1, gridSpacing: 1,
}, },
imgList: [],
detail: null, detail: null,
config: getHostApi(), config: getHostApi(),
newApiApiHost: "", newApiApiHost: "",
downloadLocation: getLocation(),
selectBgColor: "#ececec", selectBgColor: "#ececec",
predefineColors: [ predefineColors: [
"#ff4500", "#ff4500",
...@@ -103,7 +105,13 @@ export default { ...@@ -103,7 +105,13 @@ export default {
return this.$store.getters.getActionList; return this.$store.getters.getActionList;
}, },
...mapState(["defaultProportion", "countryList", "orderType", "grid"]), ...mapState([
"defaultProportion",
"countryList",
"orderType",
"grid",
"imgList",
]),
}, },
mounted() { mounted() {
// console.log(pkg, "pkg"); // console.log(pkg, "pkg");
...@@ -112,6 +120,7 @@ export default { ...@@ -112,6 +120,7 @@ export default {
this.selectGridIndex = 0; this.selectGridIndex = 0;
this.setting.gridValue = 0; this.setting.gridValue = 0;
}); });
this.$store.commit("changeDesktopDevice", getDesktopDevice());
}, },
created() { created() {
localStorage.setItem("desktoVersion", "print"); localStorage.setItem("desktoVersion", "print");
...@@ -139,6 +148,9 @@ export default { ...@@ -139,6 +148,9 @@ export default {
immediate: true, immediate: true,
deep: true, deep: true,
}, },
desktopDevice(val) {
this.checked = false;
},
}, },
methods: { methods: {
checkUpdate() { checkUpdate() {
...@@ -183,9 +195,18 @@ export default { ...@@ -183,9 +195,18 @@ export default {
} else if (this.orderType === "US") { } else if (this.orderType === "US") {
params.podJomallOrderUsId = data.podJomallOrderUsId; params.podJomallOrderUsId = data.podJomallOrderUsId;
} }
const canCallApi =
await this.$api.post("/completeDelivery", params).then(() => {}); this.desktoVersion !== 3 ||
(data.saveImgList?.every((el) => el.power) ?? false);
if (canCallApi) {
console.log("生产完成数据", data);
console.log("本地数据:", getOrderInfo());
removeFromOrderInfo(data.newId);
return;
await this.$api.post("/completeDelivery", params);
this.$message.success("操作成功"); this.$message.success("操作成功");
}
}, },
async sureData() { async sureData() {
if (!this.detail || Object.keys(this.detail).length <= 1) { if (!this.detail || Object.keys(this.detail).length <= 1) {
...@@ -306,17 +327,17 @@ export default { ...@@ -306,17 +327,17 @@ export default {
} }
return new File([u8arr], fileName, { type: "image/png" }); return new File([u8arr], fileName, { type: "image/png" });
}, },
async downloadImage() { // async downloadImage() {
if (!this.detail || Object.keys(this.detail).length === 0) // if (!this.detail || Object.keys(this.detail).length === 0)
return this.$message.warning("请扫描生产单号"); // return this.$message.warning("请扫描生产单号");
let params = { // let params = {
productionNo: this.detail.factorySubOrderNumber, // productionNo: this.detail.factorySubOrderNumber,
imgList: this.imgList, // imgList: this.imgList,
}; // };
let res = await this.$api.post("/downloadByDesignId", params); // let res = await this.$api.post("/downloadByDesignId", params);
this.$message.success(res.msg); // this.$message.success(res.msg);
}, // },
async saveImgByUrl(url) { async saveImgByUrl(url) {
try { try {
let res = await this.$api.post("/saveImgByUrl", { url }); let res = await this.$api.post("/saveImgByUrl", { url });
...@@ -325,7 +346,7 @@ export default { ...@@ -325,7 +346,7 @@ export default {
throw new Error(e.message); // 或者直接 throw e; throw new Error(e.message); // 或者直接 throw e;
} }
}, },
async hasDesignImagesCanvasJsonList(designImagesCanvasJsonList) { async hasDesignImagesCanvasJsonList(designImagesCanvasJsonList, bool) {
let imageResList = []; let imageResList = [];
if ( if (
!this.checked && !this.checked &&
...@@ -362,7 +383,7 @@ export default { ...@@ -362,7 +383,7 @@ export default {
// } // }
} }
} }
if (!imageResList.length) { if (!imageResList.length && !bool) {
// console.log(347, this.orderType); // console.log(347, this.orderType);
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示 // 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
...@@ -371,11 +392,17 @@ export default { ...@@ -371,11 +392,17 @@ export default {
device: this.$store.state.desktopDevice, device: this.$store.state.desktopDevice,
orderType: this.orderType, orderType: this.orderType,
}); });
console.log("downloadBySubOrderNumber", res);
if (!res.data.length) return this.$message.warning("未找到素材图!"); if (!res.data.length) return this.$message.warning("未找到素材图!");
res.data.forEach((el) => { res.data.forEach((el) => {
imageResList = imageResList.concat(el.list || []); imageResList = imageResList.concat(el.list || []);
}); });
} else if (bool) {
imageResList = this.detail?.saveImgList || [];
} }
if (this.checked) { if (this.checked) {
imageResList = await this.cutImgFn(imageResList); imageResList = await this.cutImgFn(imageResList);
imageResList.forEach((el) => { imageResList.forEach((el) => {
...@@ -384,7 +411,7 @@ export default { ...@@ -384,7 +411,7 @@ export default {
} }
// 延迟后强制激活窗口 // 延迟后强制激活窗口
if (this.desktopDevice !== 1) { if (this.desktopDevice == 2) {
if (imageResList.length) { if (imageResList.length) {
let pathUrl = imageResList[0].productionFile; let pathUrl = imageResList[0].productionFile;
setTimeout(async () => { setTimeout(async () => {
...@@ -446,11 +473,29 @@ export default { ...@@ -446,11 +473,29 @@ export default {
height: this.detail.mssHeight, height: this.detail.mssHeight,
}; };
} }
if (newImgList.length > 1 && !bool) {
const templateobj = { ...this.detail };
templateobj["saveImgList"] = [...newImgList].map((el) => {
el.power = false;
return { ...el };
});
addToOrderInfo(templateobj);
console.log("本地数据:", getOrderInfo());
}
bus.$emit("busEmit", obj); bus.$emit("busEmit", obj);
} }
}, },
async getDataInfo() { async getDataInfo() {
if (this.detail && this.imgList?.length && this.desktopDevice === 3) {
const item = this.detail?.saveImgList?.find(
(el) => el.fileName == this.imgList[0].fileName,
);
if (item) item.power = true;
updateOrderInfoItem(this.detail.newId, this.detail);
console.log("本地数据:", getOrderInfo());
}
if ( if (
this.detail && this.detail &&
Object.keys(this.detail).length > 0 && Object.keys(this.detail).length > 0 &&
...@@ -495,45 +540,47 @@ export default { ...@@ -495,45 +540,47 @@ export default {
this.$store.commit("setOrderType", str); this.$store.commit("setOrderType", str);
} }
// console.log(423, this.productionNo);
try { try {
// const urlArr = { const arr = await getOrderInfo();
// CN: { const localItem = getOrderInfoItem(this.productionNo);
// field: "factorySubOrderNumber",
// fn: getProductCnByFactorySubOrderNumberApi,
// },
// US: {
// field: "factorySubOrderNumber",
// fn:
// "factory/podJomallOrderProductUs/getProductUsByFactorySubOrderNumber",
// },
// GC: {
// field: "thirdSubOrderNumber",
// fn:
// "factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber",
// },
// };
// //查找生产单号信息
// const findByPodProductionNo = getProductCnByFactorySubOrderNumberApi(
// this.productionNo,
// );
// console.log(494, findByPodProductionNo);
const findByPodProductionNo = await this.$api.post( let findByPodProductionNo;
"/findByPodProductionNo", const apiRequestParams = {
{
thirdSubOrderNumber: this.productionNo, thirdSubOrderNumber: this.productionNo,
orderType: this.orderType, orderType: this.orderType,
}, };
if (this.desktopDevice === 3) {
if (arr.length > 0) {
findByPodProductionNo =
{ data: { ...localItem } } ||
(await this.$api.post(
"/findByPodProductionNo",
apiRequestParams,
));
} else {
findByPodProductionNo = await this.$api.post(
"/findByPodProductionNo",
apiRequestParams,
); );
}
} else {
findByPodProductionNo = await this.$api.post(
"/findByPodProductionNo",
apiRequestParams,
);
}
console.log("findByPodProductionNo", findByPodProductionNo);
this.detail = findByPodProductionNo.data; this.detail = findByPodProductionNo.data;
// console.log(491, this.detail); this.detail["newId"] = this.productionNo;
this.imgList = [];
let designImagesCanvasJsonList = this.detail.drParam; let designImagesCanvasJsonList = this.detail.drParam;
// this.detail.drParam; await this.hasDesignImagesCanvasJsonList(
await this.hasDesignImagesCanvasJsonList(designImagesCanvasJsonList); designImagesCanvasJsonList,
this.desktopDevice === 3 ? (localItem ? true : false) : false,
);
this.$store.commit("setProductDetail", findByPodProductionNo.data); this.$store.commit("setProductDetail", findByPodProductionNo.data);
ipcRenderer.send("win-subScreen", findByPodProductionNo.data); ipcRenderer.send("win-subScreen", findByPodProductionNo.data);
this.$dataStore.set("production_no", this.productionNo); this.$dataStore.set("production_no", this.productionNo);
...@@ -651,6 +698,7 @@ export default { ...@@ -651,6 +698,7 @@ export default {
this.selectedOption = command; // 根据选中的项来更新 selectedOption this.selectedOption = command; // 根据选中的项来更新 selectedOption
}, },
changeDesktopDeviceFn(value) { changeDesktopDeviceFn(value) {
console.log("changeDesktopDeviceFn", value);
setDesktopDevice(value); setDesktopDevice(value);
this.$store.commit("changeDesktopDevice", value); this.$store.commit("changeDesktopDevice", value);
this.$store.commit("changeImgList", []); this.$store.commit("changeImgList", []);
...@@ -766,24 +814,6 @@ export default { ...@@ -766,24 +814,6 @@ export default {
return null; return null;
} }
}, },
changeLocation() {
// setLocation("");
ipcRenderer.send("request-select-folder");
const handleFolderResult = (event, folderPath) => {
// 移除监听(关键:避免多次点击后触发多次回调)
ipcRenderer.removeListener("select-folder-result", handleFolderResult);
// 3. 如果用户未取消选择,赋值给 downloadLocation
if (folderPath) {
this.downloadLocation = folderPath;
// setLocation("");
setLocation(folderPath);
}
};
// 4. 监听主进程返回的结果消息
ipcRenderer.on("select-folder-result", handleFolderResult);
},
}, },
}; };
</script> </script>
...@@ -956,19 +986,6 @@ export default { ...@@ -956,19 +986,6 @@ export default {
>检查更新 >检查更新
</el-button> </el-button>
</el-form-item> </el-form-item>
<div>
<el-form-item label="下载位置">
<div style="display: flex; ">
<el-input
:title="downloadLocation"
v-model="downloadLocation"
:disabled="true"
style="flex: 1;margin-right: 5px;"
></el-input>
<el-button @click="changeLocation">浏览</el-button>
</div>
</el-form-item>
</div>
</el-form> </el-form>
</div> </div>
<el-tooltip slot="reference" content="设置"> <el-tooltip slot="reference" content="设置">
...@@ -1007,14 +1024,11 @@ export default { ...@@ -1007,14 +1024,11 @@ export default {
type="success" type="success"
>生产完成 >生产完成
</el-button> </el-button>
<!-- <div class="check">
<el-checkbox v-model="isAutoFinish">自动完成上一单</el-checkbox>
</div> -->
</div> </div>
<div style="margin-left: 10px;"> <div style="margin-left: 10px;">
<el-checkbox v-model="isAutoFinish">自动完成上一单</el-checkbox> <el-checkbox v-model="isAutoFinish">自动完成上一单</el-checkbox>
</div> </div>
<div style="margin-left: 10px;"> <div style="margin-left: 10px;" v-show="desktopDevice != 3">
<el-checkbox v-model="checked">自动裁切</el-checkbox> <el-checkbox v-model="checked">自动裁切</el-checkbox>
</div> </div>
<!-- <el-button <!-- <el-button
......
...@@ -34,6 +34,10 @@ export default { ...@@ -34,6 +34,10 @@ export default {
type: Object, type: Object,
default: () => {}, default: () => {},
}, },
newDesktopDevice: {
type: [String, Number],
default: "1",
},
}, },
watch: { watch: {
visible: { visible: {
...@@ -48,6 +52,20 @@ export default { ...@@ -48,6 +52,20 @@ export default {
if (this.item) { if (this.item) {
this.getCurrentItem(this.item); this.getCurrentItem(this.item);
} else {
this.form = {
x: 0,
rate: 0,
sx: 0,
zIndex: 0,
sh: 0,
sw: 0,
sy: 0,
y: 0,
w: 0,
h: 0,
r: 0,
};
} }
}, },
immediate: true, immediate: true,
...@@ -58,7 +76,7 @@ export default { ...@@ -58,7 +76,7 @@ export default {
pxToUnit, pxToUnit,
unitToPx, unitToPx,
getCurrentItem(item) { getCurrentItem(item) {
let setting = this.$dataStore.get("setting"); // let setting = this.$dataStore.get("setting");
this.item.y = item.y - item.h / 2; this.item.y = item.y - item.h / 2;
this.item.x = item.x - item.w / 2; this.item.x = item.x - item.w / 2;
this.$dataStore.set( this.$dataStore.set(
...@@ -152,7 +170,7 @@ export default { ...@@ -152,7 +170,7 @@ export default {
<template> <template>
<div class="drawer"> <div class="drawer">
<div class="img-form"> <div class="img-form" v-show="newDesktopDevice != 3">
<div class="title"> <div class="title">
图片编辑(单位:{{ $dataStore.get("setting").unit }} 图片编辑(单位:{{ $dataStore.get("setting").unit }}
</div> </div>
...@@ -161,6 +179,7 @@ export default { ...@@ -161,6 +179,7 @@ export default {
:disabled="!(item && !isPreView)" :disabled="!(item && !isPreView)"
style="" style=""
:model="form" :model="form"
ref="formRef"
label-position="left" label-position="left"
label-width="30px" label-width="30px"
> >
...@@ -306,6 +325,7 @@ export default { ...@@ -306,6 +325,7 @@ export default {
.img-form { .img-form {
padding: 5px 10px; padding: 5px 10px;
border: 1px solid #ececec; border: 1px solid #ececec;
border-bottom: none;
} }
::v-deep { ::v-deep {
......
<script> <script>
import VueDragResizeRotate from "@minogin/vue-drag-resize-rotate"; import VueDragResizeRotate from "@minogin/vue-drag-resize-rotate";
// import PicScrollbarBox from "../../../components/PicScrollbarBox.vue";
const { ipcRenderer } = require("electron"); const { ipcRenderer } = require("electron");
// import { fabric } from "fabric";
import ImgSetting from "./imgSetting.vue"; import ImgSetting from "./imgSetting.vue";
import bus from "@/bus"; import bus from "@/bus";
import PrintDialog from "@/views/design/head/printDialog.vue"; import PrintDialog from "@/views/design/head/printDialog.vue";
...@@ -13,12 +9,16 @@ import { mmToPx, extractValue } from "@/utils"; ...@@ -13,12 +9,16 @@ import { mmToPx, extractValue } from "@/utils";
const path = require("path"); const path = require("path");
const fs = require("fs"); const fs = require("fs");
const uuid = require("uuid"); const uuid = require("uuid");
// import { startLoading, endLoading } from "@/utils/axios.js"; import { copySingleImage } from "@/server/utils/index.js";
import { mapState } from "vuex"; import { mapState } from "vuex";
const img = require("../../../assets/bg_tshirt_shadow.png"); const img = require("../../../assets/bg_tshirt_shadow.png");
const { getDesktopDevice } = require("@/server/utils/store"); const {
getDesktopDevice,
setLocation,
getLocation,
} = require("@/server/utils/store");
export default { export default {
components: { components: {
...@@ -121,11 +121,15 @@ export default { ...@@ -121,11 +121,15 @@ export default {
}, },
returnItem() { returnItem() {
// console.log(128, this.imgList);
if (this.selectIndex < 0 && this.imgList.length) { if (this.selectIndex < 0 && this.imgList.length) {
// this.showImgSetting = false; // this.showImgSetting = false;
this.selectIndex = 0; this.selectIndex = 0;
} }
let item = this.imgList[this.selectIndex]; let item = this.imgList[this.selectIndex];
// console.log("item", item);
if (item) { if (item) {
item = JSON.parse(JSON.stringify(item)); item = JSON.parse(JSON.stringify(item));
item.x = Number(item.x) - Number(item.w); item.x = Number(item.x) - Number(item.w);
...@@ -203,11 +207,13 @@ export default { ...@@ -203,11 +207,13 @@ export default {
topPosition: "52%", topPosition: "52%",
currentImgData: null, currentImgData: null,
newDesktopDevice: getDesktopDevice(), newDesktopDevice: getDesktopDevice(),
downloadLocation1: getLocation("downloadLocation1"),
downloadLocation2: getLocation("downloadLocation2"),
}; };
}, },
watch: { watch: {
imgList: { imgList: {
handler(newValue) { async handler(newValue) {
const image = document.getElementById("imgBox"); const image = document.getElementById("imgBox");
if (newValue.length && image) { if (newValue.length && image) {
...@@ -217,6 +223,23 @@ export default { ...@@ -217,6 +223,23 @@ export default {
let bh = bw.clientHeight; let bh = bw.clientHeight;
bw = bw.clientWidth; bw = bw.clientWidth;
this.$nextTick(() => {
let dom = document.getElementsByClassName("drr");
console.log(228, dom);
this.imgList.forEach((el, i) => {
let dom_i = document.getElementsByClassName("drr")[i];
dom_i.style.zIndex =
dom_i.style.zIndex === "" || !dom_i.style.zIndex
? 0
: dom_i.style.zIndex;
dom[i].addEventListener("click", () => {
this.selectIndex = i;
this.selectItem(i);
});
});
});
const output = [ const output = [
`-------------------------------------------------`, `-------------------------------------------------`,
`生产单号:${this.detail.factorySubOrderNumber}`, `生产单号:${this.detail.factorySubOrderNumber}`,
...@@ -231,41 +254,38 @@ export default { ...@@ -231,41 +254,38 @@ export default {
)}mm,高度--${Number((h * 0.84183).toFixed(1))}mm`, )}mm,高度--${Number((h * 0.84183).toFixed(1))}mm`,
`-------------------------------------------------`, `-------------------------------------------------`,
]; ];
// if (this.downloadLocation1) {
// }
// console.log(240, newValue);
// if (this.downloadLocation1 && this.newDesktopDevice == 3) {
// try {
// copySingleImage(newValue[0].url, this.downloadLocation1);
// copySingleImage(newValue[0].url, this.downloadLocation2);
// this.$message.success("图片已发送目标文件夹下");
// } catch (error) {
// this.$message.error("发送失败");
// console.log(error);
// }
// }
console.log(output.join("\n")); // console.log(output.join("\n"));
console.log(`后端返回图片大小:\n`, this.currentImgData); // console.log(`后端返回图片大小:\n`, this.currentImgData);
console.log(`当前网格大小:\n`, this.gridSpacing); // console.log(`当前网格大小:\n`, this.gridSpacing);
console.log( // console.log(
`当前整体数据:\n`, // `当前整体数据:\n`,
newValue[0], // newValue[0],
`\n`, // `\n`,
`rate由后端返回图片高度除以宽度得出\n`, // `rate由后端返回图片高度除以宽度得出\n`,
`如果高度大于宽度则 height_px = 压板高度 * (7.5 / 10)\n`, // `如果高度大于宽度则 height_px = 压板高度 * (7.5 / 10)\n`,
`如果宽度度大于高度则 width_px = 压板宽度 * (2 / 3)\n`, // `如果宽度度大于高度则 width_px = 压板宽度 * (2 / 3)\n`,
`剩下的高度或宽度则由(height_px或者width_px)/rate\n`, // `剩下的高度或宽度则由(height_px或者width_px)/rate\n`,
); // );
console.log( // console.log(
`获取当前图片在压板中的大小公式:\n 宽度:${image?.clientWidth}(image.clientWidth)px /${this.WHproportion}(扩大比例)=${w}\n 高度:${image?.clientHeight}(image.clientHeight)px /${this.WHproportion}(扩大比例)=${h}`, // `获取当前图片在压板中的大小公式:\n 宽度:${image?.clientWidth}(image.clientWidth)px /${this.WHproportion}(扩大比例)=${w}\n 高度:${image?.clientHeight}(image.clientHeight)px /${this.WHproportion}(扩大比例)=${h}`,
); // );
} }
if (this.imgList.length > 0) {
this.$nextTick(() => {
let dom = document.getElementsByClassName("drr");
this.imgList.forEach((el, i) => {
let dom_i = document.getElementsByClassName("drr")[i];
dom_i.style.zIndex =
dom_i.style.zIndex === "" || !dom_i.style.zIndex
? 0
: dom_i.style.zIndex;
dom[i].addEventListener("click", () => {
this.selectIndex = i;
this.selectItem(i);
});
});
});
}
this.$store.commit("changeImgList", this.imgList); this.$store.commit("changeImgList", this.imgList);
}, },
deep: true, deep: true,
...@@ -282,12 +302,12 @@ export default { ...@@ -282,12 +302,12 @@ export default {
}, },
desktopDevice(newValue) { desktopDevice(newValue) {
this.newDesktopDevice = getDesktopDevice(); this.newDesktopDevice = getDesktopDevice();
if (newValue == 2) { this.detail = {};
this.imgList = []; this.imgList = [];
this.selectImgList = []; this.selectImgList = [];
this.selectIndex = -1; this.selectIndex = -1;
this.selectImgIndex = 0; this.selectImgIndex = 0;
}
}, },
desktoVersion(newValue) { desktoVersion(newValue) {
if (newValue) { if (newValue) {
...@@ -672,6 +692,8 @@ export default { ...@@ -672,6 +692,8 @@ export default {
this.imgHistoryList.push(JSON.parse(JSON.stringify(this.imgList))); this.imgHistoryList.push(JSON.parse(JSON.stringify(this.imgList)));
}, },
outsideClick(e) { outsideClick(e) {
if (this.newDesktopDevice == 3) return;
if ( if (
!( !(
e.target.className.includes("drr") || e.target.className.includes("drr") ||
...@@ -1183,6 +1205,17 @@ export default { ...@@ -1183,6 +1205,17 @@ export default {
} }
}); });
}, },
changeLocation(v) {
ipcRenderer.send("request-select-folder");
const handleFolderResult = (event, folderPath) => {
ipcRenderer.removeListener("select-folder-result", handleFolderResult);
if (folderPath) {
this[v] = folderPath;
setLocation(folderPath, v);
}
};
ipcRenderer.on("select-folder-result", handleFolderResult);
},
}, },
mounted() { mounted() {
this.imgHeight = window.screen.height + "px"; this.imgHeight = window.screen.height + "px";
...@@ -1259,13 +1292,14 @@ export default { ...@@ -1259,13 +1292,14 @@ export default {
</script> </script>
<template> <template>
<div class="page-main" v-if="newDesktopDevice != 3"> <div class="page-main">
<img-setting <img-setting
ref="imgSetting" ref="imgSetting"
@ev="ev" @ev="ev"
@change="formChange" @change="formChange"
:item="returnItem" :item="returnItem"
@close="close" @close="close"
:newDesktopDevice="newDesktopDevice"
> >
<template #content> <template #content>
<div class="information-content"> <div class="information-content">
...@@ -1295,7 +1329,7 @@ export default { ...@@ -1295,7 +1329,7 @@ export default {
style="display: flex;justify-content: space-between;align-items: center;padding: 0 10px;" style="display: flex;justify-content: space-between;align-items: center;padding: 0 10px;"
> >
<div>素材图</div> <div>素材图</div>
<div v-if="selectImgList.length"> <div v-if="selectImgList.length && newDesktopDevice != 3">
<el-button <el-button
type="primary" type="primary"
size="small" size="small"
...@@ -1475,6 +1509,40 @@ export default { ...@@ -1475,6 +1509,40 @@ export default {
</div> </div>
</div> </div>
</div> </div>
<div
class="main"
v-show="newDesktopDevice == 3"
style="margin-top: 20px;"
>
<el-form>
<el-form-item label="下载位置1">
<div style="display: flex; ">
<el-input
:title="downloadLocation1"
v-model="downloadLocation1"
:disabled="true"
style="flex: 1;margin-right: 5px;"
></el-input>
<el-button @click="changeLocation('downloadLocation1')"
>浏览</el-button
>
</div>
</el-form-item>
<el-form-item label="下载位置2">
<div style="display: flex; ">
<el-input
:title="downloadLocation2"
v-model="downloadLocation2"
:disabled="true"
style="flex: 1;margin-right: 5px;"
></el-input>
<el-button @click="changeLocation('downloadLocation2')"
>浏览</el-button
>
</div>
</el-form-item>
</el-form>
</div>
</template> </template>
</img-setting> </img-setting>
<div <div
...@@ -1668,7 +1736,7 @@ export default { ...@@ -1668,7 +1736,7 @@ export default {
:style="{ 'z-index': isView ? '0' : '-1' }" :style="{ 'z-index': isView ? '0' : '-1' }"
/> />
</div> </div>
<div> <div v-show="newDesktopDevice != 3">
<print-dialog <print-dialog
:isDisabled="isView" :isDisabled="isView"
:visible="printDialogShow" :visible="printDialogShow"
...@@ -1941,7 +2009,7 @@ img { ...@@ -1941,7 +2009,7 @@ img {
.information-content { .information-content {
border: 1px solid #ececec; border: 1px solid #ececec;
border-top: none; // border-top: none;
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
.main { .main {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment