赵灿 面料二维码

zhc4dev
赵灿 2 years ago
parent 35440a10e0
commit 10f84dd2ef
  1. 17
      ant-design-vue-jeecg/src/views/erp/fabric/ZyFabricList.vue
  2. 12
      ant-design-vue-jeecg/src/views/erp/fabric/modules/ZyFabricForm.vue
  3. 6
      jeecg-boot/jeecg-boot-module-erp/pom.xml
  4. 45
      jeecg-boot/jeecg-boot-module-erp/src/main/java/org/jeecg/modules/demo/fabric/controller/ZyFabricController.java

@ -24,6 +24,7 @@
<a-input placeholder="名称" v-model="queryParam.name"></a-input>
</a-form-item>
</a-col>
<template v-if="toggleSearchStatus">
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="颜色">
<a-input placeholder="请输入颜色" v-model="queryParam.color"></a-input>
@ -39,6 +40,7 @@
<j-search-select-tag placeholder="请选择材质" v-model="queryParam.material" dict="material"/>
</a-form-item>
</a-col>
</template>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
@ -99,6 +101,9 @@
<span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
<img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
</template>
<template slot="imgeSlot" slot-scope="text">
<img :src="text" height="" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
</template>
<template slot="fileSlot" slot-scope="text">
<span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
<a-button
@ -241,11 +246,17 @@ import ZyFabricFormDetail from './modules/ZyFabricFormDetail'
align:"center",
dataIndex: 'status_dictText'
},
// {
// title:'',
// align:"center",
// dataIndex: 'qrcode',
// scopedSlots: {customRender: 'imgeSlot'}
// },
{
title:'二维码',
title:"二维码",
align:"center",
dataIndex: 'qRcode',
scopedSlots: {customRender: 'imgSlot'}
dataIndex: 'qrcode',
scopedSlots: {customRender: 'imgeSlot'}
},
{
title:'等级',

@ -62,13 +62,13 @@
</a-form-model-item>
</a-col>
<a-col :span="24">
<a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandId">
<j-search-select-tag v-model="model.brandId" dict="brand" />
<a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
<j-dict-select-tag v-model="model.unit" type="radioButton" title="单位" dictCode="unit1" />
</a-form-model-item>
</a-col>
<a-col :span="24">
<a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
<j-search-select-tag v-model="model.unit" dict="unit1" />
<a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandId">
<j-search-select-tag v-model="model.brandId" dict="brand" />
</a-form-model-item>
</a-col>
<a-col :span="24">
@ -88,7 +88,7 @@
</a-col>
<a-col :span="24">
<a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
<j-search-select-tag v-model="model.status" dict="fabric_status" />
<j-dict-select-tag v-model="model.status" type="radioButton" title="状态" dictCode="fabric_status" />
</a-form-model-item>
</a-col>
<!-- <a-col :span="24">-->
@ -153,6 +153,8 @@
data () {
return {
model:{
unit : '1',
status : '1',
},
labelCol: {
xs: { span: 24 },

@ -25,6 +25,12 @@
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

@ -1,8 +1,19 @@
package org.jeecg.modules.demo.fabric.controller;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.fabric.entity.ZyFabric;
@ -63,11 +74,43 @@ public class ZyFabricController extends JeecgController<ZyFabric, IZyFabricServi
public Result<?> queryPageList(ZyFabric zyFabric,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
HttpServletRequest req) throws IOException, WriterException {
QueryWrapper<ZyFabric> queryWrapper = QueryGenerator.initQueryWrapper(zyFabric, req.getParameterMap());
// QueryWrapper queryWrapper = new QueryWrapper();
Page<ZyFabric> page = new Page<>(pageNo, pageSize);
IPage<ZyFabric> pageList = zyFabricService.page(page, queryWrapper);
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
@SuppressWarnings("rawtypes")
Map hints = new HashMap();
//设置UTF-8, 防止中文乱码
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
//设置二维码四周白色区域的大小
hints.put(EncodeHintType.MARGIN, 1);
//设置二维码的容错性
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
//width:图片完整的宽;height:图片完整的高
//因为要在二维码下方附上文字,所以把图片设置为长方形(高大于宽)
int width = 150;
int height = 150;
//画二维码,记得调用multiFormatWriter.encode()时最后要带上hints参数,不然上面设置无效
QRCodeWriter qrCodeWriter = new QRCodeWriter();
List<Object> img= new ArrayList<>();
String content="";
//批量生成二维码
for (int i=0;i<pageList.getRecords().size();i++){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String fabricNumber = pageList.getRecords().get(i).getFabricNumber();
String name = pageList.getRecords().get(i).getName();
content = "面料名称:"+name+",面料编号:"+fabricNumber;
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
Base64.Encoder encoder = Base64.getEncoder();
String text = encoder.encodeToString(outputStream.toByteArray());
pageList.getRecords().get(i).setQRcode("data:image/png;base64,"+text);
}
return Result.OK(pageList);
}

Loading…
Cancel
Save