Claw 项目完整结构提交
This commit is contained in:
243
Claw/client/wechat_app/pages/user/user.js
Normal file
243
Claw/client/wechat_app/pages/user/user.js
Normal file
@@ -0,0 +1,243 @@
|
||||
// 用户中心页面逻辑
|
||||
const { API, util, constants } = require('../../utils/api.js')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
userId: '',
|
||||
userStatus: 'online',
|
||||
statusText: '在线',
|
||||
taskStats: {
|
||||
total: 0,
|
||||
completed: 0,
|
||||
processing: 0
|
||||
},
|
||||
deviceInfo: {},
|
||||
appVersion: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const app = getApp()
|
||||
this.setData({
|
||||
appVersion: app.globalData.version,
|
||||
deviceInfo: app.globalData.systemInfo
|
||||
})
|
||||
|
||||
this.loadUserData()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadUserData()
|
||||
this.loadTaskStats()
|
||||
},
|
||||
|
||||
// 加载用户数据
|
||||
loadUserData() {
|
||||
const userInfo = wx.getStorageSync('userInfo')
|
||||
const userId = wx.getStorageSync('userId') || 'anonymous'
|
||||
|
||||
if (userInfo) {
|
||||
this.setData({
|
||||
userInfo: userInfo,
|
||||
userId: userId
|
||||
})
|
||||
} else {
|
||||
// 如果没有用户信息,尝试获取
|
||||
this.getUserProfile()
|
||||
}
|
||||
},
|
||||
|
||||
// 获取用户资料
|
||||
getUserProfile() {
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善用户资料',
|
||||
success: (res) => {
|
||||
const userInfo = res.userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
this.setData({
|
||||
userInfo: userInfo
|
||||
})
|
||||
|
||||
// 发送用户信息到服务器
|
||||
this.sendUserInfoToServer(userInfo)
|
||||
},
|
||||
fail: () => {
|
||||
// 使用默认信息
|
||||
this.setData({
|
||||
userInfo: {
|
||||
nickName: '访客用户',
|
||||
avatarUrl: '/assets/images/default-avatar.png'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 发送用户信息到服务器
|
||||
async sendUserInfoToServer(userInfo) {
|
||||
try {
|
||||
await API.request('/user/info', 'POST', {
|
||||
userInfo: userInfo,
|
||||
deviceId: this.data.deviceInfo.model
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('发送用户信息失败:', error)
|
||||
}
|
||||
},
|
||||
|
||||
// 加载任务统计
|
||||
async loadTaskStats() {
|
||||
try {
|
||||
const result = await API.getTaskList(1, 100) // 获取所有任务进行统计
|
||||
|
||||
if (result.success && result.data) {
|
||||
const tasks = result.data.tasks
|
||||
const stats = {
|
||||
total: tasks.length,
|
||||
completed: tasks.filter(task => task.status === 'completed').length,
|
||||
processing: tasks.filter(task => task.status === 'processing').length
|
||||
}
|
||||
|
||||
this.setData({
|
||||
taskStats: stats
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载任务统计失败:', error)
|
||||
}
|
||||
},
|
||||
|
||||
// 显示任务历史
|
||||
showTaskHistory() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/task-history/task-history'
|
||||
})
|
||||
},
|
||||
|
||||
// 显示设置
|
||||
showSettings() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/settings/settings'
|
||||
})
|
||||
},
|
||||
|
||||
// 显示关于
|
||||
showAbout() {
|
||||
wx.showModal({
|
||||
title: '关于智控未来',
|
||||
content: `智控未来 v${this.data.appVersion}\n\n企业微信智能控制系统\n基于微信小程序原生技术栈开发\n\n功能特点:\n• 智能聊天对话\n• 任务管理处理\n• 多设备状态同步\n• WebSocket实时通信\n\n技术支持:\n• Rust后端服务\n• Embedded-Redis状态管理\n• HeedDB数据存储\n• LMStudio AI集成`,
|
||||
showCancel: false
|
||||
})
|
||||
},
|
||||
|
||||
// 显示帮助
|
||||
showHelp() {
|
||||
wx.showModal({
|
||||
title: '使用帮助',
|
||||
content: `快速上手:\n\n1. 智能聊天\n • 在聊天页面输入问题\n • 支持文本、图片、文件消息\n • 实时接收AI回复\n\n2. 任务管理\n • 创建新任务并设置类型\n • 查看任务处理进度\n • 管理任务状态\n\n3. 用户中心\n • 查看个人信息\n • 查看任务统计\n • 系统设置\n\n常见问题:\n• 网络连接失败请检查网络\n• 任务长时间未响应可重试\n• 如有问题请联系技术支持`,
|
||||
showCancel: false
|
||||
})
|
||||
},
|
||||
|
||||
// 刷新数据
|
||||
async refreshData() {
|
||||
util.showLoading('刷新中...')
|
||||
|
||||
try {
|
||||
// 重新加载用户数据
|
||||
this.loadUserData()
|
||||
|
||||
// 重新加载任务统计
|
||||
await this.loadTaskStats()
|
||||
|
||||
util.hideLoading()
|
||||
util.showSuccess('数据已刷新')
|
||||
} catch (error) {
|
||||
util.hideLoading()
|
||||
console.error('刷新数据失败:', error)
|
||||
util.showError('刷新失败')
|
||||
}
|
||||
},
|
||||
|
||||
// 清除缓存
|
||||
async clearCache() {
|
||||
const confirmed = await util.showModal('确认清除', '确定要清除本地缓存吗?这将删除聊天记录和临时文件。')
|
||||
|
||||
if (confirmed) {
|
||||
util.showLoading('清除中...')
|
||||
|
||||
try {
|
||||
// 清除本地存储
|
||||
wx.removeStorageSync('chatHistory')
|
||||
wx.removeStorageSync('taskHistory')
|
||||
|
||||
// 清除临时文件
|
||||
const fileSystemManager = wx.getFileSystemManager()
|
||||
try {
|
||||
fileSystemManager.readdir({
|
||||
dirPath: `${wx.env.USER_DATA_PATH}/`,
|
||||
success: (res) => {
|
||||
res.files.forEach(file => {
|
||||
if (file.startsWith('tmp_')) {
|
||||
fileSystemManager.unlink({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/${file}`
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('清除临时文件失败:', e)
|
||||
}
|
||||
|
||||
util.hideLoading()
|
||||
util.showSuccess('缓存已清除')
|
||||
} catch (error) {
|
||||
util.hideLoading()
|
||||
console.error('清除缓存失败:', error)
|
||||
util.showError('清除失败')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 退出登录
|
||||
async logout() {
|
||||
const confirmed = await util.showModal('确认退出', '确定要退出登录吗?')
|
||||
|
||||
if (confirmed) {
|
||||
util.showLoading('退出中...')
|
||||
|
||||
try {
|
||||
// 通知服务器退出
|
||||
await API.request('/user/logout', 'POST')
|
||||
|
||||
// 清除本地数据
|
||||
wx.removeStorageSync('token')
|
||||
wx.removeStorageSync('userInfo')
|
||||
wx.removeStorageSync('userId')
|
||||
wx.removeStorageSync('chatHistory')
|
||||
|
||||
util.hideLoading()
|
||||
|
||||
// 返回首页
|
||||
wx.reLaunch({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
} catch (error) {
|
||||
util.hideLoading()
|
||||
console.error('退出登录失败:', error)
|
||||
util.showError('退出失败')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 分享
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '智控未来 - 我的个人中心',
|
||||
path: '/pages/user/user',
|
||||
imageUrl: '/assets/images/share-user.png'
|
||||
}
|
||||
}
|
||||
})
|
||||
3
Claw/client/wechat_app/pages/user/user.json
Normal file
3
Claw/client/wechat_app/pages/user/user.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "个人中心"
|
||||
}
|
||||
101
Claw/client/wechat_app/pages/user/user.wxml
Normal file
101
Claw/client/wechat_app/pages/user/user.wxml
Normal file
@@ -0,0 +1,101 @@
|
||||
<!-- 用户中心页面 -->
|
||||
<view class="user-container">
|
||||
<!-- 用户信息卡片 -->
|
||||
<view class="user-card">
|
||||
<view class="avatar-section">
|
||||
<user-avatar
|
||||
src="{{userInfo.avatarUrl}}"
|
||||
size="large"
|
||||
shape="circle"
|
||||
showStatus="{{true}}"
|
||||
status="{{userStatus}}"
|
||||
/>
|
||||
<view class="user-info">
|
||||
<text class="nickname">{{userInfo.nickName}}</text>
|
||||
<text class="user-id">ID: {{userId}}</text>
|
||||
<text class="status-text">{{statusText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="user-stats">
|
||||
<view class="stat-item">
|
||||
<text class="stat-number">{{taskStats.total}}</text>
|
||||
<text class="stat-label">总任务</text>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-number">{{taskStats.completed}}</text>
|
||||
<text class="stat-label">已完成</text>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-number">{{taskStats.processing}}</text>
|
||||
<text class="stat-label">处理中</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 功能菜单 -->
|
||||
<view class="menu-section">
|
||||
<view class="menu-title">功能设置</view>
|
||||
|
||||
<view class="menu-list">
|
||||
<view class="menu-item" bindtap="showTaskHistory">
|
||||
<image class="menu-icon" src="/assets/icons/history.png"></image>
|
||||
<text class="menu-text">任务历史</text>
|
||||
<text class="menu-badge">{{taskStats.total}}</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" bindtap="showSettings">
|
||||
<image class="menu-icon" src="/assets/icons/settings.png"></image>
|
||||
<text class="menu-text">设置</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" bindtap="showAbout">
|
||||
<image class="menu-icon" src="/assets/icons/about.png"></image>
|
||||
<text class="menu-text">关于</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" bindtap="showHelp">
|
||||
<image class="menu-icon" src="/assets/icons/help.png"></image>
|
||||
<text class="menu-text">帮助</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 系统信息 -->
|
||||
<view class="system-info">
|
||||
<view class="info-item">
|
||||
<text class="info-label">版本号:</text>
|
||||
<text class="info-value">{{appVersion}}</text>
|
||||
</view>
|
||||
<view class="info-item">
|
||||
<text class="info-label">设备型号:</text>
|
||||
<text class="info-value">{{deviceInfo.model}}</text>
|
||||
</view>
|
||||
<view class="info-item">
|
||||
<text class="info-label">系统版本:</text>
|
||||
<text class="info-value">{{deviceInfo.system}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<view class="action-buttons">
|
||||
<button class="action-btn primary" bindtap="refreshData">
|
||||
<image src="/assets/icons/refresh.png"></image>
|
||||
刷新数据
|
||||
</button>
|
||||
|
||||
<button class="action-btn secondary" bindtap="clearCache">
|
||||
<image src="/assets/icons/clear.png"></image>
|
||||
清除缓存
|
||||
</button>
|
||||
|
||||
<button class="action-btn danger" bindtap="logout">
|
||||
<image src="/assets/icons/logout.png"></image>
|
||||
退出登录
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
223
Claw/client/wechat_app/pages/user/user.wxss
Normal file
223
Claw/client/wechat_app/pages/user/user.wxss
Normal file
@@ -0,0 +1,223 @@
|
||||
/* 用户中心页面样式 */
|
||||
.user-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
background-color: #f5f5f5;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
/* 用户信息卡片 */
|
||||
.user-card {
|
||||
background: white;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.avatar-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
margin-left: 30rpx;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.nickname {
|
||||
display: block;
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.user-id {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.status-text {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #07c160;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 用户统计 */
|
||||
.user-stats {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding-top: 30rpx;
|
||||
border-top: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 40rpx;
|
||||
font-weight: bold;
|
||||
color: #07c160;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* 菜单区域 */
|
||||
.menu-section {
|
||||
background: white;
|
||||
border-radius: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
padding: 30rpx 30rpx 20rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.menu-list {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.menu-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.menu-item:active {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
margin-right: 20rpx;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.menu-text {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.menu-badge {
|
||||
background: #dd524d;
|
||||
color: white;
|
||||
font-size: 20rpx;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 20rpx;
|
||||
margin-right: 20rpx;
|
||||
min-width: 32rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.menu-arrow {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 系统信息 */
|
||||
.system-info {
|
||||
background: white;
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.info-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 操作按钮 */
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-top: auto;
|
||||
padding-top: 40rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 30rpx 20rpx;
|
||||
border: none;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
transition: all 0.3s ease;
|
||||
min-height: 120rpx;
|
||||
}
|
||||
|
||||
.action-btn.primary {
|
||||
background: linear-gradient(135deg, #07c160 0%, #06a050 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-btn.secondary {
|
||||
background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-btn.danger {
|
||||
background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-btn:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.action-btn image {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
margin-bottom: 10rpx;
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
Reference in New Issue
Block a user