fixed init userinfo
This commit is contained in:
parent
92ede7aca3
commit
25f6fd13ed
@ -13,6 +13,34 @@
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-game:before {
|
||||
content: "\e6df";
|
||||
}
|
||||
|
||||
.icon-gift:before {
|
||||
content: "\e681";
|
||||
}
|
||||
|
||||
.icon-sign-in:before {
|
||||
content: "\e60d";
|
||||
}
|
||||
|
||||
.icon-nav_profile:before {
|
||||
content: "\e669";
|
||||
}
|
||||
|
||||
.icon-vip-fill:before {
|
||||
content: "\e78f";
|
||||
}
|
||||
|
||||
.icon-f-coupon:before {
|
||||
content: "\e778";
|
||||
}
|
||||
|
||||
.icon-collection:before {
|
||||
content: "\e6a5";
|
||||
}
|
||||
|
||||
.icon-clear:before {
|
||||
content: "\e649";
|
||||
}
|
||||
@ -46,6 +74,7 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**global style**/
|
||||
image{
|
||||
max-width: 100%;
|
||||
|
@ -6,31 +6,41 @@ App<IAppOption>({
|
||||
onLaunch() {
|
||||
this.updateUserInfo();
|
||||
},
|
||||
initLoginInfo(resolve, reject) {
|
||||
wx.login({
|
||||
fail: reject,
|
||||
success: (e) => {
|
||||
if (e.code) {
|
||||
info(e.code).then(userinfo => {
|
||||
if (userinfo.token) {
|
||||
wx.setStorageSync("user-token", userinfo.token)
|
||||
}
|
||||
this.globalData.userInfo = userinfo;
|
||||
resolve(userinfo);
|
||||
}).catch(reject)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
updateUserInfo() {
|
||||
return new Promise<UserInfo>((resolve, reject) => {
|
||||
// 展示本地存储能力
|
||||
const token = wx.getStorageSync('user-token')
|
||||
if (token) {
|
||||
this.globalData.token = token;
|
||||
info().then(userinfo => {
|
||||
info('', false).then(userinfo => {
|
||||
console.log(userinfo)
|
||||
this.globalData.userInfo = userinfo;
|
||||
resolve(userinfo);
|
||||
}).catch(reject)
|
||||
} else {
|
||||
wx.login({
|
||||
fail: reject,
|
||||
success: (e) => {
|
||||
if (e.code) {
|
||||
info(e.code).then(userinfo => {
|
||||
if (userinfo.token) {
|
||||
wx.setStorageSync("user-token", userinfo.token)
|
||||
}
|
||||
this.globalData.userInfo = userinfo;
|
||||
resolve(userinfo);
|
||||
}).catch(reject)
|
||||
}
|
||||
}).catch((e) => {
|
||||
if (e.code == 403) {
|
||||
this.initLoginInfo(resolve, reject)
|
||||
return;
|
||||
}
|
||||
reject(e)
|
||||
})
|
||||
} else {
|
||||
this.initLoginInfo(resolve, reject)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -54,6 +54,48 @@
|
||||
<div class="content unicode" style="display: block;">
|
||||
<ul class="icon_lists dib-box">
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">game</div>
|
||||
<div class="code-name">&#xe6df;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">gift</div>
|
||||
<div class="code-name">&#xe681;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">sign-in</div>
|
||||
<div class="code-name">&#xe60d;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">个人信息</div>
|
||||
<div class="code-name">&#xe669;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">vip-fill</div>
|
||||
<div class="code-name">&#xe78f;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">f-coupon</div>
|
||||
<div class="code-name">&#xe778;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">collection</div>
|
||||
<div class="code-name">&#xe6a5;</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont"></span>
|
||||
<div class="name">clear</div>
|
||||
@ -120,9 +162,9 @@
|
||||
<pre><code class="language-css"
|
||||
>@font-face {
|
||||
font-family: 'iconfont';
|
||||
src: url('iconfont.woff2?t=1669601953874') format('woff2'),
|
||||
url('iconfont.woff?t=1669601953874') format('woff'),
|
||||
url('iconfont.ttf?t=1669601953874') format('truetype');
|
||||
src: url('iconfont.woff2?t=1669628868947') format('woff2'),
|
||||
url('iconfont.woff?t=1669628868947') format('woff'),
|
||||
url('iconfont.ttf?t=1669628868947') format('truetype');
|
||||
}
|
||||
</code></pre>
|
||||
<h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
|
||||
@ -148,6 +190,69 @@
|
||||
<div class="content font-class">
|
||||
<ul class="icon_lists dib-box">
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-game"></span>
|
||||
<div class="name">
|
||||
game
|
||||
</div>
|
||||
<div class="code-name">.icon-game
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-gift"></span>
|
||||
<div class="name">
|
||||
gift
|
||||
</div>
|
||||
<div class="code-name">.icon-gift
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-sign-in"></span>
|
||||
<div class="name">
|
||||
sign-in
|
||||
</div>
|
||||
<div class="code-name">.icon-sign-in
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-nav_profile"></span>
|
||||
<div class="name">
|
||||
个人信息
|
||||
</div>
|
||||
<div class="code-name">.icon-nav_profile
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-vip-fill"></span>
|
||||
<div class="name">
|
||||
vip-fill
|
||||
</div>
|
||||
<div class="code-name">.icon-vip-fill
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-f-coupon"></span>
|
||||
<div class="name">
|
||||
f-coupon
|
||||
</div>
|
||||
<div class="code-name">.icon-f-coupon
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-collection"></span>
|
||||
<div class="name">
|
||||
collection
|
||||
</div>
|
||||
<div class="code-name">.icon-collection
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<span class="icon iconfont icon-clear"></span>
|
||||
<div class="name">
|
||||
@ -247,6 +352,62 @@
|
||||
<div class="content symbol">
|
||||
<ul class="icon_lists dib-box">
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-game"></use>
|
||||
</svg>
|
||||
<div class="name">game</div>
|
||||
<div class="code-name">#icon-game</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-gift"></use>
|
||||
</svg>
|
||||
<div class="name">gift</div>
|
||||
<div class="code-name">#icon-gift</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-sign-in"></use>
|
||||
</svg>
|
||||
<div class="name">sign-in</div>
|
||||
<div class="code-name">#icon-sign-in</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-nav_profile"></use>
|
||||
</svg>
|
||||
<div class="name">个人信息</div>
|
||||
<div class="code-name">#icon-nav_profile</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-vip-fill"></use>
|
||||
</svg>
|
||||
<div class="name">vip-fill</div>
|
||||
<div class="code-name">#icon-vip-fill</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-f-coupon"></use>
|
||||
</svg>
|
||||
<div class="name">f-coupon</div>
|
||||
<div class="code-name">#icon-f-coupon</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-collection"></use>
|
||||
</svg>
|
||||
<div class="name">collection</div>
|
||||
<div class="code-name">#icon-collection</div>
|
||||
</li>
|
||||
|
||||
<li class="dib">
|
||||
<svg class="icon svg-icon" aria-hidden="true">
|
||||
<use xlink:href="#icon-clear"></use>
|
||||
|
@ -0,0 +1,75 @@
|
||||
@font-face {
|
||||
font-family: "iconfont"; /* Project id 3795683 */
|
||||
src: url('iconfont.woff2?t=1669628868947') format('woff2'),
|
||||
url('iconfont.woff?t=1669628868947') format('woff'),
|
||||
url('iconfont.ttf?t=1669628868947') format('truetype');
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-family: "iconfont" !important;
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-game:before {
|
||||
content: "\e6df";
|
||||
}
|
||||
|
||||
.icon-gift:before {
|
||||
content: "\e681";
|
||||
}
|
||||
|
||||
.icon-sign-in:before {
|
||||
content: "\e60d";
|
||||
}
|
||||
|
||||
.icon-nav_profile:before {
|
||||
content: "\e669";
|
||||
}
|
||||
|
||||
.icon-vip-fill:before {
|
||||
content: "\e78f";
|
||||
}
|
||||
|
||||
.icon-f-coupon:before {
|
||||
content: "\e778";
|
||||
}
|
||||
|
||||
.icon-collection:before {
|
||||
content: "\e6a5";
|
||||
}
|
||||
|
||||
.icon-clear:before {
|
||||
content: "\e649";
|
||||
}
|
||||
|
||||
.icon-circle:before {
|
||||
content: "\e7b1";
|
||||
}
|
||||
|
||||
.icon-date:before {
|
||||
content: "\e689";
|
||||
}
|
||||
|
||||
.icon-qrcode:before {
|
||||
content: "\e7dd";
|
||||
}
|
||||
|
||||
.icon-cash:before {
|
||||
content: "\e656";
|
||||
}
|
||||
|
||||
.icon-clear1:before {
|
||||
content: "\e600";
|
||||
}
|
||||
|
||||
.icon-vips:before {
|
||||
content: "\e662";
|
||||
}
|
||||
|
||||
.icon-search:before {
|
||||
content: "\e67d";
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -5,6 +5,55 @@
|
||||
"css_prefix_text": "icon-",
|
||||
"description": "",
|
||||
"glyphs": [
|
||||
{
|
||||
"icon_id": "41958",
|
||||
"name": "game",
|
||||
"font_class": "game",
|
||||
"unicode": "e6df",
|
||||
"unicode_decimal": 59103
|
||||
},
|
||||
{
|
||||
"icon_id": "248956",
|
||||
"name": "gift",
|
||||
"font_class": "gift",
|
||||
"unicode": "e681",
|
||||
"unicode_decimal": 59009
|
||||
},
|
||||
{
|
||||
"icon_id": "1238496",
|
||||
"name": "sign-in",
|
||||
"font_class": "sign-in",
|
||||
"unicode": "e60d",
|
||||
"unicode_decimal": 58893
|
||||
},
|
||||
{
|
||||
"icon_id": "3550634",
|
||||
"name": "个人信息",
|
||||
"font_class": "nav_profile",
|
||||
"unicode": "e669",
|
||||
"unicode_decimal": 58985
|
||||
},
|
||||
{
|
||||
"icon_id": "11488335",
|
||||
"name": "vip-fill",
|
||||
"font_class": "vip-fill",
|
||||
"unicode": "e78f",
|
||||
"unicode_decimal": 59279
|
||||
},
|
||||
{
|
||||
"icon_id": "12773718",
|
||||
"name": "f-coupon",
|
||||
"font_class": "f-coupon",
|
||||
"unicode": "e778",
|
||||
"unicode_decimal": 59256
|
||||
},
|
||||
{
|
||||
"icon_id": "16618139",
|
||||
"name": "collection",
|
||||
"font_class": "collection",
|
||||
"unicode": "e6a5",
|
||||
"unicode_decimal": 59045
|
||||
},
|
||||
{
|
||||
"icon_id": "736618",
|
||||
"name": "clear",
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -76,7 +76,7 @@ Page({
|
||||
// 所有其他的商品
|
||||
this.loadGoodsList(this.data.page);
|
||||
},
|
||||
createOrder(e) {
|
||||
createOrder(e: any) {
|
||||
if(!app.globalData.token){
|
||||
// message.toast('请先完成登录','none',()=>{
|
||||
// })
|
||||
@ -98,5 +98,6 @@ Page({
|
||||
}).finally(() => {
|
||||
message.hideLoading()
|
||||
})
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
@ -14,12 +14,17 @@
|
||||
.icon{
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(to right,#91b2ff,#136dff);
|
||||
margin: 10px auto;
|
||||
}
|
||||
.iconfont{
|
||||
font-size: 26px;
|
||||
color: white;
|
||||
}
|
||||
.icon-sign{
|
||||
background: linear-gradient(to right,#ffdfa5,#ff9a31);
|
||||
background: linear-gradient(to right,#ddba7a,#ff9a31);
|
||||
|
||||
}
|
||||
.icon-game{
|
||||
|
@ -69,6 +69,10 @@ Page({
|
||||
|
||||
},
|
||||
openPage(e: any) {
|
||||
if(!app.globalData.userInfo){
|
||||
// 没有登录
|
||||
return;
|
||||
}
|
||||
const dataset = e.currentTarget.dataset
|
||||
if (dataset.url) {
|
||||
wx.navigateTo({
|
||||
|
@ -18,25 +18,33 @@
|
||||
<view>
|
||||
<view class="grid">
|
||||
<view class="grid-item" bindtap="openPage" data-url="/pages/sign/index">
|
||||
<view class="icon icon-sign"></view>
|
||||
<view class="icon icon-sign">
|
||||
<text class="iconfont icon-sign-in"></text>
|
||||
</view>
|
||||
<view class="text">
|
||||
<text>每次签到</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="grid-item">
|
||||
<view class="icon icon-history"></view>
|
||||
<view class="icon icon-history">
|
||||
<text class="iconfont icon-date"></text>
|
||||
</view>
|
||||
<view class="text">
|
||||
<text>兑换记录</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="grid-item">
|
||||
<view class="icon icon-game"></view>
|
||||
<view class="icon icon-game">
|
||||
<text class="iconfont icon-game"></text>
|
||||
</view>
|
||||
<view class="text">
|
||||
<text>积分游戏</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="grid-item">
|
||||
<view class="icon icon-collection"></view>
|
||||
<view class="icon icon-collection">
|
||||
<text class="iconfont icon-gift"></text>
|
||||
</view>
|
||||
<view class="text">
|
||||
<text>我的收藏</text>
|
||||
</view>
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
.header{
|
||||
// 签到信息
|
||||
background-color: #ceb17f;
|
||||
.sign-info{
|
||||
margin-left: 10px;
|
||||
font-size: 14px;
|
||||
|
@ -1,6 +1,8 @@
|
||||
import message from "../../utils/message"
|
||||
import { signInfo, sign } from "../../service/user-api"
|
||||
|
||||
// 获取应用实例
|
||||
const app = getApp<IAppOption>();
|
||||
// pages/sign/index.ts
|
||||
Page({
|
||||
|
||||
@ -8,16 +10,17 @@ Page({
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
pointValue: 0,
|
||||
signToday: false,
|
||||
continuousDays: 0,
|
||||
dayTextArray:[
|
||||
{text:'一',value:5},
|
||||
{text:'二',value:10},
|
||||
{text:'三',value:15},
|
||||
{text:'四',value:20},
|
||||
{text:'五',value:25},
|
||||
{text:'六',value:30},
|
||||
{text:'七',value:35},
|
||||
dayTextArray: [
|
||||
{ text: '一', value: 5 },
|
||||
{ text: '二', value: 10 },
|
||||
{ text: '三', value: 15 },
|
||||
{ text: '四', value: 20 },
|
||||
{ text: '五', value: 25 },
|
||||
{ text: '六', value: 30 },
|
||||
{ text: '七', value: 35 },
|
||||
]
|
||||
},
|
||||
|
||||
@ -25,17 +28,26 @@ Page({
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {
|
||||
signInfo().then(res=>{
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({
|
||||
pointValue: app.globalData.userInfo?.pointInfo?.totalPoint
|
||||
})
|
||||
signInfo().then(res => {
|
||||
this.setData(res)
|
||||
})
|
||||
} else {
|
||||
// 需要登录
|
||||
message.toast('请先登录')
|
||||
wx.navigateBack();
|
||||
}
|
||||
},
|
||||
onSignTag(){
|
||||
onSignTag() {
|
||||
message.showLoading({})
|
||||
sign().then(res=>{
|
||||
getApp<IAppOption>().updateUserInfo();
|
||||
sign().then(res => {
|
||||
app.updateUserInfo();
|
||||
message.hideLoading()
|
||||
this.setData(res)
|
||||
}).catch(err=>{
|
||||
}).catch(err => {
|
||||
message.hideLoading()
|
||||
message.toast(err.message)
|
||||
})
|
||||
|
@ -20,7 +20,7 @@
|
||||
</view>
|
||||
<view class="user-score">
|
||||
<image class="icon-coin" src="./../../assets/images/coin.svg"></image>
|
||||
<text>111</text>
|
||||
<text>{{pointValue}}</text>
|
||||
</view>
|
||||
</div>
|
||||
</view>
|
||||
|
@ -20,6 +20,6 @@ export function sign() {
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
export function info(code: string = '') {
|
||||
return request<UserInfo>('/user/info', { code }, "GET");
|
||||
export function info(code: string = '', showLogin = true) {
|
||||
return request<UserInfo>('/user/info', { code }, "GET", showLogin);
|
||||
}
|
@ -27,7 +27,7 @@ type ApiResponse<T> = {
|
||||
}
|
||||
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"
|
||||
|
||||
function request<T>(api: string, data: any = null, method: HttpMethod = 'POST') {
|
||||
function request<T>(api: string, data: any = null, method: HttpMethod = 'POST',autoShowLogin: boolean = true) {
|
||||
const header: {
|
||||
[key: string]: string
|
||||
} = {}
|
||||
@ -61,7 +61,7 @@ function request<T>(api: string, data: any = null, method: HttpMethod = 'POST')
|
||||
const result = res.data
|
||||
// 验证接口是否正确
|
||||
if (result.code !== 0) {
|
||||
if (result.code === 403) {
|
||||
if (result.code === 403 && autoShowLogin) {
|
||||
wx.switchTab({
|
||||
url: '/pages/personal/personal'
|
||||
})
|
||||
|
3
typings/index.d.ts
vendored
3
typings/index.d.ts
vendored
@ -6,5 +6,6 @@ interface IAppOption {
|
||||
token?: string
|
||||
}
|
||||
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
|
||||
updateUserInfo:()=>Promise<UserInfo>
|
||||
updateUserInfo: () => Promise<UserInfo>
|
||||
initLoginInfo: (resolve: (value: any) => void, reject: (reason: any) => void) => void
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user