-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
108 lines (95 loc) · 2.23 KB
/
app.js
File metadata and controls
108 lines (95 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const config = require('./config.js')
App({
onLaunch() {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
traceUser: true,
env: config.envId
})
}
this.checkAuth()
},
onShow(options) {
console.log('App Show', options)
},
onHide() {
console.log('App Hide')
},
globalData: {
userInfo: null,
isAuthorized: false,
envId: config.envId,
mode: '审核',
auditTime: '2026-03-09 11:40'
},
onShareAppMessage() {
return {
title: '美食展 - 探索美味菜谱',
path: '/pages/index/index'
}
},
onShareTimeline() {
return {
title: '美食展 - 探索美味菜谱',
query: ''
}
},
checkAuth() {
const userInfo = wx.getStorageSync('userInfo')
if (userInfo) {
this.globalData.userInfo = userInfo
this.globalData.isAuthorized = true
}
},
isInAuditWindow() {
const mode = this.globalData.mode
if (mode !== '审核') {
return false
}
const auditTimeStr = this.globalData.auditTime
if (!auditTimeStr) {
return false
}
const auditTime = new Date(auditTimeStr).getTime()
const now = new Date().getTime()
const diff = now - auditTime
const thirtyMinutes = 30 * 60 * 1000
return diff >= 0 && diff <= thirtyMinutes
},
getUserProfile(callback) {
wx.getUserProfile({
desc: '用于完善用户资料',
success: (res) => {
this.globalData.userInfo = res.userInfo
this.globalData.isAuthorized = true
wx.setStorageSync('userInfo', res.userInfo)
if (callback) callback(true)
},
fail: () => {
wx.showToast({ title: '授权失败', icon: 'none' })
if (callback) callback(false)
}
})
},
checkAndAuthorize(callback) {
if (this.globalData.isAuthorized) {
if (callback) callback(true)
return true
}
wx.showModal({
title: '提示',
content: '请先授权登录',
confirmText: '去授权',
success: (res) => {
if (res.confirm) {
wx.switchTab({
url: '/pages/profile/profile'
})
}
}
})
return false
}
})