为啥wps.ShowDialog在同一个函数执行多次,关闭第一窗口,其他窗口也会自动关闭
async function queryPositiveProductBomForm() {
try {
let dialogWidth = 1280;
let dialogHeight = 800;
let sheet = wps.Application.ActiveSheet;
let selection = wps.Application.Selection;
let areaCount = selection.Areas.Count;
let limitCellCount = 10;
let totalCellCount = 0;
for (let i = 1; i <= areaCount; i++) {
let area = selection.Areas.Item(i);
let cellsCount = area.Cells.Count;
for (let j = 1; j <= cellsCount; j++) {
let firstCellValue = String(area.Cells.Item(j).Value2).trim();
if (!firstCellValue) continue;
let obj = await queryNewBomInfoByProductCode(firstCellValue);
if (!obj) { continue; }
let productInfo = await queryMaterialInfoByProductCode(firstCellValue);
//查询是否有工艺路线
await Promise.all(obj.data.map(async (item) => {
const result = await queryRoutingInfoByProductCode(item.component_part);
item.route =result===null?false:true;
item.hasTime=item.route;
}));
// alert(JSON.stringify(obj.data));
totalCellCount++;
if (totalCellCount > limitCellCount) {
alert("最多只能打开" + limitCellCount + "个窗口");
return;
}
let data = {
productid: productInfo.total > 0 ? productInfo.data[0].material_no : obj.mainProductId,
productname: productInfo.total > 0 ? productInfo.data[0].item_name : obj.mainProductName,
costcenter: productInfo.total > 0 ? productInfo.data[0].default_cost_center : obj.mainCostCenter,
costcenterdesc: productInfo.total > 0 ? productInfo.data[0].default_cost_center_desc : obj.mainCostCenterDesc,
supplystrategy: productInfo.total > 0 ? productInfo.data[0].replenishment_strategy_desc : "",
bomDetail: obj.data
};
wps.PluginStorage.setItem("totalCellCount", totalCellCount);
wps.PluginStorage.setItem("bomData" + totalCellCount, JSON.stringify(data));
let htmlPath = Application.Env.GetAppDataPath() + "/kingsoft/wps/jsaddons/WN_EXT_ADDINS_0.01/index_NewBomForm.html";
let timestamp = new Date().getTime();
let urlWithTimestamp = htmlPath + "?t=" + timestamp;
let dialog = wps.ShowDialog(
urlWithTimestamp,
"BOM正查层级展示", // 窗口标题
dialogWidth, // 宽(px)
dialogHeight, // 高(px)
false, // 非模态
);
}
}
// 使用独立上下文打开每个窗口
//wps.PluginStorage.setItem("bomFormID", "bomHierarchy");
} catch (e) {
alert("错误:" + e.message);
}
}
