Browse Source

纸张选择bug

master
han\hanst 5 months ago
parent
commit
248e46643c
  1. 12
      src/utils/zplGenerator.js
  2. 140
      src/views/modules/labelSetting/components/PaperSelector.vue

12
src/utils/zplGenerator.js

@ -179,12 +179,12 @@ export class ZPLGenerator {
fontCmd += ` ^CWJ,E:${fontFile}` fontCmd += ` ^CWJ,E:${fontFile}`
console.log(`ZPL字体映射: ${fontFamily} -> ${fontFile}`) console.log(`ZPL字体映射: ${fontFamily} -> ${fontFile}`)
} else { } else {
fontCmd += ' ^CWJ,E:MSYH.TTF' // 默认字体
fontCmd += ' ^CWJ,E:ARIAL.TTF' // 默认字体
console.warn(`未找到字体映射: ${fontFamily},使用默认字体`) console.warn(`未找到字体映射: ${fontFamily},使用默认字体`)
} }
} else { } else {
fontCmd += ' ^CWJ,E:MSYH.TTF' // 默认字体
console.log('使用默认字体: MSYH.TTF')
fontCmd += ' ^CWJ,E:ARIAL.TTF' // 默认字体
console.log('使用默认字体: ARIAL.TTF')
} }
// 设置字体大小 // 设置字体大小
@ -261,8 +261,8 @@ export class ZPLGenerator {
'Snell Roundhand': 'SNELLROUND.TTF', 'Snell Roundhand': 'SNELLROUND.TTF',
// 默认字体 // 默认字体
'default': 'MSYH.TTF',
'Default': 'MSYH.TTF'
'default': 'ARIAL.TTF',
'Default': 'ARIAL.TTF'
} }
// 如果找不到精确匹配,尝试模糊匹配 // 如果找不到精确匹配,尝试模糊匹配
@ -275,7 +275,7 @@ export class ZPLGenerator {
} }
} }
return fontMapping[fontFamily] || 'MSYH.TTF' // 默认返回微软雅黑
return fontMapping[fontFamily] || 'ARIAL.TTF' // 默认返回ARIAL
} }
/** /**

140
src/views/modules/labelSetting/components/PaperSelector.vue

@ -11,12 +11,13 @@
<!-- 纸张类型选择 --> <!-- 纸张类型选择 -->
<div class="paper-type-select"> <div class="paper-type-select">
<el-select <el-select
:value="selectedPaper"
:value="normalizedSelectedPaper"
@change="handlePaperChange" @change="handlePaperChange"
placeholder="选择纸张类型" placeholder="选择纸张类型"
size="small" size="small"
:loading="loading" :loading="loading"
:style="horizontalMode ? 'width: 120px;' : 'width: 100%;'" :style="horizontalMode ? 'width: 120px;' : 'width: 100%;'"
filterable
> >
<el-option <el-option
v-for="option in paperOptions" v-for="option in paperOptions"
@ -31,74 +32,6 @@
</el-option> </el-option>
</el-select> </el-select>
</div> </div>
<!-- 打印方向选择 -->
<!-- <div class="orientation-select" :class="{ 'horizontal-inline': horizontalMode }">
<el-radio-group
:value="orientation"
@change="handleOrientationChange"
size="small"
>
<el-radio label="portrait">纵向</el-radio>
<el-radio label="landscape">横向</el-radio>
</el-radio-group>
</div>-->
<!-- 纸张预览 -->
<div class="paper-preview">
<div class="preview-container">
<div
class="preview-paper"
:style="previewStyle"
:class="{ landscape: orientation === 'landscape' }"
>
<div class="preview-label">
{{ currentSize.width }}×{{ currentSize.height }}
</div>
</div>
</div>
</div>
<!-- 当前画布信息 -->
<div class="canvas-info">
<div class="info-item">
<span class="label">画布尺寸:</span>
<span class="value">{{ currentSize.width }} × {{ currentSize.height }}px</span>
</div>
<div class="info-item">
<span class="label">打印方向:</span>
<span class="value">
{{ orientationText }}
<i :class="orientationIcon" style="margin-left: 4px;"></i>
</span>
</div>
<div v-if="originalPaperInfo" class="info-item">
<span class="label">纸张规格:</span>
<span class="value">{{ originalPaperInfo }}</span>
</div>
<div v-if="currentSize.description" class="info-item description">
<span class="label">说明:</span>
<span class="value">{{ currentSize.description }}</span>
</div>
</div>
<!-- 快速尺寸按钮 -->
<div class="quick-sizes">
<div class="quick-title">常用尺寸</div>
<div class="quick-buttons">
<el-button
v-for="size in quickSizes"
:key="size.value"
:type="selectedPaper === size.value ? 'primary' : ''"
size="mini"
@click="handlePaperChange(size.value)"
>
{{ size.label }}
</el-button>
</div>
</div>
</div> </div>
</template> </template>
@ -163,33 +96,18 @@ export default {
paper: paper paper: paper
})) }))
}, },
currentSize() {
// ID
if (typeof this.selectedPaper === 'number') {
const paper = this.dynamicPapers.find(p => p.id === this.selectedPaper)
if (paper) {
return dynamicPaperConfig.calculatePixelSize(paper, 203, this.orientation)
}
}
//
if (typeof this.selectedPaper === 'string') {
const legacyPaper = dynamicPaperConfig.findPaperByLegacyType(this.selectedPaper)
if (legacyPaper) {
return dynamicPaperConfig.calculatePixelSize(legacyPaper, 203, this.orientation)
}
//
return getCanvasSize(this.selectedPaper, this.orientation)
// ID
normalizedSelectedPaper() {
if (this.selectedPaper === null || this.selectedPaper === undefined) {
return null
} }
//
if (this.dynamicPapers.length > 0) {
const defaultPaper = this.dynamicPapers[0]
return dynamicPaperConfig.calculatePixelSize(defaultPaper, 203, this.orientation)
//
if (typeof this.selectedPaper === 'string' && /^\d+$/.test(this.selectedPaper)) {
return parseInt(this.selectedPaper, 10)
} }
return { width: 400, height: 300, name: '默认', description: '默认尺寸' }
return this.selectedPaper
}, },
orientationText() { orientationText() {
return this.orientation === 'portrait' ? '纵向' : '横向' return this.orientation === 'portrait' ? '纵向' : '横向'
}, },
@ -200,41 +118,10 @@ export default {
label: paper.name.replace('英寸', '').replace('×', '×') label: paper.name.replace('英寸', '').replace('×', '×')
})) }))
}, },
//
originalPaperInfo() {
if (typeof this.selectedPaper === 'number') {
const paper = this.dynamicPapers.find(p => p.id === this.selectedPaper)
return paper ? `${paper.name} (${paper.widthMm}×${paper.heightMm}mm)` : ''
}
//
const paper = PAPER_SIZES[this.selectedPaper]
return paper ? `${paper.name} (${paper.width}×${paper.height}px)` : ''
},
// //
orientationIcon() { orientationIcon() {
return this.orientation === 'portrait' ? 'el-icon-mobile-phone' : 'el-icon-monitor' return this.orientation === 'portrait' ? 'el-icon-mobile-phone' : 'el-icon-monitor'
}, },
//
previewStyle() {
const { width, height } = this.currentSize
const maxWidth = 80
const maxHeight = 50
//
const scaleX = maxWidth / width
const scaleY = maxHeight / height
const scale = Math.min(scaleX, scaleY, 1)
const previewWidth = width * scale
const previewHeight = height * scale
return {
width: `${previewWidth}px`,
height: `${previewHeight}px`,
backgroundColor: this.orientation === 'landscape' ? '#e3f2fd' : '#f3e5f5'
}
}
}, },
methods: { methods: {
// //
@ -276,8 +163,9 @@ export default {
// //
getCurrentPaper() { getCurrentPaper() {
if (typeof this.selectedPaper === 'number') {
return this.dynamicPapers.find(p => p.id === this.selectedPaper)
const paperId = this.normalizedSelectedPaper
if (typeof paperId === 'number') {
return this.dynamicPapers.find(p => p.id === paperId)
} }
return null return null
} }

Loading…
Cancel
Save