oms/frontend/src/components/RecordPickerDialog.vue
yin 60a7db4085 refactor(frontend): 业务弹窗统一为 task-panel 面板,统一确认框样式
新增统一弹窗外壳与样式:
- 新增 TaskPanelDialog.vue(自绘标题+副标题 / 可滚动内容区 / 底部提示+操作区),
  默认点遮罩不关闭,内容区 max-height 内部滚动
- 新增 styles/task-panel.css 并在 main.ts 引入:section 分组、栅格字段行
  (88px 标签 + 控件)、提示条、表格区、底部按钮区(small / gap 6)
- 新增 ReasonPromptDialog.vue:替换 ElMessageBox.prompt,用于作废 / 取消 /
  手工标记推送失败等需填原因的操作,支持必填校验、多行、按钮类型与提示

页面改造(el-dialog / el-drawer → TaskPanelDialog + task-panel 栅格):
- 订单、发货单、状态面板、订单同步、入库单(列表/新建)、出库单(列表/新建)、
  库存单据、导出任务、导出按钮、商品查询、单据选择、商品(新增/编辑/批量导入,
  抽屉改弹窗)、店铺、店铺商品、组合商品、自定义快递、外接 API、
  外接打印平台/快递接口、组织(集团设置/下属公司)、权限角色组、主体、主体用户、
  商品属性、用户资料

交互与样式统一:
- ElMessageBox.confirm 统一挂 customClass="app-confirm-box"(App.vue 中定义按钮
  高度/内边距/间距),状态面板封装 ElMessageBox 别名统一注入
- 侧边栏 BasicLayout:加 contain: layout、菜单内部 overflow 滚动、
  关闭子菜单折叠过渡,避免展开时逐帧重排扩散到主内容区
2026-11-19 18:00:54 +08:00

162 lines
4.5 KiB
Vue

<script setup lang="ts">
/**
* 通用「列表选择」弹窗
*
* 用于批量操作需要指定目标(仓库 / 店铺)的场景:
* 打开后展示可选项列表(支持关键词过滤),选中一行后确认返回该行数据,
* 避免之前用输入框让用户手输名称/编码的交互。
*/
import { computed, ref, watch } from 'vue'
import DataTable from '@/components/DataTable.vue'
import TaskPanelDialog from '@/components/TaskPanelDialog.vue'
export interface PickerColumn {
prop: string
label: string
width?: number | string
minWidth?: number | string
}
const props = withDefaults(
defineProps<{
modelValue: boolean
title: string
/** 可选项列表(任意对象,按 columns 展示) */
options: Array<Record<string, unknown>>
columns: PickerColumn[]
/** 行唯一标识字段,默认 id */
valueKey?: string
/** 关键词过滤用字段,匹配任一即可 */
searchProps?: string[]
/** 当前已选中的值(打开时默认高亮) */
current?: string | number | null
confirmText?: string
emptyText?: string
}>(),
{
valueKey: 'id',
searchProps: () => [],
current: null,
confirmText: '确定',
emptyText: '暂无可选项',
},
)
const emit = defineEmits<{
'update:modelValue': [value: boolean]
confirm: [row: Record<string, unknown>]
}>()
const keyword = ref('')
const selected = ref<string | number | null>(null)
/** 关键词过滤后的列表 */
const filtered = computed(() => {
const text = keyword.value.trim().toLowerCase()
if (!text) return props.options
const keys = props.searchProps.length ? props.searchProps : [ props.valueKey ]
return props.options.filter(row =>
keys.some(key => String(row[key] ?? '').toLowerCase().includes(text)),
)
})
/** 已选中行的展示文案(取第一列) */
const selectedLabel = computed(() => {
if (selected.value == null) return '未选择'
const row = props.options.find(item => item[props.valueKey] === selected.value)
const key = props.columns[0]?.prop
return row && key ? String(row[key] ?? selected.value) : String(selected.value)
})
watch(
() => props.modelValue,
(open) => {
if (!open) return
keyword.value = ''
selected.value = props.current ?? null
},
)
function close() {
emit('update:modelValue', false)
}
function onRowClick(row: Record<string, unknown>) {
selected.value = row[props.valueKey] as string | number
}
function confirm() {
if (selected.value == null) return
const hit = props.options.find(row => row[props.valueKey] === selected.value)
if (!hit) return
emit('confirm', hit)
close()
}
</script>
<template>
<TaskPanelDialog
:model-value="modelValue"
:title="title"
subtitle="点击一行选择,或双击直接确认"
width="min(640px, 94vw)"
body-max-height="64vh"
@update:model-value="emit('update:modelValue', $event)"
>
<div class="task-panel__form">
<div class="picker-toolbar">
<el-input v-model="keyword" placeholder="输入关键词过滤" clearable style="width: 260px" />
<span class="picker-tip">共 {{ filtered.length }} 项可选项</span>
</div>
<DataTable
:data="filtered"
height="320"
highlight-current-row
@row-click="onRowClick"
@row-dblclick="(_row: Record<string, unknown>) => { onRowClick(_row); confirm() }"
>
<el-table-column label="" width="48" align="center">
<template #default="{ row }">
<el-radio :model-value="selected" :value="row[valueKey]" class="picker-radio">
<span />
</el-radio>
</template>
</el-table-column>
<el-table-column
v-for="col in columns"
:key="col.prop"
:prop="col.prop"
:label="col.label"
:width="col.width"
:min-width="col.minWidth"
show-overflow-tooltip
/>
<template #empty>
<span>{{ emptyText }}</span>
</template>
</DataTable>
</div>
<template #hint>已选中:{{ selectedLabel }}</template>
<template #actions>
<el-button size="small" @click="close">取消</el-button>
<el-button size="small" type="primary" :disabled="selected == null" @click="confirm">{{ confirmText }}</el-button>
</template>
</TaskPanelDialog>
</template>
<style scoped>
.picker-toolbar {
display: flex;
align-items: center;
gap: 12px;
}
.picker-tip {
font-size: 12px;
color: var(--el-text-color-secondary);
}
.picker-radio :deep(.el-radio__label) {
display: none;
}
</style>