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