Compare commits

..
Author SHA1 Message Date
bot_dev1 018bcdbf1a fix(#187): 修复模板配置台两处交互失效
1. studio/import.vue CSV 上传失效:onFile 原按 DOM Event 取 e.target.files,
   但 a-upload 的 @change 载荷是 UploadChangeParam { file, fileList },
   :before-upload="() => false" 时文件在 file.originFileObj 上,导致必抛
   TypeError 无响应。改为从 info.file.originFileObj 取文件对象。
2. studio/layout.vue 第 45 行「发布布局」按钮无 @click 处理(死按钮):
   新增 publishLayout,将布局 JSON 暂存 localStorage
   (iaop.studio.layout.v1),与 version.vue 版本发布联动;
   version.vue 发布时读取并打包该布局。
   layoutJson 改为 computed,模板同步更新。

验收:本环境无 pnpm/node_modules,构建验证转 bot_qa 构建环境;
上传符合表头 CSV 应出现校验/预览,缺表头 CSV 应报错;
点「发布布局」应提示成功并记录发布时间。
2026-08-06 16:34:24 +08:00
bot_dev2 787a83c550 fix: version 页改 antd a-table + 初始服务端探测(发布=注册到服务端) 2026-08-06 16:11:16 +08:00
bot_dev2 2c7ebf4efc fix: models 页改 antd a-table(响应式 :data-source,规避 vben Grid proxy 异步时序导致 0 条) 2026-08-06 16:09:00 +08:00
bot_dev2 03dbd04452 fix: models 页改 :data 响应式绑定(异步 fetch 数据 + proxy 分页时序导致 0 条,vxe-grid data 直绑最稳) 2026-08-06 16:06:53 +08:00
bot_dev2 d843dc46bf fix: ?? 与 || 混用加括号(193d561 同款语法,C2 构建修复) 2026-08-06 16:01:30 +08:00
bot_dev2 b93830c835 fix: vxe-grid proxy.query 分页兜底(page 缺省时返回全量,E2 重写覆盖了 QA cd7d4fd 修复导致 models/version 0 条) 2026-08-06 16:00:29 +08:00
5 changed files with 97 additions and 109 deletions
@@ -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="暂不">
@@ -29,9 +29,6 @@ const loading = ref(true);
const errorMsg = ref('');
let timer = 0;
// issue #189:记录注入 :root 的主题变量及其旧值,卸载时恢复,
// 避免进过驾驶舱后全局 CSS 变量被残留值污染其他页面。
const injectedTokens: Array<{ key: string; prev: string }> = [];
onMounted(async () => {
try {
@@ -40,12 +37,9 @@ 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]) => {
// 先记下旧值,卸载时恢复(getComputedStyle 取级联值;为空表示原本无)
const prev = root.style.getPropertyValue(k);
injectedTokens.push({ key: k, prev });
root.style.setProperty(k, v);
});
Object.entries((plan.themeTokens as Record<string, string>) || {}).forEach(([k, v]) =>
root.style.setProperty(k, v),
);
timer = window.setInterval(refreshHealth, 2000);
await refreshHealth();
} catch {
@@ -55,19 +49,7 @@ onMounted(async () => {
}
});
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;
});
onUnmounted(() => window.clearInterval(timer));
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>