Skip to content

Commit 7adec13

Browse files
committed
feat: hello uni-app 新增 指纹示例 , SQLite 示例
1 parent 08f49e5 commit 7adec13

4 files changed

Lines changed: 602 additions & 314 deletions

File tree

‎pages.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@
474474
"navigationBarTitleText": "数据存储"
475475
}
476476
},
477+
{
478+
"path": "pages/API/sqlite/sqlite",
479+
"style": {
480+
"navigationBarTitleText": "SQLite"
481+
}
482+
},
477483
{
478484
"path": "platforms/app-plus/speech/speech",
479485
"style": {
@@ -535,6 +541,12 @@
535541
"navigationBarTitleText": "蓝牙"
536542
}
537543
},
544+
{
545+
"path": "pages/API/fingerprint/fingerprint",
546+
"style": {
547+
"navigationBarTitleText": "指纹"
548+
}
549+
},
538550
// #endif
539551
{
540552
"path": "pages/API/vibrate/vibrate",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<view class="uni-btn-v"><button type="primary" @tap="fingerprint()" :disabled="disabled">按下开始识别指纹</button></view>
6+
<view style="width: 100%;text-align: center;">{{ result }}</view>
7+
</view>
8+
</view>
9+
</template>
10+
11+
<script>
12+
export default {
13+
data() {
14+
return {
15+
title: '指纹',
16+
result: '',
17+
disabled: true
18+
};
19+
},
20+
onLoad() {
21+
// #ifdef APP-PLUS
22+
if (!plus.fingerprint.isSupport()) {
23+
this.result = '此设备不支持指纹识别';
24+
this.disabled = true;
25+
} else if (!plus.fingerprint.isKeyguardSecure()) {
26+
this.result = '此设备未设置密码锁屏,无法使用指纹识别';
27+
this.disabled = true;
28+
} else if (!plus.fingerprint.isEnrolledFingerprints()) {
29+
this.result = '此设备未录入指纹,请到设置中开启';
30+
this.disabled = true;
31+
} else {
32+
this.result = '此设备支持指纹识别';
33+
this.disabled = false;
34+
}
35+
// #endif
36+
// #ifdef MP-WEIXIN
37+
this.disabled = false;
38+
this.result = '请在微信真机中使用,模拟器不支持';
39+
// #endif
40+
// #ifndef APP-PLUS || MP-WEIXIN
41+
this.result = '此平台不支持指纹识别';
42+
// #endif
43+
},
44+
methods: {
45+
fingerprint: function() {
46+
// #ifdef APP-PLUS
47+
plus.fingerprint.authenticate(
48+
function() {
49+
plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
50+
plus.nativeUI.alert('指纹识别成功');
51+
},
52+
function(e) {
53+
switch (e.code) {
54+
case e.AUTHENTICATE_MISMATCH:
55+
plus.nativeUI.toast('指纹匹配失败,请重新输入');
56+
break;
57+
case e.AUTHENTICATE_OVERLIMIT:
58+
plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
59+
plus.nativeUI.alert('指纹识别失败次数超出限制,请使用其它方式进行认证');
60+
break;
61+
case e.CANCEL:
62+
plus.nativeUI.toast('已取消识别');
63+
break;
64+
default:
65+
plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
66+
plus.nativeUI.alert('指纹识别失败,请重试');
67+
break;
68+
}
69+
}
70+
);
71+
// Android平台手动弹出等待提示框
72+
if ('Android' == plus.os.name) {
73+
plus.nativeUI.showWaiting('指纹识别中...').onclose = function() {
74+
plus.fingerprint.cancel();
75+
};
76+
}
77+
// #endif
78+
79+
// #ifdef MP-WEIXIN
80+
wx.startSoterAuthentication({
81+
requestAuthModes: ['fingerPrint'],
82+
challenge: '123456',
83+
authContent: '请用指纹解锁',
84+
success(res) {
85+
uni.showToast({
86+
title: '识别成功',
87+
mask: false,
88+
duration: 1500
89+
});
90+
}
91+
});
92+
// #endif
93+
}
94+
}
95+
};
96+
</script>
97+
98+
<style></style>

‎pages/API/sqlite/sqlite.vue‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<template>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<view class="uni-btn-v"><button type="primary" @click="openDB">打开数据库test.db</button></view>
6+
<view class="uni-btn-v"><button type="primary" @click="executeSQL">创建表database及插入数据</button></view>
7+
<view class="uni-btn-v"><button type="primary" @click="selectSQL">查询表database的数据</button></view>
8+
<view class="uni-btn-v"><button type="primary" @click="droptable">删除表database</button></view>
9+
<view class="uni-btn-v"><button type="primary" @click="closeDB">关闭数据库test.db</button></view>
10+
<view class="uni-btn-v"><button type="primary" @click="isOpenDB">查询是否打开数据库</button></view>
11+
12+
13+
14+
15+
</view>
16+
</view>
17+
</template>
18+
19+
<script>
20+
export default {
21+
data() {
22+
return {
23+
title: 'SQLite'
24+
};
25+
},
26+
methods: {
27+
openDB: function() {
28+
plus.sqlite.openDatabase({
29+
name: 'first',
30+
path: '_doc/test.db',
31+
success: function(e) {
32+
plus.nativeUI.alert('打开数据库test.db: ' + JSON.stringify(e));
33+
},
34+
fail: function(e) {
35+
plus.nativeUI.alert('打开数据库test.db: ' + JSON.stringify(e));
36+
}
37+
});
38+
},
39+
// 执行SQL语句
40+
executeSQL: function() {
41+
plus.sqlite.executeSql({
42+
name: 'first',
43+
sql: 'create table if not exists database("name" CHAR(110),"sex" CHAR(10),"age" INT(11))',
44+
success: function(e) {
45+
plus.sqlite.executeSql({
46+
name: 'first',
47+
sql: "insert into database values('彦','女','7000')",
48+
success: function(e) {
49+
plus.nativeUI.alert('执行SQL语句: ' + JSON.stringify(e));
50+
},
51+
fail: function(e) {
52+
plus.nativeUI.alert('执行SQL语句: ' + JSON.stringify(e));
53+
}
54+
});
55+
},
56+
fail: function(e) {
57+
plus.nativeUI.alert('执行SQL语句: ' + JSON.stringify(e));
58+
}
59+
});
60+
},
61+
// 查询SQL语句
62+
selectSQL: function() {
63+
plus.sqlite.selectSql({
64+
name: 'first',
65+
sql: 'select * from database',
66+
success: function(e) {
67+
plus.nativeUI.alert('查询SQL语句: ' + JSON.stringify(e));
68+
},
69+
fail: function(e) {
70+
plus.nativeUI.alert('查询SQL语句: ' + JSON.stringify(e));
71+
}
72+
});
73+
},
74+
// 删除表
75+
droptable: function() {
76+
plus.sqlite.executeSql({
77+
name: 'first',
78+
sql: 'drop table database',
79+
success: function(e) {
80+
plus.nativeUI.alert('删除表database: ' + JSON.stringify(e));
81+
},
82+
fail: function(e) {
83+
plus.nativeUI.alert('删除表database: ' + JSON.stringify(e));
84+
}
85+
});
86+
},
87+
// 关闭数据库
88+
closeDB: function() {
89+
plus.sqlite.closeDatabase({
90+
name: 'first',
91+
success: function(e) {
92+
plus.nativeUI.alert('关闭数据库: ' + JSON.stringify(e));
93+
},
94+
fail: function(e) {
95+
plus.nativeUI.alert('关闭数据库: ' + JSON.stringify(e));
96+
}
97+
});
98+
},
99+
isOpenDB: function() {
100+
if (
101+
plus.sqlite.isOpenDatabase({
102+
name: 'first',
103+
path: '_doc/test.db'
104+
})
105+
) {
106+
plus.nativeUI.alert('Opened!');
107+
} else {
108+
plus.nativeUI.alert('Unopened!');
109+
}
110+
}
111+
}
112+
};
113+
</script>
114+
115+
<style>
116+
.uni-btn-v {
117+
margin: 20upx 0;
118+
padding: 0;
119+
}
120+
</style>

0 commit comments

Comments
 (0)