Commit ba078303 authored by 张海景's avatar 张海景

update: 提交打印方法

parent b9bf8ecb
import request from "@/utils/request";
//打印pdf
export function postPrintPdf(data) {
return request({
url: "/common/print",
method: "post",
responseType: 'blob',
data
});
}
import request from "@/utils/request";
/** /**
* 通用js方法封装处理 * 通用js方法封装处理
...@@ -8,22 +8,25 @@ ...@@ -8,22 +8,25 @@
// 日期格式化 // 日期格式化
export function parseTime(time, pattern) { export function parseTime(time, pattern) {
if (arguments.length === 0 || !time) { if (arguments.length === 0 || !time) {
return null return null;
} }
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}";
let date let date;
if (typeof time === 'object') { if (typeof time === "object") {
date = time date = time;
} else { } else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { if (typeof time === "string" && /^[0-9]+$/.test(time)) {
time = parseInt(time) time = parseInt(time);
} else if (typeof time === 'string') { } else if (typeof time === "string") {
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), ''); time = time
.replace(new RegExp(/-/gm), "/")
.replace("T", " ")
.replace(new RegExp(/\.[\d]{3}/gm), "");
} }
if ((typeof time === 'number') && (time.toString().length === 10)) { if (typeof time === "number" && time.toString().length === 10) {
time = time * 1000 time = time * 1000;
} }
date = new Date(time) date = new Date(time);
} }
const formatObj = { const formatObj = {
y: date.getFullYear(), y: date.getFullYear(),
...@@ -32,18 +35,20 @@ export function parseTime(time, pattern) { ...@@ -32,18 +35,20 @@ export function parseTime(time, pattern) {
h: date.getHours(), h: date.getHours(),
i: date.getMinutes(), i: date.getMinutes(),
s: date.getSeconds(), s: date.getSeconds(),
a: date.getDay() a: date.getDay(),
} };
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key] let value = formatObj[key];
// Note: getDay() returns 0 on Sunday // Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] } if (key === "a") {
return ["日", "一", "二", "三", "四", "五", "六"][value];
}
if (result.length > 0 && value < 10) { if (result.length > 0 && value < 10) {
value = '0' + value value = "0" + value;
} }
return value || 0 return value || 0;
}) });
return time_str return time_str;
} }
// 表单重置 // 表单重置
...@@ -56,14 +61,19 @@ export function resetForm(refName) { ...@@ -56,14 +61,19 @@ export function resetForm(refName) {
// 添加日期范围 // 添加日期范围
export function addDateRange(params, dateRange, propName) { export function addDateRange(params, dateRange, propName) {
let search = params; let search = params;
search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {}; search.params =
typeof search.params === "object" &&
search.params !== null &&
!Array.isArray(search.params)
? search.params
: {};
dateRange = Array.isArray(dateRange) ? dateRange : []; dateRange = Array.isArray(dateRange) ? dateRange : [];
if (typeof (propName) === 'undefined') { if (typeof propName === "undefined") {
search.params['beginTime'] = dateRange[0]; search.params["beginTime"] = dateRange[0];
search.params['endTime'] = dateRange[1]; search.params["endTime"] = dateRange[1];
} else { } else {
search.params['begin' + propName] = dateRange[0]; search.params["begin" + propName] = dateRange[0];
search.params['end' + propName] = dateRange[1]; search.params["end" + propName] = dateRange[1];
} }
return search; return search;
} }
...@@ -75,15 +85,15 @@ export function selectDictLabel(datas, value) { ...@@ -75,15 +85,15 @@ export function selectDictLabel(datas, value) {
} }
var actions = []; var actions = [];
Object.keys(datas).some((key) => { Object.keys(datas).some((key) => {
if (datas[key].value == ('' + value)) { if (datas[key].value == "" + value) {
actions.push(datas[key].label); actions.push(datas[key].label);
return true; return true;
} }
}) });
if (actions.length === 0) { if (actions.length === 0) {
actions.push(value); actions.push(value);
} }
return actions.join(''); return actions.join("");
} }
// 回显数据字典(字符串数组) // 回显数据字典(字符串数组)
...@@ -97,30 +107,32 @@ export function selectDictLabels(datas, value, separator) { ...@@ -97,30 +107,32 @@ export function selectDictLabels(datas, value, separator) {
Object.keys(value.split(currentSeparator)).some((val) => { Object.keys(value.split(currentSeparator)).some((val) => {
var match = false; var match = false;
Object.keys(datas).some((key) => { Object.keys(datas).some((key) => {
if (datas[key].value == ('' + temp[val])) { if (datas[key].value == "" + temp[val]) {
actions.push(datas[key].label + currentSeparator); actions.push(datas[key].label + currentSeparator);
match = true; match = true;
} }
}) });
if (!match) { if (!match) {
actions.push(temp[val] + currentSeparator); actions.push(temp[val] + currentSeparator);
} }
}) });
return actions.join('').substring(0, actions.join('').length - 1); return actions.join("").substring(0, actions.join("").length - 1);
} }
// 字符串格式化(%s ) // 字符串格式化(%s )
export function sprintf(str) { export function sprintf(str) {
var args = arguments, flag = true, i = 1; var args = arguments,
flag = true,
i = 1;
str = str.replace(/%s/g, function () { str = str.replace(/%s/g, function () {
var arg = args[i++]; var arg = args[i++];
if (typeof arg === 'undefined') { if (typeof arg === "undefined") {
flag = false; flag = false;
return ''; return "";
} }
return arg; return arg;
}); });
return flag ? str : ''; return flag ? str : "";
} }
// 转换字符串,undefined,null等转化为"" // 转换字符串,undefined,null等转化为""
...@@ -145,7 +157,7 @@ export function mergeRecursive(source, target) { ...@@ -145,7 +157,7 @@ export function mergeRecursive(source, target) {
} }
} }
return source; return source;
}; }
/** /**
* 构造树型结构数据 * 构造树型结构数据
...@@ -156,9 +168,9 @@ export function mergeRecursive(source, target) { ...@@ -156,9 +168,9 @@ export function mergeRecursive(source, target) {
*/ */
export function handleTree(data, id, parentId, children) { export function handleTree(data, id, parentId, children) {
let config = { let config = {
id: id || 'id', id: id || "id",
parentId: parentId || 'parentId', parentId: parentId || "parentId",
childrenList: children || 'children' childrenList: children || "children",
}; };
var childrenListMap = {}; var childrenListMap = {};
...@@ -199,19 +211,19 @@ export function handleTree(data, id, parentId, children) { ...@@ -199,19 +211,19 @@ export function handleTree(data, id, parentId, children) {
} }
/** /**
* 参数处理 * 参数处理
* @param {*} params 参数 * @param {*} params 参数
*/ */
export function tansParams(params) { export function tansParams(params) {
let result = '' let result = "";
for (const propName of Object.keys(params)) { for (const propName of Object.keys(params)) {
const value = params[propName]; const value = params[propName];
var part = encodeURIComponent(propName) + "="; var part = encodeURIComponent(propName) + "=";
if (value !== null && typeof (value) !== "undefined") { if (value !== null && typeof value !== "undefined") {
if (typeof value === 'object') { if (typeof value === "object") {
for (const key of Object.keys(value)) { for (const key of Object.keys(value)) {
if (value[key] !== null && typeof (value[key]) !== 'undefined') { if (value[key] !== null && typeof value[key] !== "undefined") {
let params = propName + '[' + key + ']'; let params = propName + "[" + key + "]";
var subPart = encodeURIComponent(params) + "="; var subPart = encodeURIComponent(params) + "=";
result += subPart + encodeURIComponent(value[key]) + "&"; result += subPart + encodeURIComponent(value[key]) + "&";
} }
...@@ -221,7 +233,7 @@ export function tansParams(params) { ...@@ -221,7 +233,7 @@ export function tansParams(params) {
} }
} }
} }
return result return result;
} }
// 验证是否为blob格式 // 验证是否为blob格式
...@@ -238,10 +250,48 @@ export async function blobValidate(data) { ...@@ -238,10 +250,48 @@ export async function blobValidate(data) {
/** /**
* 格式化金钱 * 格式化金钱
*/ */
export function formatMoney(val, prefix = '¥ ') { export function formatMoney(val, prefix = "¥ ") {
if (val === '' || val == null) return null if (val === "" || val == null) return null;
let str = Number(val).toFixed(2); let str = Number(val).toFixed(2);
let intSum = str.substring(0, str.indexOf(".")).replace(/\B(?=(?:\d{3})+$)/g, ',');//取到整数部分 let intSum = str
let dot = str.substring(str.length, str.indexOf("."))//取到小数部分搜索 .substring(0, str.indexOf("."))
.replace(/\B(?=(?:\d{3})+$)/g, ","); //取到整数部分
let dot = str.substring(str.length, str.indexOf(".")); //取到小数部分搜索
return prefix + intSum + dot; return prefix + intSum + dot;
} }
function printPdf(res) {
const blob = new Blob([res], { type: "application/pdf" });
var date = new Date().getTime();
var ifr = document.createElement("iframe");
ifr.style.frameborder = "no";
ifr.style.display = "none";
ifr.style.pageBreakBefore = "always";
ifr.setAttribute("id", "printPdf" + date);
ifr.setAttribute("name", "printPdf" + date);
ifr.src = window.URL.createObjectURL(blob);
document.body.appendChild(ifr);
var ordonnance = document.getElementById("printPdf" + date).contentWindow;
setTimeout(() => {
ordonnance.print();
}, 100);
window.URL.revokeObjectURL(ifr.src); // 释放URL 对象
}
/**
* 打印pdf方法
* responseType: 'blob',
* 接口请求加上responseType
*/
export function postPrintPdf(data) {
request({
url: "/common/print",
method: "post",
responseType: 'blob',
data
}).then(res => {
printPdf(res)
})
}
<template>
<div>
<el-button type="primary" @click="PrintBtnClick">打印</el-button>
</div>
</template>
<script>
import { postPrintPdf } from '@/utils/ruoyi'
export default {
data() {
return {
}
},
methods: {
PrintBtnClick() {
postPrintPdf({
    reportName:"mysql:qrcode-100*100",
    values:{
        "header":{"qrcode":"123456789","other":"q"},
        "detail": [{"name":"lily","age":12,"qrcode":"123"},{"name":"jeff","age":32,"qrcode":"qqq"},
        {"name":"jeff","age":32,"qrcode":"qqq1"},{"name":"jeff","age":32,"qrcode":"qqq2"}],
        "detail2":[{"orderno":"123","quantity":20031}]
    }
})
},
}
}
</script>
...@@ -328,7 +328,7 @@ export default { ...@@ -328,7 +328,7 @@ export default {
  "toolMachinesRecordId": this.form.toolMachinesRecordId,   "toolMachinesRecordId": this.form.toolMachinesRecordId,
  "warehouseDesc": this.form.warehouseDesc   "warehouseDesc": this.form.warehouseDesc
} }
updateRecordWarehouse(this.form).then(response => { updateRecordWarehouse(params).then(response => {
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
this.open = false; this.open = false;
this.getList(); this.getList();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment