248 lines
8.0 KiB
HTML
248 lines
8.0 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>扩展设置</title>
|
|
<link rel="stylesheet" href="/iframe/css/index.css" />
|
|
<style>
|
|
::-webkit-scrollbar {
|
|
height: 0.25rem;
|
|
width: 0.25rem;
|
|
}
|
|
::-webkit-scrollbar-thumb {
|
|
background: rgba(0, 0, 0, 0.2);
|
|
}
|
|
*:focus {
|
|
outline: none;
|
|
}
|
|
|
|
input[type='checkbox'] {
|
|
appearance: none;
|
|
-webkit-appearance: none;
|
|
width: 2rem;
|
|
height: 1rem;
|
|
background-color: #d1d5db; /* Tailwind's gray-300 */
|
|
border-radius: 9999px; /* Full rounded */
|
|
position: relative;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s;
|
|
}
|
|
input[type='checkbox']::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0.125rem;
|
|
left: 0.125rem;
|
|
width: 0.75rem;
|
|
height: 0.75rem;
|
|
background-color: white;
|
|
border-radius: 9999px;
|
|
transition: transform 0.2s;
|
|
}
|
|
input[type='checkbox']:checked {
|
|
background-color: #3b82f6;
|
|
}
|
|
input[type='checkbox']:checked::before {
|
|
transform: translateX(1rem);
|
|
}
|
|
input[type='checkbox']:disabled {
|
|
background-color: #9ca3af;
|
|
cursor: not-allowed;
|
|
}
|
|
input[type='checkbox']:disabled::before {
|
|
background-color: #f3f4f6;
|
|
}
|
|
|
|
/* Tooltip 基础样式 */
|
|
.tooltip-box {
|
|
position: fixed;
|
|
background: #1f2937;
|
|
color: white;
|
|
padding: 8px 12px;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
white-space: nowrap;
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
transition: opacity 0.2s ease;
|
|
z-index: 1000;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.tooltip-box.show {
|
|
opacity: 1;
|
|
}
|
|
|
|
.tooltip-box::after {
|
|
content: '';
|
|
position: absolute;
|
|
left: var(--arrow-left, 12px);
|
|
border: 6px solid transparent;
|
|
}
|
|
|
|
.tooltip-box:not(.below)::after {
|
|
top: 100%;
|
|
border-top-color: #1f2937;
|
|
}
|
|
|
|
.tooltip-box.below::after {
|
|
bottom: 100%;
|
|
border-bottom-color: #1f2937;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-100">
|
|
<div class="min-h-screen bg-gray-100">
|
|
<div class="bg-white p-4 rounded-lg w-[400px]">
|
|
<h2 class="text-lg font-semibold text-gray-800 mb-4">
|
|
通用设置
|
|
<span class="text-[12px] text-gray-500 font-light ml-2"> 扩展通用设置 </span>
|
|
</h2>
|
|
<div class="flex items-center justify-between mb-4">
|
|
<label for="settings-server-host" class="text-gray-700">服务器地址</label>
|
|
<input type="text" id="settings-server-host" class="border border-gray-300 rounded pl-2 py-0.5 w-48" />
|
|
</div>
|
|
<div class="flex items-center justify-between mb-4">
|
|
<label for="settings-server-auto-run" class="text-gray-700">
|
|
允许拉起服务端
|
|
<span class="tooltip text-sm text-gray-500 font-light" data-tooltip="允许拉起本地 LEYE 服务端">?</span>
|
|
</label>
|
|
<input type="checkbox" id="settings-server-auto-run" />
|
|
</div>
|
|
<div class="flex items-center justify-between mb-4">
|
|
<label for="settings-auto-fill-bom" class="text-gray-700">出库自动填充 BOM</label>
|
|
<input type="checkbox" id="settings-auto-fill-bom" />
|
|
</div>
|
|
</div>
|
|
<div class="bg-white p-4 rounded-lg w-[400px]">
|
|
<h2 class="text-lg font-semibold text-gray-800 mb-4">
|
|
高级设置
|
|
<span class="text-[12px] text-gray-500 font-light ml-2"> 实验或调试选项 </span>
|
|
</h2>
|
|
<div class="flex items-center justify-between mb-4">
|
|
<label for="settings-auto-check-update" class="text-gray-700">
|
|
自动检查更新
|
|
<span class="tooltip text-sm text-gray-500 font-light" data-tooltip="允许在启动 EDA 时检查更新">?</span>
|
|
</label>
|
|
<input type="checkbox" id="settings-auto-check-update" />
|
|
</div>
|
|
<div class="flex items-center justify-between mb-4">
|
|
<label for="settings-clean-cache" class="text-gray-700">
|
|
清除缓存
|
|
<span class="tooltip text-sm text-gray-500 font-light" data-tooltip="库存数据异常可尝试使用此功能修复">?</span>
|
|
</label>
|
|
<button id="settings-clean-cache" class="bg-red-600 text-white px-4 py-1 rounded hover:bg-red-700">清除</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
const serverHostInput = document.getElementById('settings-server-host');
|
|
const serverAutoRun = document.getElementById('settings-server-auto-run');
|
|
const autoFillBomInput = document.getElementById('settings-auto-fill-bom');
|
|
const autoCheckUpdateInput = document.getElementById('settings-auto-check-update');
|
|
const cleanCacheBtn = document.getElementById('settings-clean-cache');
|
|
|
|
serverHostInput.value = (await eda.sys_Storage.getExtensionUserConfig('server-host')) ?? 'http://localhost:21816/api';
|
|
serverAutoRun.checked = (await eda.sys_Storage.getExtensionUserConfig('server-auto-run')) ?? true;
|
|
autoFillBomInput.checked = (await eda.sys_Storage.getExtensionUserConfig('auto-fill-bom')) ?? false;
|
|
autoCheckUpdateInput.checked = (await eda.sys_Storage.getExtensionUserConfig('auto-check-update')) ?? true;
|
|
|
|
serverHostInput.addEventListener('change', async () => {
|
|
saveConfig('server-host', serverHostInput.value);
|
|
});
|
|
serverAutoRun.addEventListener('change', async () => {
|
|
saveConfig('server-auto-run', serverAutoRun.checked);
|
|
});
|
|
autoFillBomInput.addEventListener('change', async () => {
|
|
saveConfig('auto-fill-bom', autoFillBomInput.checked);
|
|
});
|
|
autoCheckUpdateInput.addEventListener('change', async () => {
|
|
saveConfig('auto-check-update', autoCheckUpdateInput.checked);
|
|
});
|
|
|
|
cleanCacheBtn.addEventListener('click', async () => {
|
|
eda.sys_Storage.deleteExtensionUserConfig('cache-leye-device-details').then((s) => {
|
|
if (s) {
|
|
eda.sys_Message.showToastMessage('缓存清除成功!', ESYS_ToastMessageType.SUCCESS);
|
|
} else {
|
|
eda.sys_Message.showToastMessage('缓存清除失败...', ESYS_ToastMessageType.ERROR);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function saveConfig(key, value) {
|
|
eda.sys_Storage.setExtensionUserConfig(key, value).then(() => {
|
|
eda.sys_Message.showToastMessage('设置已保存', ESYS_ToastMessageType.SUCCESS);
|
|
});
|
|
}
|
|
</script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const tooltipContainer = document.createElement('div');
|
|
tooltipContainer.className = 'global-tooltip-container';
|
|
document.body.appendChild(tooltipContainer);
|
|
|
|
const tooltipElements = document.querySelectorAll('.tooltip');
|
|
|
|
tooltipElements.forEach((element) => {
|
|
const tooltipText = element.dataset.tooltip;
|
|
if (!tooltipText) return;
|
|
|
|
const tooltip = document.createElement('div');
|
|
tooltip.className = 'tooltip-box';
|
|
tooltip.textContent = tooltipText;
|
|
tooltipContainer.appendChild(tooltip);
|
|
|
|
const showTooltip = () => {
|
|
tooltip.classList.add('show');
|
|
positionTooltip(element, tooltip);
|
|
};
|
|
|
|
const hideTooltip = () => {
|
|
tooltip.classList.remove('show');
|
|
};
|
|
|
|
element.addEventListener('mouseenter', showTooltip);
|
|
element.addEventListener('mouseleave', hideTooltip);
|
|
element.addEventListener('focus', showTooltip);
|
|
element.addEventListener('blur', hideTooltip);
|
|
});
|
|
|
|
function positionTooltip(target, tooltip) {
|
|
const rect = target.getBoundingClientRect();
|
|
const tooltipRect = tooltip.getBoundingClientRect();
|
|
|
|
let top = rect.top - tooltipRect.height - 8;
|
|
let left = rect.left - 12;
|
|
|
|
if (top < 8) {
|
|
top = rect.bottom + 8;
|
|
tooltip.classList.add('below');
|
|
} else {
|
|
tooltip.classList.remove('below');
|
|
}
|
|
|
|
if (left < 8) {
|
|
left = 8;
|
|
} else if (left + tooltipRect.width > window.innerWidth - 8) {
|
|
left = window.innerWidth - tooltipRect.width - 8;
|
|
}
|
|
|
|
tooltip.style.top = `${top}px`;
|
|
tooltip.style.left = `${left}px`;
|
|
|
|
tooltip.style.setProperty('--arrow-left', '12px');
|
|
}
|
|
|
|
window.addEventListener('scroll', () => {
|
|
document.querySelectorAll('.tooltip-box.show').forEach((t) => {
|
|
t.classList.remove('show');
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|