uu
This commit is contained in:
parent
4fde89e5af
commit
7fc3ae98d1
@ -54,8 +54,9 @@ export const getLatestNotices = (data = {})=> {
|
|||||||
return coreRequest(url.getLatestNotices, data, {}, "GET")
|
return coreRequest(url.getLatestNotices, data, {}, "GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 接口返回-文件流
|
||||||
export const getStaffQRCodePng = (data = {})=> {
|
export const getStaffQRCodePng = (data = {})=> {
|
||||||
return coreRequest(url.getStaffQRCodePng, data, {}, "GET")
|
return coreRequest(url.getStaffQRCodePng, data, {}, "GET", { _isFile: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -91,9 +91,7 @@ export const getNextStationList = (data = {})=> {
|
|||||||
return coreRequest(url.getNextStationList, data, {}, "GET")
|
return coreRequest(url.getNextStationList, data, {}, "GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 扫描-获取下一网点
|
// 获取运单详细信息-图片 接口返回-文件流
|
||||||
export const getRealGetWaybillPrintData = (data = {})=> {
|
export const getRealGetWaybillPrintData = (data = {})=> {
|
||||||
return coreRequest(url.getRealGetWaybillPrintData, data, {}, "GET")
|
return coreRequest(url.getRealGetWaybillPrintData, data, {}, "GET", { _isFile: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { goto } from "./untool";
|
import { goto } from "./untool";
|
||||||
import { showToast, showLoading, hideLoading } from "./untool"
|
import { showToast, showLoading, hideLoading, downloadFile } from "./untool"
|
||||||
import { setSessionXToken, getSessionXToken } from "@/session"
|
import { setSessionXToken, getSessionXToken } from "@/session"
|
||||||
|
import { textEncoder, textDecoder } from "./util"
|
||||||
|
|
||||||
const getCommonReqData = ()=> {
|
const getCommonReqData = ()=> {
|
||||||
const xToken = getSessionXToken()
|
const xToken = getSessionXToken()
|
||||||
@ -12,7 +13,7 @@ const getCommonReqData = ()=> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 请求接口
|
// 请求接口
|
||||||
function dealRequest(def, url, param) {
|
function dealRequest(def, url, param, coreParams) {
|
||||||
if(param && param._loading) {
|
if(param && param._loading) {
|
||||||
showLoading()
|
showLoading()
|
||||||
}
|
}
|
||||||
@ -38,7 +39,8 @@ function dealRequest(def, url, param) {
|
|||||||
reject,
|
reject,
|
||||||
url,
|
url,
|
||||||
header,
|
header,
|
||||||
param
|
param,
|
||||||
|
coreParams
|
||||||
});
|
});
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
console.log('request url==========1', url)
|
console.log('request url==========1', url)
|
||||||
@ -63,30 +65,22 @@ function dealRequest(def, url, param) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理响应
|
// 处理响应
|
||||||
function handleResponse({
|
async function handleResponse({
|
||||||
data,
|
data,
|
||||||
header,
|
header,
|
||||||
resolve,
|
resolve,
|
||||||
reject,
|
reject,
|
||||||
url,
|
url,
|
||||||
param
|
param,
|
||||||
|
coreParams
|
||||||
}) {
|
}) {
|
||||||
// 图片类型数据特殊处理
|
// 图片类型数据特殊处理
|
||||||
if(header['content-type']?.indexOf?.("image/") > -1) {
|
if(header['content-type']?.indexOf?.("image/") > -1) {
|
||||||
uni.downloadFile({
|
const base64 = "data:image/png;base64," + uni.arrayBufferToBase64(data)
|
||||||
url: data,
|
let { tempFilePath } = await downloadFile(base64)
|
||||||
success: (res) => {
|
resolve({ data: { fileUrl: tempFilePath } })
|
||||||
debugger
|
return
|
||||||
},
|
|
||||||
fail: (err)=>{
|
|
||||||
debugger
|
|
||||||
console.log("downloadFile:err", err)
|
|
||||||
reject(err)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
debugger
|
|
||||||
}
|
|
||||||
|
|
||||||
data = data || {}
|
data = data || {}
|
||||||
const { msg, code } = data
|
const { msg, code } = data
|
||||||
if ((code == 200)) {
|
if ((code == 200)) {
|
||||||
|
|||||||
@ -3,9 +3,12 @@ import { showToast } from "./untool"
|
|||||||
import { host } from "./api"
|
import { host } from "./api"
|
||||||
import { getSessionXToken } from "@/session"
|
import { getSessionXToken } from "@/session"
|
||||||
|
|
||||||
const coreRequestBase = (url, reqParams, options = {}, methodType = "POST") => {
|
const coreRequestBase = (url, reqParams, options = {}, methodType = "POST", coreParams = {}) => {
|
||||||
|
|
||||||
let comReqData = getCommonReqData()
|
let comReqData = getCommonReqData()
|
||||||
|
if(coreParams._isFile) {
|
||||||
|
coreParams.responseType = "arraybuffer"
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
@ -16,6 +19,7 @@ const coreRequestBase = (url, reqParams, options = {}, methodType = "POST") => {
|
|||||||
...options
|
...options
|
||||||
},
|
},
|
||||||
method: methodType,
|
method: methodType,
|
||||||
|
...coreParams,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
},
|
},
|
||||||
@ -28,14 +32,19 @@ const coreRequestBase = (url, reqParams, options = {}, methodType = "POST") => {
|
|||||||
|
|
||||||
const BaseParam = {}
|
const BaseParam = {}
|
||||||
// 请求处理
|
// 请求处理
|
||||||
let coreRequest = function(url, params = {}, options = {}, methodType) {
|
let coreRequest = function(url, params = {}, options = {}, methodType, coreParams) {
|
||||||
// 统一把emo转unicode
|
// 统一把emo转unicode
|
||||||
// emoUnicode(params)
|
// emoUnicode(params)
|
||||||
const reqParams = {
|
const reqParams = {
|
||||||
...BaseParam,
|
...BaseParam,
|
||||||
...params,
|
...params,
|
||||||
}
|
}
|
||||||
return dealRequest(coreRequestBase(url, reqParams, options, methodType), url, reqParams).then(res => {
|
return dealRequest(
|
||||||
|
coreRequestBase(url, reqParams, options, methodType, coreParams),
|
||||||
|
url,
|
||||||
|
reqParams,
|
||||||
|
coreParams
|
||||||
|
).then(res => {
|
||||||
// 解析unicode
|
// 解析unicode
|
||||||
// emoUnicode(res, 2)
|
// emoUnicode(res, 2)
|
||||||
return res
|
return res
|
||||||
|
|||||||
@ -169,6 +169,16 @@ const throttle = (fn, wait) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TextEncoder
|
||||||
|
const textEncoder = (input)=> {
|
||||||
|
return unescape(encodeURIComponent(input)).split("").map(val => val.charCodeAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
//TextDecoder
|
||||||
|
const textDecoder = (input)=> {
|
||||||
|
return decodeURIComponent(escape(String.fromCharCode(...[input])));
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getAddressDetail,
|
getAddressDetail,
|
||||||
setAddresModalParam,
|
setAddresModalParam,
|
||||||
@ -179,4 +189,6 @@ export {
|
|||||||
transListKeyTitle,
|
transListKeyTitle,
|
||||||
debounce,
|
debounce,
|
||||||
throttle,
|
throttle,
|
||||||
|
textEncoder,
|
||||||
|
textDecoder
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<tpx-bluetooth v-model:value="blueToothData">
|
<tpx-bluetooth v-model:value="blueToothData">
|
||||||
<template v-slot:button>
|
<template v-slot:button>
|
||||||
|
{{canvasHeight}}
|
||||||
<u-button @click="writeBLECharacteristicValue" type="primary" :disabled="!(blueToothData.deviceId && blueToothData.serviceId && blueToothData.characteristicId)">打印</u-button>
|
<u-button @click="writeBLECharacteristicValue" type="primary" :disabled="!(blueToothData.deviceId && blueToothData.serviceId && blueToothData.characteristicId)">打印</u-button>
|
||||||
</template>
|
</template>
|
||||||
</tpx-bluetooth>
|
</tpx-bluetooth>
|
||||||
<canvas canvas-id="shareCanvas" :style="{width:canvas_width+'px', height: canvas_height+'px'}"></canvas>
|
<canvas canvas-id="shareCanvas" :style="{width:canvasWidth + 'px', height: canvasHeight + 'px'}"></canvas>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -14,14 +15,30 @@ import * as printerUtil from './print/printerutil.js'
|
|||||||
import * as util from './print/util.js'
|
import * as util from './print/util.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
props:{
|
||||||
|
imageUrl: {
|
||||||
|
default () {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
canvasWidth: {
|
||||||
|
default () {
|
||||||
|
return 320
|
||||||
|
}
|
||||||
|
},
|
||||||
|
canvasHeight: {
|
||||||
|
default () {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
canvasId: 'shareCanvas',
|
canvasId: 'shareCanvas',
|
||||||
canvas_width: 480,
|
imgZipData: '',
|
||||||
canvas_height: 480,
|
|
||||||
blueToothData: {
|
blueToothData: {
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
serviceId: '',
|
serviceId: '',
|
||||||
@ -36,11 +53,11 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async initData() {
|
async initData() {
|
||||||
this.pic_res = await this.renderPic();
|
this.imgZipData = await this.renderCanvasImg();
|
||||||
},
|
},
|
||||||
// 打印-发送二进制数据
|
// 打印-发送二进制数据
|
||||||
async writeBLECharacteristicValue(){
|
async writeBLECharacteristicValue(){
|
||||||
let pic_res = this.pic_res
|
let imgZipData = this.imgZipData
|
||||||
let printerJobs = new PrinterJobs()
|
let printerJobs = new PrinterJobs()
|
||||||
|
|
||||||
printerJobs
|
printerJobs
|
||||||
@ -51,7 +68,7 @@ export default {
|
|||||||
// .setBold(true)
|
// .setBold(true)
|
||||||
// .print(`叫那位非常漂亮的小姐姐送来,其他人送来拒收`)
|
// .print(`叫那位非常漂亮的小姐姐送来,其他人送来拒收`)
|
||||||
// .print(printerUtil.fillLine())
|
// .print(printerUtil.fillLine())
|
||||||
.printQrcode(pic_res, this.canvas_width)
|
.printQrcode(imgZipData, this.canvasWidth)
|
||||||
// .setSize(1, 1)
|
// .setSize(1, 1)
|
||||||
// .setBold(false)
|
// .setBold(false)
|
||||||
// .print(printerUtil.fillLine('*'))
|
// .print(printerUtil.fillLine('*'))
|
||||||
@ -121,8 +138,8 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
renderPic() {
|
renderCanvasImg() {
|
||||||
let filePath = 'http://image-c.weimobwmc.com/ol-6NoQb/c2a90db027fa4cd19d2300f21fd8e593.jpg' // TODO
|
let filePath = this.imageUrl
|
||||||
let that = this
|
let that = this
|
||||||
return new Promise((resolve, reject)=> {
|
return new Promise((resolve, reject)=> {
|
||||||
const cxt = uni.createCanvasContext(that.canvasId, that);
|
const cxt = uni.createCanvasContext(that.canvasId, that);
|
||||||
@ -131,11 +148,15 @@ export default {
|
|||||||
src: filePath,
|
src: filePath,
|
||||||
success(res) {
|
success(res) {
|
||||||
// 按原图比例算出 新的画图高度
|
// 按原图比例算出 新的画图高度
|
||||||
that.canvas_height = parseInt(that.canvas_width * (res.height / res.width))
|
let height = that.canvasHeight
|
||||||
cxt.drawImage(filePath, 0, 0, that.canvas_width, that.canvas_height);
|
if(!height) {
|
||||||
|
height = parseInt(that.canvasWidth * (res.height / res.width))
|
||||||
|
that.$emit("update:canvasHeight", height)
|
||||||
|
}
|
||||||
|
cxt.drawImage(filePath, 0, 0, that.canvasWidth, that.canvasHeight);
|
||||||
cxt.draw(true, ()=> {
|
cxt.draw(true, ()=> {
|
||||||
setTimeout( async ()=> {
|
setTimeout( async ()=> {
|
||||||
let data = await that.getImageZip({ canvasId: that.canvasId, width: that.canvas_width, height: that.canvas_height, })
|
let data = await that.getImageZip({ canvasId: that.canvasId, width: that.canvasWidth, height, })
|
||||||
resolve(data)
|
resolve(data)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
});
|
});
|
||||||
@ -180,6 +201,6 @@ export default {
|
|||||||
canvas {
|
canvas {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: -999;
|
z-index: -999;
|
||||||
top: -999rpx;
|
top: -999px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -1,6 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<tpx-page>
|
<tpx-page>
|
||||||
<tpx-bluetooth-print></tpx-bluetooth-print>
|
<tpx-bluetooth-print v-if="!pageLoading" :imageUrl="queryOption.imageUrl" :canvasWidth="queryOption.canvasWidth"
|
||||||
|
v-model:canvasHeight="queryOption.canvasHeight"
|
||||||
|
></tpx-bluetooth-print>
|
||||||
</tpx-page>
|
</tpx-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -8,12 +10,18 @@
|
|||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
pageLoading: true,
|
||||||
|
queryOption: {
|
||||||
|
imageUrl: '',
|
||||||
|
canvasWidth: '',
|
||||||
|
canvasHeight: '',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
@ -21,9 +29,15 @@ export default {
|
|||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
|
|
||||||
|
},
|
||||||
|
onLoad(option) {
|
||||||
|
this.queryOption = option
|
||||||
|
this.initData();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
initData(){
|
||||||
|
this.pageLoading = false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -157,10 +157,9 @@
|
|||||||
handleScanValChange: debounce(function(val){
|
handleScanValChange: debounce(function(val){
|
||||||
// val && ()
|
// val && ()
|
||||||
}),
|
}),
|
||||||
handleSubmit() {
|
async handleSubmit() {
|
||||||
this.getRealGetWaybillPrintData()
|
let res = await this.getRealGetWaybillPrintData()
|
||||||
this.goto("print/bluetoothPrinter")
|
this.goto(`print/bluetoothPrinter?imageUrl=${res.data.fileUrl}&canvasWidth=${480}`)
|
||||||
// this.goto("print/bluetooth-mini-printer")
|
|
||||||
},
|
},
|
||||||
handleSelAll() {
|
handleSelAll() {
|
||||||
if(this.submitParam.subBillCodeRange.length == this.yundanList.length) {
|
if(this.submitParam.subBillCodeRange.length == this.yundanList.length) {
|
||||||
@ -174,7 +173,8 @@
|
|||||||
param.printType = param.printType.join(',')
|
param.printType = param.printType.join(',')
|
||||||
param.subBillCodeRange = param.subBillCodeRange.join(',')
|
param.subBillCodeRange = param.subBillCodeRange.join(',')
|
||||||
// param.isNeedPdf = param.isNeedPdf ? 'T' : ''
|
// param.isNeedPdf = param.isNeedPdf ? 'T' : ''
|
||||||
let res = await apiService.getRealGetWaybillPrintData(param)
|
let res = await apiService.getRealGetWaybillPrintData(param, { _loading: true })
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@
|
|||||||
methods: {
|
methods: {
|
||||||
async initData(){
|
async initData(){
|
||||||
let res = await apiService.getStaffQRCodePng({ _loading: true })
|
let res = await apiService.getStaffQRCodePng({ _loading: true })
|
||||||
this.qrCodeImgUrl = res.data
|
this.qrCodeImgUrl = res?.data?.fileUrl
|
||||||
},
|
},
|
||||||
async handleSave(){
|
async handleSave(){
|
||||||
this.saveNetFile(this.qrCodeImgUrl)
|
this.saveNetFile(this.qrCodeImgUrl)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user