feature: 使用deepseek进行了代码和页面优化

This commit is contained in:
2026-09-05 00:07:47 +08:00
parent b26dc207c2
commit 1896d1032b
17 changed files with 1255 additions and 1699 deletions
+537 -124
View File
@@ -1,40 +1,114 @@
<template>
<div class="toolbar">
<div class="toolbar-submit">
<label>模板</label>
<Select :data="people" v-model="selectedPerson"></Select>
<Input type="number" title="数量" v-model="count"></Input>
<Input type="number" title="上下边距" v-model="marginHeight"></Input>
<Input type="number" title="左右边距" v-model="marginHorizontal"></Input>
<button class="btn btn-primary" @click="onAdd">添加</button>
<button class="btn btn-primary" @click="onPrint">打印</button>
<button class="btn btn-primary" @click="onRest">清空</button>
</div>
<div class="layout">
<!-- 顶部操作栏 -->
<header class="topbar">
<div class="brand">
<span class="brand-icon">🏷️</span>
<div>
<div class="brand-title">标签打印</div>
<div class="brand-sub">4 × 11 标签排版</div>
</div>
</div>
<DynamicForm :key="selectedPerson.label" v-show="currentFormSchema" :formConfig="currentFormSchema"
:initialData="currentConfig" @submit="updateConfig" />
</div>
<div class="page" :style="marginVars">
<template v-for="(item, index) in data" :key="index">
<component :is="getComponent(item)" :id="index" :config="item.config"></component>
</template>
<div class="toolbar">
<div class="tool-group">
<span class="tool-label">批量模板</span>
<Select :data="people" v-model="selectedPerson" />
</div>
<div class="tool-group">
<span class="tool-label">打印设置</span>
<div class="tool-inputs">
<Input type="number" title="数量" v-model="count" />
<Input type="number" title="上下边距" v-model="marginHeight" />
<Input type="number" title="左右边距" v-model="marginHorizontal" />
</div>
</div>
<div class="tool-buttons">
<button class="btn btn-primary" :disabled="usedCount >= TOTAL" @click="onAddBatch">批量添加</button>
<button class="btn btn-success" :disabled="usedCount === 0" @click="onPrint">打印</button>
<button class="btn btn-ghost" :disabled="usedCount === 0" @click="onRest">清空全部</button>
</div>
<div class="stats">
<span class="chip chip-filled">已填 {{ usedCount }}</span>
<span class="chip">剩余 {{ TOTAL - usedCount }}</span>
</div>
</div>
</header>
<!-- 主体:左侧编辑面板 + 右侧标签纸 -->
<div class="body">
<aside class="panel">
<!-- 批量填充 -->
<section class="card">
<h3><span>① 批量填充设置</span></h3>
<p class="hint">编辑好模板内容后点「保存模板配置」,再点上方「批量添加」依次填入空格。</p>
<DynamicForm :key="'batch-' + selectedPerson.label" :form-config="batchSchema"
:initial-data="batchConfig" submit-text="保存模板配置" @submit="onBatchConfig" />
</section>
<!-- 单格编辑 -->
<section v-if="selectedIndex >= 0" class="card card-cell">
<h3>
<span>② 编辑第 {{ selectedIndex + 1 }} 格</span>
<button class="btn btn-icon-only" title="关闭面板" @click="selectedIndex = -1">✕</button>
</h3>
<p v-if="!hasCellContent" class="hint">这是一个空格:选择模板 → 填内容 → 「填入该格」。</p>
<p v-else class="hint">当前为「{{ selectedSlot.name }}」模板<template v-if="selectedSlot.hidden">,已隐藏不打印</template>。</p>
<div class="cell-template">
<span class="tool-label">该格使用模板</span>
<Select :data="people" v-model="cellTemplate" />
</div>
<DynamicForm :key="cellFormKey" :form-config="cellSchema" :initial-data="cellInitial"
:submit-text="hasCellContent ? '保存到该格' : '填入该格'" @submit="saveCell" />
<div v-if="hasCellContent" class="cell-actions">
<button class="btn btn-ghost btn-sm" @click="toggleCellHidden">
{{ selectedSlot.hidden ? '恢复显示' : '隐藏(不打印)' }}
</button>
<button class="btn btn-danger btn-sm" @click="clearCell">删除该格</button>
</div>
</section>
<!-- 未选中时的提示 -->
<section v-else class="card card-tip">
<h3><span>逐格编辑</span></h3>
<ul class="tips">
<li>单击任意<span class="hl">格子</span> → 编辑这一格的内容</li>
<li>双击格子 → 隐藏 / 恢复内容(打印时留空)</li>
<li>上方「批量添加」可一次填满后续空格</li>
</ul>
</section>
</aside>
<!-- 标签纸 -->
<main class="sheet">
<div class="page">
<LabelCell v-for="(slot, i) in slots" :key="i" :index="i" :item="slot"
:selected="selectedIndex === i" @select="onCellSelect(i)" @toggle-hide="toggleHidden(i)">
<component :is="templateMap.get(slot.name)" v-if="slot.name" :config="slot.config" />
</LabelCell>
</div>
</main>
</div>
</div>
</template>
<script setup>
import { reactive, ref, watch, computed } from "vue";
// 导入所有组件(确保路径正确)
// import Disk_After_Sales from "./Disk_After_Sales.vue";
import { computed, reactive, ref, watch } from "vue";
// 导入所有模板组件(default = 标签内容渲染组件,formSchema/initialValues = 表单配置)
import Error, { formSchema as formSchema_Error, initialValues as initialValues_Error } from './Error.vue';
import I5_10400F_16G_256G_1060, { formSchema as formSchema_I510400F, initialValues as initialValues_I510400F } from "./I5_10400F_16G_256G_1060.vue";
import I5_10400F_16G_512G_2060, { formSchema as formSchema_I510400F2060, initialValues as initialValues_I510400F2060 } from './I5_10400F_16G_512G_2060.vue';
import I5_10400F_16G_512G_2060, { formSchema as formSchema_I510400F2060, initialValues as initialValues_I510400F2060 } from "./I5_10400F_16G_512G_2060.vue";
import I5_9400F_16G_256G_1060, { formSchema as formSchema_I59400F, initialValues as initialValues_I59400F } from "./I5_9400F_16G_256G_1060.vue";
import I5_4590_8G_120G, { formSchema as formSchema_I54590, initialValues as initialValues_I54590 } from './I5_4590_8G_120G.vue';
import I3_4130_8G_120G, { formSchema as formSchema_I34130, initialValues as initialValues_I34130 } from './I3_4130_8G_120G.vue';
import G3260_8G_120G, {
formSchema as formSchema_G3260,
initialValues as initialValues_G3260
} from './G3260_8G_120G.vue';
import G3260_8G_120G, { formSchema as formSchema_G3260, initialValues as initialValues_G3260 } from './G3260_8G_120G.vue';
import All_in_one_22_4G_120G, { formSchema as formSchema_22AllInOne, initialValues as initialValues_22AllInOne } from "./22寸一体机_4G_120G.vue";
import All_in_one_24_8G_256G, { formSchema as formSchema_24AllInOne, initialValues as initialValues_24AllInOne } from "./24寸一体机_I5_3代_8G_256G.vue";
import HardDisk, { formSchema as formSchema_HardDisk, initialValues as initialValues_HardDisk } from "./HardDisk.vue";
@@ -43,132 +117,206 @@ import CustomTag, { formSchema as formSchema_CustomTag, initialValues as initial
import DynamicForm from './DynamicForm.vue';
import Input from './Input/Index.vue';
import Select from './Select/index.vue';
import LabelCell from './LabelCell.vue';
// 修复1: 确保所有配置都有表单数据
const people = reactive([
// 深拷贝:避免编辑表单 / 快照进格子时共享引用
const clone = (obj) => JSON.parse(JSON.stringify(obj));
// 模板注册表:新增模板只需在数组中加一项
const templates = [
{
label: 'I5_10400F_16G_256G_1060',
component: I5_10400F_16G_256G_1060,
formSchema: formSchema_I510400F,
formData: initialValues_I510400F
},
{
label: 'I5_10400F_16G_256G_2060',
component: I5_10400F_16G_512G_2060,
formSchema: formSchema_I510400F2060,
formData: initialValues_I510400F2060
},
{
label: 'I5_9400F_16G_256G_1060',
component: I5_9400F_16G_256G_1060,
formSchema: formSchema_I59400F,
formData: initialValues_I59400F
},
{
label: 'I5_4590_8G_120G',
component: I5_4590_8G_120G,
formSchema: formSchema_I54590,
formData: initialValues_I54590
},
{
label: 'I3_4130_8G_120G',
component: I3_4130_8G_120G,
formSchema: formSchema_I34130,
formData: initialValues_I34130
},
{
label: 'G3260_8G_120G',
component: G3260_8G_120G,
formSchema: formSchema_G3260,
formData: initialValues_G3260
},
{
label: '24寸一体机_I5_3代_8G_256G',
component: All_in_one_24_8G_256G,
formSchema: formSchema_24AllInOne,
formData: initialValues_24AllInOne
},
{
label: '22寸一体机_4G_120G',
component: All_in_one_22_4G_120G,
formSchema: formSchema_22AllInOne,
formData: initialValues_22AllInOne
},
{
label: 'HardDisk',
component: HardDisk,
formSchema: formSchema_HardDisk,
formData: initialValues_HardDisk
},
{
label: 'Error',
component: Error,
formSchema: formSchema_Error,
formData: initialValues_Error
},
{
label: 'CustomTag',
component: CustomTag,
formSchema: formSchema_CustomTag,
formData: initialValues_CustomTag
},
]);
}
];
// 修复2: 初始化选中项为G3260配置
// 下拉数据与名称 → 渲染组件映射
const people = reactive(
templates.map(({ label, formSchema, formData }) => ({ label, formSchema, formData }))
);
const templateMap = new Map(templates.map(({ label, component }) => [label, component]));
// ---------- 固定 44 个格子(每格可单独编辑) ----------
const TOTAL = 44;
const emptySlot = () => ({ name: null, config: null, hidden: false });
const slots = ref(Array.from({ length: TOTAL }, emptySlot));
const usedCount = computed(() => slots.value.filter((s) => s.name).length);
// 当前选中的格子(-1 = 未选中)
const selectedIndex = ref(-1);
const selectedSlot = computed(() =>
selectedIndex.value >= 0 ? slots.value[selectedIndex.value] : null
);
const hasCellContent = computed(() => !!selectedSlot.value?.name);
// ---------- 批量填充(沿用原有语义) ----------
const selectedPerson = ref(people[0]);
const data = ref([]);
// 打印数量
const count = ref(1);
// 上下边距
const marginHeight = ref(0.89);
// 左右边距
const marginHorizontal = ref(0.8);
const currentConfig = ref({ ...initialValues_G3260 });
const currentFormSchema = ref(formSchema_G3260);
// 打印样式表引用
let printStyle = null;
const batchSchema = ref(people[0].formSchema);
const batchConfig = ref(clone(people[0].formData));
// 计算样式变量
const marginVars = computed(() => ({
'--margin-height': `${marginHeight.value}cm`,
'--margin-horizontal': `${marginHorizontal.value}cm`
}));
// 修复3: 正确的watch处理
watch(selectedPerson, (newVal) => {
currentConfig.value = { ...newVal.formData };
currentFormSchema.value = newVal.formSchema;
watch(selectedPerson, (nv) => {
batchSchema.value = nv.formSchema;
batchConfig.value = clone(nv.formData);
}, { immediate: true });
const getComponent = (item) => {
switch (item.name) {
case 'I5_10400F_16G_256G_1060': return I5_10400F_16G_256G_1060;
case 'I5_10400F_16G_512G_2060': return I5_10400F_16G_512G_2060;
case 'I5_9400F_16G_256G_1060': return I5_9400F_16G_256G_1060;
case 'I5_4590_8G_120G': return I5_4590_8G_120G;
case 'I3_4130_8G_120G': return I3_4130_8G_120G;
case 'G3260_8G_120G': return G3260_8G_120G;
case '24寸一体机_I5_3代_8G_256G': return All_in_one_24_8G_256G;
case '22寸一体机_4G_120G': return All_in_one_22_4G_120G;
case 'Error': return Error;
case 'HardDisk': return HardDisk;
case 'CustomTag': return CustomTag;
default: return Error;
// 打印数量 / 边距
const count = ref(1);
const marginHeight = ref(0.89);
const marginHorizontal = ref(0.8);
let printStyle = null;
// ---------- 单格编辑 ----------
const cellTemplate = ref(people[0]); // 该格当前使用的模板
const cellRev = ref(0); // 保存后递增,用于刷新表单
const cellSchema = computed(() => cellTemplate.value?.formSchema || people[0].formSchema);
const cellInitial = computed(() => {
const slot = selectedSlot.value;
const tpl = cellTemplate.value;
if (!tpl) return {};
// 已有内容且模板未变 → 回填该格当前配置;否则显示该模板默认值
if (slot?.name && slot.name === tpl.label) return clone(slot.config ?? tpl.formData);
return clone(tpl.formData);
});
const cellFormKey = computed(() =>
`${selectedIndex.value}|${cellTemplate.value?.label || ''}|${cellRev.value}`
);
// 单击选择格子;再次单击取消选择
const onCellSelect = (i) => {
if (selectedIndex.value === i) {
selectedIndex.value = -1;
return;
}
}
selectedIndex.value = i;
const slot = slots.value[i];
// 有内容的格子:自动把“该格模板”切到它的模板,方便直接修改
if (slot?.name) {
const tpl = people.find((p) => p.label === slot.name);
if (tpl) cellTemplate.value = tpl;
}
};
const onAdd = () => {
const maxItems = 44;
const availableSlots = maxItems - data.value.length;
const addCount = Math.min(count.value, availableSlots);
// 双击:隐藏/恢复该格内容(打印时留空,保留格子边框)
const toggleHidden = (i) => {
const slot = slots.value[i];
if (!slot?.name) return;
slot.hidden = !slot.hidden;
};
if (addCount <= 0) return;
// 单格表单提交:填入(空格)或保存(有内容)
const saveCell = (cfg) => {
const i = selectedIndex.value;
if (i < 0) return;
const tpl = cellTemplate.value;
slots.value[i] = {
name: tpl.label,
config: clone(cfg),
hidden: slots.value[i]?.hidden || false
};
cellRev.value++;
};
const newItems = Array.from({ length: addCount }, () => ({
name: selectedPerson.value.label,
config: { ...currentConfig.value }
}));
const clearCell = () => {
const i = selectedIndex.value;
if (i < 0) return;
slots.value[i] = emptySlot();
cellRev.value++;
};
const toggleCellHidden = () => {
const slot = selectedSlot.value;
if (slot) slot.hidden = !slot.hidden;
};
// ---------- 批量操作 ----------
const onBatchConfig = (cfg) => {
batchConfig.value = clone(cfg);
};
const onAddBatch = () => {
const n = Math.min(parseInt(count.value, 10) || 1, TOTAL - usedCount.value);
if (n <= 0) return;
const tpl = selectedPerson.value;
let placed = 0;
slots.value = slots.value.map((s) => {
if (placed < n && !s.name) {
placed++;
return { name: tpl.label, config: clone(batchConfig.value), hidden: false };
}
return s;
});
};
data.value.push(...newItems);
}
// 重置打印网格
const onRest = () => {
data.value = [];
}
const updateConfig = (newConfig) => {
currentConfig.value = newConfig;
}
slots.value = Array.from({ length: TOTAL }, emptySlot);
selectedIndex.value = -1;
};
// ---------- 打印 ----------
const onPrint = () => {
applyPrintStyles();
if (window?.electronAPI?.silentPrint) {
@@ -176,42 +324,308 @@ const onPrint = () => {
} else {
window.print();
}
}
};
// 应用打印样式
const applyPrintStyles = () => {
// 移除旧的打印样式
if (printStyle) {
document.head.removeChild(printStyle);
}
// 创建新的打印样式
printStyle = document.createElement('style');
printStyle.setAttribute('media', 'print');
printStyle.textContent = `
@page {
margin: ${marginHeight.value}cm ${marginHorizontal.value}cm 0;
}
@media print {
body {
margin: 0;
padding: 0;
}
body { margin: 0; padding: 0; }
}
`;
document.head.appendChild(printStyle);
};
</script>
<style>
/* 原有样式保持不变 */
/* ================= 全局页面布局 ================= */
html,
body {
max-width: none !important;
margin: 0 !important;
padding: 0rem !important;
margin: 0;
padding: 0;
}
body {
font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
background: #e9eef5;
color: #1e293b;
}
.layout {
display: flex;
flex-direction: column;
gap: 14px;
padding: 16px;
min-height: 100vh;
box-sizing: border-box;
}
/* ---------------- 顶部操作栏 ---------------- */
.topbar {
display: flex;
align-items: center;
gap: 22px;
flex-wrap: wrap;
background: #ffffff;
border-radius: 14px;
padding: 14px 18px;
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.07);
}
.brand {
display: flex;
align-items: center;
gap: 10px;
}
.brand-icon {
font-size: 26px;
line-height: 1;
}
.brand-title {
font-size: 17px;
font-weight: 700;
line-height: 1.2;
}
.brand-sub {
font-size: 12px;
color: #94a3b8;
}
.toolbar {
display: flex;
align-items: flex-end;
gap: 18px;
flex-wrap: wrap;
flex: 1;
min-width: 0;
}
.tool-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.tool-label {
font-size: 12px;
font-weight: 600;
color: #64748b;
}
.tool-inputs {
display: flex;
gap: 10px;
}
.tool-buttons {
display: flex;
gap: 10px;
align-items: flex-end;
}
/* 顶栏与面板内的输入框更紧凑 */
.topbar .input-group,
.panel .input-group {
margin-bottom: 0;
width: 150px;
}
.topbar .input-group input,
.panel .input-group input {
width: 118px;
padding: 8px 12px;
}
.topbar .input-group i {
display: none;
}
.topbar .input-group .floating-label,
.panel .input-group .floating-label {
left: 12px;
}
.stats {
display: flex;
gap: 8px;
margin-left: auto;
align-items: center;
}
.chip {
background: #f1f5f9;
color: #475569;
font-size: 12.5px;
font-weight: 600;
padding: 5px 12px;
border-radius: 999px;
white-space: nowrap;
}
.chip-filled {
background: #dbeafe;
color: #1d4ed8;
}
/* ---------------- 主体:左面板 + 右纸面 ---------------- */
.body {
display: flex;
gap: 16px;
align-items: flex-start;
flex-wrap: wrap;
}
.panel {
width: 356px;
flex: none;
display: flex;
flex-direction: column;
gap: 14px;
position: sticky;
top: 12px;
max-height: calc(100vh - 24px);
overflow-y: auto;
}
.card {
background: #fff;
border-radius: 14px;
padding: 16px 18px;
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}
.card h3 {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 0 8px;
font-size: 15px;
}
.hint {
margin: 0 0 12px;
font-size: 12.5px;
color: #94a3b8;
line-height: 1.6;
}
.tips {
margin: 6px 0 0;
padding-left: 18px;
font-size: 13px;
line-height: 2;
color: #475569;
}
.tips .hl {
color: #2563eb;
font-weight: 700;
}
.cell-template {
margin-bottom: 6px;
}
.cell-actions {
display: flex;
gap: 10px;
margin-top: 12px;
flex-wrap: wrap;
}
/* ---------------- 按钮 ---------------- */
.btn {
display: inline-block;
padding: 8px 16px;
border: none;
border-radius: 9px;
font-size: 13.5px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
line-height: 1.3;
}
.btn:disabled {
opacity: 0.45;
cursor: not-allowed;
transform: none !important;
}
.btn-primary {
background: #2563eb;
color: #fff;
}
.btn-primary:hover:not(:disabled) {
background: #1d4ed8;
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.btn-success {
background: #16a34a;
color: #fff;
}
.btn-success:hover:not(:disabled) {
background: #15803d;
box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}
.btn-ghost {
background: #f1f5f9;
color: #334155;
}
.btn-ghost:hover:not(:disabled) {
background: #e2e8f0;
}
.btn-danger {
background: #fee2e2;
color: #b91c1c;
}
.btn-danger:hover:not(:disabled) {
background: #fecaca;
}
.btn-sm {
padding: 5px 11px;
font-size: 12.5px;
}
.btn-icon-only {
padding: 2px 8px;
background: #f1f5f9;
color: #64748b;
border-radius: 7px;
font-size: 13px;
}
.btn-icon-only:hover {
background: #e2e8f0;
color: #0f172a;
}
/* ---------------- 标签纸(屏幕预览) ---------------- */
.sheet {
flex: 1;
min-width: 0;
display: flex;
justify-content: center;
padding: 8px;
box-sizing: border-box;
}
.page {
@@ -220,39 +634,37 @@ body {
grid-template-columns: repeat(4, 48.5mm);
grid-template-rows: repeat(11, 25.4mm);
gap: 0;
/* margin: var(--margin-height) var(--margin-horizontal) 0; */
}
.toolbar {
display: flex;
flex-direction: row;
margin-bottom: 30px;
}
.toolbar .toolbar-submit {
width: 300px;
}
.toolbar-submit button.btn:nth-of-type(n+2) {
margin-left: 20px;
background: #fff;
border-radius: 3mm;
box-shadow: 0 8px 26px rgba(15, 23, 42, 0.16);
overflow: hidden;
}
/* ================= 打印 ================= */
@media print {
html,
body {
padding: 0 !important;
margin: 0 !important;
background: #fff !important;
}
body * {
visibility: hidden;
}
.toolbar {
display: none;
.layout,
.body,
.sheet {
display: block;
padding: 0;
margin: 0;
background: transparent;
}
.topbar,
.panel {
display: none !important;
}
.page,
@@ -263,12 +675,13 @@ body {
.page {
width: 194mm;
height: auto;
padding: 0;
border-radius: 0;
box-shadow: none;
overflow: visible;
}
}
@page {
/* margin: var(--margin-height) var(--margin-horizontal) 0; */
margin: 0.89cm 0.80cm 0;
}
</style>
</style>