|
|
|
|
<template>
|
|
|
|
|
<div class="content">
|
|
|
|
|
<tn-button shape="round" backgroundColor="#01BEFF" fontColor="#080808" @click="jumpToPage('/pages/scan/Barcode')">跳转Barcode页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Book')">跳转Book页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Calendar')">跳转Calendar页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @clicksss="jumpToPage('/pages/scan/Contacts')">跳转Contacts页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Email')">跳转Email页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Location')">跳转Location页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Paypal')">跳转Paypal页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Product')">跳转Product页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Sms')">跳转Sms页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Tel')">跳转Tel页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Text')">跳转Text页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Url')">跳转Url页面</tn-button>
|
|
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Wifi')">跳转Wifi页面</tn-button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<button @click="scanCode()">扫码</button>
|
|
|
|
|
<button type="primary" @click="clearData()">清空数据</button>
|
|
|
|
|
<button type="primary" @click="deleteTable()">删除数据表</button>
|
|
|
|
|
<!-- <button @click="writeToDb()">添加数据</button> -->
|
|
|
|
|
<!-- <tn-button type="primary" @click="writeToDb()">添加数据</tn-button> -->
|
|
|
|
|
<!-- <tn-toast ref="toast"></tn-toast> -->
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { openSqlite,executeSql,closedb} from "@/utils/database";
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
title: 'Scan',
|
|
|
|
|
tableName:"scan_code"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
// this.scanCode();
|
|
|
|
|
},
|
|
|
|
|
async onShow(){
|
|
|
|
|
let that = this;
|
|
|
|
|
//打开db
|
|
|
|
|
await that.openSqlite();
|
|
|
|
|
},
|
|
|
|
|
onHide() {
|
|
|
|
|
let that = this;
|
|
|
|
|
that.closedb();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
// 打开数据库
|
|
|
|
|
async openSqlite(){
|
|
|
|
|
try{
|
|
|
|
|
let b = await openSqlite()
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
// title:"open db success",
|
|
|
|
|
// icon:"none"
|
|
|
|
|
// })
|
|
|
|
|
console.log('db打开了');
|
|
|
|
|
}catch(e){
|
|
|
|
|
console.error("open db error",e)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 关闭数据库
|
|
|
|
|
closedb(){
|
|
|
|
|
try{
|
|
|
|
|
closedb()
|
|
|
|
|
console.log('db关闭了');
|
|
|
|
|
}catch(e){
|
|
|
|
|
console.error("close db error",e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async clearData(){
|
|
|
|
|
try{
|
|
|
|
|
await executeSql("DELETE FROM scan_code")
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title:"清除数据成功",
|
|
|
|
|
icon:"none"
|
|
|
|
|
});
|
|
|
|
|
}catch(e){
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title:"清除数据报错,请查看控制台",
|
|
|
|
|
icon:"none"
|
|
|
|
|
});
|
|
|
|
|
console.error("清除数据报错",e)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async deleteTable(){
|
|
|
|
|
try{
|
|
|
|
|
await executeSql("drop table scan_code")
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title:"删除数据表成功",
|
|
|
|
|
icon:"none"
|
|
|
|
|
})
|
|
|
|
|
}catch(e){
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title:"删除数据表失败",
|
|
|
|
|
icon:"none"
|
|
|
|
|
})
|
|
|
|
|
console.error("删除数据表失败scan_code",e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//根据扫码返回结果判断跳转到哪个指定页面
|
|
|
|
|
jumpToPage(url,category,data){
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url: url + '?data='+ data + '&category=' + category
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//mlkit扫码
|
|
|
|
|
scanCode(){
|
|
|
|
|
let that = this;
|
|
|
|
|
var mlscan = uni.requireNativePlugin("JY-MLScanSDK");
|
|
|
|
|
//console.log(mlscan)
|
|
|
|
|
mlscan.startScan(res=> {
|
|
|
|
|
that.analyserCode(res);
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
// icon:'none',
|
|
|
|
|
// title:JSON.stringify(res)
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
analyserCode(res){
|
|
|
|
|
let that = this;
|
|
|
|
|
let result = JSON.parse(JSON.stringify(res))
|
|
|
|
|
console.log('result',result)
|
|
|
|
|
let data = JSON.parse(result.data)
|
|
|
|
|
console.log('data',data)
|
|
|
|
|
let type = data[0].type
|
|
|
|
|
console.log('type',type)
|
|
|
|
|
let data2 = data[0].data
|
|
|
|
|
console.log('data2',data2)
|
|
|
|
|
// let data3 = JSON.stringify(data[0].data)
|
|
|
|
|
// console.log('data3',data3)
|
|
|
|
|
if(result.errorCode != "0"){
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon:'none',
|
|
|
|
|
title: 'scan error!'
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
if(type === 1){
|
|
|
|
|
that.jumpToPage('/pages/scan/Contacts','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 2){
|
|
|
|
|
that.jumpToPage('/pages/scan/Email','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 3){
|
|
|
|
|
that.jumpToPage('/pages/scan/Book','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 4){
|
|
|
|
|
that.jumpToPage('/pages/scan/Tel','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 5){
|
|
|
|
|
that.jumpToPage('/pages/scan/Product','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 6){
|
|
|
|
|
that.jumpToPage('/pages/scan/Sms','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 7){
|
|
|
|
|
that.jumpToPage('/pages/scan/Text','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 8){
|
|
|
|
|
that.jumpToPage('/pages/scan/Url','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 9){
|
|
|
|
|
that.jumpToPage('/pages/scan/Wifi','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 10){
|
|
|
|
|
that.jumpToPage('/pages/scan/Location','scan',JSON.stringify(data2))
|
|
|
|
|
}else if(type === 11){
|
|
|
|
|
that.jumpToPage('/pages/scan/Calendar','scan',JSON.stringify(data2))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
|
|
|
|
.content {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|