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.
@@ -222,25 +222,37 @@
222
222
  label-position="top"
223
223
  size="small">
224
224
  <el-form-item label="表数据选择">
225
- <el-select
226
- v-model="listCode"
227
- @change="tableFieldChange">
228
- <el-option
229
- v-for="d in dataSourceList"
230
- :label="d.label"
231
- :value="d.value"></el-option>
232
- </el-select>
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
- <el-select v-model="col.field">
240
- <el-option
241
- v-for="d in listColumns"
242
- :value="d"></el-option>
243
- </el-select>
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
- import { onMounted, ref, onActivated, onDeactivated, computed, watch } from "vue";
269
- import { hiprint, defaultElementTypeProvider, fontSize, scale, zIndex, panel, usePaper, useScale, useDataSource, jquery as $ } from "yh-hiprint";
270
- import { useRoute, onBeforeRouteUpdate } from "vue-router";
271
- import { ElMessageBox, ElMessage } from "element-plus";
272
- import axios from "@/libs/api.request";
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 { paperType, paperWidth, paperHeight, setPaper } = usePaper();
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.setPaper(paperWidth.value, paperHeight.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 { scaleValue, scalePercentage, canZoomIn, canZoomOut, zoomIn, zoomOut } = useScale(() => {
285
- hiprintTemplate.value.zoom(scaleValue.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: { list, json },
314
+ data: {list, json},
294
315
  } = await axios.request({
295
316
  url: `/printTemplate/data/${detailData.value.code}`,
296
- method: "post",
297
- type: "json",
317
+ method: 'post',
318
+ type: 'json',
298
319
  data: [
299
320
  {
300
- code: "50101820",
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({ template: JSON.parse(json) }).getHtml(list)[0].innerHTML;
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
- title: "警告",
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.getJson();
358
+ let json = hiprintTemplate.value?.getJson();
339
359
  json.panels[0].printElements.forEach((item) => {
340
- if (item.printElementType.type === "table") {
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: "/printTemplate/save",
348
- method: "post",
349
- type: "json",
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 { detailData, getDetail, listCode, dataSourceList, listColumns, formCode, formColumns, dataSourceForm, getDataSourceList } = useDataSource(axios);
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 === "table") {
393
- return currentElementObj.value.options.columns[0]["columns"] || [];
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("field", val);
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: "scale",
426
- after: "transform",
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: "styler",
454
+ name: 'styler',
435
455
  hidden: true,
436
456
  },
437
457
  {
438
- name: "scale",
439
- after: "transform",
458
+ name: 'scale',
459
+ after: 'transform',
440
460
  hidden: false,
441
461
  },
442
462
  {
443
- name: "formatter",
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: "field",
475
+ name: 'field',
456
476
  hidden: false,
457
477
  },
458
478
  {
459
- name: "src",
479
+ name: 'src',
460
480
  hidden: false,
461
481
  },
462
482
  {
463
- name: "fit",
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: [{ options: [{ name: "field", hidden: true }] }],
491
+ tabs: [{options: [{name: 'field', hidden: true}]}],
472
492
  },
473
493
  });
474
494
 
475
- hiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
476
- $("#hiprint-printTemplate").empty();
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
- { title: "微软雅黑", value: "Microsoft YaHei" },
483
- { title: "黑体", value: "STHeitiSC-Light" },
484
- { title: "宋体", value: "SimSun" },
485
- { title: "cursive", value: "cursive" },
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: "#PrintElementOptionSetting",
494
- paginationContainer: ".hiprint-printPagination",
513
+ settingContainer: '#PrintElementOptionSetting',
514
+ paginationContainer: '.hiprint-printPagination',
495
515
  });
496
516
 
497
- hiprintTemplate.value?.design("#hiprint-printTemplate", { grid: true });
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
- $(".hiprint-designer").on("mousedown", ".hiprint-printElement", (e) => {
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
- $("#PrintElementOptionSetting").on("input", "input[type=number]", ($el) => {
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("setTemplateId") > -1) {
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 { width, height } = jsonObj.panels[0];
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: { content: "", rotate: 25, timestamp: false, format: "YYYY-MM-DD HH:mm" },
589
+ watermarkOptions: {content: '', rotate: 25, timestamp: false, format: 'YYYY-MM-DD HH:mm'},
570
590
  },
571
591
  ],
572
592
  });
@@ -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 = route.query;
34
+ let query = getQuery();
35
+ debugger;
22
36
  if (query.code) {
23
37
  sessionStorage.printQuery = JSON.stringify(query);
24
38
  getData(query);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yh-hiprint",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "description": "Hiprint for Vue3 by NoahLiu in ForceCon in Hunan Changesha",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",