JeecgBoot3.6.1 中打印功能实现

JeecgBoot3.6.1中实现打印功能

前言

在项目开发中我们可能会遇到打印得需求,基于JeecgBoot框架做了如下案例

一、前端

1、vue页面代码:List.vue

<template>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--本身的列表代码省略-->	
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="print"> 重打指引单</a-button>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="triage-hisOpWaitQueue" setup>
  import { ref } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, searchFormSchema } from './List.data';
  import { list, selectTeacInfo } from './List.api';
  import { useUserStore } from '/@/store/modules/user';
  import { useMessage } from '/@/hooks/web/useMessage';
  import printJS from 'print-js';

  const checkedKeys = ref<Array<string | number>>([]);
  const userStore = useUserStore();
  const { createWarningModal } = useMessage();
  // 定义一个响应式 ref 作为表格数据源
  const dataSource = ref([]);
  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: '',
      dataSource,
      api: list,
      columns,
      canResize: false,
      formConfig: {
        //labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [],
        fieldMapToTime: [],
      },
      actionColumn: {
        width: 150,
        fixed: 'right',
      },
    },
  });

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  /**
   * 打印公共方法
   * 
   */
  async function print() {
    const printInfo = await selectTeacInfo({
      queryType: '1',
      queryValue: '213123213213123',
    });
    console.log(JSON.stringify(printInfo));
    if (printInfo.state == 0) {
      createWarningModal({ title: '温馨提示', content: '数据为空' });
    } else {
      const data = {
        标题: printInfo.teaVO.title + '(学生明细)',
        教师名称: printInfo.teaVO.teaName,
        教师年龄: printInfo.teaVO.teaAge,
        教师性别: printInfo.teaVO.teaSex,
      };

      // 根据stuList生成二维数组
      let htmlContent2 = '';
      const data2D = [];
        for (const item of printInfo.stuList) {
          data2D.push([
            item.teaName || '-', // 学生名称
            item.teaAge, // 学生年龄
            item.describe || '-', // 学生描述(如果不存在特殊提示,则用破折号填充)
          ]);
        }

        // 构建HTML内容
        htmlContent2 =
          '<tr><td colspan="3" style="text-align: center;font-weight: bold;">学生明细</td></tr>' +
          // 添加列标题行
          '<tr style="text-align: center;font-weight: bold;"><td>学生名称</td><td>学生年龄</td><td>学生描述</td></tr>';

      let htmlContent = '<table>';
      for (const key in data) {
        htmlContent += '<tr><td>' + key + '</td><td colspan="3">' + data[key] + '</td></tr>';
      }

      // 遍历每一行
      for (const row of data2D) {
        htmlContent2 += '<tr>';

        // 遍历每一列
        for (const item of row) {
          htmlContent2 += `<td style="width: 15ch; word-wrap: break-word; overflow-wrap: break-word;">${item}</td>`;
        }

        htmlContent2 += '</tr>';
      }
      htmlContent += htmlContent2;
      htmlContent += '</table>';
      htmlContent = htmlContent.replace('Document', 'Guide Bill');
      printJS({
        printable: htmlContent,
        type: 'raw-html',
        header: 'Guide Bill',
        style:
          '.printable { font-family: Arial; } .description { font-weight: bold; } table { border-collapse: collapse; width: 100%; } td { border: 1px solid black; padding: 5px; }',
      });
    }
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
</script>

<style scoped>
  .btn {
    margin-right: 4px;
  }
</style>

2、List.api.ts

import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  selectTeacInfo= '/teacher/teacher/selectTeacInfo',
}

/**
 * 查询打印信息
 * @param params
 * @returns
 */
export const selectTeacInfo = (params) => defHttp.get({ url: Api.selectTeacInfo, params });

3、后端返回数据结构

{
	"stuList": [{
		"id": 1,
		"stuName": '张三',
		"stuAge": 15
		"describe": "优秀",
	}, {
		"id": 2,
		"stuName": '李四',
		"stuAge": 15
		"describe": "有进步空间",
	}],
	"teaVO": {
		"title": '数据列表',
		"teaAge": 26,
		"teaSex": 1,
	},
	"state": 1,
}

二、后端

@ApiOperation(value = "根据教师查询打印信息", notes = "根据教师查询打印信息")
@GetMapping(value = "/selectTeacInfo")
public Result<Map> selectTeacInfo(String identificationValue){
	Map map = new HashMap();
	if(StringUtils.isBlank(identificationValue)){
	    return Result.error("identificationValue参数为空");
	}else{
		// 判断是否有值
		int state = 1;
		List<Student> studentList = null;// 查询所有得学生记录
		QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(Teacher::getId,identificationValue);
		Teacher teacher = teacherService.getOne(queryWrapper);
		if (teacher!=null){
			teacher.setTitle("数据列表");// 此字段数据库中不存在,仅为显示服务
			QueryWrapper<Student> queryWrapper1 = new QueryWrapper<>();
			queryWrapper1.lambda().eq(Student::getClassId,teacher.getId());
			// 查询学生
			studentList = teacherService.list(queryWrapper1);
		}else{
			state = 0;
		}
		
		map.put("stuList",studentList);
		map.put("teaVo",teacher);
		map.put("state",state);
		return Result.ok(map);
	    }else{
		return Result.error("数据不存在");
	    }
	}
}

执行结果:

在这里插入图片描述

总结

道阻且长,一起加油哦!!!

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: batchplot3.6.1是一款CAD软件的批处理工具。它可以帮助CAD用户快速、高效地批量打印、发布、导出、转换图形文件,大大减轻了用户的工作负担,并提高了工作效率。 该软件支持多种输出格式,包括图像、PDF、DWF、DWFx等。用户可根据需要灵活选择输出方式,以便于更好地与相关部门或人员共享设计图纸。 此外,batchplot3.6.1还可以设置打印、发布等参数,如打印纸张尺寸、图层设置等,使得输出的设计文件更加符合用户的要求。 总之,batchplot3.6.1是一款非常有用的批处理工具,可以帮助CAD设计师在日常工作更好地完成任务,并提高工作效率。 ### 回答2: Batchplot3.6.1是一款专业的CAD图纸批量打印软件,适用于AutoCAD、MicroStation、ZWCAD等多种CAD软件,可以大幅提高CAD图纸打印的效率和质量。 该软件可以轻松地将大量的CAD图纸进行自动排版和批量打印,同时支持多种打印机类型和打印纸型号,用户可以根据需要快速选择合适的打印机和纸张。 此外,Batchplot3.6.1还具有强大的图纸管理功能,可以对图纸进行分类、排序和筛选,以保证打印的顺序和效果。 在使用Batchplot3.6.1时,用户还可以自定义打印设置,包括打印样式、旋转角度、线宽等,以满足不同打印需求。 总的来说,Batchplot3.6.1是一款功能强大、易于使用的CAD图纸批量打印软件,可以极大地提高CAD绘图和工程设计人员的工作效率,是一款不容错过的优秀软件。 ### 回答3: BatchPlot3.6.1是一款专业的CAD图纸批量打印软件,它为用户提供了一种快捷高效的批量打印解决方案。 使用BatchPlot3.6.1,用户可以轻松地管理和打印各种类型的CAD图纸,包括平面布局、图纸图块、模型空间和纸张空间。该软件支持多种文件格式,如DWG、DXF、DWF、PDF等,并能够按照用户的需求进行自动排版和打印。 除此之外,BatchPlot3.6.1还提供了多种打印设置选项,包括纸张大小、打印质量、线宽、颜色、图层等,并能够将这些设置应用于所有图纸。此外,该软件还支持打印预览和多线程打印功能,大大提高了打印效率。 总的来说,BatchPlot3.6.1是一款功能丰富、易于使用的CAD图纸批量打印软件,它可以帮助用户快速高效地完成CAD图纸的批量打印任务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值