src/views/inspectionManagement/components/qrCodeDia.vue
@@ -5,15 +5,15 @@
      <el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="设备名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入设备名称" maxlength="30" />
            <el-form-item label="设备名称" prop="deviceName">
              <el-input v-model="form.deviceName" placeholder="请输入设备名称" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="地点" prop="taxTrans">
              <el-input v-model="form.taxTrans" placeholder="请输入地点" maxlength="30"/>
            <el-form-item label="所在位置描述" prop="location">
              <el-input v-model="form.location" placeholder="请输入所在位置描述" maxlength="30"/>
            </el-form-item>
          </el-col>
        </el-row>
@@ -31,7 +31,8 @@
<script setup>
import useUserStore from "@/store/modules/user.js";
import {reactive, ref} from "vue";
import printJS from 'print-js'; // 引入 print.js
import printJS from 'print-js';
import {addOrEditQrCode} from "@/api/inspectionUpload/index.js";
const { proxy } = getCurrentInstance()
const emit = defineEmits()
@@ -40,16 +41,18 @@
const isShowQrCode = ref(false);
const operationType = ref('add');
const qrCodeValue = ref('https://example.com');
const qrCodeValue = ref('');
const qrCodeSize = ref(100);
const data = reactive({
  form: {
    name: '',
    taxTrans: '',
    deviceName: '',
    location: '',
    qrCodeId: '',
    id: ''
  },
  rules: {
    name: [{ required: true, message: '请输入设备名称', trigger: 'blur' }],
    taxTrans: [{ required: true, message: '请输入地点', trigger: 'blur' }]
    deviceName: [{ required: true, message: '请输入设备名称', trigger: 'blur' }],
    location: [{ required: true, message: '请输入地点', trigger: 'blur' }]
  }
})
const { form, rules } = toRefs(data)
@@ -58,15 +61,33 @@
// 打开弹框
const openDialog = async (type, row) => {
  dialogVisitable.value = true
  qrCodeValue.value = ''
  isShowQrCode.value = false;
  if (type === 'edit') {
    form.value.id = row.id
    form.value.qrCodeId = row.id
    form.value.deviceName = row.deviceName
    form.value.location = row.location
    // 将表单数据转为 JSON 字符串作为二维码内容
    qrCodeValue.value = JSON.stringify(form.value);
    isShowQrCode.value = true;
  }
}
// 提交合并表单
const submitForm = () => {
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      addOrEditQrCode(form.value).then((res) => {
        form.value.qrCodeId = res.data
      })
      // 将表单数据转为 JSON 字符串作为二维码内容
      qrCodeValue.value = JSON.stringify(form.value);
      isShowQrCode.value = true;
      showQrCode()
    }
  })
}
const showQrCode = () => {
      // 延迟执行打印,避免 DOM 更新前就调用打印
      setTimeout(() => {
        printJS({
@@ -93,8 +114,6 @@
          font_size: '0.20cm',
        });
      }, 300);
    }
  })
}
// 关闭合并表单
const cancel = () => {