文件
jw-beauty/miniprogram/pages/profile/profile.js
T
Guoguo 8d1cde8636 fix: resolve 8 bugs and add admin features
Miniprogram:
- Profile "我的设备": show unbind option when device bound, scan when not
- Add device status indicator (已绑定/未绑定) to profile menu

Admin console:
- Login: add @confirm to inputs so Enter key submits the form
- Record detail: wire up 详情 link with modal showing full record info
- Dashboard: add subscription stats row (月卡/年卡/试用/收入)
- Subscription: add 取消 action for active subscriptions
- Format: fix -8h timezone display for UTC ISO date strings

Server:
- POST /api/v1/admin/subscriptions/cancel: cancel active subscriptions
- Dashboard API: include sub_stats (plan counts + monthly revenue)
- IP extraction: add X-Forwarded-For fallback for logging
2026-04-29 05:33:12 -07:00

92 行
2.4 KiB
JavaScript

var http = require('../../utils/request')
var app = getApp()
Page({
data: {
userInfo: null,
subscription: null,
deviceCount: 0,
subRemaining: 0
},
onShow: function () {
this.loadProfile()
},
loadProfile: function () {
var self = this
http.get('/api/v1/user/profile').then(function (profile) {
self.setData({
userInfo: profile,
deviceCount: profile.device_count || 0
})
}).catch(function () {})
http.get('/api/v1/subscription').then(function (sub) {
self.setData({
subscription: sub,
subRemaining: sub.remaining_days || 0
})
}).catch(function () {})
},
onManageDevice: function () {
var self = this
if (this.data.deviceCount > 0) {
wx.showActionSheet({
itemList: ['解绑当前设备'],
success: function (res) {
if (res.tapIndex === 0) {
wx.showModal({
title: '确认解绑',
content: '解绑后将无法使用该设备,确定要解绑吗?',
success: function (modalRes) {
if (modalRes.confirm) {
http.post('/api/v1/device/unbind', {}).then(function () {
wx.showToast({ title: '已解绑', icon: 'success' })
self.loadProfile()
}).catch(function (err) {
wx.showToast({ title: err.message || '解绑失败', icon: 'none' })
})
}
}
})
}
}
})
} else {
wx.navigateTo({ url: '/pages/scan/scan' })
}
},
onViewSubscription: function () {
if (!this.data.subscription || this.data.subscription.status !== 'active') {
wx.navigateTo({ url: '/pages/subscribe-plans/subscribe-plans' })
} else {
var sub = this.data.subscription
wx.showModal({
title: '订阅信息',
content: '套餐类型:' + (sub.plan || '未知') + '\n剩余天数:' + (sub.remaining_days || 0) + '天',
showCancel: false
})
}
},
onViewHistory: function () {
wx.switchTab({ url: '/pages/history/history' })
},
onLogout: function () {
wx.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success: function (res) {
if (res.confirm) {
wx.removeStorageSync('token')
wx.reLaunch({ url: '/pages/login/login' })
}
}
})
}
})