yh-hiprint 2.2.5 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiprintDesigner.vue +90 -70
- package/hiprintPreview.vue +15 -1
- package/package.json +1 -1
package/HiprintDesigner.vue
CHANGED
|
@@ -222,25 +222,37 @@
|
|
|
222
222
|
label-position="top"
|
|
223
223
|
size="small">
|
|
224
224
|
<el-form-item label="表数据选择">
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
<template v-if="formCode">
|
|
226
|
+
<el-select
|
|
227
|
+
v-model="listCode"
|
|
228
|
+
@change="tableFieldChange">
|
|
229
|
+
<el-option
|
|
230
|
+
v-for="d in dataSourceList"
|
|
231
|
+
:label="d.label"
|
|
232
|
+
:value="d.value"></el-option>
|
|
233
|
+
</el-select>
|
|
234
|
+
</template>
|
|
235
|
+
<template v-else>
|
|
236
|
+
<el-input
|
|
237
|
+
v-model="listCode"
|
|
238
|
+
@change="tableFieldChange"></el-input>
|
|
239
|
+
</template>
|
|
233
240
|
</el-form-item>
|
|
234
241
|
<el-row gutter="10">
|
|
235
242
|
<el-col
|
|
236
243
|
:span="12"
|
|
237
244
|
v-for="col in currentElementObjColumns">
|
|
238
245
|
<el-form-item :label="col.title">
|
|
239
|
-
<
|
|
240
|
-
<el-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
<template v-if="formCode">
|
|
247
|
+
<el-select v-model="col.field">
|
|
248
|
+
<el-option
|
|
249
|
+
v-for="d in listColumns"
|
|
250
|
+
:value="d"></el-option>
|
|
251
|
+
</el-select>
|
|
252
|
+
</template>
|
|
253
|
+
<template v-else>
|
|
254
|
+
<el-input v-model="col.field"></el-input>
|
|
255
|
+
</template>
|
|
244
256
|
</el-form-item>
|
|
245
257
|
</el-col>
|
|
246
258
|
</el-row>
|
|
@@ -265,39 +277,48 @@
|
|
|
265
277
|
</el-dialog>
|
|
266
278
|
</template>
|
|
267
279
|
<script setup lang="ts">
|
|
268
|
-
|
|
269
|
-
import {
|
|
270
|
-
import {
|
|
271
|
-
import {
|
|
272
|
-
import
|
|
280
|
+
// @ts-nocheck
|
|
281
|
+
import {onMounted, ref, onActivated, onDeactivated, computed, watch} from 'vue';
|
|
282
|
+
import {hiprint, defaultElementTypeProvider, fontSize, scale, zIndex, panel, usePaper, useScale, useDataSource, jquery as $} from 'yh-hiprint';
|
|
283
|
+
import {useRoute, onBeforeRouteUpdate} from 'vue-router';
|
|
284
|
+
import {ElMessageBox, ElMessage} from 'element-plus';
|
|
285
|
+
import axios from '@/libs/api.request';
|
|
286
|
+
|
|
287
|
+
interface HiprintTemplate {
|
|
288
|
+
setPaper: (width: number, height: number) => void;
|
|
289
|
+
zoom: (scale: number) => void;
|
|
290
|
+
getJson: () => any;
|
|
291
|
+
clear: () => void;
|
|
292
|
+
}
|
|
273
293
|
|
|
274
294
|
const route = useRoute();
|
|
275
|
-
const
|
|
295
|
+
const hiprintTemplate = ref<HiprintTemplate | null>(null);
|
|
296
|
+
|
|
297
|
+
const {paperType, paperWidth, paperHeight, setPaper} = usePaper();
|
|
276
298
|
function setPaperHandler(type) {
|
|
277
299
|
setPaper(type, () => {
|
|
278
|
-
hiprintTemplate.value
|
|
300
|
+
hiprintTemplate.value?.setPaper(paperWidth.value, paperHeight.value);
|
|
279
301
|
});
|
|
280
302
|
}
|
|
281
303
|
|
|
282
|
-
const hiprintTemplate = ref(null);
|
|
283
304
|
const canvasRef = ref();
|
|
284
|
-
const {
|
|
285
|
-
hiprintTemplate.value
|
|
305
|
+
const {scaleValue, scalePercentage, canZoomIn, canZoomOut, zoomIn, zoomOut} = useScale(() => {
|
|
306
|
+
hiprintTemplate.value?.zoom(scaleValue.value);
|
|
286
307
|
canvasRef?.value.update();
|
|
287
308
|
});
|
|
288
309
|
|
|
289
310
|
const previewShow = ref(false);
|
|
290
|
-
const previewHtml = ref(
|
|
311
|
+
const previewHtml = ref('');
|
|
291
312
|
async function previewPrint() {
|
|
292
313
|
let {
|
|
293
|
-
data: {
|
|
314
|
+
data: {list, json},
|
|
294
315
|
} = await axios.request({
|
|
295
316
|
url: `/printTemplate/data/${detailData.value.code}`,
|
|
296
|
-
method:
|
|
297
|
-
type:
|
|
317
|
+
method: 'post',
|
|
318
|
+
type: 'json',
|
|
298
319
|
data: [
|
|
299
320
|
{
|
|
300
|
-
code:
|
|
321
|
+
code: '50101820',
|
|
301
322
|
},
|
|
302
323
|
],
|
|
303
324
|
});
|
|
@@ -323,39 +344,38 @@ async function previewPrint() {
|
|
|
323
344
|
} else {
|
|
324
345
|
list = [];
|
|
325
346
|
}
|
|
326
|
-
previewHtml.value = new hiprint.PrintTemplate({
|
|
347
|
+
previewHtml.value = new hiprint.PrintTemplate({template: JSON.parse(json)}).getHtml(list)[0].innerHTML;
|
|
327
348
|
previewShow.value = true;
|
|
328
349
|
} else {
|
|
329
350
|
ElMessage.warning({
|
|
330
|
-
|
|
331
|
-
message: "模板配置不存在,请检查",
|
|
351
|
+
message: '模板配置不存在,请检查',
|
|
332
352
|
});
|
|
333
353
|
}
|
|
334
354
|
}
|
|
335
355
|
|
|
336
356
|
function saveConfig() {
|
|
337
357
|
let arr = [].concat(formCode.value);
|
|
338
|
-
let json = hiprintTemplate.value
|
|
358
|
+
let json = hiprintTemplate.value?.getJson();
|
|
339
359
|
json.panels[0].printElements.forEach((item) => {
|
|
340
|
-
if (item.printElementType.type ===
|
|
360
|
+
if (item.printElementType.type === 'table') {
|
|
341
361
|
arr.push(item.options.field);
|
|
342
362
|
}
|
|
343
363
|
});
|
|
344
364
|
|
|
345
365
|
axios
|
|
346
366
|
.request({
|
|
347
|
-
url:
|
|
348
|
-
method:
|
|
349
|
-
type:
|
|
367
|
+
url: '/printTemplate/save',
|
|
368
|
+
method: 'post',
|
|
369
|
+
type: 'json',
|
|
350
370
|
data: {
|
|
351
371
|
id: detailData.value.id,
|
|
352
372
|
json: JSON.stringify(json),
|
|
353
|
-
dsIds: arr.join(
|
|
373
|
+
dsIds: arr.join(','),
|
|
354
374
|
},
|
|
355
375
|
})
|
|
356
376
|
.then((res) => {
|
|
357
377
|
ElMessage.success({
|
|
358
|
-
message:
|
|
378
|
+
message: '恭喜模板保存成功',
|
|
359
379
|
});
|
|
360
380
|
});
|
|
361
381
|
}
|
|
@@ -364,7 +384,7 @@ function clearPrint() {
|
|
|
364
384
|
hiprintTemplate.value?.clear();
|
|
365
385
|
}
|
|
366
386
|
|
|
367
|
-
const {
|
|
387
|
+
const {detailData, getDetail, listCode, dataSourceList, listColumns, formCode, formColumns, dataSourceForm, getDataSourceList} = useDataSource(axios);
|
|
368
388
|
|
|
369
389
|
watch(
|
|
370
390
|
() => formColumns.value,
|
|
@@ -379,7 +399,7 @@ watch(
|
|
|
379
399
|
})
|
|
380
400
|
);
|
|
381
401
|
} else {
|
|
382
|
-
hiprintTemplate.value?.setFields(
|
|
402
|
+
hiprintTemplate.value?.setFields('');
|
|
383
403
|
}
|
|
384
404
|
},
|
|
385
405
|
{
|
|
@@ -389,15 +409,15 @@ watch(
|
|
|
389
409
|
);
|
|
390
410
|
let currentElementObj = ref(null);
|
|
391
411
|
let currentElementObjColumns = computed(() => {
|
|
392
|
-
if (currentElementObj.value?.printElementType.type ===
|
|
393
|
-
return currentElementObj.value.options.columns[0][
|
|
412
|
+
if (currentElementObj.value?.printElementType.type === 'table') {
|
|
413
|
+
return currentElementObj.value.options.columns[0]['columns'] || [];
|
|
394
414
|
} else {
|
|
395
415
|
return [];
|
|
396
416
|
}
|
|
397
417
|
});
|
|
398
418
|
|
|
399
419
|
function tableFieldChange(val) {
|
|
400
|
-
currentElementObj.value.updateOption(
|
|
420
|
+
currentElementObj.value.updateOption('field', val);
|
|
401
421
|
}
|
|
402
422
|
|
|
403
423
|
function tableColumnCancel() {
|
|
@@ -419,11 +439,11 @@ function init() {
|
|
|
419
439
|
options: [],
|
|
420
440
|
},
|
|
421
441
|
{
|
|
422
|
-
name:
|
|
442
|
+
name: '样式',
|
|
423
443
|
options: [
|
|
424
444
|
{
|
|
425
|
-
name:
|
|
426
|
-
after:
|
|
445
|
+
name: 'scale',
|
|
446
|
+
after: 'transform',
|
|
427
447
|
hidden: false,
|
|
428
448
|
},
|
|
429
449
|
],
|
|
@@ -431,16 +451,16 @@ function init() {
|
|
|
431
451
|
],
|
|
432
452
|
supportOptions: [
|
|
433
453
|
{
|
|
434
|
-
name:
|
|
454
|
+
name: 'styler',
|
|
435
455
|
hidden: true,
|
|
436
456
|
},
|
|
437
457
|
{
|
|
438
|
-
name:
|
|
439
|
-
after:
|
|
458
|
+
name: 'scale',
|
|
459
|
+
after: 'transform',
|
|
440
460
|
hidden: false,
|
|
441
461
|
},
|
|
442
462
|
{
|
|
443
|
-
name:
|
|
463
|
+
name: 'formatter',
|
|
444
464
|
hidden: true,
|
|
445
465
|
},
|
|
446
466
|
],
|
|
@@ -449,18 +469,18 @@ function init() {
|
|
|
449
469
|
tabs: [
|
|
450
470
|
{
|
|
451
471
|
replace: true,
|
|
452
|
-
name:
|
|
472
|
+
name: '基本',
|
|
453
473
|
options: [
|
|
454
474
|
{
|
|
455
|
-
name:
|
|
475
|
+
name: 'field',
|
|
456
476
|
hidden: false,
|
|
457
477
|
},
|
|
458
478
|
{
|
|
459
|
-
name:
|
|
479
|
+
name: 'src',
|
|
460
480
|
hidden: false,
|
|
461
481
|
},
|
|
462
482
|
{
|
|
463
|
-
name:
|
|
483
|
+
name: 'fit',
|
|
464
484
|
hidden: false,
|
|
465
485
|
},
|
|
466
486
|
],
|
|
@@ -468,21 +488,21 @@ function init() {
|
|
|
468
488
|
],
|
|
469
489
|
},
|
|
470
490
|
table: {
|
|
471
|
-
tabs: [{
|
|
491
|
+
tabs: [{options: [{name: 'field', hidden: true}]}],
|
|
472
492
|
},
|
|
473
493
|
});
|
|
474
494
|
|
|
475
|
-
hiprint.PrintElementTypeManager.buildByHtml($(
|
|
476
|
-
$(
|
|
495
|
+
hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
|
|
496
|
+
$('#hiprint-printTemplate').empty();
|
|
477
497
|
let template = JSON.parse(detailData.value.json) || panel;
|
|
478
498
|
hiprintTemplate.value = new hiprint.PrintTemplate({
|
|
479
499
|
template,
|
|
480
500
|
onImageChooseClick: (target) => {},
|
|
481
501
|
fontList: [
|
|
482
|
-
{
|
|
483
|
-
{
|
|
484
|
-
{
|
|
485
|
-
{
|
|
502
|
+
{title: '微软雅黑', value: 'Microsoft YaHei'},
|
|
503
|
+
{title: '黑体', value: 'STHeitiSC-Light'},
|
|
504
|
+
{title: '宋体', value: 'SimSun'},
|
|
505
|
+
{title: 'cursive', value: 'cursive'},
|
|
486
506
|
],
|
|
487
507
|
dataMode: 1,
|
|
488
508
|
history: true,
|
|
@@ -490,11 +510,11 @@ function init() {
|
|
|
490
510
|
onUpdateError: (e) => {
|
|
491
511
|
console.error(e);
|
|
492
512
|
},
|
|
493
|
-
settingContainer:
|
|
494
|
-
paginationContainer:
|
|
513
|
+
settingContainer: '#PrintElementOptionSetting',
|
|
514
|
+
paginationContainer: '.hiprint-printPagination',
|
|
495
515
|
});
|
|
496
516
|
|
|
497
|
-
hiprintTemplate.value?.design(
|
|
517
|
+
hiprintTemplate.value?.design('#hiprint-printTemplate', {grid: true});
|
|
498
518
|
scaleValue.value = hiprintTemplate.value.editingPanel.scale || 1;
|
|
499
519
|
window.ht = hiprintTemplate.value;
|
|
500
520
|
|
|
@@ -508,7 +528,7 @@ function init() {
|
|
|
508
528
|
})
|
|
509
529
|
);
|
|
510
530
|
}
|
|
511
|
-
$(
|
|
531
|
+
$('.hiprint-designer').on('mousedown', '.hiprint-printElement', (e) => {
|
|
512
532
|
let t = e.currentTarget;
|
|
513
533
|
let pes = hiprintTemplate.value?.editingPanel.printElements;
|
|
514
534
|
let index = pes.map((item) => item.designTarget[0]).indexOf(t);
|
|
@@ -518,7 +538,7 @@ function init() {
|
|
|
518
538
|
listCode.value = pe.options.field;
|
|
519
539
|
}
|
|
520
540
|
});
|
|
521
|
-
$(
|
|
541
|
+
$('#PrintElementOptionSetting').on('input', 'input[type=number]', ($el) => {
|
|
522
542
|
let val = parseInt($el.target.value);
|
|
523
543
|
if (val < 1) {
|
|
524
544
|
$el.target.value = 1;
|
|
@@ -531,8 +551,8 @@ function init() {
|
|
|
531
551
|
console.log(error.message);
|
|
532
552
|
clearPrint();
|
|
533
553
|
hiprintTemplate.value = null;
|
|
534
|
-
if (error.message.indexOf(
|
|
535
|
-
ElMessageBox.alert(
|
|
554
|
+
if (error.message.indexOf('setTemplateId') > -1) {
|
|
555
|
+
ElMessageBox.alert('模板有错误,请返回列表手动修改或这清空模板!');
|
|
536
556
|
}
|
|
537
557
|
}
|
|
538
558
|
}
|
|
@@ -548,7 +568,7 @@ async function updateTemplate(code) {
|
|
|
548
568
|
if (detailData.value && detailData.value.json) {
|
|
549
569
|
let jsonObj = JSON.parse(detailData.value.json);
|
|
550
570
|
hiprintTemplate.value?.update(jsonObj);
|
|
551
|
-
let {
|
|
571
|
+
let {width, height} = jsonObj.panels[0];
|
|
552
572
|
paperWidth.value = width;
|
|
553
573
|
paperHeight.value = height;
|
|
554
574
|
hiprintTemplate.value?.setPaper(width, height);
|
|
@@ -566,7 +586,7 @@ async function updateTemplate(code) {
|
|
|
566
586
|
paperNumberLeft: 430,
|
|
567
587
|
paperNumberTop: 5,
|
|
568
588
|
printElements: [],
|
|
569
|
-
watermarkOptions: {
|
|
589
|
+
watermarkOptions: {content: '', rotate: 25, timestamp: false, format: 'YYYY-MM-DD HH:mm'},
|
|
570
590
|
},
|
|
571
591
|
],
|
|
572
592
|
});
|
package/hiprintPreview.vue
CHANGED
|
@@ -17,8 +17,22 @@ import { useRoute } from "vue-router";
|
|
|
17
17
|
import axios from "@/libs/api.request.js";
|
|
18
18
|
import { hiprint } from "yh-hiprint";
|
|
19
19
|
|
|
20
|
+
function getQuery(){
|
|
21
|
+
let query = {}
|
|
22
|
+
try {
|
|
23
|
+
decodeURIComponent(location.hash).split("?")[1].split('&').forEach(str => {
|
|
24
|
+
let strArr = str.split("=");
|
|
25
|
+
query[strArr[0]] = strArr[1];
|
|
26
|
+
})
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("hiprint Preview getQuery on error:",error);
|
|
29
|
+
}
|
|
30
|
+
return query
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
onMounted(() => {
|
|
21
|
-
let query =
|
|
34
|
+
let query = getQuery();
|
|
35
|
+
debugger;
|
|
22
36
|
if (query.code) {
|
|
23
37
|
sessionStorage.printQuery = JSON.stringify(query);
|
|
24
38
|
getData(query);
|