File tree Expand file tree Collapse file tree 5 files changed +73
-10
lines changed
cloudfunctions/saveUserinfo Expand file tree Collapse file tree 5 files changed +73
-10
lines changed Original file line number Diff line number Diff line change 1+ const cloud = require ( 'wx-server-sdk' )
2+
3+ cloud . init ( )
4+ const db = cloud . database ( )
5+
6+ // 云函数入口函数
7+ exports . main = async ( event ) => {
8+ const { OPENID : openid } = cloud . getWXContext ( )
9+ const table = db . collection ( 'user_info' )
10+
11+ const { data } = await table . where ( { openid } ) . get ( )
12+
13+ if ( data . length > 0 ) return { errno : 0 , errmsg : 'duplicated user' }
14+
15+ await table . add ( {
16+ data : {
17+ ...event ,
18+ openid,
19+ createTime : new Date ( )
20+ }
21+ } )
22+
23+ return { errno : 0 , errmsg : 'ok' }
24+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " saveUserinfo" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "author" : " " ,
10+ "license" : " ISC" ,
11+ "dependencies" : {
12+ "wx-server-sdk" : " ~2.5.3"
13+ }
14+ }
Original file line number Diff line number Diff line change 11import Toast from 'tdesign-miniprogram/toast/index' ;
22
3+ const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
4+
35Page ( {
46 data : {
57 value : 'my' ,
8+ avatarUrl : defaultAvatarUrl ,
69 tabbars : [ {
710 text : '首页' ,
811 value : 'index' ,
@@ -36,6 +39,18 @@ Page({
3639 } )
3740 } ,
3841
42+ onChooseAvatar ( e ) {
43+ const { avatarUrl } = e . detail ;
44+
45+ this . setData ( { avatarUrl } )
46+ wx . cloud . callFunction ( {
47+ name : 'saveUserinfo' ,
48+ data : {
49+ avatarUrl,
50+ } ,
51+ } )
52+ } ,
53+
3954 handleTabbarChange ( { detail } ) {
4055 const { value } = detail ;
4156
Original file line number Diff line number Diff line change 11.avatar {
2- width : 150 rpx ;
3- height : 150 rpx ;
4- border-radius : 20 rpx ;
2+ width : 120 rpx ;
3+ height : 120 rpx ;
4+ border-radius : 30 rpx ;
55 overflow : hidden ;
6- margin-right : 32 rpx;
7- }
6+
7+ &-button {
8+ margin-right : 32 rpx;
9+ height : 120 rpx;
10+ padding : 0 ;
11+ background : transparent ;
12+
13+ & ::after , & ::before {
14+ display : none ;
15+ }
16+ }
17+ }
Original file line number Diff line number Diff line change 11<view class="container">
22 <t-cell
3- title="点击复制 GitHub 地址 "
3+ title="HowToCookOnMiniprogram "
44 arrow
5- description="GitHub 搜索 HowToCookOnMiniprogram "
5+ description="点击复制 GitHub 地址 "
66 t-class-image="title-image"
77 data-msg="https://github.com/LeeJim/HowToCookOnMiniprogram"
88 bind:click="handleCopy"
99 >
10- <view class="avatar" slot="left-icon">
11- <open-data type="userAvatarUrl" / >
12- </view >
10+ <button class="avatar-button" hover-class="none" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar " slot="left-icon">
11+ <image class="avatar" src="{{avatarUrl}}" catch:tap=""></image >
12+ </button >
1313 </t-cell>
1414 <t-cell title="订阅更新" hover arrow bind:click="handleSubscribe">
1515 <t-icon name="notification" slot="left-icon" />
You can’t perform that action at this time.
0 commit comments