From 398500b9526f7a544a1c3eedef215f84c5583ee0 Mon Sep 17 00:00:00 2001 From: qiqi Date: Tue, 17 Nov 2026 15:59:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugins):=20=E8=AE=BE=E7=BD=AE=E5=86=85?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=B8=82=E5=9C=BA=E6=94=B9=E6=88=90=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E5=A2=99=EF=BC=88=E5=9B=BE=E6=A0=87/=E6=A0=87?= =?UTF-8?q?=E7=AD=BE/=E7=8A=B6=E6=80=81/=E5=AE=89=E8=A3=85=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=89=EF=BC=8C=E4=B8=8E=20market=20=E9=A1=B5?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E5=A5=97=E8=A7=86=E8=A7=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui-settings-sections.js | 95 ++++++++++++++++++------------------- style.css | 14 +++++- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/src/ui-settings-sections.js b/src/ui-settings-sections.js index 5b8e3c6..41b4b5a 100644 --- a/src/ui-settings-sections.js +++ b/src/ui-settings-sections.js @@ -190,9 +190,47 @@ const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null return (F && F.dir && F.dir()) ? (F.dir() + '/plugins/') : '资料目录/plugins/' })() + const tagRow = (arr) => el('div', { className: 'iwb-mk-tags' }, (arr || []).map((t) => el('span', { key: t, className: 'iwb-mk-tag' }, t))) + const kb = (n) => (!n ? '' : (n >= 1048576 ? (n / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round(n / 1024)) + ' KB')) + const card = (item, mode) => { + const p = item + const isInst = mode === 'installed' + const rt = (wRuntimePlugins || []).find((r) => r && r.id === p.id) + const statusText = !isInst ? '' : (!p.registered ? '未加载' : (rt && rt.status === 'error' ? '加载失败' : '已加载')) + const warn = statusText && statusText !== '已加载' + const icon = p.icon || '◻' + const color = p.color || '#eef2f6' + const bits = [] + if (p.author) bits.push(p.author === 'official' ? '官方' : p.author) + if (p.version) bits.push('v' + p.version) + if (p.size) bits.push(kb(p.size)) + return el('div', { key: p.id, className: 'iwb-mk-card' }, + el('div', { className: 'iwb-mk-head' }, + el('span', { className: 'iwb-mk-avatar', style: { background: color } }, icon), + el('div', { className: 'iwb-mk-titles' }, + el('div', { className: 'iwb-mk-name' }, p.name || p.id, + statusText ? el('span', { className: 'iwb-plugin-tag' + (warn ? ' iwb-plugin-tag-warn' : ''), title: (rt && rt.error) || '', style: { marginLeft: 6 } }, statusText) : null, + p.newer ? el('span', { className: 'iwb-plugin-tag', style: { marginLeft: 4 } }, '可更新') : null, + ), + el('div', { className: 'iwb-mk-sub' }, bits.join(' · ')), + ), + ), + p.desc ? el('div', { className: 'iwb-mk-desc' }, p.desc) : null, + (p.tags && p.tags.length) ? tagRow(p.tags) : null, + el('div', { className: 'iwb-mk-actions' }, + isInst + ? [ + p.registered ? el('button', { key: 'set', className: 'iwb-btn iwb-btn-sm', onClick: () => setTab('plugin:' + p.id) }, '设置') : null, + p.newer ? el('button', { key: 'upd', className: 'iwb-btn iwb-btn-sm', disabled: !!busy, onClick: () => act('install', p.id) }, busy === p.id ? '处理中…' : '更新') : null, + el('button', { key: 'rm', className: 'iwb-btn iwb-btn-sm', disabled: !!busy, onClick: () => act('uninstall', p.id) }, '移除'), + ] + : el('button', { className: 'iwb-btn iwb-btn-sm iwb-btn-primary', disabled: !!busy || p.registered, onClick: () => act('install', p.id) }, busy === p.id ? '处理中…' : (p.registered ? '已安装' : '安装')), + ), + ) + } return el('div', { className: 'iwb-set-page' }, el('div', { className: 'iwb-set-page-title' }, '插件'), - el('div', { className: 'iwb-hint' }, '插件从市场安装到:' + dirHint + '(应用本体不再自带插件)'), + el('div', { className: 'iwb-hint' }, '插件从市场安装到:' + dirHint + '(装完重启应用生效)'), el('div', { className: 'iwb-row' }, el('label', { className: 'iwb-check', title: '本地开发用:把插件放到 plugins/local//plugin.js' }, el('input', { @@ -205,61 +243,22 @@ setMsg(on ? '已开启开发者模式,重启后加载 plugins/local/ 下的插件' : '已关闭开发者模式,重启后只加载市场安装的插件') }, }), - ' 开发者模式(加载 plugins/local//plugin.js,未签名)'), + ' 开发者模式(加载 plugins/local/ 下的未签名插件)'), + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: refresh }, '刷新市场'), ), el('div', { className: 'iwb-row' }, - el('label', { className: 'iwb-check', title: '用于本地开发:把插件放到 plugins/local//plugin.js' }, - el('input', { - type: 'checkbox', checked: devMode, - onChange: (e) => { - const on = e.target.checked - setDevMode(on) - pluginDevSet(on) - setMsg(on ? '已开启开发者模式,重启后加载 plugins/local/ 下的插件' : '已关闭开发者模式,重启后只加载市场安装的插件') - }, - }), - ' 开发者模式(加载 plugins/local//plugin.js,未签名)'), - ), - el('div', { className: 'iwb-row' }, - el('input', { className: 'iwb-input iwb-grow', placeholder: '搜索已安装的插件…', value: q, onChange: (e) => setQ(e.target.value) }), + el('input', { className: 'iwb-input iwb-grow', placeholder: '搜索插件,例如:出图、抠图、矢量…', value: q, onChange: (e) => setQ(e.target.value) }), ), el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-hint', style: { flex: '1 1 auto' } }, '已安装 ' + installedRows.length + ' 个' + (mList.length ? (' · 市场 ' + mList.length + ' 个 · 可安装 ' + availRows.length + ' 个') : '') + (updatable ? (' · 可更新 ' + updatable + ' 个') : '')), - el('button', { className: 'iwb-btn iwb-btn-sm', onClick: refresh }, '检查更新'), ), - el('div', { className: 'iwb-section-sub' }, '已安装插件'), - installedRows.length ? installedRows.map((p) => { - const rt = (wRuntimePlugins || []).find((r) => r && r.id === p.id) - const status = !p.registered ? '未加载' : (rt && rt.status === 'error' ? '加载失败' : '已加载') - const tagWarn = status !== '已加载' - return el('div', { key: p.id, className: 'iwb-plugin-item' }, - el('div', { className: 'iwb-plugin-main' }, - el('label', { className: 'iwb-plugin-title' }, - el('input', { type: 'checkbox', checked: p.enabled, disabled: !p.registered || !p.compatible, onChange: (e) => p.registered && toggle(regById[p.id], e.target.checked) }), - el('span', null, p.name + ' v' + p.version), - el('span', { className: 'iwb-plugin-tag' + (tagWarn ? ' iwb-plugin-tag-warn' : ''), title: (rt && rt.error) || '' }, status), - p.newer ? el('span', { className: 'iwb-plugin-tag' }, '可更新') : null, - ), - p.desc ? el('div', { className: 'iwb-plugin-desc' }, p.desc) : null, - ), - el('div', { className: 'iwb-plugin-actions' }, - p.registered ? el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => setTab('plugin:' + p.id) }, '设置') : null, - p.newer ? el('button', { className: 'iwb-btn iwb-btn-sm', disabled: !!busy, onClick: () => act('install', p.id) }, '更新') : null, - el('button', { className: 'iwb-btn iwb-btn-sm', disabled: !!busy, onClick: () => act('uninstall', p.id) }, '移除'), - ), - ) - }) : el('div', { className: 'iwb-hint' }, kw ? '没有匹配的插件' : '还没有安装插件——从下面的市场里挑一个'), + el('div', { className: 'iwb-section-sub' }, '已安装'), + installedRows.length + ? el('div', { className: 'iwb-mk-grid' }, installedRows.map((p) => card(p, 'installed'))) + : el('div', { className: 'iwb-hint' }, kw ? '没有匹配的插件' : '还没有安装插件——从下面的市场里挑一个'), availRows.length ? el('div', { className: 'iwb-section-sub' }, '可安装(市场)') : null, - availRows.map((m) => el('div', { key: m.id, className: 'iwb-plugin-item' }, - el('div', { className: 'iwb-plugin-main' }, - el('div', { className: 'iwb-plugin-title' }, el('span', null, (m.name || m.id) + ' v' + m.version)), - m.desc ? el('div', { className: 'iwb-plugin-desc' }, m.desc) : null, - ), - el('div', { className: 'iwb-plugin-actions' }, - el('button', { className: 'iwb-btn iwb-btn-sm', disabled: !!busy, onClick: () => act('install', m.id) }, busy === m.id ? '处理中…' : '安装'), - ), - )), + availRows.length ? el('div', { className: 'iwb-mk-grid' }, availRows.map((m) => card(m, 'available'))) : null, restart ? el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-hint', style: { flex: '1 1 auto' } }, '需要重启应用才能生效'), el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => window.location.reload() }, '立即重启'), diff --git a/style.css b/style.css index a3014f0..5b306ce 100644 --- a/style.css +++ b/style.css @@ -1965,4 +1965,16 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-confirm-box { width: min(460px, calc(100vw - 48px)); background: var(--iwb-layer); color: var(--iwb-text); border-radius: 12px; padding: 18px 20px 14px; box-shadow: 0 12px 40px rgba(0,0,0,.28); } .iwb-confirm-title { font-weight: 650; font-size: 15px; margin-bottom: 8px; } .iwb-confirm-text { font-size: 13.5px; line-height: 1.65; color: var(--iwb-text2); white-space: pre-wrap; word-break: break-word; } -.iwb-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; } \ No newline at end of file +.iwb-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; } +/* 插件市场卡片(设置 → 插件 / 与 market.maqiart.eu.org 同一套视觉) */ +.iwb-mk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin: 4px 0 6px; } +.iwb-mk-card { border: 1px solid var(--iwb-border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 132px; } +.iwb-mk-head { display: flex; gap: 10px; align-items: center; } +.iwb-mk-avatar { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex: 0 0 36px; } +.iwb-mk-titles { min-width: 0; } +.iwb-mk-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; flex-wrap: wrap; } +.iwb-mk-sub { color: var(--iwb-text2); font-size: 12px; margin-top: 2px; } +.iwb-mk-desc { color: var(--iwb-text2); font-size: 12.5px; line-height: 1.5; flex: 1 1 auto; } +.iwb-mk-tags { display: flex; gap: 6px; flex-wrap: wrap; } +.iwb-mk-tag { padding: 1px 8px; border-radius: 999px; background: var(--iwb-layer2); color: var(--iwb-text2); font-size: 11px; } +.iwb-mk-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 2px; } \ No newline at end of file