|
|
@@ -0,0 +1,100 @@
|
|
|
+/**
|
|
|
+ * 九宫格首页模块卡「呈现样式」注册表。
|
|
|
+ *
|
|
|
+ * 扩展入口:新增一种样式只需要
|
|
|
+ * 1) 写一个实现 <props: moduleCode/cells/loading> 的 Vue SFC 放到同目录;
|
|
|
+ * 2) 在下面 HOME_CARD_STYLES 里加一条 { code, label, description, thumbnail, component }。
|
|
|
+ * s0.vue 的样式选择器与 HomeModuleKpiCard.vue 的动态派发都会自动读取。
|
|
|
+ * 约束:
|
|
|
+ * - code 与后端 AdoSmartOpsHomeModule.LayoutPattern 值保持一致(snake_case,<=32 字符);
|
|
|
+ * - thumbnail 为内嵌 SVG 字符串,viewBox 统一为 "0 0 80 48",黑底半透明浅线;
|
|
|
+ * - 默认样式(DEFAULT_STYLE_CODE)必须存在于注册表中。
|
|
|
+ */
|
|
|
+import type { Component } from 'vue';
|
|
|
+import HomeCardGridView from './HomeCardGridView.vue';
|
|
|
+import HomeCardTableView from './HomeCardTableView.vue';
|
|
|
+
|
|
|
+export interface HomeCardStyleDef {
|
|
|
+ /** 后端 LayoutPattern 值(snake_case) */
|
|
|
+ code: string;
|
|
|
+ /** 建模页下拉/单选显示的短标签 */
|
|
|
+ label: string;
|
|
|
+ /** 说明文案(hover/tooltip 可用) */
|
|
|
+ description?: string;
|
|
|
+ /** 内嵌 SVG 缩略图字符串(viewBox 0 0 80 48) */
|
|
|
+ thumbnail: string;
|
|
|
+ /** 对应渲染组件 */
|
|
|
+ component: Component;
|
|
|
+}
|
|
|
+
|
|
|
+export const DEFAULT_STYLE_CODE = 'card_grid';
|
|
|
+
|
|
|
+const SVG_CARD_GRID = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 48" width="100%" height="100%">
|
|
|
+ <rect x="0.5" y="0.5" width="79" height="47" rx="4" fill="rgba(30,41,59,0.55)" stroke="rgba(100,116,139,0.7)"/>
|
|
|
+ <rect x="6" y="6" width="32" height="16" rx="2" fill="rgba(96,165,250,0.18)" stroke="rgba(96,165,250,0.55)"/>
|
|
|
+ <rect x="42" y="6" width="32" height="16" rx="2" fill="rgba(94,234,212,0.18)" stroke="rgba(94,234,212,0.55)"/>
|
|
|
+ <rect x="6" y="26" width="32" height="16" rx="2" fill="rgba(250,204,21,0.18)" stroke="rgba(250,204,21,0.55)"/>
|
|
|
+ <rect x="42" y="26" width="32" height="16" rx="2" fill="rgba(251,146,60,0.18)" stroke="rgba(251,146,60,0.55)"/>
|
|
|
+ <line x1="12" y1="12" x2="20" y2="12" stroke="#cbd5e1" stroke-width="1"/>
|
|
|
+ <line x1="12" y1="16" x2="30" y2="16" stroke="#e2e8f0" stroke-width="2"/>
|
|
|
+ <line x1="48" y1="12" x2="56" y2="12" stroke="#cbd5e1" stroke-width="1"/>
|
|
|
+ <line x1="48" y1="16" x2="66" y2="16" stroke="#e2e8f0" stroke-width="2"/>
|
|
|
+ <line x1="12" y1="32" x2="20" y2="32" stroke="#cbd5e1" stroke-width="1"/>
|
|
|
+ <line x1="12" y1="36" x2="30" y2="36" stroke="#e2e8f0" stroke-width="2"/>
|
|
|
+ <line x1="48" y1="32" x2="56" y2="32" stroke="#cbd5e1" stroke-width="1"/>
|
|
|
+ <line x1="48" y1="36" x2="66" y2="36" stroke="#e2e8f0" stroke-width="2"/>
|
|
|
+</svg>`;
|
|
|
+
|
|
|
+const SVG_TABLE_LIST = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 48" width="100%" height="100%">
|
|
|
+ <rect x="0.5" y="0.5" width="79" height="47" rx="4" fill="rgba(30,41,59,0.55)" stroke="rgba(100,116,139,0.7)"/>
|
|
|
+ <rect x="4" y="6" width="72" height="9" rx="1.5" fill="rgba(96,165,250,0.22)"/>
|
|
|
+ <line x1="28" y1="6" x2="28" y2="42" stroke="rgba(100,116,139,0.45)" stroke-width="0.6"/>
|
|
|
+ <line x1="44" y1="6" x2="44" y2="42" stroke="rgba(100,116,139,0.45)" stroke-width="0.6"/>
|
|
|
+ <line x1="60" y1="6" x2="60" y2="42" stroke="rgba(100,116,139,0.45)" stroke-width="0.6"/>
|
|
|
+ <line x1="4" y1="15" x2="76" y2="15" stroke="rgba(100,116,139,0.55)" stroke-width="0.6"/>
|
|
|
+ <line x1="4" y1="24" x2="76" y2="24" stroke="rgba(100,116,139,0.35)" stroke-width="0.6"/>
|
|
|
+ <line x1="4" y1="33" x2="76" y2="33" stroke="rgba(100,116,139,0.35)" stroke-width="0.6"/>
|
|
|
+ <line x1="7" y1="10.5" x2="25" y2="10.5" stroke="#e2e8f0" stroke-width="1"/>
|
|
|
+ <line x1="31" y1="10.5" x2="40" y2="10.5" stroke="#e2e8f0" stroke-width="1"/>
|
|
|
+ <line x1="47" y1="10.5" x2="56" y2="10.5" stroke="#e2e8f0" stroke-width="1"/>
|
|
|
+ <line x1="63" y1="10.5" x2="73" y2="10.5" stroke="#e2e8f0" stroke-width="1"/>
|
|
|
+ <line x1="7" y1="19.5" x2="25" y2="19.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="31" y1="19.5" x2="40" y2="19.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="47" y1="19.5" x2="56" y2="19.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="63" y1="19.5" x2="73" y2="19.5" stroke="#fb923c" stroke-width="0.8"/>
|
|
|
+ <line x1="7" y1="28.5" x2="25" y2="28.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="31" y1="28.5" x2="40" y2="28.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="47" y1="28.5" x2="56" y2="28.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="63" y1="28.5" x2="73" y2="28.5" stroke="#4ade80" stroke-width="0.8"/>
|
|
|
+ <line x1="7" y1="37.5" x2="25" y2="37.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="31" y1="37.5" x2="40" y2="37.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="47" y1="37.5" x2="56" y2="37.5" stroke="#cbd5e1" stroke-width="0.8"/>
|
|
|
+ <line x1="63" y1="37.5" x2="73" y2="37.5" stroke="#facc15" stroke-width="0.8"/>
|
|
|
+</svg>`;
|
|
|
+
|
|
|
+/** 全局样式注册表。新增样式在此追加一条即可。 */
|
|
|
+export const HOME_CARD_STYLES: HomeCardStyleDef[] = [
|
|
|
+ {
|
|
|
+ code: 'card_grid',
|
|
|
+ label: '卡片样式',
|
|
|
+ description: 'KPI 方格布局(S4 首页样式)。适合 ≤8 个一级指标,视觉突出。',
|
|
|
+ thumbnail: SVG_CARD_GRID,
|
|
|
+ component: HomeCardGridView,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'table_list',
|
|
|
+ label: '表格样式',
|
|
|
+ description: '表格列表(指标 / 目标 / 当前 / 期量差)。适合较多指标或数据对比场景,无溢出风险。',
|
|
|
+ thumbnail: SVG_TABLE_LIST,
|
|
|
+ component: HomeCardTableView,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+/** 按 code 取样式定义;找不到时回落到默认样式,保证永不返回 undefined。 */
|
|
|
+export function getStyleDef(code: string | null | undefined): HomeCardStyleDef {
|
|
|
+ const key = String(code || '').toLowerCase();
|
|
|
+ return (
|
|
|
+ HOME_CARD_STYLES.find((s) => s.code === key) ||
|
|
|
+ HOME_CARD_STYLES.find((s) => s.code === DEFAULT_STYLE_CODE)!
|
|
|
+ );
|
|
|
+}
|