Skip to content

Commit 85ed6c2

Browse files
committed
feat: update my page
1 parent 1b2a816 commit 85ed6c2

File tree

5 files changed

+73
-10
lines changed

5 files changed

+73
-10
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

miniprogram/pages/my/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import Toast from 'tdesign-miniprogram/toast/index';
22

3+
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
4+
35
Page({
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

miniprogram/pages/my/index.less

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
.avatar {
2-
width: 150rpx;
3-
height: 150rpx;
4-
border-radius: 20rpx;
2+
width: 120rpx;
3+
height: 120rpx;
4+
border-radius: 30rpx;
55
overflow: hidden;
6-
margin-right: 32rpx;
7-
}
6+
7+
&-button {
8+
margin-right: 32rpx;
9+
height: 120rpx;
10+
padding: 0;
11+
background: transparent;
12+
13+
&::after, &::before {
14+
display: none;
15+
}
16+
}
17+
}

miniprogram/pages/my/index.wxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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" />

0 commit comments

Comments
 (0)