Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01f4e4b55b | ||
|
|
b80fe6ab0f | ||
|
|
be2730fe13 | ||
|
|
282c46afd9 | ||
|
|
018bcdbf1a | ||
|
|
4a12aa9d4b | ||
|
|
787a83c550 | ||
|
|
2c7ebf4efc | ||
|
|
03dbd04452 | ||
|
|
d843dc46bf | ||
|
|
b93830c835 |
Binary file not shown.
@@ -2,16 +2,15 @@
|
||||
/**
|
||||
* 模型管理(issue #183 [E2] 前端接入注册表 API)
|
||||
* - 数据源:服务端注册表 API(list/promote/rollback 全走服务端,多用户共享);
|
||||
* - 降级:API 不可达时回退 localStorage(iaop.admin.models.v1,旧版 key),UI 标注「离线演示模式」;
|
||||
* - 降级:API 不可达时回退 localStorage(iaop.admin.models.v1),UI 标注「离线演示模式」;
|
||||
* - 迁移:检测 localStorage 有数据且服务端在线时提示导入。
|
||||
* - 表格:antd a-table(响应式 :data-source 直绑,规避 vxe-grid proxy 异步时序问题)。
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page, VbenButton } from '@vben/common-ui';
|
||||
import { message } from 'antdv-next';
|
||||
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
fetchRegistryModels,
|
||||
promoteModel,
|
||||
@@ -45,39 +44,25 @@ function saveLocal(list: LocalModel[]) {
|
||||
}
|
||||
}
|
||||
|
||||
const online = ref(false); // 注册表服务在线?
|
||||
const online = ref(false);
|
||||
const loading = ref(true);
|
||||
const models = ref<RegistryModel[]>([]);
|
||||
const migrateVisible = ref(false);
|
||||
|
||||
const gridOptions: VxeTableGridOptions = {
|
||||
rowConfig: { keyField: 'name' },
|
||||
height: 'auto',
|
||||
stripe: true,
|
||||
columns: [
|
||||
{ title: '模型', field: 'name', minWidth: 180 },
|
||||
{ title: '版本', field: 'version', width: 120 },
|
||||
{ title: '阶段', field: 'stage', width: 110, slots: { default: 'stage' } },
|
||||
{ title: '说明', field: 'description', minWidth: 220 },
|
||||
{ title: '操作', field: 'action', width: 170, slots: { default: 'action' } },
|
||||
],
|
||||
proxy: {
|
||||
query: async ({ page }) => ({
|
||||
items: models.value.slice((page.currentPage - 1) * page.pageSize, page.currentPage * page.pageSize),
|
||||
total: models.value.length,
|
||||
}),
|
||||
},
|
||||
};
|
||||
const columns = [
|
||||
{ title: '模型', dataIndex: 'name', key: 'name', width: 200 },
|
||||
{ title: '版本', dataIndex: 'version', key: 'version', width: 120 },
|
||||
{ title: '阶段', dataIndex: 'stage', key: 'stage', width: 110 },
|
||||
{ title: '说明', dataIndex: 'description', key: 'description' },
|
||||
{ title: '操作', key: 'action', width: 180 },
|
||||
];
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
|
||||
|
||||
async function refresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
const tagColor = (stage: string) =>
|
||||
stage === 'prod' ? 'green' : stage === 'staging' ? 'orange' : 'blue';
|
||||
|
||||
async function loadFromServer() {
|
||||
const resp = await fetchRegistryModels();
|
||||
models.value = resp.models;
|
||||
models.value = resp.models || [];
|
||||
}
|
||||
|
||||
async function init() {
|
||||
@@ -85,7 +70,7 @@ async function init() {
|
||||
try {
|
||||
await loadFromServer();
|
||||
online.value = true;
|
||||
// 迁移提示:本地有数据且服务端在线(且本地有服务端没有的模型)
|
||||
// 迁移提示:本地有服务端没有的模型
|
||||
const local = loadLocal();
|
||||
const serverNames = new Set(models.value.map((m) => `${m.name}@${m.version}`));
|
||||
const localExtra = local.filter((m) => !serverNames.has(`${m.name}@${m.version}`));
|
||||
@@ -101,7 +86,6 @@ async function init() {
|
||||
}));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,17 +94,14 @@ async function promote(m: RegistryModel) {
|
||||
try {
|
||||
await promoteModel(m.name, m.version);
|
||||
await loadFromServer();
|
||||
refresh();
|
||||
return;
|
||||
} catch (e) {
|
||||
message.error(`提升失败:${(e as Error).message}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 离线降级
|
||||
m.stage = m.stage === 'staging' ? 'prod' : m.stage === 'dev' ? 'staging' : m.stage;
|
||||
saveLocal(models.value.map((x) => ({ name: x.name, version: x.version, stage: x.stage, desc: x.description })));
|
||||
refresh();
|
||||
}
|
||||
|
||||
async function rollback(m: RegistryModel) {
|
||||
@@ -128,7 +109,6 @@ async function rollback(m: RegistryModel) {
|
||||
try {
|
||||
await rollbackModel(m.name, 'prod', m.version);
|
||||
await loadFromServer();
|
||||
refresh();
|
||||
return;
|
||||
} catch (e) {
|
||||
message.error(`回滚失败:${(e as Error).message}`);
|
||||
@@ -137,7 +117,6 @@ async function rollback(m: RegistryModel) {
|
||||
}
|
||||
m.stage = 'staging';
|
||||
saveLocal(models.value.map((x) => ({ name: x.name, version: x.version, stage: x.stage, desc: x.description })));
|
||||
refresh();
|
||||
}
|
||||
|
||||
async function migrateLocal() {
|
||||
@@ -153,7 +132,6 @@ async function migrateLocal() {
|
||||
}
|
||||
}
|
||||
await loadFromServer();
|
||||
refresh();
|
||||
migrateVisible.value = false;
|
||||
if (fail === 0) {
|
||||
localStorage.removeItem(MODELS_KEY);
|
||||
@@ -163,9 +141,6 @@ async function migrateLocal() {
|
||||
}
|
||||
}
|
||||
|
||||
const tagColor = (stage: string) =>
|
||||
stage === 'prod' ? 'green' : stage === 'staging' ? 'orange' : 'blue';
|
||||
|
||||
onMounted(init);
|
||||
</script>
|
||||
|
||||
@@ -175,15 +150,17 @@ onMounted(init);
|
||||
<a-tag :color="online ? 'green' : 'orange'">{{ online ? '● 服务端在线' : '● 离线演示模式' }}</a-tag>
|
||||
</template>
|
||||
<a-spin :spinning="loading">
|
||||
<Grid>
|
||||
<template #stage="{ row }">
|
||||
<a-tag :color="tagColor(row.stage)">{{ row.stage }}</a-tag>
|
||||
<a-table :data-source="models" :columns="columns" row-key="name" size="small" :pagination="{ pageSize: 10 }">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'stage'">
|
||||
<a-tag :color="tagColor(record.stage)">{{ record.stage }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<VbenButton size="small" :disabled="record.stage === 'prod'" @click="promote(record)">提升</VbenButton>
|
||||
<VbenButton size="small" variant="outline" :disabled="record.stage !== 'prod'" @click="rollback(record)">回滚</VbenButton>
|
||||
</template>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<VbenButton size="small" :disabled="row.stage === 'prod'" @click="promote(row)">提升</VbenButton>
|
||||
<VbenButton size="small" variant="outline" :disabled="row.stage !== 'prod'" @click="rollback(row)">回滚</VbenButton>
|
||||
</template>
|
||||
</Grid>
|
||||
</a-table>
|
||||
</a-spin>
|
||||
<a-modal v-model:open="migrateVisible" title="本地模型导入注册表"
|
||||
:on-ok="migrateLocal" ok-text="导入服务端" cancel-text="暂不">
|
||||
|
||||
@@ -30,6 +30,9 @@ const loading = ref(true);
|
||||
const errorMsg = ref('');
|
||||
|
||||
let timer = 0;
|
||||
// issue #189:记录注入 :root 的主题变量及其旧值,卸载时恢复,
|
||||
// 避免进过驾驶舱后全局 CSS 变量被残留值污染其他页面。
|
||||
const injectedTokens: Array<{ key: string; prev: string }> = [];
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -38,9 +41,12 @@ onMounted(async () => {
|
||||
widgets.value = (plan.widgets as unknown as PlanWidget[]) || [];
|
||||
// 主题 token 注入 CSS 变量(切模板 = 换一套变量)
|
||||
const root = document.documentElement;
|
||||
Object.entries((plan.themeTokens as Record<string, string>) || {}).forEach(([k, v]) =>
|
||||
root.style.setProperty(k, v),
|
||||
);
|
||||
Object.entries((plan.themeTokens as Record<string, string>) || {}).forEach(([k, v]) => {
|
||||
// 先记下旧值,卸载时恢复(getComputedStyle 取级联值;为空表示原本无)
|
||||
const prev = root.style.getPropertyValue(k);
|
||||
injectedTokens.push({ key: k, prev });
|
||||
root.style.setProperty(k, v);
|
||||
});
|
||||
timer = window.setInterval(refreshHealth, 2000);
|
||||
await refreshHealth();
|
||||
} catch {
|
||||
@@ -50,7 +56,19 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => window.clearInterval(timer));
|
||||
onUnmounted(() => {
|
||||
window.clearInterval(timer);
|
||||
// issue #189:清理本次注入到 :root 的主题变量,恢复旧值,杜绝全局污染
|
||||
const root = document.documentElement;
|
||||
for (const { key, prev } of injectedTokens) {
|
||||
if (prev) {
|
||||
root.style.setProperty(key, prev);
|
||||
} else {
|
||||
root.style.removeProperty(key);
|
||||
}
|
||||
}
|
||||
injectedTokens.length = 0;
|
||||
});
|
||||
|
||||
const inferOnline = ref(false);
|
||||
async function refreshHealth() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ref } from 'vue';
|
||||
import { Page, VbenButton } from '@vben/common-ui';
|
||||
import { BxsFile } from '@vben/icons';
|
||||
|
||||
import type { UploadChangeParam } from 'antdv-next';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
|
||||
@@ -33,14 +34,19 @@ const gridOptions: VxeTableGridOptions<Record<string, string>> = {
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
|
||||
|
||||
function onFile(e: Event) {
|
||||
const el = e.target as HTMLInputElement;
|
||||
const file = el.files?.[0];
|
||||
if (!file) return;
|
||||
function onFile(info: UploadChangeParam) {
|
||||
// a-upload 的 @change 载荷是 UploadChangeParam { file, fileList },
|
||||
// 在 :before-upload="() => false"(禁止自动上传)时文件对象在 file.originFileObj 上,
|
||||
// 不是 DOM Event,不能用 e.target.files(会抛 TypeError 导致无响应)。
|
||||
const { file } = info;
|
||||
// 仅在选中文件后处理一次(removed 状态时跳过,避免清空预览)
|
||||
if (file.status === 'removed') return;
|
||||
const raw = file.originFileObj ?? file;
|
||||
if (!raw) return;
|
||||
fileName.value = file.name;
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => parseCsv(String(reader.result || ''));
|
||||
reader.readAsText(file);
|
||||
reader.readAsText(raw as Blob);
|
||||
}
|
||||
|
||||
function parseCsv(text: string) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page, VbenButton } from '@vben/common-ui';
|
||||
import { MaterialSymbolsEdit } from '@vben/icons';
|
||||
import { message } from 'antdv-next';
|
||||
|
||||
const components = ref([
|
||||
{ type: 'process_view', title: '四状态工艺流程', enabled: true },
|
||||
@@ -24,7 +25,25 @@ const move = (i: number, dir: number) => {
|
||||
components.value[j] = t;
|
||||
};
|
||||
|
||||
const layoutJson = () => JSON.stringify({ widgets: components.value.filter((c) => c.enabled) }, null, 2);
|
||||
const layoutJson = computed(() =>
|
||||
JSON.stringify({ widgets: components.value.filter((c) => c.enabled) }, null, 2),
|
||||
);
|
||||
|
||||
// 发布布局:将布局 JSON 暂存到 localStorage(与版本发布页联动——
|
||||
// version.vue 发布时一并打包该布局),注册表服务落地后可改为注册到服务端。
|
||||
const LAYOUT_STORAGE_KEY = 'iaop.studio.layout.v1';
|
||||
const lastPublishedAt = ref('');
|
||||
|
||||
async function publishLayout() {
|
||||
const payload = layoutJson.value;
|
||||
try {
|
||||
localStorage.setItem(LAYOUT_STORAGE_KEY, payload);
|
||||
lastPublishedAt.value = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
||||
message.success('布局已发布(暂存本地,将在「版本发布」时一并打包)');
|
||||
} catch {
|
||||
message.error('布局发布失败:本地存储不可用');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -41,8 +60,9 @@ const layoutJson = () => JSON.stringify({ widgets: components.value.filter((c) =
|
||||
</a-list>
|
||||
</a-card>
|
||||
<a-card title="导出布局 JSON(由驾驶舱渲染)" :bordered="false" class="col">
|
||||
<pre class="json-body">{{ layoutJson() }}</pre>
|
||||
<VbenButton variant="solid"><MaterialSymbolsEdit class="size-4" />发布布局(版本发布见「版本发布」页)</VbenButton>
|
||||
<pre class="json-body">{{ layoutJson }}</pre>
|
||||
<a-tag v-if="lastPublishedAt" color="green">最近发布:{{ lastPublishedAt }}</a-tag>
|
||||
<VbenButton variant="solid" @click="publishLayout"><MaterialSymbolsEdit class="size-4" />发布布局(版本发布见「版本发布」页)</VbenButton>
|
||||
</a-card>
|
||||
</div>
|
||||
</Page>
|
||||
|
||||
@@ -2,16 +2,15 @@
|
||||
/**
|
||||
* 模板版本发布(issue #183 [E2]):发布 = 注册新版本到服务端注册表;
|
||||
* 注册表离线时降级本地记录并标注。
|
||||
* 表格:antd a-table(响应式直绑,规避 vxe-grid proxy 时序)。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { Page, VbenButton } from '@vben/common-ui';
|
||||
import { MaterialSymbolsAdd } from '@vben/icons';
|
||||
import { message } from 'antdv-next';
|
||||
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { registerModel } from '#/api/iaop/registry';
|
||||
import { fetchRegistryModels, registerModel } from '#/api/iaop/registry';
|
||||
|
||||
interface VersionRow {
|
||||
version: string;
|
||||
@@ -28,38 +27,41 @@ const rows = ref<VersionRow[]>([
|
||||
{ version: 'v0.8.0', stage: 'dev', time: '2026-08-03 09:00', author: 'bot_dev1', note: '布局资产初版' },
|
||||
]);
|
||||
|
||||
const gridOptions: VxeTableGridOptions = {
|
||||
rowConfig: { keyField: 'version' },
|
||||
height: 'auto',
|
||||
stripe: true,
|
||||
columns: [
|
||||
{ title: '版本', field: 'version', width: 110 },
|
||||
{ title: '阶段', field: 'stage', width: 100, slots: { default: 'stage' } },
|
||||
{ title: '时间', field: 'time', width: 170 },
|
||||
{ title: '作者', field: 'author', width: 110 },
|
||||
{ title: '说明', field: 'note', minWidth: 200 },
|
||||
],
|
||||
proxy: {
|
||||
query: async ({ page }) => ({
|
||||
items: rows.value.slice((page.currentPage - 1) * page.pageSize, page.currentPage * page.pageSize),
|
||||
total: rows.value.length,
|
||||
}),
|
||||
},
|
||||
};
|
||||
const columns = [
|
||||
{ title: '版本', dataIndex: 'version', key: 'version', width: 120 },
|
||||
{ title: '阶段', dataIndex: 'stage', key: 'stage', width: 110 },
|
||||
{ title: '时间', dataIndex: 'time', key: 'time', width: 180 },
|
||||
{ title: '作者', dataIndex: 'author', key: 'author', width: 120 },
|
||||
{ title: '说明', dataIndex: 'note', key: 'note' },
|
||||
];
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
|
||||
const tagColor = (stage: string) =>
|
||||
stage === 'prod' ? 'green' : stage === 'staging' ? 'orange' : 'blue';
|
||||
|
||||
onMounted(async () => {
|
||||
// 初始探测服务端在线状态(注册表可达 → 在线)
|
||||
try {
|
||||
await fetchRegistryModels();
|
||||
online.value = true;
|
||||
} catch {
|
||||
online.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
async function publish() {
|
||||
const version = `v${Date.now() % 100000}`;
|
||||
const name = 'iaop-template';
|
||||
// 一并打包「驾驶舱布局编排」页发布的布局(issue #187:发布布局与版本发布联动)
|
||||
const layoutJson = localStorage.getItem('iaop.studio.layout.v1') || '';
|
||||
const description = layoutJson ? '手动发布(前端,含布局)' : '手动发布(前端)';
|
||||
try {
|
||||
// 发布 = 注册新版本到服务端注册表(staging)
|
||||
await registerModel({ name, version, stage: 'staging', description: '手动发布(前端)' });
|
||||
// 发布 = 注册新版本到服务端注册表(staging);description 含布局标记(issue #187 联动)
|
||||
await registerModel({ name, version, stage: 'staging', description });
|
||||
online.value = true;
|
||||
rows.value.unshift({
|
||||
version, stage: 'staging',
|
||||
time: new Date().toISOString().slice(0, 16).replace('T', ' '),
|
||||
author: 'admin', note: '已发布到服务端注册表',
|
||||
author: 'admin', note: layoutJson ? '已发布到服务端注册表(含布局)' : '已发布到服务端注册表',
|
||||
});
|
||||
message.success(`已注册 ${name}@${version}(staging)`);
|
||||
} catch {
|
||||
@@ -71,7 +73,6 @@ async function publish() {
|
||||
});
|
||||
message.warning('注册表服务不可达:本次发布仅本地记录');
|
||||
}
|
||||
gridApi.query();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -80,10 +81,12 @@ async function publish() {
|
||||
<template #extra>
|
||||
<VbenButton variant="solid" @click="publish"><MaterialSymbolsAdd class="size-4" />发布新版本</VbenButton>
|
||||
</template>
|
||||
<Grid>
|
||||
<template #stage="{ row }">
|
||||
<a-tag :color="row.stage === 'prod' ? 'green' : row.stage === 'staging' ? 'orange' : 'blue'">{{ row.stage }}</a-tag>
|
||||
<a-table :data-source="rows" :columns="columns" row-key="version" size="small" :pagination="false">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'stage'">
|
||||
<a-tag :color="tagColor(record.stage)">{{ record.stage }}</a-tag>
|
||||
</template>
|
||||
</template>
|
||||
</Grid>
|
||||
</a-table>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user