feat: production readiness — feature gaps + config hardening
Miniprogram: - Add BLE reconnect button on home page when disconnected - Add loading states to index, profile, subscribe-plans pages - Add profile editing (avatar + nickname) with COS upload - Enable pull-to-refresh on history page - Fix auto-scan self.options → self.data inconsistency - Add console.error to silent catch blocks - Gate 'Simple Peripheral' BLE scan behind __DEV__ flag - Add production config comment to env.js Admin console: - Add empty state '暂无数据' to all 5 list views - Replace plain text plan input with select dropdown - Add type="date" to record date filters - Add production config comment Server: - CORS origin restricted in production (env CORS_ORIGIN) - DB pool size configurable via DB_POOL_SIZE env var - .env.example updated with WeChat Pay + production fields
这个提交包含在:
@@ -1,4 +1,5 @@
|
||||
var api = require('../../utils/api')
|
||||
var config = require('../../config/env')
|
||||
var app = getApp()
|
||||
|
||||
Page({
|
||||
@@ -6,7 +7,12 @@ Page({
|
||||
userInfo: null,
|
||||
subscription: null,
|
||||
deviceCount: 0,
|
||||
subRemaining: 0
|
||||
subRemaining: 0,
|
||||
loading: true,
|
||||
editing: false,
|
||||
editNickname: '',
|
||||
editAvatarUrl: '',
|
||||
saving: false
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
@@ -15,19 +21,29 @@ Page({
|
||||
|
||||
loadProfile: function () {
|
||||
var self = this
|
||||
api.getProfile().then(function (profile) {
|
||||
self.setData({ loading: true })
|
||||
|
||||
var p1 = api.getProfile().then(function (profile) {
|
||||
self.setData({
|
||||
userInfo: profile,
|
||||
deviceCount: profile.device_count || 0
|
||||
})
|
||||
}).catch(function () {})
|
||||
}).catch(function (err) {
|
||||
console.error('getProfile failed', err)
|
||||
})
|
||||
|
||||
api.getSubscription().then(function (sub) {
|
||||
var p2 = api.getSubscription().then(function (sub) {
|
||||
self.setData({
|
||||
subscription: sub,
|
||||
subRemaining: sub.remaining_days || 0
|
||||
})
|
||||
}).catch(function () {})
|
||||
}).catch(function (err) {
|
||||
console.error('getSubscription failed', err)
|
||||
})
|
||||
|
||||
Promise.all([p1, p2]).then(function () {
|
||||
self.setData({ loading: false })
|
||||
})
|
||||
},
|
||||
|
||||
onManageDevice: function () {
|
||||
@@ -75,6 +91,93 @@ Page({
|
||||
wx.navigateTo({ url: '/pages/contact/contact' })
|
||||
},
|
||||
|
||||
onEditProfile: function () {
|
||||
var info = this.data.userInfo || {}
|
||||
this.setData({
|
||||
editing: true,
|
||||
editNickname: info.nickname || '',
|
||||
editAvatarUrl: info.avatar || ''
|
||||
})
|
||||
},
|
||||
|
||||
onCancelEdit: function () {
|
||||
this.setData({ editing: false })
|
||||
},
|
||||
|
||||
onEditNicknameInput: function (e) {
|
||||
this.setData({ editNickname: e.detail.value || '' })
|
||||
},
|
||||
|
||||
onPickAvatar: function () {
|
||||
var self = this
|
||||
wx.chooseMedia({
|
||||
count: 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: function (res) {
|
||||
if (res.tempFiles && res.tempFiles[0]) {
|
||||
self.setData({ editAvatarUrl: res.tempFiles[0].tempFilePath })
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
uploadAvatar: function (tempPath) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var token = wx.getStorageSync('token')
|
||||
wx.uploadFile({
|
||||
url: config.API_BASE + '/api/v1/user/avatar',
|
||||
filePath: tempPath,
|
||||
name: 'file',
|
||||
header: { Authorization: 'Bearer ' + token },
|
||||
success: function (res) {
|
||||
try {
|
||||
var data = JSON.parse(res.data)
|
||||
if (data.code === 0 && data.data && data.data.avatar) {
|
||||
resolve(data.data.avatar)
|
||||
} else {
|
||||
reject(new Error(data.message || '上传失败'))
|
||||
}
|
||||
} catch (e) {
|
||||
reject(new Error('上传失败'))
|
||||
}
|
||||
},
|
||||
fail: function () { reject(new Error('上传失败')) }
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
onSaveProfile: function () {
|
||||
var self = this
|
||||
var nickname = (self.data.editNickname || '').trim()
|
||||
if (!nickname) {
|
||||
wx.showToast({ title: '昵称不能为空', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
self.setData({ saving: true })
|
||||
|
||||
var avatarUrl = self.data.editAvatarUrl
|
||||
var isLocalFile = avatarUrl && (avatarUrl.indexOf('wxfile://') === 0 || avatarUrl.indexOf('http://tmp') === 0)
|
||||
var avatarPromise = isLocalFile
|
||||
? self.uploadAvatar(avatarUrl)
|
||||
: Promise.resolve(avatarUrl || '')
|
||||
|
||||
avatarPromise.then(function (permanentUrl) {
|
||||
return api.updateProfile({
|
||||
nickname: nickname,
|
||||
avatar: permanentUrl || ''
|
||||
})
|
||||
}).then(function () {
|
||||
self.setData({ saving: false, editing: false })
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
self.loadProfile()
|
||||
}).catch(function (err) {
|
||||
self.setData({ saving: false })
|
||||
wx.showToast({ title: err.message || '保存失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
onLogout: function () {
|
||||
wx.showModal({
|
||||
title: '退出登录',
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
<view class="page">
|
||||
<view class="page-content">
|
||||
<view class="loading-container" wx:if="{{loading}}">
|
||||
<view class="loading-spinner"></view>
|
||||
<text class="loading-text">加载中...</text>
|
||||
</view>
|
||||
|
||||
<view class="page-content" wx:if="{{!loading}}">
|
||||
<view class="user-row">
|
||||
<view class="user-avatar">👤</view>
|
||||
<image class="user-avatar-img" wx:if="{{userInfo.avatar}}" src="{{userInfo.avatar}}" mode="aspectFill"></image>
|
||||
<view class="user-avatar" wx:else>👤</view>
|
||||
<view class="user-info">
|
||||
<view class="user-name">{{userInfo.nickname || '未登录'}}</view>
|
||||
<view class="user-phone">{{userInfo.phone || ''}}</view>
|
||||
</view>
|
||||
<view class="edit-profile-btn" bindtap="onEditProfile">编辑资料</view>
|
||||
</view>
|
||||
|
||||
<view class="sub-card" wx:if="{{subscription && subscription.status === 'active' && subRemaining > 0}}">
|
||||
@@ -55,4 +62,23 @@
|
||||
|
||||
<view class="logout-btn" bindtap="onLogout">退出登录</view>
|
||||
</view>
|
||||
|
||||
<!-- Edit profile modal -->
|
||||
<view class="edit-mask" wx:if="{{editing}}" bindtap="onCancelEdit"></view>
|
||||
<view class="edit-modal" wx:if="{{editing}}">
|
||||
<view class="edit-modal-title">编辑资料</view>
|
||||
<view class="edit-avatar-row" bindtap="onPickAvatar">
|
||||
<image class="edit-avatar-img" wx:if="{{editAvatarUrl}}" src="{{editAvatarUrl}}" mode="aspectFill"></image>
|
||||
<view class="edit-avatar-placeholder" wx:else>👤</view>
|
||||
<text class="edit-avatar-hint">点击更换头像</text>
|
||||
</view>
|
||||
<view class="edit-field">
|
||||
<text class="edit-label">昵称</text>
|
||||
<input class="edit-input" value="{{editNickname}}" bindinput="onEditNicknameInput" placeholder="请输入昵称" maxlength="20" />
|
||||
</view>
|
||||
<view class="edit-actions">
|
||||
<button class="btn-secondary edit-btn" bindtap="onCancelEdit">取消</button>
|
||||
<button class="btn-primary edit-btn" bindtap="onSaveProfile" disabled="{{saving}}" loading="{{saving}}">保存</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -107,11 +107,144 @@
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 200rpx 0;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border: 6rpx solid #f0f0f0;
|
||||
border-top-color: #E6508C;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
margin-top: 20rpx;
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.sub-card-inactive {
|
||||
background: #f5f5f5;
|
||||
border: 1px dashed #d9d9d9;
|
||||
}
|
||||
|
||||
.user-avatar-img {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.edit-profile-btn {
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.6);
|
||||
border-radius: 24rpx;
|
||||
padding: 6rpx 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.edit-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.edit-modal {
|
||||
position: fixed;
|
||||
left: 10%;
|
||||
right: 10%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: #fff;
|
||||
border-radius: 24rpx;
|
||||
padding: 40rpx;
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
.edit-modal-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
margin-bottom: 32rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.edit-avatar-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.edit-avatar-img {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.edit-avatar-placeholder {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 56rpx;
|
||||
}
|
||||
|
||||
.edit-avatar-hint {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.edit-field {
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.edit-label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 12rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.edit-input {
|
||||
border: 2rpx solid #e0e0e0;
|
||||
border-radius: 12rpx;
|
||||
padding: 16rpx 20rpx;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.edit-actions {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.edit-btn {
|
||||
flex: 1;
|
||||
margin: 0 !important;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
text-align: center;
|
||||
color: #ff4d4f;
|
||||
|
||||
在新工单中引用
屏蔽一个用户