|
|
|
@ -1,5 +1,5 @@ |
|
|
|
<template> |
|
|
|
<view class="content"> |
|
|
|
<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> |
|
|
|
@ -15,20 +15,20 @@ |
|
|
|
<tn-button shape="round" @click="jumpToPage('/pages/scan/Wifi')">跳转Wifi页面</tn-button> |
|
|
|
|
|
|
|
|
|
|
|
<tn-button type="primary" @click="scanCode()">扫码</tn-button> |
|
|
|
<tn-button type="primary" @click="testAdd">相加</tn-button> |
|
|
|
<tn-button type="primary" @click="writeToDb()">添加数据</tn-button> |
|
|
|
<tn-toast ref="toast"></tn-toast> |
|
|
|
</view> |
|
|
|
<button @click="scanCode()">扫码</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,isTable,addSql} from "@/utils/database"; |
|
|
|
//import { openSqlite,executeSql,closedb,isTable,addSql} from "@/utils/database"; |
|
|
|
export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
title: 'Scan', |
|
|
|
tableName:"scancode", |
|
|
|
tableName:"scancode" |
|
|
|
} |
|
|
|
}, |
|
|
|
created() { |
|
|
|
@ -36,132 +36,144 @@ |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
|
|
|
|
testAdd(){ |
|
|
|
const testModule = uni.requireNativePlugin('scanCode'); |
|
|
|
testModule.add({ |
|
|
|
a:1, |
|
|
|
b:2 |
|
|
|
},res => { |
|
|
|
uni.showToast({ |
|
|
|
title: '提示', |
|
|
|
content: JSON.stringify(res) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
//写入扫描记录 |
|
|
|
async writeToDb(){ |
|
|
|
try{ |
|
|
|
let b = await addSql(this.tableName,{title:"你好,世界!",content:"世界:你好呀!",desc:"嘻嘻"}) |
|
|
|
uni.showToast({ |
|
|
|
title:"添加成功", |
|
|
|
icon:"none" |
|
|
|
}); |
|
|
|
}catch(e){ |
|
|
|
console.error("insert data error!",e) |
|
|
|
} |
|
|
|
}, |
|
|
|
// async writeToDb(){ |
|
|
|
// try{ |
|
|
|
// let b = await addSql(this.tableName,{title:"你好,世界!",content:"世界:你好呀!",desc:"嘻嘻"}) |
|
|
|
// uni.showToast({ |
|
|
|
// title:"添加成功", |
|
|
|
// icon:"none" |
|
|
|
// }); |
|
|
|
// }catch(e){ |
|
|
|
// console.error("insert data error!",e) |
|
|
|
// } |
|
|
|
// }, |
|
|
|
|
|
|
|
// 创建表 |
|
|
|
async createTable(){ |
|
|
|
let sql = this.createTableSql_outbound() |
|
|
|
try{ |
|
|
|
let exist = await isTable(this.tableName) |
|
|
|
console.log("表是否存在",exist) |
|
|
|
if(!exist){ |
|
|
|
let res = await executeSql(sql) |
|
|
|
uni.showToast({ |
|
|
|
title:"insert table ok", |
|
|
|
icon:"none" |
|
|
|
}) |
|
|
|
console.log("新增表scancode",res) |
|
|
|
}else{ |
|
|
|
uni.showToast({ |
|
|
|
title:"table exist", |
|
|
|
icon:"none" |
|
|
|
}) |
|
|
|
} |
|
|
|
}catch(e){ |
|
|
|
uni.showToast({ |
|
|
|
title:"insert table error", |
|
|
|
icon:"none" |
|
|
|
}) |
|
|
|
console.error("新增表报错scancode",e) |
|
|
|
} |
|
|
|
}, |
|
|
|
// async createTable(){ |
|
|
|
// let sql = this.createTableSql_outbound() |
|
|
|
// try{ |
|
|
|
// let exist = await isTable(this.tableName) |
|
|
|
// console.log("表是否存在",exist) |
|
|
|
// if(!exist){ |
|
|
|
// let res = await executeSql(sql) |
|
|
|
// uni.showToast({ |
|
|
|
// title:"insert table ok", |
|
|
|
// icon:"none" |
|
|
|
// }) |
|
|
|
// console.log("新增表scancode",res) |
|
|
|
// }else{ |
|
|
|
// uni.showToast({ |
|
|
|
// title:"table exist", |
|
|
|
// icon:"none" |
|
|
|
// }) |
|
|
|
// } |
|
|
|
// }catch(e){ |
|
|
|
// uni.showToast({ |
|
|
|
// title:"insert table error", |
|
|
|
// icon:"none" |
|
|
|
// }) |
|
|
|
// console.error("新增表报错scancode",e) |
|
|
|
// } |
|
|
|
// }, |
|
|
|
|
|
|
|
// 打开数据库 |
|
|
|
async openSqlite(){ |
|
|
|
try{ |
|
|
|
let b = await openSqlite() |
|
|
|
uni.showToast({ |
|
|
|
title:"open db success", |
|
|
|
icon:"none" |
|
|
|
}) |
|
|
|
}catch(e){ |
|
|
|
console.error("open db error",e) |
|
|
|
} |
|
|
|
}, |
|
|
|
// async openSqlite(){ |
|
|
|
// try{ |
|
|
|
// let b = await openSqlite() |
|
|
|
// uni.showToast({ |
|
|
|
// title:"open db success", |
|
|
|
// icon:"none" |
|
|
|
// }) |
|
|
|
// }catch(e){ |
|
|
|
// console.error("open db error",e) |
|
|
|
// } |
|
|
|
// }, |
|
|
|
|
|
|
|
// 关闭数据库 |
|
|
|
closedb(){ |
|
|
|
try{ |
|
|
|
closedb() |
|
|
|
}catch(e){ |
|
|
|
console.error("close db error",e) |
|
|
|
} |
|
|
|
// closedb(){ |
|
|
|
// try{ |
|
|
|
// closedb() |
|
|
|
// }catch(e){ |
|
|
|
// console.error("close db error",e) |
|
|
|
// } |
|
|
|
|
|
|
|
}, |
|
|
|
// }, |
|
|
|
|
|
|
|
//根据扫码返回结果判断跳转到哪个指定页面 |
|
|
|
jumpToPage(url){ |
|
|
|
jumpToPage(url,data){ |
|
|
|
uni.navigateTo({ |
|
|
|
url: url |
|
|
|
url: url + '?data='+ data |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
//阿里扫描 |
|
|
|
// scanCode() { |
|
|
|
// var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module") |
|
|
|
// mpaasScanModule.mpaasScan({ |
|
|
|
// // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有 |
|
|
|
// // 'scanType': ['qrCode', 'barCode'], |
|
|
|
// // 是否隐藏相册,默认false不隐藏 |
|
|
|
// 'hideAlbum': false, |
|
|
|
// }, |
|
|
|
// (ret) => { |
|
|
|
// console.log(JSON.stringify(ret)) |
|
|
|
// this.$refs.toast.show({ |
|
|
|
// title: '支付成功', |
|
|
|
// content: JSON.stringify(ret), |
|
|
|
// icon: 'success', |
|
|
|
// duration: 2000 |
|
|
|
// }); |
|
|
|
// console.log('24123123') |
|
|
|
// }) |
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
|
|
//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) |
|
|
|
// }) |
|
|
|
this.$refs.toast.show({ |
|
|
|
title: 'scan success', |
|
|
|
content: JSON.stringify(res), |
|
|
|
icon: 'success', |
|
|
|
duration: 2000 |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
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',JSON.stringify(data2)) |
|
|
|
}else if(type === 2){ |
|
|
|
that.jumpToPage('/pages/scan/Email',JSON.stringify(data2)) |
|
|
|
}else if(type === 3){ |
|
|
|
that.jumpToPage('/pages/scan/Book',JSON.stringify(data2)) |
|
|
|
}else if(type === 4){ |
|
|
|
that.jumpToPage('/pages/scan/Tel',JSON.stringify(data2)) |
|
|
|
}else if(type === 5){ |
|
|
|
that.jumpToPage('/pages/scan/Product',JSON.stringify(data2)) |
|
|
|
}else if(type === 6){ |
|
|
|
that.jumpToPage('/pages/scan/Sms',JSON.stringify(data2)) |
|
|
|
}else if(type === 7){ |
|
|
|
that.jumpToPage('/pages/scan/Text',JSON.stringify(data2)) |
|
|
|
}else if(type === 8){ |
|
|
|
that.jumpToPage('/pages/scan/Url',JSON.stringify(data2)) |
|
|
|
}else if(type === 9){ |
|
|
|
that.jumpToPage('/pages/scan/Wifi',JSON.stringify(data2)) |
|
|
|
}else if(type === 10){ |
|
|
|
that.jumpToPage('/pages/scan/Location',JSON.stringify(data2)) |
|
|
|
}else if(type === 11){ |
|
|
|
that.jumpToPage('/pages/scan/Calendar',JSON.stringify(data2)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<style lang="scss"> |
|
|
|
|
|
|
|
.content { |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
@ -169,22 +181,4 @@ |
|
|
|
justify-content: center; |
|
|
|
} |
|
|
|
|
|
|
|
.logo { |
|
|
|
height: 200rpx; |
|
|
|
width: 200rpx; |
|
|
|
margin-top: 200rpx; |
|
|
|
margin-left: auto; |
|
|
|
margin-right: auto; |
|
|
|
margin-bottom: 50rpx; |
|
|
|
} |
|
|
|
|
|
|
|
.text-area { |
|
|
|
display: flex; |
|
|
|
justify-content: center; |
|
|
|
} |
|
|
|
|
|
|
|
.title { |
|
|
|
font-size: 36rpx; |
|
|
|
color: #8f8f94; |
|
|
|
} |
|
|
|
</style> |
|
|
|
|