You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
246 lines
6.9 KiB
246 lines
6.9 KiB
<!-- 管理员登录页 -->
|
|
<template>
|
|
<view class="page1" style="overflow: scroll;">
|
|
<official-account :bindload="successRes" :binderror="errorRes">
|
|
<view style="width: 100%;height: 100rpx;background: #000;">关注</view>
|
|
</official-account>
|
|
<view style="width:100%;height: 500rpx;color: #000;">
|
|
<kk-printer ref="kkprinter" :bufferData="bufferData" :defaultText="'打印小票'"
|
|
@onPrintSmall="onPrintSmall1"></kk-printer>
|
|
<!-- <button @tap="onPrintSmall1">打印小票</button> -->
|
|
</view>
|
|
<view style="width: 95%;border: 1px solid #000;margin-bottom: 50rpx;">
|
|
<input type="text" v-model="imgData" placeholder="输入地址转位图">
|
|
</view>
|
|
<view @tap="getImage16" style="width: 50%;height: 200rpx;background: #000;color: #fff;">
|
|
转位图
|
|
</view>
|
|
<view @tap="clearImage" style="width: 50%;height: 200rpx;background: #000;color: #fff;">
|
|
清空
|
|
</view>
|
|
<button @click="sendMessage()">发送送消息</button>
|
|
<view style="position: absolute;top: -1500px;z-index: -1;opacity: 0;">
|
|
<canvas canvas-id="myCanvas1" style="width: 32px; height: 32px;"></canvas>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import kkPrinter from '@/components/kk-printer/index.vue';
|
|
import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js';
|
|
export default {
|
|
data() {
|
|
return {
|
|
imgData: '',
|
|
bufferData: [],
|
|
str: ''
|
|
}
|
|
},
|
|
components: {
|
|
kkPrinter
|
|
},
|
|
onShow() {
|
|
|
|
},
|
|
onLoad(option) {
|
|
this.getToken()
|
|
},
|
|
methods: {
|
|
clearImage(){
|
|
this.imgData = ""
|
|
this.$forceUpdate()
|
|
},
|
|
getImage16(){
|
|
let that = this
|
|
const ctx = uni.createCanvasContext('myCanvas1', this);
|
|
//背景图
|
|
// let imgA = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/80a0bf8137804e9088ce605baabf8fdb.png';
|
|
uni.getImageInfo({
|
|
src: this.imgData,
|
|
success: function(image) {
|
|
that.canvasWidth = image.width
|
|
that.canvasHeight = image.height
|
|
ctx.setFillStyle('#fff');
|
|
ctx.fillRect(0, 0, that.canvasWidth, that.canvasHeight);
|
|
ctx.drawImage(image.path, 0, 0, image.width, image.height);
|
|
ctx.draw()
|
|
let width = image.width
|
|
let height = image.height
|
|
let imageData
|
|
setTimeout(res => {
|
|
uni.canvasGetImageData({
|
|
canvasId: 'myCanvas1',
|
|
x: 0,
|
|
y: 0,
|
|
width: image.width,
|
|
height: image.height,
|
|
success(res) {
|
|
imageData = res.data
|
|
/* for(let i=0; i<imageData.length; i += 4){
|
|
// 计算平均亮度
|
|
const avg=(imageData[i]+ imageData[i +1]+ imageData[i + 2])/ 3;
|
|
// 应用同值(例如128),将像素转为纯黑或纯白
|
|
const color=avg>128?255 :0
|
|
imageData[i]=imageData[i+1]=imageData[i+2]= color
|
|
//Alpha通道保持不变
|
|
} */
|
|
that.str = blesdk.addCPCLImageCmd(image.width, image.height, {
|
|
width: image.width, //图像宽度1
|
|
height: image.height, //图像高度
|
|
imageData: imageData, //图像数据
|
|
})
|
|
console.log('222', that.str)
|
|
}
|
|
})
|
|
}, 2000)
|
|
}
|
|
});
|
|
},
|
|
//打印小票
|
|
onPrintSmall1() {
|
|
let that = this;
|
|
let strCmd = ''
|
|
strCmd = blesdk.CreatCPCLPage(1080, 500, 1, 0, 0);
|
|
strCmd += that.str
|
|
|
|
//strCmd += 'EG 6 32 42 32 04000000FFC006000000FFC003800000FFC001C00000FFC0C0C00001FFC0C0600003FFC07F3BC0E7FFC0719F63BEFFC0307E3E1FFFC030160C3AFFC030038070FFC03001C0E0FFC01800C1C0FFC018007380FFC008003F00FFC00C001E00FFC00C001E00FFC004003E00FFC006007380FFC00600E1C0FFC00201C0E0FFC003038070FFC003070038FFC0010E001CFFC0019C000EFFC001B80007FFC000F00003FFC000FFFFFFFFC001C00000FFC003800000FFC006000000FFC006000000FFC0\n'
|
|
strCmd += blesdk.addCPCLPrint();
|
|
that.bufferData.push(strCmd);
|
|
setTimeout(res=>{
|
|
that.bufferData = []
|
|
},5000)
|
|
},
|
|
successRes() {
|
|
|
|
},
|
|
|
|
//获取code
|
|
getToken() {
|
|
let that = this;
|
|
uni.login({
|
|
provider: 'weixin',
|
|
success(res) {
|
|
console.log(res);
|
|
uni.getUserInfo({
|
|
provider: 'weixin',
|
|
success: function(infoRes) {
|
|
console.log(infoRes);
|
|
// that.getOpenId(res.code,infoRes.userInfo.nickName)
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
},
|
|
//获取小程序openid
|
|
getOpenId(code, name) {
|
|
this.tui.request("/user/login", "post", {
|
|
jsCode: code,
|
|
customId: uni.getStorageSync('id'),
|
|
wechatName: name,
|
|
userType: uni.getStorageSync('wayValue')
|
|
}, false, false).then((res) => {
|
|
this.status = 'nomore';
|
|
if (res.code == 200) {
|
|
|
|
} else {
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
},
|
|
//根据openid查询用户信息
|
|
getUserInfo(openId) {
|
|
this.tui.request("", "post", {
|
|
openId: openId
|
|
}, false, false).then((res) => {
|
|
this.status = 'nomore';
|
|
if (res.code == 200) {
|
|
|
|
} else {
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
},
|
|
/*
|
|
发送模板消息
|
|
|
|
⦁对账单模板template_id:xAoOMfWdnT8pwfj_OOskJGKQHVU-8_AYwx1A5I5wBTM
|
|
参数:
|
|
订单金额:{{amount1.DATA}}
|
|
交易时间{{time3.DATA}}
|
|
商户名称{{thing4.DATA}}
|
|
客户姓名{{thing5.DATA}}
|
|
|
|
⦁充值成功模板template_id:WKCcMlr0UoXvulrhX-cBUeEELAd_ar_NnAnw30DjnQE
|
|
参数:
|
|
充值金额{{amount1.DATA}}
|
|
充值时间{{time2.DATA}}
|
|
账户总额{{amount3.DATA}}
|
|
顾客姓名{{thing4.DATA}}
|
|
门店名称{{thing11.DATA}}
|
|
|
|
⦁店铺上新template_id:M45X8AmPi58c16M9YVTMEOhwEVEa9s5md-6i3TwjpRQ
|
|
参数:
|
|
公司名称{{thing3.DATA}}
|
|
提交时间{{time2.DATA}}
|
|
*/
|
|
sendMessage() {
|
|
this.tui.request("/social/wechat/sendWechatTempMessage", "post", {
|
|
touser: "", //openid
|
|
tempId: "M45X8AmPi58c16M9YVTMEOhwEVEa9s5md-6i3TwjpRQ",
|
|
title:"测试",
|
|
content:"{'thing3':'快石科技','time2':'2014-02-01'}",
|
|
categoryId:"",
|
|
userId:"",
|
|
pagePath:"package1/index/shareStyle"
|
|
}, false, false).then((res) => {
|
|
this.status = 'nomore';
|
|
if (res.code == 200) {
|
|
|
|
} else {
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
},
|
|
//店铺上新
|
|
sendMessageUpNew() {
|
|
this.tui.request("", "post", {
|
|
wxList: {
|
|
template_id: '',
|
|
miniprogram: {
|
|
appid: "wx6d7d4fb58d1502db",
|
|
pagepath: ""
|
|
},
|
|
data: {
|
|
keyword1: {
|
|
value: "巧克力"
|
|
},
|
|
keyword2: {
|
|
value: "39.8元"
|
|
},
|
|
keyword3: {
|
|
value: "2014年9月22日"
|
|
}
|
|
}
|
|
},
|
|
categoryId: ""
|
|
}, false, false).then((res) => {
|
|
this.status = 'nomore';
|
|
if (res.code == 200) {
|
|
|
|
} else {
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
page,
|
|
.page1 {
|
|
background: #eee;
|
|
height: 100%;
|
|
}
|
|
</style>
|