Ben Lin
2024-06-20 de7e6c408b6209158b08991d729c4bcc72055eec
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
<template>
 
  <PageWrapper title="生成二维码">
    <div class="mb-4 pt-4" style="background-color: white; width: 99%;">
       <BasicForm @register="register">
      <template #search="{ field }">
          <Button v-if="field" style="margin-left: 0;" @click="onSearch">生成</Button>
        </template>
      </BasicForm>
    </div>
   
    <div class="flex flex-wrap" v-if="show">
      <!-- <CollapseContainer title="二维码" class="text-center qrcode-demo-item"></CollapseContainer> -->
      <div class="mb-4 pt-4 text-center" style="background-color: white; width: 99%;">
        <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> -->
        <!-- <div class="msg">要进行扩展绘制则不能将tag设为img</div> -->
      </div>
    </div>
  </PageWrapper>
</template>
<script lang="ts"  setup>
import { ref } from 'vue';
import { QrCode } from '/@/components/Qrcode/index';
import LogoImg from '/@/assets/images/logo.png';
import { CollapseContainer } from '/@/components/Container/index';
import { GetQrCode } from '/@/api/tigerapi/wms/qrcode';
import { useMessage } from '/@/hooks/web/useMessage';
import { PageWrapper } from '/@/components/Page';
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
import { Button } from '/@/components/Button';
 
const schemas: FormSchema[] = [
  {
    field: 'SN',
      component: 'Input',
      label: 'SN',
      colProps: {
        span: 8,
      },
     
  },{
        field: '0',
        component: 'Input',
        slot: 'search',
        colProps: {
          span: 4,
        },
      }
];
 
const { createMessage } = useMessage();
const show = ref(false)
const qrCodeUrl = 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, 200);
  }
}
async function onSearch({ ctx }: any) {
  var barcode=getFieldsValue();
 if(barcode.SN!=''){
  
  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=value.value;
    createMessage.error('条码系统不存在');
  }
 }else{
  createMessage.error('输入的条码为空');
 }
 
}
</script>
<style scoped>
  .qrcode-demo-item {
    width: 100%;
    margin-right: 1%;
  }
</style>