- 后端:sys_config 存插件配置(识别前缀/生效站点/模板),平台管理员 GET/PUT /api/web/admin/extension; 插件读取 GET /api/web/extension/config(Redis 缓存 1 小时,保存即失效) - 前端:平台管理 → 插件配置页(只维护前缀,单号正则由服务端生成) - 插件:改为只拉取执行(每 5 分钟 + 手动同步),移除规则编辑/试跑/导入导出;安装包地址自动取最新发布 - 桌面端:工具 → 安装/卸载谷歌插件(生成 .reg + reg import 写 HKLM 策略,读注册表验证); 跨网下载改走云端中转;局域网探测补排障日志;自动更新按包类型取 md5Exe/sizeExe - 发布:npm run extension:publish(crx + updates.xml)、extension:zip(商店上传包), nginx 对 /download/extension/updates.xml 关缓存 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
395 lines
11 KiB
Vue
395 lines
11 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* 平台管理 · Chrome 插件配置
|
||
*
|
||
* 接口:`GET/PUT /api/web/admin/extension`(平台管理员)
|
||
*
|
||
* 这里只维护**能用一句话说清的东西**:
|
||
* - 单号前缀(`YT` / `SF` / `32`…):单号正则由服务端拼,页面只读预览;
|
||
* - 生效站点(插件允许在哪些域名工作,支持 `*.abc.com` 这种通配);
|
||
* - 跳转模板与桌面端安装包地址。
|
||
*
|
||
* 插件端不提供任何编辑/试跑/导入导出:它每小时拉一次 `GET /api/web/extension/config`,
|
||
* 版本号变了就换配置并重新扫描页面。
|
||
*/
|
||
import { onMounted, reactive, ref } from 'vue';
|
||
import AppLayout from '@/components/AppLayout.vue';
|
||
import { ApiError } from '@/api/client';
|
||
import { fetchExtensionConfig, saveExtensionConfig, type ExtensionConfig } from '@/api/extension';
|
||
import { formatTime } from '@/utils/format';
|
||
|
||
const loading = ref(false);
|
||
const saving = ref(false);
|
||
const error = ref('');
|
||
const ok = ref('');
|
||
|
||
/** 服务端算出来的只读信息 */
|
||
const meta = reactive({ version: 0, updatedAt: '' as string, pattern: '', flags: 'g' });
|
||
|
||
const form = reactive({
|
||
enabled: true,
|
||
hosts: [] as string[],
|
||
prefixes: [] as string[],
|
||
minDigits: 10,
|
||
maxDigits: 16,
|
||
urlTemplate: '',
|
||
appUrlTemplate: '',
|
||
downloadUrl: '',
|
||
});
|
||
|
||
const hostInput = ref('');
|
||
const prefixInput = ref('');
|
||
|
||
const patternPreview = ref('');
|
||
|
||
/** 错误文案带上 HTTP 状态码:404 = 后端没重启/没这个接口,422 = 校验不过,500 = 服务器异常 */
|
||
function describe(err: unknown, fallback: string): string {
|
||
if (err instanceof ApiError) return err.status ? `${err.message}(HTTP ${err.status})` : err.message;
|
||
return fallback;
|
||
}
|
||
|
||
function applyConfig(cfg: ExtensionConfig) {
|
||
form.enabled = cfg.enabled;
|
||
form.hosts = [...cfg.hosts];
|
||
form.prefixes = [...cfg.prefixes];
|
||
form.minDigits = cfg.minDigits;
|
||
form.maxDigits = cfg.maxDigits;
|
||
form.urlTemplate = cfg.urlTemplate;
|
||
form.appUrlTemplate = cfg.appUrlTemplate;
|
||
form.downloadUrl = cfg.downloadUrl || '';
|
||
meta.version = cfg.version;
|
||
meta.updatedAt = cfg.updatedAt || '';
|
||
meta.pattern = cfg.pattern;
|
||
meta.flags = cfg.flags;
|
||
patternPreview.value = cfg.pattern;
|
||
}
|
||
|
||
async function load() {
|
||
loading.value = true;
|
||
error.value = '';
|
||
try {
|
||
applyConfig(await fetchExtensionConfig());
|
||
} catch (err) {
|
||
error.value = describe(err, '加载失败');
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
function addHost() {
|
||
const value = hostInput.value.trim();
|
||
if (!value) return;
|
||
// 粘 URL 时只留主机名:https://abc.com/xx → abc.com
|
||
const cleaned = value.replace(/^[a-z]+:\/\//i, '').split('/')[0].trim().toLowerCase();
|
||
if (cleaned && !form.hosts.includes(cleaned)) form.hosts.push(cleaned);
|
||
hostInput.value = '';
|
||
}
|
||
|
||
function removeHost(index: number) {
|
||
form.hosts.splice(index, 1);
|
||
}
|
||
|
||
function addPrefix() {
|
||
// 支持一次粘一串:`YT SF JD` 或 `YT,SF,JD`
|
||
const parts = prefixInput.value.split(/[\s,,、]+/).map(item => item.trim().toUpperCase()).filter(Boolean);
|
||
for (const item of parts) {
|
||
if (!/^[A-Z0-9]{1,8}$/.test(item)) {
|
||
error.value = `前缀「${item}」不合法:只能是大写字母或数字,1~8 位`;
|
||
return;
|
||
}
|
||
if (!form.prefixes.includes(item)) form.prefixes.push(item);
|
||
}
|
||
prefixInput.value = '';
|
||
error.value = '';
|
||
}
|
||
|
||
function removePrefix(index: number) {
|
||
form.prefixes.splice(index, 1);
|
||
}
|
||
|
||
async function save() {
|
||
ok.value = '';
|
||
error.value = '';
|
||
|
||
if (form.prefixes.length === 0) {
|
||
error.value = '至少要有一个单号前缀';
|
||
return;
|
||
}
|
||
if (!(form.minDigits >= 4 && form.maxDigits <= 24) || form.minDigits > form.maxDigits) {
|
||
error.value = '单号位数要在 4~24 之间,且最小位数不能大于最大位数';
|
||
return;
|
||
}
|
||
if (!form.urlTemplate.includes('{code}')) {
|
||
error.value = '网页跳转模板必须包含 {code}';
|
||
return;
|
||
}
|
||
if (!form.appUrlTemplate.includes('{code}')) {
|
||
error.value = '唤起协议模板必须包含 {code}';
|
||
return;
|
||
}
|
||
|
||
saving.value = true;
|
||
try {
|
||
applyConfig(await saveExtensionConfig({
|
||
enabled: form.enabled,
|
||
hosts: form.hosts,
|
||
prefixes: form.prefixes,
|
||
minDigits: form.minDigits,
|
||
maxDigits: form.maxDigits,
|
||
urlTemplate: form.urlTemplate.trim(),
|
||
appUrlTemplate: form.appUrlTemplate.trim(),
|
||
downloadUrl: form.downloadUrl.trim(),
|
||
}));
|
||
ok.value = `已保存(v${meta.version})。插件每小时自动拉一次,也可以在插件里点「立即同步」。`;
|
||
} catch (err) {
|
||
error.value = describe(err, '保存失败');
|
||
} finally {
|
||
saving.value = false;
|
||
}
|
||
}
|
||
|
||
onMounted(load);
|
||
</script>
|
||
|
||
<template>
|
||
<!-- 表单页**不能用 fill**:fill 是给列表页的(内容区不滚动),长表单会被截断、保存按钮点不到 -->
|
||
<AppLayout>
|
||
<template #title>插件配置</template>
|
||
|
||
<div v-if="error" class="alert alert-error">{{ error }}</div>
|
||
<div v-if="ok" class="alert alert-ok">{{ ok }}</div>
|
||
|
||
<div class="card">
|
||
<h3>
|
||
Chrome 插件(单号注入)
|
||
<span class="badge badge-ok">v{{ meta.version }}</span>
|
||
<span v-if="meta.updatedAt" class="cell-sub inline">上次保存 {{ formatTime(meta.updatedAt) }}</span>
|
||
</h3>
|
||
<p class="hint">
|
||
插件**只拉取执行**:这里保存后,插件每小时自动同步一次(插件里也能点「立即同步」)。
|
||
插件端不提供正则编辑、试跑、导入导出。
|
||
</p>
|
||
|
||
<div class="row">
|
||
<label class="switch">
|
||
<input v-model="form.enabled" type="checkbox" />
|
||
<span>启用插件(关掉后所有站点都不识别单号)</span>
|
||
</label>
|
||
</div>
|
||
|
||
<h4>生效站点</h4>
|
||
<p class="hint">插件只在这些域名下工作,支持通配:<code>*.abc-wms.com</code>、<code>192.168.11.206</code>。留空 = 不限制。</p>
|
||
<div class="tag-box">
|
||
<span v-for="(host, index) in form.hosts" :key="host" class="tag">
|
||
{{ host }}
|
||
<button type="button" class="tag-x" @click="removeHost(index)">×</button>
|
||
</span>
|
||
<input
|
||
v-model="hostInput"
|
||
class="tag-input"
|
||
placeholder="输入域名后回车,例如 *.abc-wms.com"
|
||
@keyup.enter="addHost"
|
||
@blur="addHost"
|
||
/>
|
||
</div>
|
||
|
||
<h4>单号前缀</h4>
|
||
<p class="hint">
|
||
只维护前缀,单号正则由服务端生成(可一次粘贴多个:<code>YT SF JD</code>)。
|
||
前缀只能是大写字母或数字(<code>32</code> / <code>77</code> 这类数字前缀也支持)。
|
||
</p>
|
||
<div class="tag-box">
|
||
<span v-for="(prefix, index) in form.prefixes" :key="prefix" class="tag tag-prefix">
|
||
{{ prefix }}
|
||
<button type="button" class="tag-x" @click="removePrefix(index)">×</button>
|
||
</span>
|
||
<input
|
||
v-model="prefixInput"
|
||
class="tag-input"
|
||
placeholder="输入前缀后回车"
|
||
@keyup.enter="addPrefix"
|
||
@blur="addPrefix"
|
||
/>
|
||
</div>
|
||
|
||
<div class="row">
|
||
<label>单号位数</label>
|
||
<input v-model.number="form.minDigits" type="number" min="4" max="24" class="num" />
|
||
<span class="hint">~</span>
|
||
<input v-model.number="form.maxDigits" type="number" min="4" max="24" class="num" />
|
||
<span class="hint">位(默认 10 ~ 16)</span>
|
||
</div>
|
||
|
||
<div class="row">
|
||
<label>生成的单号正则</label>
|
||
<code class="pattern">{{ patternPreview || '(没有前缀,不会识别任何单号)' }}</code>
|
||
<span class="hint">只读 · flags={{ meta.flags }} · 插件端不展示</span>
|
||
</div>
|
||
|
||
<h4>跳转地址</h4>
|
||
<div class="field">
|
||
<label>网页模板</label>
|
||
<input v-model="form.urlTemplate" placeholder="http://localhost:7301/local?code={code}" />
|
||
<span class="hint">没装本机软件时点单号打开的页面,必须含 <code>{code}</code></span>
|
||
</div>
|
||
<div class="field">
|
||
<label>唤起协议</label>
|
||
<input v-model="form.appUrlTemplate" placeholder="yuncang://open?code={code}" />
|
||
<span class="hint">与桌面端注册的协议一致,必须含 <code>{code}</code></span>
|
||
</div>
|
||
<p class="hint">
|
||
桌面端安装包地址**不用配**:插件同步时会自己读 <code>/download/version.json</code>,
|
||
永远用最新发布版本(和网页顶栏「下载桌面端」是同一份)。
|
||
</p>
|
||
|
||
<div class="actions">
|
||
<button class="btn" :disabled="saving || loading" @click="save">{{ saving ? '保存中…' : '保存并下发' }}</button>
|
||
<button class="btn btn-plain" :disabled="saving || loading" @click="load">放弃修改</button>
|
||
</div>
|
||
</div>
|
||
</AppLayout>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.card h4 {
|
||
margin: 18px 0 6px;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.card h3 {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.cell-sub {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
font-weight: 400;
|
||
}
|
||
|
||
.inline {
|
||
margin-left: 4px;
|
||
}
|
||
|
||
.row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
margin: 10px 0;
|
||
}
|
||
|
||
.row label {
|
||
font-size: 13px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.switch {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.tag-box {
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
padding: 6px 8px;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
background: #fff;
|
||
min-height: 38px;
|
||
}
|
||
|
||
.tag {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
padding: 2px 6px 2px 8px;
|
||
border-radius: 6px;
|
||
background: #eef4ff;
|
||
color: #1d4ed8;
|
||
font-size: 12px;
|
||
font-family: var(--mono, ui-monospace, Consolas, monospace);
|
||
}
|
||
|
||
.tag-prefix {
|
||
background: #f1f5f9;
|
||
color: #0f172a;
|
||
}
|
||
|
||
.tag-x {
|
||
border: 0;
|
||
background: transparent;
|
||
color: inherit;
|
||
cursor: pointer;
|
||
font-size: 14px;
|
||
line-height: 1;
|
||
padding: 0 2px;
|
||
}
|
||
|
||
.tag-input {
|
||
flex: 1;
|
||
min-width: 180px;
|
||
border: 0;
|
||
outline: none;
|
||
font-size: 13px;
|
||
background: transparent;
|
||
}
|
||
|
||
.num {
|
||
width: 72px;
|
||
}
|
||
|
||
.pattern {
|
||
padding: 4px 8px;
|
||
border-radius: 6px;
|
||
background: #f8fafc;
|
||
border: 1px solid var(--border);
|
||
font-size: 12px;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.field {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
margin: 10px 0;
|
||
}
|
||
|
||
.field label {
|
||
font-size: 13px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.inline-row {
|
||
display: flex;
|
||
gap: 8px;
|
||
align-items: center;
|
||
}
|
||
|
||
.inline-row input {
|
||
flex: 1;
|
||
}
|
||
|
||
.hint code {
|
||
background: #f1f5f9;
|
||
padding: 0 3px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.actions {
|
||
position: sticky;
|
||
bottom: 0;
|
||
display: flex;
|
||
gap: 8px;
|
||
margin-top: 18px;
|
||
padding: 12px 0;
|
||
background: linear-gradient(to bottom, rgba(255, 255, 255, .85), #fff 40%);
|
||
}
|
||
</style>
|