Commit d9ffb4e5 by linjinhong

fix:修改router接口路径

parent b44635e8
// import { const { getHostApi } = require("@/server/utils/store");
// downloadImage, import { Loading } from "element-ui";
// downloadOtherImage,
// toSend, import { downloadImage, downloadOtherImage } from "@/server/utils";
// writeProfileXml,
// } from "@/server/utils";
// const {
// cropImageTransparentEdges,
// cropTransparentEdges,
// processImages,
// } = require("../utils/setImage");
import axios from "../utils/axios"; import axios from "../utils/axios";
// import { returnLogFilePath } from "../utils/log"; let loading;
// var request = require("request");
// const compressing = require("compressing"); function startLoading() {
// const uuid = require("uuid"); loading = Loading.service({
// const path = require("path"); lock: true,
// const fs = require("fs"); text: "拼命加载中...",
// const os = require("os"); spinner: "el-icon-loading",
// const { app } = require("electron"); background: "rgba(0,0,0,.7)",
});
}
function endLoading() {
loading.close();
}
axios.defaults.timeout = 12600000; axios.defaults.timeout = 12600000;
// const multiparty = require("multiparty");
export function getProductCnByFactorySubOrderNumberApi(factorySubOrderNumber) { // ===================== 订单查询相关 =====================
// let env = getHostApi().apiApiHost; const QUERY_ORDER_API_MAP = {
const url = CN: {
"factory/podJomallOrderProductCn/getProductCnByFactorySubOrderNumber"; path: "factory/podJomallOrderProductCn/getProductCnByFactorySubOrderNumber",
return axios.get(url, { paramKey: "factorySubOrderNumber", // 参数名:工厂子订单号
params: { },
factorySubOrderNumber, US: {
path: "factory/podJomallOrderProductUs/getProductUsByFactorySubOrderNumber",
paramKey: "factorySubOrderNumber", // 参数名:工厂子订单号
}, },
GC: {
path: "factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber",
paramKey: "thirdSubOrderNumber", // 参数名:第三方子订单号(老pod)
},
};
/**
* 通用查询订单接口
* @param {string} type - 订单类型(CN/US/GC,GC代表老pod)
* @param {string} orderNumber - 订单号(根据type自动匹配参数名:factorySubOrderNumber/thirdSubOrderNumber)
* @returns {Promise} axios请求Promise对象
* @throws {Error} 类型不支持/参数缺失时抛出异常
*/
export function findByPodProductionNoApi(orderNumber) {
// 1. 前置参数校验
if (!orderNumber.orderType) {
throw new Error("查询订单失败:订单类型type为必传项(支持CN/US/GC)");
}
// 2. 校验订单类型是否支持
const apiConfig = QUERY_ORDER_API_MAP[orderNumber.orderType];
if (!apiConfig) {
throw new Error(
`查询订单失败:不支持的订单类型${orderNumber.orderType},仅支持CN/US/GC`,
);
}
// 3. 构造请求参数(根据类型自动匹配参数名)
const requestParams = {
[apiConfig.paramKey]: orderNumber.thirdSubOrderNumber,
resizable: orderNumber.resizable,
};
// 4. 获取基地址并发送GET请求
const env = getHostApi().apiApiHost;
return axios.get(apiConfig.path, {
baseURL: env,
params: requestParams,
}); });
} }
// ===================== 素材下载相关 =====================
const downloadDesignImagesBaseApi = (urlPath, params) => {
const env = getHostApi().apiApiHost;
// 空值校验:避免params.ids不存在导致的报错
const requestData = Array.isArray(params?.ids) ? [...params.ids] : [];
export function getProductUsByFactorySubOrderNumberApi(factorySubOrderNumber) { return axios.post(urlPath, requestData, { baseURL: env, skipLoading: true });
return axios.get( };
`factory/podJomallOrderProductUs/getProductUsByFactorySubOrderNumber`, // 接口路径映射表(集中管理,便于维护)
{ const API_PATH_MAP = {
params: { CN: "factory/podJomallOrderProductCn/downloadDesignImages",
factorySubOrderNumber, US: "factory/podJomallOrderProductUs/downloadDesignImages",
}, GC: "factory/podJomallOrder/downloadByProduction",
}, USHLC: "factory/podJomallOrderProductUs/downloadCompatibleDesignImages",
CNHLC: "factory/podJomallOrderProductCn/downloadCompatibleDesignImages",
};
/**
* 根据子订单号下载素材
* @param {string} type - 订单类型(CN/US/GC/USHLC/CNHLC)
* @param {object} params - 请求参数(包含ids数组)
* @param {number} device - 设备类型(2/3)
* @returns {Promise} 下载结果
*/
export async function downloadBySubOrderNumberApi(params) {
try {
startLoading();
// 2. 处理设备类型为3时的订单类型映射(惠立彩)
let targetType = params.orderType;
if (params.device === 3) {
targetType = params.orderType === "CN" ? "CNHLC" : "USHLC";
}
// 4. 发送请求获取下载链接
const { data, message } = await downloadDesignImagesBaseApi(
API_PATH_MAP[targetType],
params,
); );
// 建议明确获取响应data(根据实际axios响应结构调整)
// 5. 处理响应数据
// 转义中文
let changeMessage;
if (message) {
changeMessage = encodeURIComponent(message);
}
let files = data || [changeMessage];
// 6. 构建下载文件列表
const fileEnv = getHostApi().fileApiUrl;
files = files.map((el) => ({ url: `${fileEnv}${el}` }));
console.log(106, files);
const downloadFunc =
params.device === 2 ? downloadOtherImage : downloadImage;
const downloadResult = await downloadFunc(files);
return {
code: 200,
message: "下载成功",
data: downloadResult,
};
} catch (error) {
// 统一错误处理:便于调试和用户提示
console.error("下载素材失败:", error);
// 可根据业务需求返回错误信息或重新抛出
throw new Error(`下载失败:${error.message}`);
} finally {
endLoading();
}
} }
export function getSubOrderByThirdSubOrderNumberApi(thirdSubOrderNumber) { /**
return axios.get( * 渲染进程调用主进程下载方法(Electron 6.x 兼容)
`factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber`, * @param {number} device - 设备类型 2/3
{ * @param {array} files - 下载文件列表
params: { * @returns {Promise} 下载结果
thirdSubOrderNumber, */
// function callMainProcessDownload(device, files) {
// // 生成唯一 requestId,用于匹配请求和响应(避免多请求冲突)
// const requestId = `download_${Date.now()}_${Math.random()
// .toString(36)
// .substr(2, 9)}`;
// return new Promise((resolve, reject) => {
// // 1. 监听主进程的响应(一次性监听,避免内存泄漏)
// const responseHandler = (event, result) => {
// // 只处理当前 requestId 的响应
// if (result.requestId !== requestId) return;
// // 移除监听(关键:避免重复监听)
// ipcRenderer.removeListener("download-image-response", responseHandler);
// // 处理结果
// if (result.success) {
// resolve(result);
// } else {
// reject(new Error(result.message));
// }
// };
// ipcRenderer.on("download-image-response", responseHandler);
// // 2. 向主进程发送下载请求
// ipcRenderer.send("download-image-request", {
// requestId,
// device,
// files,
// });
// // 3. 超时处理(避免一直等待)
// setTimeout(() => {
// ipcRenderer.removeListener("download-image-response", responseHandler);
// reject(new Error("调用主进程下载方法超时"));
// }, 120000); // 2分钟超时
// });
// }
// ===================== 订单完成相关 =====================
/**
* 通用完成订单接口
* @param {string} type - 订单类型(CN/US/GC,GC代表老pod)
* @param {object} params - 完成订单的请求参数
* @returns {Promise} axios请求Promise对象
* @throws {Error} 类型不支持/参数错误时抛出异常
*/
export function completeDeliveryApi(params) {
const COMPLETE_DELIVERY_API_MAP = {
CN: {
data: {
id: params.id,
podJomallOrderCnId: params.podJomallOrderCnId || "",
}, },
url: "factory/podJomallOrderProductCn/completeDelivery",
}, },
); US: {
data: {
id: params.id,
podJomallOrderUsId: params.podJomallOrderUsId || "",
},
url: "factory/podJomallOrderProductUs/completeDelivery",
},
GC: {
data: { id: params.id },
url: "factory/podJomallOrderProduct/completeDelivery",
},
};
// 2. 校验订单类型是否支持
const apiPath = COMPLETE_DELIVERY_API_MAP[params.orderType];
// 3. 获取基地址并发送请求
const env = getHostApi().apiApiHost;
return axios.post(apiPath.url, apiPath.data, { baseURL: env });
} }
export function checkUpdate(version) { export function checkUpdate(version) {
......
...@@ -4,6 +4,7 @@ import { app, protocol, BrowserWindow, globalShortcut } from "electron"; ...@@ -4,6 +4,7 @@ import { app, protocol, BrowserWindow, globalShortcut } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import { createServer } from "@/server/index.js"; import { createServer } from "@/server/index.js";
import { autoUpdater } from "electron-updater"; import { autoUpdater } from "electron-updater";
const fs = require("fs"); const fs = require("fs");
import path from "path"; // 引入 path 模块 import path from "path"; // 引入 path 模块
......
export const pathMap = {
findByPodProductionNo: {
CN: "factory/podJomallOrderProductCn/getProductCnByFactorySubOrderNumber",
US: "factory/podJomallOrderProductUs/getProductUsByFactorySubOrderNumber",
GC: "factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber",
},
downloadBySubOrderNumber: {
CN: "factory/podJomallOrderProductCn/downloadDesignImages",
US: "factory/podJomallOrderProductUs/downloadDesignImages",
GC: "factory/podJomallOrder/downloadByProduction",
USHLC: "factory/podJomallOrderProductUs/downloadCompatibleDesignImages",
CNHLC: "factory/podJomallOrderProductCn/downloadCompatibleDesignImages",
},
completeDelivery: {
CN: "factory/podJomallOrderProductCn/completeDelivery",
US: "factory/podJomallOrderProductUs/completeDelivery",
GC: "factory/podJomallOrderProduct/completeDelivery",
},
};
export function autoRegisterRouter(router, funcKey, handler) {
const configGroup = pathMap[funcKey];
// 遍历配置自动注册路由
Object.values(configGroup).forEach((el) => {
router.post(`/${el}`, (req, res) => {
handler(req, res);
});
});
}
...@@ -172,11 +172,11 @@ export default { ...@@ -172,11 +172,11 @@ export default {
let files = data.data || [data.message]; let files = data.data || [data.message];
files = files.map((el) => ({ url: `${fileEnv}${el}` })); files = files.map((el) => ({ url: `${fileEnv}${el}` }));
console.log(175, files);
const downloadFunc = const downloadFunc =
params.device === 2 ? downloadOtherImage : downloadImage; params.device === 2 ? downloadOtherImage : downloadImage;
const result = await downloadFunc(files); const result = await downloadFunc(files);
res.setHeader("Request-URL", url);
res.json({ code: 200, data: result }); res.json({ code: 200, data: result });
} catch (err) { } catch (err) {
......
import express from "express"; import express from "express";
import fn from "../entity/function.js"; import fn from "../entity/function.js";
const { autoRegisterRouter } = require("@/config/index.js");
let router = express.Router(); let router = express.Router();
// 执行打印命令 // 执行打印命令
...@@ -19,13 +19,16 @@ router.get("/getCompanyList", fn.getCompanyList); ...@@ -19,13 +19,16 @@ router.get("/getCompanyList", fn.getCompanyList);
// 提交授权申请 // 提交授权申请
router.post("/commitApply", fn.commitApply); router.post("/commitApply", fn.commitApply);
// 下载素材到本地 // 下载素材到本地
router.post("/downloadByDesignId", fn.downloadByDesignId); router.post("/downloadByDesignId", fn.downloadByDesignId);
// 获取 生产单号返回素材地址 // 获取 生产单号返回素材地址
router.post("/downloadBySubOrderNumber", fn.downloadBySubOrderNumber); autoRegisterRouter(
router,
"downloadBySubOrderNumber",
fn.downloadBySubOrderNumber,
);
// 提交生产完成 // 提交生产完成
router.post("/completeDelivery", fn.completeDelivery); autoRegisterRouter(router, "completeDelivery", fn.completeDelivery);
// 根据生产单号查询详情
router.post("/findByPodProductionNo", fn.findByPodProductionNo);
// 查询版本更新 // 查询版本更新
router.get("/checkUpdate", fn.checkUpdate); router.get("/checkUpdate", fn.checkUpdate);
// 增量更新 // 增量更新
...@@ -41,6 +44,7 @@ router.post("/cleanDirectorySync", fn.cleanDirectorySync); ...@@ -41,6 +44,7 @@ router.post("/cleanDirectorySync", fn.cleanDirectorySync);
// 保存生成后得图片返回地址 // 保存生成后得图片返回地址
router.post("/saveToPng", fn.saveToPng); router.post("/saveToPng", fn.saveToPng);
// 保存生成后得图片返回地址 // 保存生成后得图片返回地址
router.post("/getAllCountry", fn.getAllCountry); router.post("/getAllCountry", fn.getAllCountry);
...@@ -50,4 +54,6 @@ router.post("/saveImgByUrl", fn.saveImgByUrl); ...@@ -50,4 +54,6 @@ router.post("/saveImgByUrl", fn.saveImgByUrl);
//复制文件夹下文件 //复制文件夹下文件
router.post("/copySingleImageFn", fn.copySingleImageFn); router.post("/copySingleImageFn", fn.copySingleImageFn);
// 根据生产单号查询详情
autoRegisterRouter(router, "findByPodProductionNo", fn.findByPodProductionNo);
export { router as default }; export { router as default };
...@@ -126,14 +126,16 @@ export default new Vuex.Store({ ...@@ -126,14 +126,16 @@ export default new Vuex.Store({
if (arr) { if (arr) {
return (state.grid = [arr]); return (state.grid = [arr]);
} }
let proportion = state.WHproportion;
console.log(130, proportion);
state.grid.forEach((el) => { state.grid.forEach((el) => {
if (el.value == 0) { if (el.value == 0) {
let proportion = state.WHproportion; // if (state.defaultProportion == 1.5) {
if (state.defaultProportion == 1.5) { // proportion = 1.4;
proportion = 1.4; // } else if (state.defaultProportion == 1.7) {
} else if (state.defaultProportion == 1.7) { // proportion = 1.4;
proportion = 1.4; // }
}
el.h = 630 * proportion; el.h = 630 * proportion;
el.w = 480 * proportion; el.w = 480 * proportion;
} else if (el.value == 1) { } else if (el.value == 1) {
...@@ -143,17 +145,17 @@ export default new Vuex.Store({ ...@@ -143,17 +145,17 @@ export default new Vuex.Store({
el.h = 480 * state.WHproportion; el.h = 480 * state.WHproportion;
el.w = 420 * state.WHproportion; el.w = 420 * state.WHproportion;
} else if (el.value == 3) { } else if (el.value == 3) {
el.h = 360 * (state.WHproportion + 0.8); el.h = 360 * state.WHproportion;
el.w = 300 * (state.WHproportion + 0.8); el.w = 300 * state.WHproportion;
} else if (el.value == 4) { } else if (el.value == 4) {
el.h = 240 * (state.WHproportion + 1.8); el.h = 240 * state.WHproportion;
el.w = 210 * (state.WHproportion + 1.8); el.w = 210 * state.WHproportion;
} else if (el.value == 5) { } else if (el.value == 5) {
el.h = 720 * 1.2; el.h = 720 * proportion;
el.w = 720 * 1.2; el.w = 720 * proportion;
} else if (el.value == 6) { } else if (el.value == 6) {
el.h = 660 * 1.4; el.h = 660 * proportion;
el.w = 540 * 1.4; el.w = 540 * proportion;
} else if (el.value == 99) { } else if (el.value == 99) {
el.h = 900; el.h = 900;
el.w = 720; el.w = 720;
......
...@@ -5,6 +5,7 @@ import bus from "@/bus"; ...@@ -5,6 +5,7 @@ import bus from "@/bus";
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import { copySingleImage } from "@/server/utils/index.js"; import { copySingleImage } from "@/server/utils/index.js";
const moment = require("moment"); const moment = require("moment");
const { pathMap } = require("@/config/index.js");
import pkg from "../../../../package.json"; import pkg from "../../../../package.json";
import UpdateDialog from "@/views/design/updateDialog.vue"; import UpdateDialog from "@/views/design/updateDialog.vue";
...@@ -262,7 +263,12 @@ export default { ...@@ -262,7 +263,12 @@ export default {
console.log("本地数据removeFromOrderInfo:", getOrderInfoMap()); console.log("本地数据removeFromOrderInfo:", getOrderInfoMap());
//生产完成后在本地删除 //生产完成后在本地删除
// return; // return;
await this.$api.post("/completeDelivery", params); // await completeDeliveryApi(params);
// await this.$api.post("/completeDelivery", params);
await this.$api.post(
pathMap["completeDelivery"][this.orderType],
params,
);
this.$message.success("操作成功"); this.$message.success("操作成功");
} }
}, },
...@@ -487,11 +493,22 @@ export default { ...@@ -487,11 +493,22 @@ export default {
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示 // 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
if (!imageResList.length && !bool) { if (!imageResList.length && !bool) {
let res = await this.$api.post("/downloadBySubOrderNumber", { let newType = this.orderType;
if (this.orderType == "CN" && this.desktopDevice == 3) {
newType = this.orderType == "CN" ? "CNHLC" : "USHLC";
}
let res = await this.$api.post(
pathMap["downloadBySubOrderNumber"][newType],
{
ids: [this.detail.id], ids: [this.detail.id],
device: this.$store.state.desktopDevice, device: this.$store.state.desktopDevice,
orderType: this.orderType, orderType: this.orderType,
}); },
);
console.log("res", 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 || []);
...@@ -582,6 +599,9 @@ export default { ...@@ -582,6 +599,9 @@ export default {
addToOrderInfo(this.detail); addToOrderInfo(this.detail);
console.log("本地数据addToOrderInfo", getOrderInfoMap()); console.log("本地数据addToOrderInfo", getOrderInfoMap());
} }
if (this.detail["saveImgList"].length == 1) {
this.faceType = this.detail["saveImgList"][0].title;
}
if (this.desktopDevice == 3) obj.faceType = this.faceType; if (this.desktopDevice == 3) obj.faceType = this.faceType;
bus.$emit("busEmit", obj); bus.$emit("busEmit", obj);
...@@ -595,7 +615,11 @@ export default { ...@@ -595,7 +615,11 @@ export default {
Object.keys(this.detail).length > 0 && Object.keys(this.detail).length > 0 &&
this.isAutoFinish this.isAutoFinish
) { ) {
try {
await this.setData(this.detail); await this.setData(this.detail);
} catch (err) {
console.error("setData 执行失败", err);
}
} }
if (this.detail && !this.isAutoFinish && this.desktopDevice == 3) { if (this.detail && !this.isAutoFinish && this.desktopDevice == 3) {
...@@ -668,12 +692,18 @@ export default { ...@@ -668,12 +692,18 @@ export default {
const item = getOrderInfoItem(this.productionNo, this.faceType); const item = getOrderInfoItem(this.productionNo, this.faceType);
console.log("本地数据getOrderInfoItem", getOrderInfoMap()); console.log("本地数据getOrderInfoItem", getOrderInfoMap());
localItem = item ? { data: item } : null; localItem = item ? { data: item } : null;
findByPodProductionNo = findByPodProductionNo =
localItem || localItem ||
(await this.$api.post("/findByPodProductionNo", apiRequestParams)); (await this.$api.post(
pathMap["findByPodProductionNo"][this.orderType],
apiRequestParams,
));
} else { } else {
console.log("path", pathMap["findByPodProductionNo"]);
findByPodProductionNo = await this.$api.post( findByPodProductionNo = await this.$api.post(
"/findByPodProductionNo", pathMap["findByPodProductionNo"][this.orderType],
apiRequestParams, apiRequestParams,
); );
} }
...@@ -788,7 +818,7 @@ export default { ...@@ -788,7 +818,7 @@ export default {
if (this.setting.gridValue == i) return; if (this.setting.gridValue == i) return;
if (i === 1) { if (i === 1) {
this.$store.commit("setWHproportion", this.defaultProportion - 0.3); // this.$store.commit("setWHproportion", this.defaultProportion - 0.3);
} else { } else {
this.$store.commit("setWHproportion", this.defaultProportion); this.$store.commit("setWHproportion", this.defaultProportion);
} }
...@@ -826,7 +856,7 @@ export default { ...@@ -826,7 +856,7 @@ export default {
this.selectGridIndex = 0; this.selectGridIndex = 0;
this.$store.commit("changeDesktoVersion", value); this.$store.commit("changeDesktoVersion", value);
ipcRenderer.send("update-version", value); ipcRenderer.send("update-version", value);
this.$store.commit("getNewGrid"); this.$store.commit("setGrid");
this.command(0); this.command(0);
}, },
async cutImgFn(arr) { async cutImgFn(arr) {
......
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
console.log(`接收到窗口尺寸:${width}x${height}`); console.log(`接收到窗口尺寸:${width}x${height}`);
let proportion; let proportion;
proportion = 1.7; proportion = 1.4;
// } else { // } else {
// proportion = 1.5; // proportion = 1.5;
// } // }
...@@ -383,7 +383,7 @@ export default { ...@@ -383,7 +383,7 @@ export default {
this.systemSetting.gridValue = 5; this.systemSetting.gridValue = 5;
} else { } else {
this.systemSetting.gridValue = 0; this.systemSetting.gridValue = 0;
this.$store.commit("setWHproportion", 1.7); this.$store.commit("setWHproportion", 1.4);
this.$store.commit("setGrid"); this.$store.commit("setGrid");
} }
}, },
...@@ -1802,7 +1802,7 @@ export default { ...@@ -1802,7 +1802,7 @@ export default {
</div> </div>
</div> </div>
</div> </div>
<div <!-- <div
class="print-tip" class="print-tip"
:style="{ left: isView ? '' : '22%' }" :style="{ left: isView ? '' : '22%' }"
v-if=" v-if="
...@@ -1824,7 +1824,7 @@ export default { ...@@ -1824,7 +1824,7 @@ export default {
}}</b }}</b
> >
<b style="color: red" v-else>该生产单需要拖动设计打印</b> <b style="color: red" v-else>该生产单需要拖动设计打印</b>
</div> </div> -->
<!-- <div class="print-tip" v-else> <!-- <div class="print-tip" v-else>
<b style="color: red">该生产单需要拖动设计打印</b> <b style="color: red">该生产单需要拖动设计打印</b>
</div> --> </div> -->
......
...@@ -37,11 +37,9 @@ export default { ...@@ -37,11 +37,9 @@ export default {
console.log(`接收到窗口尺寸:${width}x${height}`); console.log(`接收到窗口尺寸:${width}x${height}`);
let proportion; let proportion;
if (height > 1000) { if (height > 1000) {
proportion = 1.7; proportion = 1.4;
} else if (height > 900 && height <= 1000) {
proportion = 1.1;
} else { } else {
proportion = 1; proportion = 0.8;
} }
this.$store.commit("setWindows", { width, height }); this.$store.commit("setWindows", { width, height });
this.$store.commit("setWHproportion", proportion); this.$store.commit("setWHproportion", proportion);
......
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