diff --git a/src/views/storage/stockcheck/config/template-config.ts b/src/views/storage/stockcheck/config/template-config.ts index 764fb13a..8076a3db 100644 --- a/src/views/storage/stockcheck/config/template-config.ts +++ b/src/views/storage/stockcheck/config/template-config.ts @@ -944,9 +944,12 @@ export function buildWhereConditions(rawConditions: Record): Record // 十、工具栏按钮系统 // ============================================================ // 按钮分为三类: -// common — 公共按钮(刷新、导出) +// common — 公共按钮(刷新) +// basic — 基础操作(字段设置、隐藏/显示详情) // function — 功能按钮(打开表单/确认窗口) -// basic — 基础操作(字段设置、隐藏详情) +// +// ⚠️ 工具栏的渲染顺序 = 本对象键的书写顺序(getTabToolbarButtons 用 Object.values,保序), +// 调整按钮排列必须直接改这里的顺序。 export interface ToolbarButtonConfig { key: string @@ -976,13 +979,30 @@ export const TOOLBAR_BUTTONS: Record = { loadingKey: 'loading', action: 'loadData' }, + // ===== 基础操作 ===== + columnConfig: { + key: 'columnConfig', + label: '字段设置', + category: 'basic', + size: 'small', + action: 'openColumnConfigPanel' + }, + toggleDetail: { + key: 'toggleDetail', + label: '显示详情', + category: 'basic', + dynamicLabelKey: 'detailToggleLabel', + size: 'small', + action: 'toggleDetailVisible' + }, // ===== 功能按钮 ===== create: { key: 'create', label: '新建盘点', category: 'function', type: 'primary', - plain: false, + // 与「快速创建」保持同款样式(白底 + 主色描边),不再用实心主色块 + plain: true, size: 'small', action: 'openCreateCheck' }, @@ -1002,7 +1022,9 @@ export const TOOLBAR_BUTTONS: Record = { }, /** * 导出选中(stock.check.export):导出表格中勾选的盘点单(单次上限 50)。 - * 无勾选时不置灰,点击后提示先勾选。 + * 无勾选时不置灰,点击后提示先勾选; + * ⚠️ 未勾选时由 index.vue 的 currentToolbarButtons 把 type 降级为 default, + * 避免 primary 样式的浅蓝底色(勾选后恢复 primary + plain)。 */ export: { key: 'export', @@ -1028,22 +1050,6 @@ export const TOOLBAR_BUTTONS: Record = { loadingKey: 'batchDeleteLoading', disabledKey: 'noSelection', action: 'handleBatchDelete' - }, - // ===== 基础操作 ===== - columnConfig: { - key: 'columnConfig', - label: '字段设置', - category: 'basic', - size: 'small', - action: 'openColumnConfigPanel' - }, - toggleDetail: { - key: 'toggleDetail', - label: '显示详情', - category: 'basic', - dynamicLabelKey: 'detailToggleLabel', - size: 'small', - action: 'toggleDetailVisible' } } diff --git a/src/views/storage/stockcheck/index.vue b/src/views/storage/stockcheck/index.vue index 52404be4..fad34c99 100644 --- a/src/views/storage/stockcheck/index.vue +++ b/src/views/storage/stockcheck/index.vue @@ -397,7 +397,8 @@ const currentToolbarButtons = computed(() => { key: btn.key, label: btn.label, size: btn.size, - type: btn.type, + // 「导出选中」在未勾选数据时不显示主色(避免 primary 的浅蓝底色),勾选后恢复 primary + type: btn.key === 'export' && selectedRows.value.length === 0 ? '' : btn.type, plain: btn.plain, loadingKey: btn.loadingKey, disabledKey: btn.disabledKey, diff --git a/src/views/system/setting/role/components/ColumnCellRenderer.vue b/src/views/system/setting/role/components/ColumnCellRenderer.vue new file mode 100644 index 00000000..d0202130 --- /dev/null +++ b/src/views/system/setting/role/components/ColumnCellRenderer.vue @@ -0,0 +1,73 @@ + + + + + + diff --git a/src/views/system/setting/role/components/OperationCellRenderer.vue b/src/views/system/setting/role/components/OperationCellRenderer.vue new file mode 100644 index 00000000..bf9aaed4 --- /dev/null +++ b/src/views/system/setting/role/components/OperationCellRenderer.vue @@ -0,0 +1,110 @@ + + + + + + diff --git a/src/views/system/setting/role/components/RoleTreePanel.vue b/src/views/system/setting/role/components/RoleTreePanel.vue new file mode 100644 index 00000000..7fc10605 --- /dev/null +++ b/src/views/system/setting/role/components/RoleTreePanel.vue @@ -0,0 +1,208 @@ + + + + + + diff --git a/src/views/system/setting/role/config/template-config.ts b/src/views/system/setting/role/config/template-config.ts new file mode 100644 index 00000000..716988c1 --- /dev/null +++ b/src/views/system/setting/role/config/template-config.ts @@ -0,0 +1,400 @@ +/** + * 角色管理(system/setting/role)— 配置驱动页面(views/mode 模板 v2) + * + * ===== 与模板的差异(有意为之)===== + * 1. 左侧面板不是 ScanBox,而是「角色架构树」(RoleTreePanel): + * 本页筛选项只有「关键词 + 包含已停用」,放在工具栏右侧;角色层级用树更直观。 + * 因此配置里**完全没有 ScanBox 相关字段**(FieldDefinition.scanBox / scanBoxFieldKeys / scanBoxFields 均已移除)。 + * 2. 不配置 api.list:`setting.role.list` 返回的是**角色树**(不是分页列表), + * 需要「先展平 → 再重建树 → 前端按树节点/关键词过滤 → 前端分页」, + * 这套逻辑放在 index.vue 里,比塞进 parseListResponse 更清楚。 + * 3. **不用「显示/隐藏详情」,也没有详情面板**(用户明确要求): + * 故无 DetailPanel / COMPONENT_REGISTRY / detailSections,表格区占满右侧全高。 + * 4. **不使用「字段设置」**:工具栏无该按钮,且 upperTableDefaults.enableColumnConfig = false。 + * + * ===== 页面结构 ===== + * ┌────────────┬──────────────────────────────────────────────┐ + * │ 角色架构树 │ OrderToolbarButtonGroup + 关键词/包含已停用 │ + * │(220px) │ ┌──────────────────────────────────────────┐│ + * │ │ │ UpperTable(角色列表 + 操作列,占满全高) ││ + * │ │ └──────────────────────────────────────────┘│ + * └────────────┴──────────────────────────────────────────────┘ + * + * 接口:setting.role(src/api/setting.role/role.ts) + * list / add / update / delete(批量停用) / permission(角色权限树) + */ + +// 注:本页是「左侧角色树 + 右侧单列表」页: +// · 没有顶部标签栏 → 不保留模板的 PAGE_CONFIG; +// · 没有详情面板 → 不保留 COMPONENT_REGISTRY / DetailPanel(组件文件已一并删除)。 + +// ============================================================ +// 一、FieldDefinition — 字段定义 +// ============================================================ +export interface FieldDefinition { + key: string + label: string + table: { + minWidth?: number + width?: number + fixed?: 'left' | 'right' | boolean + align?: 'left' | 'center' | 'right' + sortable?: boolean + showOverflowTooltip?: boolean + copyAction?: 'copy' | 'copyQr' + copyValue?: (row: any) => any + } | null + slot: { + type: 'tag' | 'text' | 'default' | 'operation' + tagType?: string | Record + tagResolver?: string + translateField?: string + format?: 'datetime' | 'date' + } | null +} + +// ============================================================ +// 二、VALUE_MAPS / 翻译 / 格式化工具 +// ============================================================ +export const VALUE_MAPS: Record> = { + /** 角色状态:后端 1=启用 0=停用 */ + status: { + '1': '启用', + '0': '停用', + '启用': '启用', + '停用': '停用' + } +} + +/** 翻译 value → label(无映射时原样返回,空值返回 —) */ +export function translate(field: string, value: any): string { + const map = VALUE_MAPS[field] + if (!map) return value === undefined || value === null || value === '' ? '—' : String(value) + return map[String(value)] ?? String(value ?? '—') +} + +/** + * 把后端各种时间形态归一化为 Date,识别不了返回 null。 + * + * 兼容: + * - 数字/纯数字串:秒(10 位) / 毫秒(13 位) / 微秒(16 位) / 纳秒(19 位),含小数串 + * - 紧凑串:'20261004'(YYYYMMDD)/ '20261004120000'(YYYYMMDDHHmmss) + * - 日期时间串:'2026-10-04'、'2026-10-04 12:00:00'、ISO + * - Date 实例 + */ +function toDate(value: any): Date | null { + if (value === undefined || value === null || value === '') return null + if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value + + const text = String(value).trim() + + // 紧凑日期串(PHP 常见):8 位 = YYYYMMDD,14 位 = YYYYMMDDHHmmss + if (/^\d{8}$/.test(text)) { + const d = new Date(`${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}T00:00:00`) + return Number.isNaN(d.getTime()) ? null : d + } + if (/^\d{14}$/.test(text)) { + const d = new Date( + `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}T${text.slice(8, 10)}:${text.slice(10, 12)}:${text.slice(12, 14)}` + ) + return Number.isNaN(d.getTime()) ? null : d + } + + // 时间戳(整数或小数) + if (/^-?\d+(\.\d+)?$/.test(text)) { + let num = Number(text) + if (!Number.isFinite(num) || num <= 0) return null + while (num > 1e14) num /= 1000 + if (num < 1e10) num *= 1000 + const d = new Date(num) + return Number.isNaN(d.getTime()) ? null : d + } + + const d = new Date(text) + return Number.isNaN(d.getTime()) ? null : d +} + +/** 格式化时间 → YYYY-MM-DD HH:mm:ss */ +export function formatTime(value: any): string { + if (value === undefined || value === null || value === '') return '—' + const d = toDate(value) + if (!d) return String(value) + const pad = (n: number) => String(n).padStart(2, '0') + return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}` +} + +/** 格式化日期 → YYYY-MM-DD */ +export function formatDate(value: any): string { + if (value === undefined || value === null || value === '') return '—' + const d = toDate(value) + if (!d) return String(value) + const pad = (n: number) => String(n).padStart(2, '0') + return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` +} + +/** 业务成功判定:与 utils/request 的 SUCCESS_CODES(200/20000/1/0)对齐 */ +export function isApiSuccess(res: any): boolean { + if (!res || typeof res !== 'object') return false + return [200, 20000, 1, 0].includes(Number(res.code)) +} + +// ============================================================ +// 三、TAG_RESOLVERS — 状态文字颜色解析器 +// ============================================================ +// 轻量状态文字(ut-status-text)替代 el-tag,减少组件数 +export const TAG_RESOLVERS: Record string> = { + /** 角色状态:1/启用 = 绿,0/停用 = 红 */ + resolveRoleStatusTag(v) { + if (v === 1 || v === '1' || v === '启用' || v === true) return 'success' + if (v === 0 || v === '0' || v === '停用' || v === false) return 'danger' + return 'info' + }, + /** 是否系统内置角色 */ + resolveRoleSystemTag(v) { + return v === 1 || v === '1' || v === true ? 'warning' : 'info' + } +} + +// ============================================================ +// 四、FIELD_DICT — 角色字段表 +// ============================================================ +export const FIELD_DICT: Record = { + role_name: { + key: 'role_name', + label: '角色名称', + table: { minWidth: 180, fixed: 'left', showOverflowTooltip: true }, + slot: null + }, + /** + * 归属层级(虚拟字段):由 index.vue 在构建列表行时写入 `parent_path` + * (= getRolePath(pid),顶级角色为「顶级层级」),后端不返回该字段。 + */ + parent_path: { + key: 'parent_path', + label: '归属层级', + table: { minWidth: 180, showOverflowTooltip: true }, + slot: { type: 'text' } + }, + role_code: { + key: 'role_code', + label: '角色编码', + table: { minWidth: 170, copyAction: 'copy', showOverflowTooltip: true }, + slot: null + }, + description: { + key: 'description', + label: '描述', + table: { minWidth: 220, showOverflowTooltip: true }, + slot: { type: 'text' } + }, + status: { + key: 'status', + label: '状态', + table: { width: 90, align: 'center' }, + slot: { type: 'tag', tagResolver: 'resolveRoleStatusTag', translateField: 'status' } + }, + /** 操作列(虚拟字段,仅用于表格列渲染) */ + operation: { + key: 'operation', + label: '操作', + table: { width: 200, fixed: 'right', align: 'center' }, + slot: { type: 'operation' } + } +} + +// ============================================================ +// 五、列 / 操作按钮配置 +// ============================================================ +export interface ColumnSlotConfig { + type: 'tag' | 'text' | 'default' | 'operation' + tagType?: string | Record + tagResolver?: string + translateField?: string + /** 时间/日期列格式化:datetime=YYYY-MM-DD HH:mm:ss,date=YYYY-MM-DD */ + format?: 'datetime' | 'date' +} + +export interface OperationButtonConfig { + key: string + label: string + type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | '' + /** 本页只支持 action(form 弹窗机制已随 COMPONENT_REGISTRY 一并移除) */ + actionType: 'action' + disabledOnField?: string + /** 按行数据决定是否渲染该按钮(返回 false 隐藏) */ + visibleWhen?: (row: Record) => boolean + /** 按行数据动态覆盖按钮文案(返回空串/undefined 时回退 label) */ + labelWhen?: (row: Record) => string + confirmMessage?: string + confirmTitle?: string + confirmType?: 'warning' | 'danger' | 'info' + confirmButtonText?: string +} + +// ============================================================ +// 六、TabPageRawConfig / TabPageConfig +// ============================================================ +export interface TabPageRawConfig { + name: string + label: string + /** 表格需要的列 key 列表 */ + tableColumnKeys: string[] + upperTableDefaults: { + title: string + enableColumnConfig?: boolean + showIndex?: boolean + showSelection?: boolean + emptyText?: string + } + operationButtons?: OperationButtonConfig[] +} + +export interface TabPageConfig { + name: string + label: string + upperTable: { + title: string + enableColumnConfig: boolean + showIndex: boolean + showSelection: boolean + emptyText: string + columns: Record[] + } + columnSlots: Record + operationButtons?: OperationButtonConfig[] +} + +// ============================================================ +// 七、resolveTabConfig — RawConfig → 完整配置 +// ============================================================ +export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig { + // 表格列 + const columns: Record[] = [] + for (const key of raw.tableColumnKeys) { + const def = FIELD_DICT[key] + if (!def || !def.table) continue + columns.push({ prop: def.key, label: def.label, ...def.table }) + } + + // 列插槽 + // 注:未显式配置 slot 的普通列也注册为「纯文本」插槽,统一交给 ColumnCellRenderer 渲染, + // 否则 UpperTable 直接输出原值,null/空串会显示成空白(需求:没有的显示 —)。 + // 带 copyAction 的列保持默认渲染,避免丢失点击复制。 + const columnSlots: Record = {} + for (const key of raw.tableColumnKeys) { + const def = FIELD_DICT[key] + if (!def || !def.table) continue + if (def.slot) { + columnSlots[def.key] = { ...def.slot } + continue + } + if (def.table.copyAction) continue + columnSlots[def.key] = { type: 'text' } + } + + return { + name: raw.name, + label: raw.label, + upperTable: { + title: raw.upperTableDefaults.title, + enableColumnConfig: raw.upperTableDefaults.enableColumnConfig ?? true, + showIndex: raw.upperTableDefaults.showIndex ?? true, + showSelection: raw.upperTableDefaults.showSelection ?? false, + emptyText: raw.upperTableDefaults.emptyText ?? '暂无数据', + columns + }, + columnSlots, + operationButtons: raw.operationButtons + } +} + +// ============================================================ +// 八、工具栏按钮系统 +// ============================================================ +// category 与 OrderToolbarButtonGroup.resolveButtonStyle 的取值保持一致: +// refresh — 蓝底白字;setting — 白底灰边;action — 白底 + 主色描边蓝字;cancel — 白底 + 红边红字 +// +// 本页只保留三个按钮(刷新 / 新增角色 / 批量删除): +// ⚠️ 按需求不使用「字段设置」与「显示/隐藏详情」功能 —— +// 字段设置:不仅去掉按钮,`upperTableDefaults.enableColumnConfig` 也置为 false +// (UpperTable 内部据此完全跳过列配置的读取/持久化,不是只隐藏入口); +// 显示/隐藏详情:本页**没有详情面板**(DetailPanel 已删),表格占满右侧全高, +// 所以也没有开关按钮。 + +export interface ToolbarButtonConfig { + key: string + label: string + category: 'refresh' | 'setting' | 'action' | 'cancel' + size?: '' | 'default' | 'small' | 'large' + type?: '' | 'primary' | 'success' | 'warning' | 'info' | 'danger' + plain?: boolean + loadingKey?: string + disabledKey?: string + action: string + dynamicLabelKey?: string + onlyForTabs?: string[] + buttonType?: 'default' | 'dropdown' + dropdownOptions?: Array<{ label: string; action: string; divided?: boolean }> + formKey?: string +} + +export const TOOLBAR_BUTTONS: Record = { + refresh: { + key: 'refresh', + label: '刷新', + category: 'refresh', + size: 'small', + loadingKey: 'loading', + action: 'loadData' + }, + create: { + key: 'create', + label: '新增角色', + category: 'action', + size: 'small', + action: 'openCreateRole' + }, + batchDelete: { + key: 'batchDelete', + label: '批量删除', + category: 'cancel', + size: 'small', + loadingKey: 'batchDeleteLoading', + disabledKey: 'noSelection', + action: 'handleBatchDelete' + } +} + +/** 按标签页名称获取工具栏按钮列表 */ +export function getTabToolbarButtons(tabName: string): ToolbarButtonConfig[] { + return Object.values(TOOLBAR_BUTTONS).filter((btn) => { + if (btn.onlyForTabs && !btn.onlyForTabs.includes(tabName)) return false + return true + }) +} + +// ============================================================ +// 九、标签页注册表(单页:仅一个「角色列表」) +// ============================================================ +export const tabPages: TabPageRawConfig[] = [ + { + name: 'all', + label: '角色列表', + tableColumnKeys: ['role_name', 'parent_path', 'role_code', 'description', 'status', 'operation'], + upperTableDefaults: { + title: '角色列表', + // 不使用「字段设置」:这里置 false 后 UpperTable 不再提供/持久化列配置 + enableColumnConfig: false, + showIndex: true, + showSelection: true, + emptyText: '暂无角色数据' + }, + // ⚠️ 不配置 api.list:setting.role.list 返回角色树,展平/重建树/过滤/分页都在 index.vue + // ⚠️ 删除按钮不配 confirmMessage:确认框在 index.vue 里弹(文案要带角色名 + 提示已停用) + operationButtons: [ + { key: 'edit', label: '编辑', actionType: 'action', type: 'primary' }, + { key: 'permission', label: '权限', actionType: 'action', type: 'warning' }, + { key: 'delete', label: '删除', actionType: 'action', type: 'danger' } + ] + } +] diff --git a/src/views/system/setting/role/index.vue b/src/views/system/setting/role/index.vue index f7893cee..d4255b63 100644 --- a/src/views/system/setting/role/index.vue +++ b/src/views/system/setting/role/index.vue @@ -1,718 +1,577 @@ -