init master

This commit is contained in:
LittleBoy 2022-11-21 08:24:09 +08:00
parent 4c648f662f
commit 39429c4347
9 changed files with 282 additions and 68 deletions

View File

@ -1,5 +1,6 @@
{ {
"pages": [ "pages": [
"pages/personal/personal",
"pages/index/index", "pages/index/index",
"pages/logs/logs" "pages/logs/logs"
], ],
@ -9,6 +10,17 @@
"navigationBarTitleText": "Weixin", "navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black"
}, },
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/personal/personal",
"text": "个人中心"
}
]
},
"style": "v2", "style": "v2",
"sitemapLocation": "sitemap.json" "sitemapLocation": "sitemap.json"
} }

View File

@ -8,11 +8,11 @@ App<IAppOption>({
wx.setStorageSync('logs', logs) wx.setStorageSync('logs', logs)
// 登录 // 登录
wx.login({ // wx.login({
success: res => { // success: res => {
console.log(res.code) // console.log(res.code)
// 发送 res.code 到后台换取 openId, sessionKey, unionId // // 发送 res.code 到后台换取 openId, sessionKey, unionId
}, // },
}) // })
}, },
}) })

View File

@ -6,6 +6,7 @@ Page({
data: { data: {
motto: 'Hello World', motto: 'Hello World',
userInfo: {}, userInfo: {},
open_id: '',
hasUserInfo: false, hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'), canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false, canIUseGetUserProfile: false,
@ -39,11 +40,46 @@ Page({
}) })
}, },
getUserInfo(e: any) { getUserInfo(e: any) {
// 不推荐使用getUserInfo获取用户信息预计自2021年4月13日起getUserInfo将不再弹出弹窗并直接返回匿名的用户个人信息 // 用户授权操作后的回调
// 并直接返回匿名的用户个人信息
console.log(e) console.log(e)
this.setData({ this.setData({
userInfo: e.detail.userInfo, userInfo: e.detail.userInfo,
hasUserInfo: true hasUserInfo: true
}) })
},
user_login() {
wx.login({
success: ({ code }) => {
if (!code) {
wx.showToast({
title: '获取授权数据失败'
})
return;
}
// 发起请求
wx.request({
url: 'http://localhost:8080/wechat/login',
data: { code },
method: 'GET',
success: (result) => {
if (result.statusCode != 200) {
wx.showToast({
title: '登录失败'
})
return;
}
this.setData({
open_id: result.data.toString()
})
}
})
},
fail: () => {
wx.showToast({
title: '授权失败'
})
}
})
} }
}) })

View File

@ -1,21 +1,27 @@
<!--index.wxml--> <!--index.wxml-->
<view class="container"> <view class="container">
<view class="userinfo"> <view class="userinfo">
<block wx:if="{{canIUseOpenData}}"> <!-- <block wx:if="{{canIUseOpenData}}">
<view class="userinfo-avatar" bindtap="bindViewTap"> <view class="userinfo-avatar" bindtap="bindViewTap">
<open-data type="userAvatarUrl"></open-data> <open-data type="userAvatarUrl"></open-data>
</view> </view>
<open-data type="userNickName"></open-data> <open-data type="userNickName"></open-data>
</block> </block> -->
<block wx:elif="{{!hasUserInfo}}"> <!-- <block wx:if="{{!hasUserInfo}}">
<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button> <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
<button wx:elif="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button> <button wx:elif="{{canIUse}}"
open-type="getUserInfo"
bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<view wx:else> 请使用1.4.4及以上版本基础库 </view> <view wx:else> 请使用1.4.4及以上版本基础库 </view>
</block> </block>
<block wx:else> <block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image> <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text> <text class="userinfo-nickname">昵称:{{userInfo.nickName}}</text>
</block> </block> -->
<button bindtap="user_login">登录</button>
<view>
{{open_id}}
</view>
</view> </view>
<view class="usermotto"> <view class="usermotto">
<text class="user-motto">{{motto}}</text> <text class="user-motto">{{motto}}</text>

View File

@ -0,0 +1,7 @@
{
"usingComponents": { },
"document-url":"https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/page.html",
"navigationBarTitleText": "个人中心",
"navigationBarBackgroundColor": "#ceb17f",
"navigationBarTextStyle": "white"
}

View File

@ -0,0 +1,37 @@
/* pages/personal.wxss */
@content-widht:90%;
.content-container{
width: @content-widht;
margin: auto;
}
.header{
background-color: #ceb17f;
color:white;
width: 100%;
padding: 30px 0;
.content-container{
display: flex;
justify-content: space-between;
align-items: center;
}
.user-info{
display: flex;
align-items: center;
}
.user-avatar-wrapper{
width: 60px;
height: 60px;
border-radius: 50%;
display: inline-block;
overflow: hidden;
}
.nickname{
margin-left: 10px;
font-size: 20px;
}
.user-avatar{
width: 100%;
height: 100%;
display: block;
}
}

View File

@ -0,0 +1,66 @@
// pages/personal.ts
Page({
/**
*
*/
data: {
},
/**
* --
*/
onLoad() {
},
/**
* --
*/
onReady() {
},
/**
* --
*/
onShow() {
},
/**
* --
*/
onHide() {
},
/**
* --
*/
onUnload() {
},
/**
* --
*/
onPullDownRefresh() {
},
/**
*
*/
onReachBottom() {
},
/**
*
*/
onShareAppMessage() {
}
})

View File

@ -0,0 +1,48 @@
<!--pages/personal.wxml-->
<view class="page-person">
<view class="header">
<div class="content-container">
<view class="user-info">
<view class="user-avatar-wrapper">
<open-data class="user-avatar" type="userAvatarUrl"></open-data>
</view>
<text class="nickname">张三</text>
</view>
<view class="user-score">
<text>1,121</text>
</view>
</div>
</view>
<view>
<view class="grid">
<view class="grid-item">
<view class="icon">
</view>
<view class="text">
<text>每次签到</text>
</view>
</view>
<view class="grid-item">
<view class="icon">
</view>
<view class="text">
<text>兑换记录</text>
</view>
</view>
<view class="grid-item">
<view class="icon">
</view>
<view class="text">
<text>积分游戏</text>
</view>
</view>
<view class="grid-item">
<view class="icon">
</view>
<view class="text">
<text>我的收藏</text>
</view>
</view>
</view>
</view>
</view>

View File

@ -2,6 +2,8 @@
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "PointApp", "projectname": "PointApp",
"setting": { "setting": {
"compileHotReLoad": true "compileHotReLoad": true,
} "urlCheck": false
},
"libVersion": "2.23.0"
} }