1
This commit is contained in:
parent
c2060e4d57
commit
98ddaf83a7
@ -2,7 +2,7 @@
|
|||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="visibleProxy"
|
v-model="visibleProxy"
|
||||||
title="批量打印(平台数据)"
|
title="批量打印(平台数据)"
|
||||||
width="min(1100px, 94vw)"
|
width="min(980px, 92vw)"
|
||||||
align-center
|
align-center
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
append-to-body
|
append-to-body
|
||||||
@ -12,89 +12,96 @@
|
|||||||
<el-alert type="error" :closable="false" :title="errorMessage" />
|
<el-alert type="error" :closable="false" :title="errorMessage" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="payload" ref="printRootRef" class="wave-print-body">
|
<div v-else-if="payload" ref="printRootRef" class="wave-print-body">
|
||||||
<p class="wave-print-api-hint">接口:<code>order.print.getWavePlatformPrintData</code></p>
|
<div class="wave-print-settings-bar">
|
||||||
<div class="wave-print-meta">
|
<el-select
|
||||||
<span>仓库 ID:<code>{{ requestMeta?.warehouse_id ?? '—' }}</code></span>
|
v-model="printSettings.station"
|
||||||
<span>请求波次 ID 数:<code>{{ requestMeta?.wave_ids?.length ?? 0 }}</code></span>
|
placeholder="请选择打印台"
|
||||||
<span>返回通过过滤波次数:<code>{{ (payload.wave_ids || []).length }}</code></span>
|
size="small"
|
||||||
|
:loading="stationLoading"
|
||||||
|
@change="handleStationChange"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in stationOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.computer_id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-alert v-if="filterHint" type="warning" :closable="false" show-icon class="wave-print-hint">
|
<div class="wave-print-meta">
|
||||||
{{ filterHint }}
|
<span>仓库:<code>{{ requestMeta?.warehouse_id ?? '—' }}</code></span>
|
||||||
</el-alert>
|
<span>请求波次:<code>{{ requestMeta?.wave_ids?.length ?? 0 }}</code></span>
|
||||||
|
<span>返回波次:<code>{{ waveGroupList.length }}</code></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<section class="wave-print-section">
|
<section class="wave-print-section">
|
||||||
<h4 class="wave-print-section__title">汇总 summary</h4>
|
<h4 class="wave-print-section__title">波次 / 平台列表</h4>
|
||||||
<el-descriptions v-if="summaryEntries.length" :column="2" border size="small">
|
<div v-if="hasWaveGroups" class="wave-group-list">
|
||||||
<el-descriptions-item v-for="[k, v] in summaryEntries" :key="k" :label="String(k)">
|
<article v-for="wave in waveGroupList" :key="wave.waveKey" class="wave-group-card">
|
||||||
{{ formatPrimitive(v) }}
|
<header class="wave-group-card__header">
|
||||||
</el-descriptions-item>
|
<div class="wave-group-card__title">
|
||||||
</el-descriptions>
|
<span>波次:</span>
|
||||||
<p v-else class="wave-print-muted">(无 summary 或为空对象)</p>
|
<code>{{ wave.wave_no }}</code>
|
||||||
</section>
|
<span class="wave-group-card__sep">|</span>
|
||||||
|
<span>ID:</span>
|
||||||
|
<code>{{ wave.wave_id }}</code>
|
||||||
|
</div>
|
||||||
|
<div class="wave-group-card__meta">
|
||||||
|
<el-tag size="small" type="info">平台 {{ wave.platforms.length }}</el-tag>
|
||||||
|
<el-tag size="small" type="success">订单 {{ wave.order_count }}</el-tag>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
<section class="wave-print-section">
|
<div v-if="wave.platforms.length" class="wave-platform-list">
|
||||||
<h4 class="wave-print-section__title">通过过滤的波次 ID wave_ids</h4>
|
<article v-for="platform in wave.platforms" :key="platform.platformKey" class="wave-platform-card">
|
||||||
<div v-if="waveIdTags.length" class="wave-print-tags">
|
<div class="wave-platform-card__header">
|
||||||
<el-tag v-for="(id, i) in waveIdTags" :key="`${id}-${i}`" size="small" class="wave-print-tag">
|
<div class="wave-platform-card__title">
|
||||||
{{ id }}
|
{{ platform.platform_name }}
|
||||||
</el-tag>
|
<span class="wave-platform-card__code">{{ platform.platform }}</span>
|
||||||
|
</div>
|
||||||
|
<el-tag size="small" type="warning">订单 {{ platform.order_count }}</el-tag>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<p v-else class="wave-print-muted">(该波次无平台数据)</p>
|
||||||
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<p v-else class="wave-print-muted">(无 wave_ids)</p>
|
<p v-else class="wave-print-muted wave-print-section__sub">(无 waveGroups)</p>
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="wave-print-section">
|
|
||||||
<h4 class="wave-print-section__title">主结构 waveGroups(波次 → 平台 → 订单)</h4>
|
|
||||||
<pre class="wave-print-json wave-print-json--tall">{{ waveGroupsJson }}</pre>
|
|
||||||
<p v-if="!hasWaveGroups" class="wave-print-muted wave-print-section__sub">
|
|
||||||
(无 waveGroups;新接口主字段为空时可查看下方兼容字段 order_list / platform_groups)
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="wave-print-section">
|
|
||||||
<h4 class="wave-print-section__title">兼容:按平台分组 platform_groups</h4>
|
|
||||||
<pre class="wave-print-json wave-print-json--tall">{{ platformGroupsJson }}</pre>
|
|
||||||
<p v-if="!hasPlatformGroups" class="wave-print-muted wave-print-section__sub">(无 platform_groups)</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="wave-print-section wave-print-section--table">
|
|
||||||
<h4 class="wave-print-section__title">兼容:逐单明细 order_list</h4>
|
|
||||||
<p class="wave-print-muted wave-print-section__sub">列为后端返回首条记录字段动态展开(至多 16 列)。</p>
|
|
||||||
<el-table v-if="orderListRows.length" :data="orderListRows" border size="small" row-key="__key" max-height="420">
|
|
||||||
<el-table-column
|
|
||||||
v-for="col in orderListColumns"
|
|
||||||
:key="col"
|
|
||||||
:label="col"
|
|
||||||
min-width="112"
|
|
||||||
show-overflow-tooltip
|
|
||||||
>
|
|
||||||
<template #default="scope">
|
|
||||||
{{ formatCell((scope.row as Record<string, unknown>)[col]) }}
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
<p v-else class="wave-print-muted">(无 order_list)</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section v-if="payload.ext && Object.keys(payload.ext).length" class="wave-print-section">
|
|
||||||
<h4 class="wave-print-section__title">扩展 ext</h4>
|
|
||||||
<pre class="wave-print-json">{{ JSON.stringify(payload.ext, null, 2) }}</pre>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="wave-print-muted">(无数据)</div>
|
<div v-else class="wave-print-muted">(无数据)</div>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="visibleProxy = false">关闭</el-button>
|
<el-button @click="visibleProxy = false">关闭</el-button>
|
||||||
<el-button :disabled="!payload" @click="copyJson">复制完整 JSON</el-button>
|
<el-button type="primary" :loading="stationPrinting" :disabled="!payload" @click="printToStation">打印到打印台</el-button>
|
||||||
<el-button type="primary" :disabled="!payload" @click="printReport">浏览器打印</el-button>
|
<el-button :disabled="!payload" @click="printReport">浏览器打印</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref } from 'vue'
|
import { computed, reactive, ref, watch } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
||||||
|
import * as stationApi from '@/api/print/print'
|
||||||
|
|
||||||
|
const WAVE_PRINT_STATION_STORAGE_KEY = 'wave_platform_print_station_id'
|
||||||
|
|
||||||
|
type AnyRecord = Record<string, unknown>
|
||||||
|
type WaveGroupPlatform = {
|
||||||
|
platformKey: string
|
||||||
|
platform: string
|
||||||
|
platform_name: string
|
||||||
|
order_count: number
|
||||||
|
}
|
||||||
|
type WaveGroupView = {
|
||||||
|
waveKey: string
|
||||||
|
wave_id: string
|
||||||
|
wave_no: string
|
||||||
|
order_count: number
|
||||||
|
platforms: WaveGroupPlatform[]
|
||||||
|
}
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: boolean
|
modelValue: boolean
|
||||||
@ -108,128 +115,194 @@ const emit = defineEmits<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const printRootRef = ref<HTMLElement | null>(null)
|
const printRootRef = ref<HTMLElement | null>(null)
|
||||||
|
const stationOptions = ref<any[]>([])
|
||||||
|
const stationLoading = ref(false)
|
||||||
|
const stationPrinting = ref(false)
|
||||||
|
const printSettings = reactive({
|
||||||
|
station: '' as string | number
|
||||||
|
})
|
||||||
|
|
||||||
const visibleProxy = computed({
|
const visibleProxy = computed({
|
||||||
get: () => props.modelValue,
|
get: () => props.modelValue,
|
||||||
set: (v: boolean) => emit('update:modelValue', v)
|
set: (v: boolean) => emit('update:modelValue', v)
|
||||||
})
|
})
|
||||||
|
|
||||||
const summaryEntries = computed(() => {
|
watch(
|
||||||
const s = props.payload?.summary
|
() => props.modelValue,
|
||||||
if (!s || typeof s !== 'object') return [] as [string, unknown][]
|
(visible) => {
|
||||||
return Object.entries(s)
|
if (visible) {
|
||||||
})
|
void loadStationOptions()
|
||||||
|
|
||||||
const filterHint = computed(() => {
|
|
||||||
const s = props.payload?.summary
|
|
||||||
if (!s || typeof s !== 'object') return ''
|
|
||||||
const o = s as Record<string, unknown>
|
|
||||||
const parts: string[] = []
|
|
||||||
const pickStr = (v: unknown) => (typeof v === 'string' && v.trim() ? v.trim() : '')
|
|
||||||
const msg = pickStr(o.message) || pickStr(o.msg) || pickStr(o.hint)
|
|
||||||
if (msg) parts.push(msg)
|
|
||||||
|
|
||||||
const candidates = [
|
|
||||||
['requested_wave_count', '请求波次数'],
|
|
||||||
['accepted_wave_count', '接受波次数'],
|
|
||||||
['filtered_wave_count', '过滤波次数'],
|
|
||||||
['skipped_wave_count', '跳过波次数'],
|
|
||||||
['order_total', '订单合计']
|
|
||||||
] as const
|
|
||||||
for (const [key, label] of candidates) {
|
|
||||||
if (o[key] !== undefined && o[key] !== null && o[key] !== '') {
|
|
||||||
parts.push(`${label}:${formatPrimitive(o[key])}`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Array.isArray(o.filtered_wave_ids) && o.filtered_wave_ids.length) {
|
)
|
||||||
parts.push(`已过滤波次 ID:${JSON.stringify(o.filtered_wave_ids)}`)
|
|
||||||
}
|
|
||||||
if (Array.isArray(o.skipped_wave_ids) && o.skipped_wave_ids.length) {
|
|
||||||
parts.push(`跳过波次 ID:${JSON.stringify(o.skipped_wave_ids)}`)
|
|
||||||
}
|
|
||||||
return parts.filter(Boolean).join(';')
|
|
||||||
})
|
|
||||||
|
|
||||||
const waveIdTags = computed(() => {
|
const waveGroupList = computed<WaveGroupView[]>(() => {
|
||||||
const ids = props.payload?.wave_ids
|
const groups = props.payload?.waveGroups
|
||||||
if (!Array.isArray(ids)) return []
|
if (!Array.isArray(groups)) return []
|
||||||
return ids.map((x) => String(x))
|
return groups
|
||||||
|
.filter((x) => x && typeof x === 'object')
|
||||||
|
.map((rawWave, waveIndex) => {
|
||||||
|
const wave = rawWave as AnyRecord
|
||||||
|
const wave_id = toText(wave.wave_id, `w-${waveIndex + 1}`)
|
||||||
|
const wave_no = toText(wave.wave_no, '—')
|
||||||
|
const rawPlatforms = Array.isArray(wave.platforms) ? wave.platforms : []
|
||||||
|
const platforms = rawPlatforms
|
||||||
|
.filter((x) => x && typeof x === 'object')
|
||||||
|
.map((rawPlatform, platformIndex) => {
|
||||||
|
const platform = rawPlatform as AnyRecord
|
||||||
|
const platformCode = toText(platform.platform, `platform-${platformIndex + 1}`)
|
||||||
|
const platformName = toText(platform.platform_name, platformCode)
|
||||||
|
return {
|
||||||
|
platformKey: `${wave_id}-${platformCode}-${platformIndex}`,
|
||||||
|
platform: platformCode,
|
||||||
|
platform_name: platformName,
|
||||||
|
order_count: toNum(platform.order_count, 0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
waveKey: `${wave_id}-${wave_no}-${waveIndex}`,
|
||||||
|
wave_id,
|
||||||
|
wave_no,
|
||||||
|
order_count: toNum(wave.order_count, platforms.reduce((sum, p) => sum + p.order_count, 0)),
|
||||||
|
platforms
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const hasWaveGroups = computed(() => {
|
const hasWaveGroups = computed(() => {
|
||||||
const g = props.payload?.waveGroups
|
return waveGroupList.value.length > 0
|
||||||
return Array.isArray(g) && g.length > 0
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const waveGroupsJson = computed(() => {
|
function toText(v: unknown, fallback = '—'): string {
|
||||||
const g = props.payload?.waveGroups
|
if (v === null || v === undefined) return fallback
|
||||||
try {
|
const s = String(v).trim()
|
||||||
return JSON.stringify(g ?? [], null, 2)
|
return s || fallback
|
||||||
} catch {
|
|
||||||
return String(g)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const hasPlatformGroups = computed(() => {
|
|
||||||
const g = props.payload?.platform_groups
|
|
||||||
return Array.isArray(g) && g.length > 0
|
|
||||||
})
|
|
||||||
|
|
||||||
const platformGroupsJson = computed(() => {
|
|
||||||
const g = props.payload?.platform_groups
|
|
||||||
try {
|
|
||||||
return JSON.stringify(g ?? [], null, 2)
|
|
||||||
} catch {
|
|
||||||
return String(g)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const orderListRows = computed(() => {
|
|
||||||
const list = props.payload?.order_list
|
|
||||||
if (!Array.isArray(list)) return []
|
|
||||||
return list.map((raw, idx) => {
|
|
||||||
const row = raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : {}
|
|
||||||
return { ...row, __key: `o-${idx}` }
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const orderListColumns = computed(() => {
|
|
||||||
const first = orderListRows.value[0]
|
|
||||||
if (!first) return []
|
|
||||||
return Object.keys(first).filter((k) => k !== '__key').slice(0, 16)
|
|
||||||
})
|
|
||||||
|
|
||||||
function formatPrimitive(v: unknown): string {
|
|
||||||
if (v === null || v === undefined) return '—'
|
|
||||||
if (typeof v === 'object') return JSON.stringify(v)
|
|
||||||
return String(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCell(v: unknown): string {
|
function toNum(v: unknown, fallback = 0): number {
|
||||||
if (v === null || v === undefined) return '—'
|
const n = Number(v)
|
||||||
if (typeof v === 'object') return JSON.stringify(v)
|
return Number.isFinite(n) ? n : fallback
|
||||||
return String(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildExportJson(): string {
|
function isApiSuccess(res: any) {
|
||||||
const p = props.payload
|
return !!res && (res.code === 0 || res.code === 200)
|
||||||
const body: WavePlatformPrintDataPayload = {
|
|
||||||
summary: p?.summary,
|
|
||||||
wave_ids: p?.wave_ids,
|
|
||||||
waveGroups: p?.waveGroups,
|
|
||||||
platform_groups: p?.platform_groups,
|
|
||||||
order_list: p?.order_list,
|
|
||||||
ext: p?.ext
|
|
||||||
}
|
|
||||||
return JSON.stringify(body, null, 2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyJson() {
|
async function loadStationOptions() {
|
||||||
|
stationLoading.value = true
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(buildExportJson())
|
const stations: any = await stationApi.getList({ page: 1, pageSize: 100, where: {} })
|
||||||
ElMessage.success('已复制平台打印数据 JSON')
|
if (!isApiSuccess(stations)) {
|
||||||
|
stationOptions.value = []
|
||||||
|
ElMessage.warning('加载打印台列表失败')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const rawList: any[] = stations.data?.list || stations.data || []
|
||||||
|
stationOptions.value = rawList.map((item: any) => ({
|
||||||
|
id: item.id ?? item.computer_id,
|
||||||
|
computer_id: item.computer_id ?? item.computerId ?? item.id,
|
||||||
|
name: item.name || item.label || String(item.computer_id ?? item.computerId ?? item.id)
|
||||||
|
}))
|
||||||
|
|
||||||
|
// 初始化默认打印台:优先本地存储,其次当前值,最后回退到首项
|
||||||
|
const savedStation = getSavedStationId()
|
||||||
|
const currentStationId = String(printSettings.station || '').trim()
|
||||||
|
const hasSaved = !!savedStation && stationOptions.value.some((item) => String(item.computer_id) === savedStation)
|
||||||
|
const hasCurrent = !!currentStationId && stationOptions.value.some((item) => String(item.computer_id) === currentStationId)
|
||||||
|
|
||||||
|
if (!stationOptions.value.length) {
|
||||||
|
printSettings.station = ''
|
||||||
|
clearSavedStationId()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSaved) {
|
||||||
|
printSettings.station = savedStation
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (hasCurrent) {
|
||||||
|
saveStationId(String(currentStationId))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallbackStation = String(stationOptions.value[0].computer_id)
|
||||||
|
printSettings.station = fallbackStation
|
||||||
|
saveStationId(fallbackStation)
|
||||||
} catch {
|
} catch {
|
||||||
ElMessage.error('复制失败,请手动选择内容复制')
|
stationOptions.value = []
|
||||||
|
ElMessage.warning('加载打印台列表失败')
|
||||||
|
} finally {
|
||||||
|
stationLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleStationChange(val: string | number) {
|
||||||
|
const stationId = String(val || '').trim()
|
||||||
|
if (!stationId) {
|
||||||
|
clearSavedStationId()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
saveStationId(stationId)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function printToStation() {
|
||||||
|
if (!printSettings.station) {
|
||||||
|
ElMessage.warning('请选择打印台')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!props.payload) {
|
||||||
|
ElMessage.warning('暂无可打印数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stationPrinting.value = true
|
||||||
|
try {
|
||||||
|
const printPayload = {
|
||||||
|
type: 'express',
|
||||||
|
computerId: String(printSettings.station),
|
||||||
|
data: {
|
||||||
|
waveGroups: props.payload.waveGroups || [],
|
||||||
|
wave_ids: props.payload.wave_ids || [],
|
||||||
|
summary: props.payload.summary || {},
|
||||||
|
request_meta: props.requestMeta || {}
|
||||||
|
},
|
||||||
|
timestamp: String(Date.now()),
|
||||||
|
count: 1
|
||||||
|
}
|
||||||
|
const res: any = await stationApi.sendPrint(printPayload as any)
|
||||||
|
if (res && (res.code === 0 || res.code === 200 || res.flag === 'success' || res.status === 'success')) {
|
||||||
|
ElMessage.success(res?.message || '已发送到打印台')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ElMessage.error(res?.msg || res?.message || '发送打印失败')
|
||||||
|
} catch {
|
||||||
|
ElMessage.error('发送打印失败,请检查打印台连接状态')
|
||||||
|
} finally {
|
||||||
|
stationPrinting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSavedStationId() {
|
||||||
|
try {
|
||||||
|
return String(localStorage.getItem(WAVE_PRINT_STATION_STORAGE_KEY) || '').trim()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveStationId(stationId: string) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(WAVE_PRINT_STATION_STORAGE_KEY, stationId)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSavedStationId() {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem(WAVE_PRINT_STATION_STORAGE_KEY)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,17 +322,13 @@ function printReport() {
|
|||||||
h1 { font-size: 18px; margin: 0 0 12px; }
|
h1 { font-size: 18px; margin: 0 0 12px; }
|
||||||
.meta { font-size: 13px; margin-bottom: 12px; color: #606266; }
|
.meta { font-size: 13px; margin-bottom: 12px; color: #606266; }
|
||||||
.meta code { background: #f4f4f5; padding: 2px 6px; border-radius: 4px; }
|
.meta code { background: #f4f4f5; padding: 2px 6px; border-radius: 4px; }
|
||||||
h4 { margin: 16px 0 8px; font-size: 14px; }
|
h4 { margin: 10px 0 6px; font-size: 13px; }
|
||||||
pre { background: #f5f7fa; padding: 10px; overflow: auto; font-size: 11px; white-space: pre-wrap; }
|
|
||||||
.hint { background: #fdf6ec; border: 1px solid #faecd8; padding: 8px 10px; margin-bottom: 12px; font-size: 12px; color: #e6a23c; }
|
|
||||||
`
|
`
|
||||||
const hintHtml = filterHint.value ? `<div class="hint">${escapeHtml(filterHint.value)}</div>` : ''
|
|
||||||
w.document.write(`<!DOCTYPE html><html><head><meta charset="utf-8"/><title>平台打印数据</title><style>${styles}</style></head><body>`)
|
w.document.write(`<!DOCTYPE html><html><head><meta charset="utf-8"/><title>平台打印数据</title><style>${styles}</style></head><body>`)
|
||||||
w.document.write(`<h1>批量打印(平台数据)</h1>`)
|
w.document.write(`<h1>批量打印(平台数据)</h1>`)
|
||||||
w.document.write(
|
w.document.write(
|
||||||
`<div class="meta">仓库 ID:<code>${escapeHtml(String(props.requestMeta?.warehouse_id ?? ''))}</code>;请求波次 ID 数:<code>${props.requestMeta?.wave_ids?.length ?? 0}</code></div>`
|
`<div class="meta">仓库 ID:<code>${escapeHtml(String(props.requestMeta?.warehouse_id ?? ''))}</code>;请求波次 ID 数:<code>${props.requestMeta?.wave_ids?.length ?? 0}</code></div>`
|
||||||
)
|
)
|
||||||
w.document.write(hintHtml)
|
|
||||||
w.document.write(el.innerHTML)
|
w.document.write(el.innerHTML)
|
||||||
w.document.write('</body></html>')
|
w.document.write('</body></html>')
|
||||||
w.document.close()
|
w.document.close()
|
||||||
@ -277,29 +346,26 @@ function escapeHtml(s: string) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.wave-print-api-hint {
|
.wave-platform-print-dialog :deep(.el-dialog) {
|
||||||
margin: 0 0 10px;
|
max-height: 80vh;
|
||||||
font-size: 13px;
|
display: flex;
|
||||||
color: #606266;
|
flex-direction: column;
|
||||||
|
|
||||||
code {
|
|
||||||
font-size: 12px;
|
|
||||||
background: #f4f4f5;
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.wave-print-error {
|
.wave-platform-print-dialog :deep(.el-dialog__body) {
|
||||||
padding: 8px 0 16px;
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wave-print-meta {
|
.wave-print-meta {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 16px;
|
gap: 10px;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 8px;
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
color: #606266;
|
color: #606266;
|
||||||
|
|
||||||
code {
|
code {
|
||||||
@ -310,16 +376,112 @@ function escapeHtml(s: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.wave-print-hint {
|
.wave-print-settings-bar {
|
||||||
margin-bottom: 12px;
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
|
||||||
|
.el-select {
|
||||||
|
min-width: 240px;
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.wave-print-body {
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wave-print-error {
|
||||||
|
padding: 6px 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wave-group-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wave-group-card {
|
||||||
|
border: 1px solid #e4e7ed;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 7px 10px;
|
||||||
|
background: #f8fafc;
|
||||||
|
border-bottom: 1px solid #ebeef5;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #303133;
|
||||||
|
|
||||||
|
code {
|
||||||
|
background: #f4f4f5;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__sep {
|
||||||
|
color: #c0c4cc;
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__meta {
|
||||||
|
display: inline-flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.wave-platform-list {
|
||||||
|
padding: 8px 10px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wave-platform-card {
|
||||||
|
border: 1px solid #ebeef5;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 6px 8px;
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #303133;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__code {
|
||||||
|
margin-left: 6px;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.wave-print-section {
|
.wave-print-section {
|
||||||
margin-bottom: 18px;
|
margin-bottom: 18px;
|
||||||
|
|
||||||
&__title {
|
&__title {
|
||||||
margin: 0 0 8px;
|
margin: 0 0 6px;
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #303133;
|
color: #303133;
|
||||||
}
|
}
|
||||||
@ -331,32 +493,8 @@ function escapeHtml(s: string) {
|
|||||||
|
|
||||||
.wave-print-muted {
|
.wave-print-muted {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
color: #909399;
|
color: #909399;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wave-print-tags {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wave-print-tag {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wave-print-json {
|
|
||||||
margin: 0;
|
|
||||||
padding: 10px 12px;
|
|
||||||
background: #f5f7fa;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.45;
|
|
||||||
overflow: auto;
|
|
||||||
max-height: 240px;
|
|
||||||
|
|
||||||
&--tall {
|
|
||||||
max-height: 320px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -405,29 +405,102 @@ export function getWaveToolbarButtons(waveType: 1 | 2): WaveToolbarButtonConfig[
|
|||||||
|
|
||||||
/** 解析 order.print.getWavePlatformPrintData 响应(支持 res.data 包裹) */
|
/** 解析 order.print.getWavePlatformPrintData 响应(支持 res.data 包裹) */
|
||||||
export function unwrapWavePlatformPrintPayload(res: unknown): WavePlatformPrintDataPayload {
|
export function unwrapWavePlatformPrintPayload(res: unknown): WavePlatformPrintDataPayload {
|
||||||
|
const toObject = (v: unknown): Record<string, unknown> | undefined => {
|
||||||
|
if (!v || typeof v !== 'object' || Array.isArray(v)) return undefined
|
||||||
|
return v as Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
const toOrderList = (v: unknown): Record<string, unknown>[] => {
|
||||||
|
if (!Array.isArray(v)) return []
|
||||||
|
return v.filter((x) => x && typeof x === 'object') as Record<string, unknown>[]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容后端直接返回数组:[{ wave_id, wave_no, order_count, platforms: [...] }]
|
||||||
|
const normalizeWaveGroups = (list: unknown): unknown[] | undefined => {
|
||||||
|
if (!Array.isArray(list)) return undefined
|
||||||
|
const groups = list
|
||||||
|
.filter((x) => x && typeof x === 'object')
|
||||||
|
.map((wave) => {
|
||||||
|
const waveObj = wave as Record<string, unknown>
|
||||||
|
const rawPlatforms = Array.isArray(waveObj.platforms) ? waveObj.platforms : []
|
||||||
|
const platforms = rawPlatforms
|
||||||
|
.filter((p) => p && typeof p === 'object')
|
||||||
|
.map((p) => {
|
||||||
|
const platformObj = p as Record<string, unknown>
|
||||||
|
return {
|
||||||
|
platform: platformObj.platform,
|
||||||
|
platform_name: platformObj.platform_name,
|
||||||
|
order_count: platformObj.order_count,
|
||||||
|
orders: toOrderList(platformObj.orders)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
wave_id: waveObj.wave_id,
|
||||||
|
wave_no: waveObj.wave_no,
|
||||||
|
order_count: waveObj.order_count,
|
||||||
|
platforms
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
|
||||||
const r = res as Record<string, unknown> | null | undefined
|
const r = res as Record<string, unknown> | null | undefined
|
||||||
|
|
||||||
|
// 情况1:顶层就是波次数组
|
||||||
|
if (Array.isArray(res)) {
|
||||||
|
const waveGroups = normalizeWaveGroups(res)
|
||||||
|
const wave_ids = (waveGroups || [])
|
||||||
|
.map((x) => (x && typeof x === 'object' ? (x as Record<string, unknown>).wave_id : undefined))
|
||||||
|
.filter((id) => id !== undefined && id !== null && id !== '') as Array<number | string>
|
||||||
|
return {
|
||||||
|
wave_ids: wave_ids.length ? wave_ids : undefined,
|
||||||
|
waveGroups,
|
||||||
|
platform_groups: undefined,
|
||||||
|
order_list: undefined,
|
||||||
|
summary: undefined,
|
||||||
|
ext: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const inner =
|
const inner =
|
||||||
r?.data !== undefined && r?.data !== null && typeof r.data === 'object' && !Array.isArray(r.data)
|
r?.data !== undefined && r?.data !== null && typeof r.data === 'object' && !Array.isArray(r.data)
|
||||||
? (r.data as Record<string, unknown>)
|
? (r.data as Record<string, unknown>)
|
||||||
: (r as Record<string, unknown>) || {}
|
: (r as Record<string, unknown>) || {}
|
||||||
|
|
||||||
|
// 情况2:res.data 是波次数组
|
||||||
|
if (Array.isArray(r?.data)) {
|
||||||
|
const waveGroups = normalizeWaveGroups(r.data)
|
||||||
|
const wave_ids = (waveGroups || [])
|
||||||
|
.map((x) => (x && typeof x === 'object' ? (x as Record<string, unknown>).wave_id : undefined))
|
||||||
|
.filter((id) => id !== undefined && id !== null && id !== '') as Array<number | string>
|
||||||
|
return {
|
||||||
|
wave_ids: wave_ids.length ? wave_ids : undefined,
|
||||||
|
waveGroups,
|
||||||
|
platform_groups: undefined,
|
||||||
|
order_list: undefined,
|
||||||
|
summary: undefined,
|
||||||
|
ext: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const summaryRaw = inner?.summary
|
const summaryRaw = inner?.summary
|
||||||
const summary =
|
const summary = toObject(summaryRaw)
|
||||||
summaryRaw !== undefined && summaryRaw !== null && typeof summaryRaw === 'object' && !Array.isArray(summaryRaw)
|
|
||||||
? (summaryRaw as Record<string, unknown>)
|
|
||||||
: undefined
|
|
||||||
const wave_ids = Array.isArray(inner?.wave_ids) ? (inner.wave_ids as Array<number | string>) : undefined
|
const wave_ids = Array.isArray(inner?.wave_ids) ? (inner.wave_ids as Array<number | string>) : undefined
|
||||||
const waveGroups = Array.isArray(inner?.waveGroups) ? inner.waveGroups : undefined
|
const waveGroups = Array.isArray(inner?.waveGroups)
|
||||||
|
? inner.waveGroups
|
||||||
|
: normalizeWaveGroups((inner as Record<string, unknown>).wave_list)
|
||||||
const platform_groups = Array.isArray(inner?.platform_groups) ? inner.platform_groups : undefined
|
const platform_groups = Array.isArray(inner?.platform_groups) ? inner.platform_groups : undefined
|
||||||
const orderListRaw = inner?.order_list
|
const order_list = toOrderList(inner?.order_list)
|
||||||
const order_list = Array.isArray(orderListRaw)
|
|
||||||
? (orderListRaw.filter((x) => x && typeof x === 'object') as Record<string, unknown>[])
|
|
||||||
: undefined
|
|
||||||
const extRaw = inner?.ext
|
const extRaw = inner?.ext
|
||||||
const ext =
|
const ext = toObject(extRaw)
|
||||||
extRaw !== undefined && extRaw !== null && typeof extRaw === 'object' && !Array.isArray(extRaw)
|
return {
|
||||||
? (extRaw as Record<string, unknown>)
|
summary,
|
||||||
: undefined
|
wave_ids,
|
||||||
return { summary, wave_ids, waveGroups, platform_groups, order_list, ext }
|
waveGroups,
|
||||||
|
platform_groups,
|
||||||
|
order_list: order_list.length ? order_list : undefined,
|
||||||
|
ext
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 异步任务状态文案 */
|
/** 异步任务状态文案 */
|
||||||
|
|||||||
@ -58,6 +58,22 @@
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template #column-expiry_remaining_days="{ row }">
|
||||||
|
<span :class="{ 'expiry-date-expired': row.is_shelf_life_warning_triggered }">
|
||||||
|
{{ row.expiry_remaining_days ?? '--' }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #column-inventory_warning_level="{ row }">
|
||||||
|
<span class="inventory-warning-level" :style="{ color: row.inventory_warning_color || '#909399' }">
|
||||||
|
{{ row.inventory_warning_level || '--' }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #column-inventory_warning_tip_text="{ row }">
|
||||||
|
<span>{{ row.inventory_warning_tip_text || '--' }}</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template #column-order_status="{ row }">
|
<template #column-order_status="{ row }">
|
||||||
<el-tag v-if="row.order_status" size="small" :type="orderStatusTagType(row.order_status)">
|
<el-tag v-if="row.order_status" size="small" :type="orderStatusTagType(row.order_status)">
|
||||||
{{ orderStatusLabel(row.order_status) }}
|
{{ orderStatusLabel(row.order_status) }}
|
||||||
@ -160,9 +176,23 @@ const columns = computed(() => {
|
|||||||
if (idx >= 0) cols.splice(idx + 1, 0, batchCol)
|
if (idx >= 0) cols.splice(idx + 1, 0, batchCol)
|
||||||
else cols.push(batchCol)
|
else cols.push(batchCol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const warningColumns = [
|
||||||
|
{ prop: 'expiry_remaining_days', label: '剩余有效期', width: '110' },
|
||||||
|
{ prop: 'inventory_warning_level', label: '预警等级', width: '110' },
|
||||||
|
{ prop: 'inventory_warning_tip_text', label: '预警提示', width: '160' }
|
||||||
|
]
|
||||||
|
const expiryIdx = cols.findIndex((x: any) => x.prop === 'expiry_date')
|
||||||
|
for (let i = warningColumns.length - 1; i >= 0; i--) {
|
||||||
|
const c = warningColumns[i]
|
||||||
|
if (cols.find((x: any) => x.prop === c.prop)) continue
|
||||||
|
if (expiryIdx >= 0) cols.splice(expiryIdx + 1, 0, c)
|
||||||
|
else cols.push(c)
|
||||||
|
}
|
||||||
|
|
||||||
return cols
|
return cols
|
||||||
}
|
}
|
||||||
return cols.filter((col: any) => !['production_date', 'expiry_date'].includes(col.prop))
|
return cols.filter((col: any) => !['production_date', 'expiry_date', 'expiry_remaining_days', 'inventory_warning_level', 'inventory_warning_tip_text'].includes(col.prop))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -213,6 +243,7 @@ async function loadData() {
|
|||||||
batch_no: item.batch_no || item.batch?.batch_no || '',
|
batch_no: item.batch_no || item.batch?.batch_no || '',
|
||||||
production_date: item.production_date || item.batch?.production_date || '',
|
production_date: item.production_date || item.batch?.production_date || '',
|
||||||
expiry_date: item.expiry_date || item.batch?.expiry_date || '',
|
expiry_date: item.expiry_date || item.batch?.expiry_date || '',
|
||||||
|
expiry_remaining_days: item.expiry_remaining_days,
|
||||||
is_shelf_life_warning_triggered: Boolean(item.is_shelf_life_warning_triggered),
|
is_shelf_life_warning_triggered: Boolean(item.is_shelf_life_warning_triggered),
|
||||||
space_code: item.space?.space_code || item.space?.custom_name || '',
|
space_code: item.space?.space_code || item.space?.custom_name || '',
|
||||||
store_name: item.store?.company_name || item.store_id || '',
|
store_name: item.store?.company_name || item.store_id || '',
|
||||||
@ -223,6 +254,9 @@ async function loadData() {
|
|||||||
last_inbound_time: item.last_inbound_time,
|
last_inbound_time: item.last_inbound_time,
|
||||||
batch_count: Number(item.batch_count || 0),
|
batch_count: Number(item.batch_count || 0),
|
||||||
is_batch_mgmt_enabled: item.stock?.is_batch_mgmt_enabled,
|
is_batch_mgmt_enabled: item.stock?.is_batch_mgmt_enabled,
|
||||||
|
inventory_warning_level: item.inventory_warning_level || '',
|
||||||
|
inventory_warning_color: item.inventory_warning_color || '',
|
||||||
|
inventory_warning_tip_text: item.inventory_warning_tip_text || '',
|
||||||
// preserve original structures for child components that need full network shape
|
// preserve original structures for child components that need full network shape
|
||||||
stock: item.stock || null,
|
stock: item.stock || null,
|
||||||
space: item.space || null,
|
space: item.space || null,
|
||||||
@ -410,6 +444,10 @@ function orderStatusTagType(val: string): any {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.inventory-warning-level {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
.upper-wrapper {
|
.upper-wrapper {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
|
|||||||
@ -51,6 +51,96 @@
|
|||||||
:active-value="true"
|
:active-value="true"
|
||||||
:inactive-value="false"
|
:inactive-value="false"
|
||||||
/>
|
/>
|
||||||
|
<div v-else-if="field.type === 'array'" class="array-editor">
|
||||||
|
<div v-if="field.itemFields && field.itemFields.length" class="array-table">
|
||||||
|
<div class="array-table__head">
|
||||||
|
<div v-for="itemField in field.itemFields" :key="`${field.key}-${itemField.key}-head`" class="array-table__cell">
|
||||||
|
{{ itemField.label }}
|
||||||
|
</div>
|
||||||
|
<div class="array-table__op">操作</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-for="(item, idx) in getArrayFieldItems(field.key)"
|
||||||
|
:key="`${field.key}-${idx}`"
|
||||||
|
class="array-table__row"
|
||||||
|
>
|
||||||
|
<div v-for="itemField in field.itemFields" :key="`${field.key}-${idx}-${itemField.key}`" class="array-table__cell">
|
||||||
|
<el-switch
|
||||||
|
v-if="itemField.type === 'boolean'"
|
||||||
|
:model-value="getArrayObjectFieldValue(item, itemField.key) as boolean"
|
||||||
|
:active-value="true"
|
||||||
|
:inactive-value="false"
|
||||||
|
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||||
|
/>
|
||||||
|
<el-select
|
||||||
|
v-else-if="itemField.type === 'select'"
|
||||||
|
:model-value="getArrayObjectFieldValue(item, itemField.key)"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
placeholder="请选择"
|
||||||
|
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="opt in itemField.options || []"
|
||||||
|
:key="`${field.key}-${idx}-${itemField.key}-${String(opt.value)}`"
|
||||||
|
:label="opt.label"
|
||||||
|
:value="opt.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
<el-color-picker
|
||||||
|
v-else-if="itemField.type === 'color'"
|
||||||
|
:model-value="String(getArrayObjectFieldValue(item, itemField.key) ?? '')"
|
||||||
|
show-alpha
|
||||||
|
:predefine="PREDEFINED_COLORS"
|
||||||
|
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||||
|
/>
|
||||||
|
<el-input-number
|
||||||
|
v-else-if="itemField.type === 'number'"
|
||||||
|
:model-value="getArrayObjectFieldValue(item, itemField.key) as number | undefined"
|
||||||
|
:min="itemField.min"
|
||||||
|
:max="itemField.max"
|
||||||
|
:step="itemField.step ?? 1"
|
||||||
|
:precision="itemField.precision"
|
||||||
|
controls-position="right"
|
||||||
|
placeholder="留空"
|
||||||
|
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||||
|
/>
|
||||||
|
<el-input
|
||||||
|
v-else
|
||||||
|
:model-value="String(getArrayObjectFieldValue(item, itemField.key) ?? '')"
|
||||||
|
clearable
|
||||||
|
placeholder="请输入"
|
||||||
|
:maxlength="itemField.maxLength"
|
||||||
|
:show-word-limit="Boolean(itemField.maxLength)"
|
||||||
|
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="array-table__op">
|
||||||
|
<el-button type="danger" plain @click="removeArrayFieldItem(field.key, idx)">删除</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else>
|
||||||
|
<div
|
||||||
|
v-for="(item, idx) in getArrayFieldItems(field.key)"
|
||||||
|
:key="`${field.key}-${idx}`"
|
||||||
|
class="array-editor__row"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
:model-value="formatArrayItemText(item)"
|
||||||
|
type="textarea"
|
||||||
|
:rows="2"
|
||||||
|
class="field-control"
|
||||||
|
placeholder="可输入文本,或输入 JSON(对象/数组)"
|
||||||
|
@update:model-value="onArrayItemInput(field.key, idx, $event)"
|
||||||
|
/>
|
||||||
|
<el-button type="danger" plain @click="removeArrayFieldItem(field.key, idx)">删除</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-button type="primary" plain @click="addArrayFieldItem(field)">新增一项</el-button>
|
||||||
|
</div>
|
||||||
<el-select
|
<el-select
|
||||||
v-else-if="field.type === 'select'"
|
v-else-if="field.type === 'select'"
|
||||||
v-model="subjectConfig[field.key]"
|
v-model="subjectConfig[field.key]"
|
||||||
@ -66,6 +156,13 @@
|
|||||||
:value="opt.value"
|
:value="opt.value"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
|
<el-color-picker
|
||||||
|
v-else-if="field.type === 'color'"
|
||||||
|
v-model="subjectConfig[field.key] as string"
|
||||||
|
class="field-color-control"
|
||||||
|
show-alpha
|
||||||
|
:predefine="PREDEFINED_COLORS"
|
||||||
|
/>
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-else-if="field.type === 'number'"
|
v-else-if="field.type === 'number'"
|
||||||
v-model="subjectConfig[field.key] as number | undefined"
|
v-model="subjectConfig[field.key] as number | undefined"
|
||||||
@ -144,11 +241,12 @@ import {
|
|||||||
} from '@/api/setting.warehouse/settingwarehouse'
|
} from '@/api/setting.warehouse/settingwarehouse'
|
||||||
|
|
||||||
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
||||||
|
const PREDEFINED_COLORS = ['#ff4d4f', '#ff7a45', '#faad14', '#fadb14', '#95de64', '#52c41a']
|
||||||
|
|
||||||
type NormalizedField = {
|
type NormalizedField = {
|
||||||
key: string
|
key: string
|
||||||
label: string
|
label: string
|
||||||
type: 'number' | 'string' | 'boolean' | 'select'
|
type: 'number' | 'string' | 'boolean' | 'select' | 'array' | 'color'
|
||||||
description?: string
|
description?: string
|
||||||
required?: boolean
|
required?: boolean
|
||||||
min?: number
|
min?: number
|
||||||
@ -156,6 +254,8 @@ type NormalizedField = {
|
|||||||
step?: number
|
step?: number
|
||||||
precision?: number
|
precision?: number
|
||||||
maxLength?: number
|
maxLength?: number
|
||||||
|
defaultValue?: unknown
|
||||||
|
itemFields?: NormalizedField[]
|
||||||
options?: { label: string; value: string | number | boolean }[]
|
options?: { label: string; value: string | number | boolean }[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +331,10 @@ function normalizeFieldMetaItem(raw: Record<string, unknown>): NormalizedField |
|
|||||||
type = 'number'
|
type = 'number'
|
||||||
} else if (rawType.includes('bool') || rawType === 'switch' || rawType === 'flag') {
|
} else if (rawType.includes('bool') || rawType === 'switch' || rawType === 'flag') {
|
||||||
type = 'boolean'
|
type = 'boolean'
|
||||||
|
} else if (rawType.includes('color')) {
|
||||||
|
type = 'color'
|
||||||
|
} else if (rawType.includes('array')) {
|
||||||
|
type = 'array'
|
||||||
} else if (rawType === 'select' || rawType === 'enum' || options.length > 0) {
|
} else if (rawType === 'select' || rawType === 'enum' || options.length > 0) {
|
||||||
type = 'select'
|
type = 'select'
|
||||||
}
|
}
|
||||||
@ -244,6 +348,8 @@ function normalizeFieldMetaItem(raw: Record<string, unknown>): NormalizedField |
|
|||||||
const step = toNumber(raw.step)
|
const step = toNumber(raw.step)
|
||||||
const precision = toNumber(raw.precision)
|
const precision = toNumber(raw.precision)
|
||||||
const maxLength = toNumber(raw.maxLength ?? raw.max_length)
|
const maxLength = toNumber(raw.maxLength ?? raw.max_length)
|
||||||
|
const defaultValue = raw.default
|
||||||
|
const itemFields = type === 'array' ? normalizeArrayItemFields(raw.item_keys ?? raw.item_key) : undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key,
|
key,
|
||||||
@ -256,10 +362,33 @@ function normalizeFieldMetaItem(raw: Record<string, unknown>): NormalizedField |
|
|||||||
step,
|
step,
|
||||||
precision,
|
precision,
|
||||||
maxLength,
|
maxLength,
|
||||||
|
defaultValue,
|
||||||
|
itemFields,
|
||||||
options: options.length ? options : undefined
|
options: options.length ? options : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeArrayItemFields(raw: unknown): NormalizedField[] {
|
||||||
|
if (!raw || typeof raw !== 'object') return []
|
||||||
|
|
||||||
|
if (Array.isArray(raw)) {
|
||||||
|
return raw
|
||||||
|
.map((item) => (item && typeof item === 'object' ? normalizeFieldMetaItem(item as Record<string, unknown>) : null))
|
||||||
|
.filter((x): x is NormalizedField => !!x)
|
||||||
|
.filter((x) => x.type !== 'array')
|
||||||
|
}
|
||||||
|
|
||||||
|
const obj = raw as Record<string, unknown>
|
||||||
|
const out: NormalizedField[] = []
|
||||||
|
for (const [k, v] of Object.entries(obj)) {
|
||||||
|
if (!v || typeof v !== 'object' || Array.isArray(v)) continue
|
||||||
|
const candidate = { key: k, ...(v as Record<string, unknown>) }
|
||||||
|
const normalized = normalizeFieldMetaItem(candidate)
|
||||||
|
if (normalized && normalized.type !== 'array') out.push(normalized)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeFieldMetaList(list: unknown): NormalizedField[] {
|
function normalizeFieldMetaList(list: unknown): NormalizedField[] {
|
||||||
if (!Array.isArray(list)) return []
|
if (!Array.isArray(list)) return []
|
||||||
const out: NormalizedField[] = []
|
const out: NormalizedField[] = []
|
||||||
@ -279,10 +408,25 @@ function cloneSubjectConfig(src: unknown): Record<string, unknown> {
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cloneValue<T>(value: T): T {
|
||||||
|
if (value === null || value === undefined) return value
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
try {
|
||||||
|
return JSON.parse(JSON.stringify(value)) as T
|
||||||
|
} catch {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
function ensureFieldDefaults(target: Record<string, unknown>, fields: NormalizedField[]) {
|
function ensureFieldDefaults(target: Record<string, unknown>, fields: NormalizedField[]) {
|
||||||
for (const f of fields) {
|
for (const f of fields) {
|
||||||
if (!(f.key in target)) {
|
if (!(f.key in target)) {
|
||||||
if (f.type === 'boolean') target[f.key] = false
|
if (f.defaultValue !== undefined) {
|
||||||
|
target[f.key] = cloneValue(f.defaultValue)
|
||||||
|
} else if (f.type === 'boolean') target[f.key] = false
|
||||||
|
else if (f.type === 'array') target[f.key] = []
|
||||||
else if (f.type === 'number') {
|
else if (f.type === 'number') {
|
||||||
/* 不写入 key,便于 el-input-number 展示为空 */
|
/* 不写入 key,便于 el-input-number 展示为空 */
|
||||||
} else if (f.type === 'select') {
|
} else if (f.type === 'select') {
|
||||||
@ -292,6 +436,101 @@ function ensureFieldDefaults(target: Record<string, unknown>, fields: Normalized
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getArrayFieldItems(key: string): unknown[] {
|
||||||
|
const current = subjectConfig[key]
|
||||||
|
if (Array.isArray(current)) return current
|
||||||
|
if (current === undefined || current === null || current === '') {
|
||||||
|
subjectConfig[key] = []
|
||||||
|
return subjectConfig[key] as unknown[]
|
||||||
|
}
|
||||||
|
subjectConfig[key] = [current]
|
||||||
|
return subjectConfig[key] as unknown[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseArrayItemText(text: string): unknown {
|
||||||
|
const trimmed = text.trim()
|
||||||
|
if (!trimmed) return ''
|
||||||
|
try {
|
||||||
|
return JSON.parse(trimmed)
|
||||||
|
} catch {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatArrayItemText(value: unknown): string {
|
||||||
|
if (value === null || value === undefined) return ''
|
||||||
|
if (typeof value === 'string') return value
|
||||||
|
try {
|
||||||
|
return JSON.stringify(value)
|
||||||
|
} catch {
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateArrayFieldItem(key: string, index: number, text: string) {
|
||||||
|
const list = [...getArrayFieldItems(key)]
|
||||||
|
list[index] = parseArrayItemText(text)
|
||||||
|
subjectConfig[key] = list
|
||||||
|
}
|
||||||
|
|
||||||
|
function onArrayItemInput(key: string, index: number, val: string | number) {
|
||||||
|
updateArrayFieldItem(key, index, String(val ?? ''))
|
||||||
|
}
|
||||||
|
|
||||||
|
function addArrayFieldItem(field: NormalizedField) {
|
||||||
|
const list = [...getArrayFieldItems(field.key)]
|
||||||
|
let next: unknown = ''
|
||||||
|
if (field.itemFields && field.itemFields.length) {
|
||||||
|
next = buildArrayObjectDefault(field.itemFields)
|
||||||
|
} else if (Array.isArray(field.defaultValue) && field.defaultValue.length > 0) {
|
||||||
|
next = cloneValue(field.defaultValue[0])
|
||||||
|
}
|
||||||
|
list.push(next)
|
||||||
|
subjectConfig[field.key] = list
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeArrayFieldItem(key: string, index: number) {
|
||||||
|
const list = [...getArrayFieldItems(key)]
|
||||||
|
list.splice(index, 1)
|
||||||
|
subjectConfig[key] = list
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildArrayObjectDefault(itemFields: NormalizedField[]): Record<string, unknown> {
|
||||||
|
const out: Record<string, unknown> = {}
|
||||||
|
for (const f of itemFields) {
|
||||||
|
if (f.defaultValue !== undefined) {
|
||||||
|
out[f.key] = cloneValue(f.defaultValue)
|
||||||
|
} else if (f.type === 'boolean') {
|
||||||
|
out[f.key] = false
|
||||||
|
} else if (f.type === 'number') {
|
||||||
|
out[f.key] = undefined
|
||||||
|
} else {
|
||||||
|
out[f.key] = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayObjectFieldValue(item: unknown, childKey: string): unknown {
|
||||||
|
if (!item || typeof item !== 'object' || Array.isArray(item)) return undefined
|
||||||
|
return (item as Record<string, unknown>)[childKey]
|
||||||
|
}
|
||||||
|
|
||||||
|
function onArrayObjectItemInput(
|
||||||
|
field: NormalizedField,
|
||||||
|
index: number,
|
||||||
|
childKey: string,
|
||||||
|
value: string | number | boolean | null | undefined
|
||||||
|
) {
|
||||||
|
const list = [...getArrayFieldItems(field.key)]
|
||||||
|
const current = list[index]
|
||||||
|
const row: Record<string, unknown> =
|
||||||
|
current && typeof current === 'object' && !Array.isArray(current) ? { ...(current as Record<string, unknown>) } : {}
|
||||||
|
row[childKey] = value
|
||||||
|
list[index] = row
|
||||||
|
subjectConfig[field.key] = list
|
||||||
|
}
|
||||||
|
|
||||||
function unwrapApiPayload(res: Record<string, any> | null | undefined): Record<string, any> {
|
function unwrapApiPayload(res: Record<string, any> | null | undefined): Record<string, any> {
|
||||||
const payload = res?.data
|
const payload = res?.data
|
||||||
if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
|
if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
|
||||||
@ -456,10 +695,20 @@ loadAll()
|
|||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.warehouse-settings-page {
|
.warehouse-settings-page {
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-card {
|
.settings-card {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
height: calc(100vh - 108px);
|
||||||
|
|
||||||
|
:deep(.el-card__body) {
|
||||||
|
height: calc(100% - 57px);
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-header {
|
.card-header {
|
||||||
@ -512,6 +761,19 @@ loadAll()
|
|||||||
|
|
||||||
.settings-tabs {
|
.settings-tabs {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
|
||||||
|
:deep(.el-tabs__content) {
|
||||||
|
height: calc(100% - 55px);
|
||||||
|
overflow: auto;
|
||||||
|
padding-right: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-tab-pane) {
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-form {
|
.settings-form {
|
||||||
@ -522,11 +784,92 @@ loadAll()
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.array-editor {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
max-width: 560px;
|
||||||
|
|
||||||
|
.array-table {
|
||||||
|
border: 1px solid #ebeef5;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow-x: auto;
|
||||||
|
overflow-y: hidden;
|
||||||
|
|
||||||
|
&__head,
|
||||||
|
&__row {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
border-bottom: 1px solid #ebeef5;
|
||||||
|
min-width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__head {
|
||||||
|
background: #f8fafc;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #606266;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__row:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__cell,
|
||||||
|
&__op {
|
||||||
|
padding: 8px;
|
||||||
|
border-right: 1px solid #ebeef5;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__cell {
|
||||||
|
flex: 0 0 140px;
|
||||||
|
min-width: 140px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__cell:last-child,
|
||||||
|
&__op:last-child {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__op {
|
||||||
|
flex: 0 0 72px;
|
||||||
|
min-width: 72px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-input),
|
||||||
|
:deep(.el-select),
|
||||||
|
:deep(.el-input-number),
|
||||||
|
:deep(.el-color-picker) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__row {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: flex-start;
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.field-control {
|
.field-control {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 420px;
|
max-width: 420px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-color-control {
|
||||||
|
max-width: 420px;
|
||||||
|
}
|
||||||
|
|
||||||
.field-control-narrow {
|
.field-control-narrow {
|
||||||
width: 220px;
|
width: 220px;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user