2022-08-24 19:55:54 +08:00
|
|
|
<template>
|
|
|
|
<div ref="labelPreview" class="label-preview">
|
|
|
|
<div class="label-preview__header">
|
|
|
|
<div class="title">
|
|
|
|
{{ i18n.t('label_templates.show.preview_title') }}
|
|
|
|
</div>
|
|
|
|
<div class="label-preview__options-button" @click="optionsOpen = !optionsOpen">
|
|
|
|
{{ i18n.t('label_templates.label_preview.options') }}
|
|
|
|
|
2022-08-25 19:25:34 +08:00
|
|
|
<i class="fas" :class="{ 'fa-chevron-down': !optionsOpen, 'fa-chevron-up': optionsOpen }"></i>
|
2022-08-24 19:55:54 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="label-preview__controls" :class="{'open': optionsOpen}">
|
|
|
|
<div class="label-preview__controls__units">
|
|
|
|
<div class="sci-input-container">
|
|
|
|
<label>{{ i18n.t('label_templates.label_preview.units') }}</label>
|
|
|
|
<DropdownSelector
|
|
|
|
:disableSearch="true"
|
|
|
|
:options="[{ value: 'in', label: i18n.t(`label_templates.label_preview.in`) }, { value: 'mm', label: i18n.t(`label_templates.label_preview.mm`) }]"
|
|
|
|
:selectorId="'UnitSelector'"
|
|
|
|
:selectedValue="unit"
|
|
|
|
@dropdown:changed="updateUnit" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="label-preview__controls__size">
|
|
|
|
<div class="sci-input-container">
|
|
|
|
<label>{{ i18n.t('label_templates.label_preview.height') }}</label>
|
2022-08-30 22:16:02 +08:00
|
|
|
<input v-model="height" type="number" class="sci-input-field" />
|
2022-08-24 19:55:54 +08:00
|
|
|
</div>
|
|
|
|
<div class="sci-input-container">
|
|
|
|
<label>{{ i18n.t('label_templates.label_preview.width') }}</label>
|
2022-08-30 22:16:02 +08:00
|
|
|
<input v-model="width" type="number" class="sci-input-field" />
|
2022-08-24 19:55:54 +08:00
|
|
|
</div>
|
|
|
|
<div class="sci-input-container">
|
|
|
|
<label>{{ i18n.t('label_templates.label_preview.density') }}</label>
|
|
|
|
<DropdownSelector
|
2022-08-30 22:16:02 +08:00
|
|
|
v-if="density"
|
2022-08-24 19:55:54 +08:00
|
|
|
:key="unit"
|
|
|
|
:disableSearch="true"
|
|
|
|
:options="unit === 'in' ? DPI_RESOLUTION_OPTIONS : DPMM_RESOLUTION_OPTIONS"
|
|
|
|
:selectorId="'DensitySelector'"
|
|
|
|
:selectedValue="density"
|
|
|
|
@dropdown:changed="updateDensity" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="label-preview__refresh" @click="refreshPreview">
|
|
|
|
<i class="fas fa-sync"></i>
|
|
|
|
{{ i18n.t('label_templates.label_preview.refresh_preview') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="base64Image" class="label-preview__image">
|
|
|
|
<img :src="`data:image/png;base64,${base64Image}`" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const DPI_RESOLUTION_OPTIONS = [
|
2022-08-30 22:16:02 +08:00
|
|
|
{ value: 6, label: '152 dpi' },
|
|
|
|
{ value: 8, label: '203 dpi' },
|
|
|
|
{ value: 12, label: '300 dpi'},
|
|
|
|
{ value: 24, label: '600 dpi' }
|
2022-08-24 19:55:54 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
const DPMM_RESOLUTION_OPTIONS = [
|
2022-08-30 22:16:02 +08:00
|
|
|
{ value: 6, label: '6 dpmm (152 dpi)' },
|
|
|
|
{ value: 8, label: '8 dpmm (203 dpi)' },
|
|
|
|
{ value: 12, label: '12 dpmm (300 dpi)' },
|
|
|
|
{ value: 24, label: '24 dpmm (600 dpi)' }
|
2022-08-24 19:55:54 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
import DropdownSelector from 'vue/shared/dropdown_selector.vue'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'LabelPreview',
|
|
|
|
components: { DropdownSelector },
|
|
|
|
props: {
|
|
|
|
zpl: { type: String, required: true },
|
|
|
|
previewUrl: { type: String, required: true }
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
DPMM_RESOLUTION_OPTIONS,
|
|
|
|
DPI_RESOLUTION_OPTIONS,
|
|
|
|
optionsOpen: false,
|
2022-08-30 22:16:02 +08:00
|
|
|
width: 2,
|
|
|
|
height: 1,
|
2022-08-24 19:55:54 +08:00
|
|
|
unit: 'in',
|
|
|
|
density: 8,
|
|
|
|
base64Image: null,
|
|
|
|
imageStyle: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.refreshPreview();
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
widthMm() {
|
|
|
|
return this.unit === 'in' ? this.width * 25.4 : this.width;
|
|
|
|
},
|
|
|
|
heightMm() {
|
|
|
|
return this.unit === 'in' ? this.height * 25.4 : this.height;
|
|
|
|
}
|
|
|
|
},
|
2022-08-30 22:16:02 +08:00
|
|
|
watch: {
|
|
|
|
unit() {
|
|
|
|
if (this.unit === 'in') {
|
|
|
|
this.width /= 25.4;
|
|
|
|
this.height /= 25.4;
|
|
|
|
} else {
|
|
|
|
this.width *= 25.4;
|
|
|
|
this.height *= 25.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setDefaults();
|
|
|
|
}
|
|
|
|
},
|
2022-08-24 19:55:54 +08:00
|
|
|
methods: {
|
2022-08-30 22:16:02 +08:00
|
|
|
setDefaults() {
|
|
|
|
!this.unit && (this.unit = 'in');
|
|
|
|
!this.density && (this.density = 8);
|
|
|
|
!this.width && (this.width = this.unit === 'in' ? 2 : 50.8);
|
|
|
|
!this.height && (this.height = this.unit === 'in' ? 1 : 25.4);
|
|
|
|
},
|
2022-08-24 19:55:54 +08:00
|
|
|
refreshPreview() {
|
|
|
|
$.ajax({
|
|
|
|
url: this.previewUrl,
|
|
|
|
type: 'GET',
|
|
|
|
data: {
|
|
|
|
zpl: this.zpl,
|
|
|
|
width: this.widthMm,
|
|
|
|
height: this.heightMm,
|
|
|
|
density: this.density
|
|
|
|
},
|
|
|
|
success: (result) => {
|
|
|
|
this.base64Image = result.base64_preview;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateUnit(unit) {
|
|
|
|
this.unit = unit;
|
|
|
|
},
|
|
|
|
updateDensity(density) {
|
|
|
|
this.density = density;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|