From c1d5d91d5c1147b8e717b4a07a1294d12cd2645e Mon Sep 17 00:00:00 2001 From: Fang_Zhijian Date: Thu, 19 Mar 2026 16:49:13 +0800 Subject: [PATCH] fix auto run bug --- CHANGELOG.md | 5 +++++ extension.json | 2 +- iframe/export.html | 23 +++++++++++++++++------ iframe/import.html | 32 +++++++++++++++++++++----------- iframe/newLeye.html | 29 ++++++++++++++++++++++------- 5 files changed, 66 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3598b..2c34682 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.0.11 + +1. 修复网页端无法自动拉起服务端的问题 +2. 修复批量出库页面 server-host 默认值错误的问题 + # 1.0.10 1. 查看库存界面新增右键菜单,支持快速跳转到立创商城、查看数据手册等功能 diff --git a/extension.json b/extension.json index 5d906cc..0d41d5e 100644 --- a/extension.json +++ b/extension.json @@ -3,7 +3,7 @@ "uuid": "944f7c94a8ca485e848f1118effcbb9a", "displayName": "LEYE", "description": "LEYE 电子元器件库存管理系统 EDA 联动扩展", - "version": "1.0.10", + "version": "1.0.11", "publisher": "Mr_Fang", "engines": { "eda": "^3.2.80" diff --git a/iframe/export.html b/iframe/export.html index 2d2bc70..49d7e04 100644 --- a/iframe/export.html +++ b/iframe/export.html @@ -297,7 +297,7 @@ return eda.sys_Message.showToastMessage('请先勾选要出库的器件', ESYS_ToastMessageType.WARNING); } - const SERVER = (await eda.sys_Storage.getExtensionUserConfig('server-host')) ?? 'http://localhost:21816'; + const SERVER = (await eda.sys_Storage.getExtensionUserConfig('server-host')) ?? 'http://localhost:21816/api'; const AUTO_RUN = (await eda.sys_Storage.getExtensionUserConfig('server-auto-run')) ?? true; let successCount = 0; let failItems = []; @@ -306,16 +306,27 @@ for (const item of selectedItems) { try { - let getRes = await eda.sys_ClientUrl.request(`${SERVER}/getLeyeList?lcscId=${item.lcscId}`, 'GET'); - let getResult = await getRes.json(); + let getResult; + try { + const getRes = await eda.sys_ClientUrl.request(`${SERVER}/getLeyeList?lcscId=${item.lcscId}`, 'GET'); + getResult = await getRes.json(); + } catch (e) { + getResult = { success: false }; + } if (AUTO_RUN && !getResult.success) { window.open('leye://open'); for (let i = 0; i < 3 && !getResult.success; i++) { eda.sys_Message.showToastMessage('等待拉起本地服务端...', ESYS_ToastMessageType.INFO); - getRes = await eda.sys_ClientUrl.request(`${SERVER}/getLeyeList?lcscId=${item.lcscId}`, 'GET'); - getResult = await getRes.json(); - await new Promise((resolve) => setTimeout(resolve, 1500)); + try { + const getRes = await eda.sys_ClientUrl.request(`${SERVER}/getLeyeList?lcscId=${item.lcscId}`, 'GET'); + getResult = await getRes.json(); + } catch (e) { + getResult = { success: false }; + } + if (!getResult.success) { + await new Promise((resolve) => setTimeout(resolve, 1500)); + } } } diff --git a/iframe/import.html b/iframe/import.html index 2414204..0822541 100644 --- a/iframe/import.html +++ b/iframe/import.html @@ -572,21 +572,31 @@ quantity: item.quantity, }); - let res = await eda.sys_ClientUrl.request(SERVER + '/addLeyeList', 'POST', postData, { - headers: { 'Content-Type': 'application/json' }, - }); - - let result = await res.json(); + let result; + try { + const res = await eda.sys_ClientUrl.request(SERVER + '/addLeyeList', 'POST', postData, { + headers: { 'Content-Type': 'application/json' }, + }); + result = await res.json(); + } catch (e) { + result = { success: false }; + } if (AUTO_RUN && !result.success) { - window.open('leye://open'); + eda.sys_Window.open('leye://open'); for (let i = 0; i < 3 && !result.success; i++) { eda.sys_Message.showToastMessage('等待拉起本地服务端...', ESYS_ToastMessageType.INFO); - res = await eda.sys_ClientUrl.request(SERVER + '/addLeyeList', 'POST', postData, { - headers: { 'Content-Type': 'application/json' }, - }); - result = await res.json(); - await new Promise((resolve) => setTimeout(resolve, 1500)); + try { + const res = await eda.sys_ClientUrl.request(SERVER + '/addLeyeList', 'POST', postData, { + headers: { 'Content-Type': 'application/json' }, + }); + result = await res.json(); + } catch (e) { + result = { success: false }; + } + if (!result.success) { + await new Promise((resolve) => setTimeout(resolve, 1500)); + } } } diff --git a/iframe/newLeye.html b/iframe/newLeye.html index 9e60523..e3c3f5a 100644 --- a/iframe/newLeye.html +++ b/iframe/newLeye.html @@ -296,17 +296,32 @@ cachedDetails = []; } - let listRes = await eda.sys_ClientUrl.request(SERVER + '/getLeyeList?pageSize=1000¤t=1'); - let listResult = await listRes.json(); + let listResult; + try { + const listRes = await eda.sys_ClientUrl.request(SERVER + '/getLeyeList?pageSize=1000¤t=1'); + listResult = await listRes.json(); + } catch (e) { + listResult = { success: false }; + } + if (AUTO_RUN && !listResult.success) { - window.open('leye://open'); + eda.sys_Window.open('leye://open'); for (let i = 0; i < 3 && !listResult.success; i++) { eda.sys_Message.showToastMessage('等待拉起本地服务端...', ESYS_ToastMessageType.INFO); - listRes = await eda.sys_ClientUrl.request(SERVER + '/getLeyeList?pageSize=1000¤t=1'); - listResult = await listRes.json(); - await new Promise((resolve) => setTimeout(resolve, 1500)); + + try { + const listRes = await eda.sys_ClientUrl.request(SERVER + '/getLeyeList?pageSize=1000¤t=1'); + listResult = await listRes.json(); + } catch (e) { + listResult = { success: false }; + } + + if (!listResult.success) { + await new Promise((resolve) => setTimeout(resolve, 1500)); + } } } + if (!listResult.success || !listResult.data) { throw new Error('同步失败'); } @@ -365,7 +380,7 @@ } catch (error) { tableBody.innerHTML = `加载失败: ${error.message}`; console.log('加载失败: ', error); - eda.sys_Log.add('加载失败: ', error.message); + eda.sys_Log.add('加载失败: ' + error.message, ESYS_LogType.ERROR); } }