文件
jw-beauty/miniprogram/app.js
T
Guoguo 91d5937d8e feat: implement P0 security and reliability improvements
- bcrypt password hashing with auto-migration from SHA-256
- BLE command retry (3 attempts, 500ms delay, skip on disconnect)
- BLE auto-reconnect with service re-discovery on disconnect
- Treatment page disconnect/reconnect event handling
- Token refresh endpoint with 3-day grace period
- Client-side token auto-refresh when <24h remaining
- Single treatment record detail API with ownership check
2026-04-28 18:12:30 -07:00

57 行
1.5 KiB
JavaScript

var http = require('./utils/request')
App({
globalData: {
userInfo: null,
userId: null,
connectedDevice: null,
currentTreatment: null,
statusBarHeight: 44
},
onLaunch: function () {
var sysInfo = wx.getSystemInfoSync()
this.globalData.statusBarHeight = sysInfo.statusBarHeight || 44
this.checkLogin()
},
checkLogin: function () {
var token = wx.getStorageSync('token')
if (!token) {
this.globalData.userInfo = null
return
}
this.loadProfile()
},
loadProfile: function () {
var self = this
http.get('/api/v1/user/profile').then(function (profile) {
self.globalData.userInfo = profile
self.globalData.userId = String(profile.user_id)
}).catch(function () {
wx.removeStorageSync('token')
})
},
doLogin: function () {
return new Promise(function (resolve, reject) {
wx.login({
success: function (res) {
http.post('/api/v1/auth/login', { code: res.code }).then(function (data) {
wx.setStorageSync('token', data.token)
wx.setStorageSync('token_expiry', String(Math.floor(Date.now() / 1000) + (data.expires_in || 604800)))
var app = getApp()
app.globalData.userInfo = data.user_info
app.globalData.userId = data.user_id
resolve(data)
}).catch(reject)
},
fail: function (err) {
reject({ code: 2002, message: err.errMsg || '微信登录失败' })
}
})
})
}
})