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.
203 lines
6.1 KiB
203 lines
6.1 KiB
<!-- 管理员登录页 -->
|
|
<template>
|
|
<view class="page1" style="overflow: scroll;">
|
|
<view @tap="addList"
|
|
style="width: 90%;height:80rpx;margin:20rpx auto;background: #088FEB;color: #fff;border-radius: 20rpx;text-align: center;line-height: 80rpx;font-size: 32rpx;">
|
|
新增
|
|
</view>
|
|
<button @tap="getQRCode">生成</button>
|
|
<uqrcode ref="uqrcode" canvas-id="qrcode" hide="true" start="false" auto="true" queue="true" :value="QrUrl">
|
|
</uqrcode>
|
|
<img v-for="(item,index) in newQRList" :src="item" alt="" />
|
|
<view> <!-- -->
|
|
<view v-for="(item,index) in QrList1" :key="index"
|
|
style="background: #fff;height: 100rpx;display: flex;line-height: 100rpx;">
|
|
<input type="text" :value="item.name" @blur="addItemName($event,index)" placeholder="输入名称"
|
|
style="width: 30%;display: block;height: 100rpx;text-align: center;font-size: 32rpx;" />
|
|
<input type="text" disabled @tap="scanCodeAdd(index)" :value="item.path" placeholder="点击扫描二维码"
|
|
style="width: 58%;display: block;height: 80rpx;border: 1px solid #eee;padding-left: 20rpx;margin-top: 10rpx;" />
|
|
<view @tap="delItem(index)" style="width:12%;margin-left: 20rpx;">
|
|
<uni-icons color="red" type="minus" size="26"></uni-icons>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view
|
|
style="width: 90%;height:80rpx;position: fixed;bottom: 40rpx;left:5%;background: #088FEB;color: #fff;border-radius: 20rpx;text-align: center;line-height: 80rpx;font-size: 32rpx;">
|
|
提交
|
|
</view>
|
|
<canvas canvas-id="aaaa" style="width: 200px;height: 200px;"></canvas>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
//旧的二维码路径
|
|
QRList: [
|
|
'wxp://f2f0egWTC-6-dnZPjtxrXAnLQemXglhjQB92wtNu01tRoeE',
|
|
'https://u.wechat.com/MINRIYDQnbErEZEUAAhuOL0',
|
|
'https://u.wechat.com/ELXU0g00OAM8huehO8nDQMQ',
|
|
'https://qr.alipay.com/fkx11051559cgeldh61dyf6'
|
|
],
|
|
QrUrl: 'https://qr.95516.com/01020001/wcqr?f=ICBCqr&X=1&T=3&P=13&I=e03d925776684b4d&N=b4cbb142eeafe2bddce7a7878c57f5ca&L=3f7aafc9dbc03de742513fbb73a3380023c77748dbca0813d7a49f63159d542ed2f1e45fac242c519fb6c9a3a51a8caaa3b79f53b538a276', //二维码临时存放
|
|
newQRList: [], // 生成的二维码临时路径的数组
|
|
QrList1: [], // 点击新增按钮,新增一条数据
|
|
aaa: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/67fd6f17a7634400afac9b6694ed9234.png'
|
|
}
|
|
},
|
|
onShow() {
|
|
|
|
},
|
|
onLoad(option) {
|
|
let that = this
|
|
let ctx = uni.createCanvasContext('aaaa', this)
|
|
uni.getImageInfo({
|
|
src: this.aaa,
|
|
success: (res) => {
|
|
// 绘制图片
|
|
ctx.drawImage(res.path, 0, 0, 200, 200);
|
|
ctx.draw(true);
|
|
},
|
|
fail: (err) => {
|
|
console.log(err)
|
|
}
|
|
});
|
|
|
|
setTimeout(res => {
|
|
// 返回canvas的位图数据
|
|
uni.canvasGetImageData({
|
|
canvasId: 'aaaa',
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
success(res) {
|
|
console.log('宽高:' + res.width + ' * ' + res.height) // 100
|
|
let data = {
|
|
width:res.width,
|
|
height:res.height,
|
|
imageData:res.data,
|
|
threshold:180
|
|
}
|
|
console.log(that.overwriteImageData(data))
|
|
}
|
|
})
|
|
}, 2000)
|
|
},
|
|
methods: {
|
|
grayPixle(pix) {
|
|
return pix[0] * 0.299 + pix[1] * 0.587 + pix[2] * 0.114;
|
|
},
|
|
overwriteImageData(data) {
|
|
let sendWidth = data.width,
|
|
sendHeight = data.height;
|
|
const threshold = data.threshold || 180;
|
|
let sendImageData = new ArrayBuffer((sendWidth * sendHeight) / 8);
|
|
sendImageData = new Uint8Array(sendImageData);
|
|
let pix = data.imageData;
|
|
const part = [];
|
|
let index = 0;
|
|
for (let i = 0; i < pix.length; i += 32) {
|
|
//横向每8个像素点组成一个字节(8位二进制数)。
|
|
for (let k = 0; k < 8; k++) {
|
|
const grayPixle1 = this.grayPixle(pix.slice(i + k * 4, i + k * 4 + (4 - 1)));
|
|
//阈值调整
|
|
if (grayPixle1 > threshold) {
|
|
//灰度值大于threshold位 白色 为第k位0不打印
|
|
part[k] = 0;
|
|
} else {
|
|
part[k] = 1;
|
|
}
|
|
}
|
|
let temp = 0;
|
|
for (let a = 0; a < part.length; a++) {
|
|
temp += part[a] * Math.pow(2, part.length - 1 - a);
|
|
}
|
|
sendImageData[index++] = temp;
|
|
}
|
|
return {
|
|
array: Array.from(sendImageData),
|
|
width: sendWidth / 8,
|
|
height: sendHeight,
|
|
};
|
|
console.log(sendImageData)
|
|
|
|
},
|
|
addList() {
|
|
if (this.QrList1.length >= 4) {
|
|
uni.showToast({
|
|
title: '最多只能添加4个二维码',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
let data = {
|
|
name: '',
|
|
path: ''
|
|
}
|
|
this.QrList1.push(data)
|
|
},
|
|
getQRCode() {
|
|
// for (let i = 0; i <= this.QRList.length; i++) {
|
|
|
|
// setTimeout(res => {
|
|
// this.QrUrl = this.QRList[i]
|
|
this.$refs.uqrcode.toTempFilePath({
|
|
success: res => {
|
|
this.newQRList.push(res.tempFilePath)
|
|
}
|
|
});
|
|
// }, 1000 * (i + 1))
|
|
// }
|
|
},
|
|
addItemName(e, index) {
|
|
this.QrList1[index].name = e.detail.value
|
|
console.log(this.QrList1)
|
|
},
|
|
scanCodeAdd(index) {
|
|
let that = this;
|
|
uni.scanCode({
|
|
success: (res) => {
|
|
if (res.result != '') {
|
|
console.log(res.result)
|
|
this.QrList1[index].path = res.result
|
|
} else {
|
|
uni.showToast({
|
|
title: '扫描失败',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
fail: (res) => {
|
|
uni.showToast({
|
|
title: '扫描失败',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
delItem(index) {
|
|
let that = this;
|
|
uni.showModal({
|
|
title: "提示",
|
|
content: "确定要删除吗?",
|
|
success: function(res) {
|
|
if (res.confirm) {
|
|
that.QrList1.splice(index, 1)
|
|
}
|
|
}
|
|
})
|
|
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
page,
|
|
.page1 {
|
|
background: #eee;
|
|
height: 100%;
|
|
}
|
|
</style>
|