lijuncheng
7 months ago
12 changed files with 79 additions and 130 deletions
@ -1,70 +1,70 @@ |
|||||
<template> |
<template> |
||||
<view class="content"> |
<view class="content"> |
||||
<view class="btn-wrap"> |
<view class="" style="position: absolute; bottom:80px ;left: 30px;z-index: 99999;"> |
||||
<kk-printer ref="kkprinter" :bufferData="bufferData" @onPrint="onPrint"></kk-printer> |
打印 |
||||
</view> |
</view> |
||||
|
<web-view src="/hybrid/html/point.html" :fullscreen='false' :webview-styles="webviewStyles"></web-view> |
||||
</view> |
</view> |
||||
</template> |
</template> |
||||
|
|
||||
<script> |
<script> |
||||
import util from '@/components/kk-printer/utils/util.js'; |
const htmlFileUrl = '/hybrid/html/point.html'; |
||||
import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js'; |
|
||||
import kkPrinter from '@/components/kk-printer/index.vue'; |
|
||||
export default { |
export default { |
||||
data() { |
data() { |
||||
return { |
return { |
||||
bufferData:'' |
webviewStyles: { |
||||
|
progress: { |
||||
|
color: '#FF3333' |
||||
|
}, |
||||
|
width: '100%', |
||||
|
height: '600px', |
||||
|
} |
||||
} |
} |
||||
}, |
}, |
||||
components:{ |
|
||||
kkPrinter |
|
||||
}, |
|
||||
mounted() { |
mounted() { |
||||
|
|
||||
}, |
}, |
||||
methods: { |
methods: { |
||||
onPrint(opt){ |
|
||||
let arr = ['2','3'] |
readFile(path, callback) { |
||||
let y = 450 |
plus.io.resolveLocalFileSystemURL(path, function(entry) { |
||||
let strCmd =blesdk.CreatCPCLPage(400,y*arr.length,1,0); |
entry.file(function(file) { |
||||
arr.forEach((item,index)=>{ |
var reader = new plus.io.FileReader(); |
||||
strCmd += blesdk.addCPCLLine(0,210 + (y*index),400,210+ (y*index),3); |
reader.onloadend = function(e) { |
||||
strCmd += blesdk.addCPCLText(10,0 + (y*index),'4','3',0,'8.14'); |
callback(e.target.result); |
||||
strCmd += blesdk.addCPCLBarCode(270,0 + (y*index),'128',80,0,1,1,'00051'); |
}; |
||||
strCmd += blesdk.addCPCLText(290,80 + (y*index),'7','2',0,'00051'); |
reader.readAsText(file); |
||||
strCmd += blesdk.addCPCLText(40,110 + (y*index),'3','0',0,'CHICKEN FEET (BONELESS)'); |
}, function(e) { |
||||
// strCmd += blesdk.addCPCLSETMAG(2,2); |
console.log("读取文件失败:" + e.message); |
||||
strCmd += blesdk.addCPCLText(40,150 + (y*index),'55','0',0,'无骨鸡爪 一盒(约1.5磅)'); |
}); |
||||
// strCmd += blesdk.addCPCLSETMAG(0,0); |
}, function(e) { |
||||
strCmd += blesdk.addCPCLText(0,180 + (y*index),'7','2',0,'2019-08-12'); |
console.log("获取图片资源失败:" + e.message); |
||||
strCmd += blesdk.addCPCLLocation(2);//循环里之后的所有的都居中了 |
}); |
||||
strCmd += blesdk.addCPCLQRCode(0,220 + (y*index),'M', 2, 6, 'qr code test'); |
|
||||
}) |
|
||||
console.log(strCmd) |
|
||||
strCmd += blesdk.addCPCLPrint(); |
|
||||
this.bufferData = strCmd; |
|
||||
} |
} |
||||
} |
}, |
||||
|
onShow() { |
||||
|
this.readFile(htmlFileUrl, function(htmlContent) { |
||||
|
console.log(htmlContent); // 这里是HTML文件的内容字符串 |
||||
|
console.log(typeof htmlContent); // 这里是HTML文件的内容字符串 |
||||
|
}); |
||||
|
// uni.request({ |
||||
|
// url: htmlFileUrl, |
||||
|
// method: 'GET', |
||||
|
// success: function(res) { |
||||
|
// // res.data就是HTML文件的内容 |
||||
|
// var htmlString = res.data; |
||||
|
// console.log(htmlString); |
||||
|
// }, |
||||
|
// fail: function(error) { |
||||
|
// console.error('请求HTML文件失败:', error); |
||||
|
// } |
||||
|
// }); |
||||
|
}, |
||||
|
|
||||
} |
} |
||||
</script> |
</script> |
||||
|
|
||||
<style> |
<style> |
||||
.content { |
|
||||
width: 100vw; |
</style> |
||||
height: 100vh; |
|
||||
display: flex; |
|
||||
flex-direction: column; |
|
||||
align-items: center; |
|
||||
justify-content: center; |
|
||||
} |
|
||||
.btn-wrap{ |
|
||||
width:180upx; |
|
||||
height: 100upx; |
|
||||
border-radius: 16upx; |
|
||||
border: 2upx solid #333333; |
|
||||
box-sizing: border-box; |
|
||||
display: flex; |
|
||||
justify-content: center; |
|
||||
align-items: center; |
|
||||
} |
|
||||
</style> |
|
Loading…
Reference in new issue