Ben Lin
2024-06-25 f73947395184fd635df3d74c1c4b2701d0c708c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
  <PageWrapper title="打印示例">
    <CollapseContainer title="json打印表格">
      <a-button type="primary" @click="jsonPrint">打印</a-button>
    </CollapseContainer>
 
    <a-button type="primary" class="mt-5" @click="imagePrint">Image Print</a-button>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { PageWrapper } from '@/components/Page';
  import { CollapseContainer } from '@/components/Container';
 
  import printJS from 'print-js';
 
  defineOptions({ name: 'AppLogo' });
 
  function jsonPrint() {
    printJS({
      printable: [
        { name: 'll', email: '123@gmail.com', phone: '123' },
        { name: 'qq', email: '456@gmail.com', phone: '456' },
      ],
      properties: ['name', 'email', 'phone'],
      type: 'json',
    });
  }
 
  function imagePrint() {
    printJS({
      printable: [
        'https://anncwb.github.io/anncwb/images/preview1.png',
        'https://anncwb.github.io/anncwb/images/preview2.png',
      ],
      type: 'image',
      header: 'Multiple Images',
      imageStyle: 'width:100%;',
    });
  }
</script>