Ben Lin
2024-10-13 234b6cf8944ef95c415c4898f19b8fb4d12e898f
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* stylelint-disable rule-empty-line-before */
<template>
  <PageWrapper title="生成二维码" contentFullHeight contentClass="flex">
    <template #headerContent>
      <BasicForm @register="register">
        <template #search="{ field }">
          <Button v-if="field" style="margin-left: 10" @click="onSearch">生成</Button>
        </template>
      </BasicForm>
    </template>
    <div class="w-2/4 xl:w-2/6 p-3" style="background-color: white">
      <a-list size="large" bordered :pagination="pagination" :data-source="hisData">
        <template #renderItem="{ item }">
          <a-list-item>
            <template #actions>
              <a key="list-loadmore-edit" @click="del(item.key)">删除</a>
            </template>
            <span @click="showQr(item.data)">{{ item.data }}</span>
            <!-- {{ item }} -->
          </a-list-item>
        </template>
        <template #header>
          <div>历史记录</div>
        </template>
        <!-- <template #footer>
          <div>Footer</div>
        </template> -->
      </a-list>
    </div>
    <div class="w-2/4 xl:w-4/6 p-5" v-if="show">
      <!-- <CollapseContainer title="二维码" class="text-center qrcode-demo-item"></CollapseContainer> -->
      <div class="mb-4 pt-4 text-center" style="width: 99%; background-color: white">
        <QrCode
          :value="qrCodeUrl"
          :width="390"
          :height="398"
          :options="{ margin: 5 }"
          ref="qrDiyRef"
          :logo="LogoImg"
          @done="onQrcodeDone"
        />
        <!-- <a-button class="mb-2" type="primary" @click="downloadDiy"> 下载 </a-button> -->
        <span class="mb-5 p-5" style="color: #0780b9">{{ qrCodeUrl }}</span>
      </div>
    </div>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { List, ListItem, ListItemMeta } from 'ant-design-vue';
  import { QrCode } from '/@/components/Qrcode/index';
  import LogoImg from '/@/assets/images/logo.png';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { PageWrapper } from '/@/components/Page';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  import { Button } from '/@/components/Button';
  import { useQrhisStore } from '/@/store/modules/qrhis';
  import { storeToRefs } from 'pinia';
  import { buildUUID } from '/@/utils/uuid';
 
  const AList = List;
  const AListItem = ListItem;
  const AListItemMeta = ListItemMeta;
  const schemas: FormSchema[] = [
    {
      field: 'SN',
      component: 'Input',
      label: 'SN',
      colProps: {
        span: 8,
      },
    },
    {
      field: '0',
      component: 'Input',
      slot: 'search',
      colProps: {
        span: 4,
      },
    },
  ];
 
  let qrDatas: any[] = [];
  const useQrhis = useQrhisStore();
  const { hisData } = storeToRefs(useQrhis);
  const { createMessage } = useMessage();
  const show = ref(false);
  const qrCodeUrl = ref('');
  const qrCodeKey = ref('');
  const [register, { validateFields, clearValidate, getFieldsValue, resetFields, setFieldsValue }] =
    useForm({
      showSubmitButton: false,
      showResetButton: false,
      labelWidth: 80,
      schemas,
      canResize: true,
      actionColOptions: {
        span: 12,
      },
    });
 
  function onQrcodeDone({ ctx }: any) {
    if (ctx instanceof CanvasRenderingContext2D) {
      // 额外绘制
      ctx.fillStyle = 'black';
      ctx.font = '16px "微软雅黑"';
      ctx.textBaseline = 'bottom';
      ctx.textAlign = 'center';
      ctx.fillText('你帅你先扫', 200, 380, 600);
    }
  }
  async function onSearch({ ctx }: any) {
    var barcode = getFieldsValue();
    if (barcode.SN != '') {
      show.value = true;
      qrCodeUrl.value = barcode.SN;
      qrCodeKey.value = buildUUID();
      useQrhis.gethisData.push({ key: qrCodeKey.value, data: qrCodeUrl.value });
      qrDatas = useQrhis.gethisData;
      useQrhis.sethisData(qrDatas);
      // var apiAction = await GetQrCode(barcode.SN)
      // if(apiAction.IsSuccessed){
      //   show.value=true;
      //   qrCodeUrl.value=apiAction.Message
      // }
      // else{
      //   //show.value=false;
      //   show.value=true;
      //   qrCodeUrl.value=barcode.SN;
      //   //createMessage.error('条码系统不存在');
      // }
      resetFields();
    } else {
      show.value = false;
      createMessage.error('输入的条码为空');
    }
  }
 
  /**
   * @description: 显示二维码
   * @param {*} code
   * @return {*}
   */
  async function showQr(code: string) {
    if (code != '') {
      show.value = true;
      qrCodeUrl.value = code;
    } else {
      show.value = false;
      createMessage.error('输入的条码为空');
    }
  }
 
  /**
   * @description: 删除
   * @param {*} code
   * @return {*}
   */
  function del(code) {
    useQrhis.hisData = useQrhis.gethisData.filter((item) => item.key !== code);
    qrDatas = useQrhis.gethisData;
    useQrhis.sethisData(qrDatas);
  }
 
  const pagination = {
    onChange: (page: number) => {
      console.log(page);
    },
    pageSize: 10,
  };
</script>
<style scoped>
  .qrcode-demo-item {
    width: 100%;
    margin-right: 1%;
  }
 
  span {
    display: block;
    width: auto;
    overflow: hidden;
    word-wrap: break-word;
    word-break: normal;
    white-space: pre-wrap;
  }
</style>