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,14 +1,26 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
"pages": [
"pages/personal/personal",
"pages/index/index",
"pages/logs/logs"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black"
},
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/personal/personal",
"text": "个人中心"
}
]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}

View File

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

View File

@ -3,47 +3,83 @@
const app = getApp<IAppOption>()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs',
})
},
onLoad() {
// @ts-ignore
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile() {
// 推荐使用wx.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认开发者妥善保管用户快速填写的头像昵称避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
data: {
motto: 'Hello World',
userInfo: {},
open_id: '',
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs',
})
}
})
},
getUserInfo(e: any) {
// 不推荐使用getUserInfo获取用户信息预计自2021年4月13日起getUserInfo将不再弹出弹窗并直接返回匿名的用户个人信息
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
},
onLoad() {
// @ts-ignore
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile() {
// 推荐使用wx.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认开发者妥善保管用户快速填写的头像昵称避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(e: any) {
// 用户授权操作后的回调
// 并直接返回匿名的用户个人信息
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
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-->
<view class="container">
<view class="userinfo">
<block wx:if="{{canIUseOpenData}}">
<!-- <block wx:if="{{canIUseOpenData}}">
<view class="userinfo-avatar" bindtap="bindViewTap">
<open-data type="userAvatarUrl"></open-data>
</view>
<open-data type="userNickName"></open-data>
</block>
<block wx:elif="{{!hasUserInfo}}">
</block> -->
<!-- <block wx:if="{{!hasUserInfo}}">
<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>
</block>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
<text class="userinfo-nickname">昵称:{{userInfo.nickName}}</text>
</block> -->
<button bindtap="user_login">登录</button>
<view>
{{open_id}}
</view>
</view>
<view class="usermotto">
<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",
"projectname": "PointApp",
"setting": {
"compileHotReLoad": true
}
"compileHotReLoad": true,
"urlCheck": false
},
"libVersion": "2.23.0"
}