tmp
This commit is contained in:
@@ -1,66 +1,222 @@
|
||||
// pages/mine/index.js
|
||||
const API = require('../../utils/api.js')
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
phoneNumber: '',
|
||||
version: '1.0.0',
|
||||
showLoginPopup: false,
|
||||
loginForm: {
|
||||
name: '',
|
||||
mobile: ''
|
||||
},
|
||||
menuList: [
|
||||
{ icon: 'user', title: '个人资料', url: '' },
|
||||
{ icon: 'notification', title: '消息通知', url: '' },
|
||||
{ icon: 'lock-on', title: '账号安全', url: '' },
|
||||
{ icon: 'help-circle', title: '帮助中心', url: '' },
|
||||
{ icon: 'info-circle', title: '关于我们', url: '' },
|
||||
]
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
onLoad() {
|
||||
this.checkLoginStatus()
|
||||
this.setData({ version: this.getAppVersion() })
|
||||
|
||||
const app = getApp()
|
||||
app.eventBus.on('user-login', this.onUserLogin)
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
const app = getApp()
|
||||
app.eventBus.off('user-login', this.onUserLogin)
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
onShow() {
|
||||
this.checkLoginStatus()
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
onUserLogin(user) {
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo: user,
|
||||
phoneNumber: this.maskPhoneNumber(user.mobile || '')
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
checkLoginStatus() {
|
||||
const app = getApp()
|
||||
const user = app.globalData.user
|
||||
if (user && user.security && user.security.token) {
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo: user,
|
||||
phoneNumber: this.maskPhoneNumber(user.mobile || '')
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
maskPhoneNumber(phone) {
|
||||
if (!phone || phone.length < 7) return phone
|
||||
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
|
||||
},
|
||||
|
||||
getAppVersion() {
|
||||
const accountInfo = wx.getAccountInfoSync()
|
||||
return accountInfo.miniProgram.version || '1.0.0'
|
||||
},
|
||||
|
||||
onShowLoginPopup() {
|
||||
this.setData({ showLoginPopup: true })
|
||||
},
|
||||
|
||||
onCloseLoginPopup() {
|
||||
this.setData({ showLoginPopup: false, loginForm: { name: '', mobile: '' } })
|
||||
},
|
||||
|
||||
onNameInput(e) {
|
||||
this.setData({ 'loginForm.name': e.detail.value })
|
||||
},
|
||||
|
||||
onMobileInput(e) {
|
||||
this.setData({ 'loginForm.mobile': e.detail.value })
|
||||
},
|
||||
|
||||
onLoginSubmit() {
|
||||
const { name, mobile } = this.data.loginForm
|
||||
|
||||
if (!name.trim()) {
|
||||
wx.showToast({ title: '请输入姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (!mobile.trim()) {
|
||||
wx.showToast({ title: '请输入手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const phoneReg = /^1[3-9]\d{9}$/
|
||||
if (!phoneReg.test(mobile.trim())) {
|
||||
wx.showToast({ title: '手机号格式不正确', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
wx.showLoading({ title: '登录中...' })
|
||||
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
if (res.code) {
|
||||
API.user.wxSignin({ phoneNumber: mobile.trim(), name: name.trim(), code: res.code })
|
||||
.then((data) => {
|
||||
if (data.code == 0) {
|
||||
const app = getApp()
|
||||
app.globalData.user = data.data.user
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo: app.globalData.user,
|
||||
phoneNumber: this.maskPhoneNumber(app.globalData.user.profile.mobile || ''),
|
||||
showLoginPopup: false,
|
||||
loginForm: { name: '', mobile: '' }
|
||||
})
|
||||
|
||||
wx.showToast({ title: '登录成功', icon: 'success' })
|
||||
} else {
|
||||
wx.showToast({ title: '登录失败', icon: 'none' })
|
||||
}
|
||||
|
||||
wx.hideLoading()
|
||||
})
|
||||
} else {
|
||||
wx.showToast({ title: '登录失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('登录失败', err)
|
||||
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
||||
}).finally(() => {
|
||||
wx.hideLoading()
|
||||
})
|
||||
},
|
||||
|
||||
onMenuTap(e) {
|
||||
const { index } = e.currentTarget.dataset
|
||||
const item = this.data.menuList[index]
|
||||
|
||||
if (!this.data.isLoggedIn) {
|
||||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (item.url) {
|
||||
wx.navigateTo({ url: item.url })
|
||||
} else {
|
||||
wx.showToast({ title: '功能开发中', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
onLogout() {
|
||||
wx.showModal({
|
||||
title: '退出登录',
|
||||
content: '确定要退出登录吗?',
|
||||
confirmColor: '#4c6ef5',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.showLoading({ title: '退出中...' })
|
||||
|
||||
API.user.signout().then(() => {
|
||||
this.doLogout()
|
||||
}).catch(() => {
|
||||
this.doLogout()
|
||||
}).finally(() => {
|
||||
wx.hideLoading()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
doLogout() {
|
||||
const app = getApp()
|
||||
app.globalData.user = null
|
||||
wx.removeStorageSync('admin_user_info')
|
||||
wx.removeStorageSync('admin_ai_session_id')
|
||||
wx.removeStorageSync('admin_ai_chat_history')
|
||||
|
||||
this.setData({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
phoneNumber: ''
|
||||
})
|
||||
|
||||
wx.showToast({ title: '已退出登录', icon: 'success' })
|
||||
},
|
||||
|
||||
onPopupContentTap() {
|
||||
// 阻止冒泡,防止点击弹窗内容时关闭弹窗
|
||||
},
|
||||
|
||||
onClearCache() {
|
||||
wx.showModal({
|
||||
title: '清除缓存',
|
||||
content: '确定要清除所有缓存数据吗?',
|
||||
confirmColor: '#4c6ef5',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.clearStorage({
|
||||
success: () => {
|
||||
const app = getApp()
|
||||
app.globalData.user = null
|
||||
this.setData({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
phoneNumber: ''
|
||||
})
|
||||
wx.showToast({ title: '缓存已清除', icon: 'success' })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
"navigationBarTitleText": "设置",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"navigationBarTextStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,91 @@
|
||||
<!--pages/mine/index.wxml-->
|
||||
<text>pages/mine/index.wxml</text>
|
||||
<view class="set-page">
|
||||
<!-- 用户信息卡片 -->
|
||||
<view class="user-card">
|
||||
<view class="user-info" wx:if="{{isLoggedIn}}">
|
||||
<view class="user-avatar">
|
||||
<text class="avatar-text">{{userInfo.nickname ? userInfo.nickname[0] : '管'}}</text>
|
||||
</view>
|
||||
<view class="user-detail">
|
||||
<text class="user-name">{{userInfo.nickname || '管理员'}}</text>
|
||||
<text class="user-phone">{{phoneNumber}}</text>
|
||||
</view>
|
||||
<view class="logout-btn" bindtap="onLogout">
|
||||
<text class="logout-text">退出</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="user-info login-area" wx:else>
|
||||
<view class="user-avatar default-avatar">
|
||||
<t-icon name="user" size="40rpx" color="#9ca3af" />
|
||||
</view>
|
||||
<view class="user-detail">
|
||||
<text class="login-title">未登录</text>
|
||||
<text class="login-desc">登录后查看更多信息</text>
|
||||
</view>
|
||||
<view class="login-btn" bindtap="onShowLoginPopup">
|
||||
<text class="login-btn-text">立即登录</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 菜单列表 -->
|
||||
<view class="menu-section">
|
||||
<view class="menu-list">
|
||||
<view class="menu-item" wx:for="{{menuList}}" wx:key="index" data-index="{{index}}" bindtap="onMenuTap">
|
||||
<view class="menu-left">
|
||||
<t-icon name="{{item.icon}}" size="32rpx" color="#4c6ef5" />
|
||||
<text class="menu-title">{{item.title}}</text>
|
||||
</view>
|
||||
<view class="menu-right">
|
||||
<t-icon name="chevron-right" size="28rpx" color="#9ca3af" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 系统操作 -->
|
||||
<view class="menu-section">
|
||||
<view class="menu-list">
|
||||
<view class="menu-item" bindtap="onClearCache">
|
||||
<view class="menu-left">
|
||||
<t-icon name="delete" size="32rpx" color="#ff6b6b" />
|
||||
<text class="menu-title danger">清除缓存</text>
|
||||
</view>
|
||||
<view class="menu-right">
|
||||
<t-icon name="chevron-right" size="28rpx" color="#9ca3af" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 登录弹窗 -->
|
||||
<view class="login-popup" wx:if="{{showLoginPopup}}" bindtap="onCloseLoginPopup">
|
||||
<view class="login-popup-content" catchtap="onPopupContentTap">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">用户登录</text>
|
||||
<view class="popup-close" bindtap="onCloseLoginPopup">
|
||||
<t-icon name="close" size="32rpx" color="#9ca3af" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="popup-body">
|
||||
<view class="form-item">
|
||||
<text class="form-label">姓名</text>
|
||||
<input class="form-input" type="text" placeholder="请输入您的姓名" value="{{loginForm.name}}" bindinput="onNameInput" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="form-label">手机号</text>
|
||||
<input class="form-input" type="number" maxlength="11" placeholder="请输入您的手机号" value="{{loginForm.mobile}}" bindinput="onMobileInput" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="popup-footer">
|
||||
<view class="submit-btn" bindtap="onLoginSubmit">
|
||||
<text class="submit-btn-text">登录</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 版本信息 -->
|
||||
<view class="version-info">
|
||||
<text class="version-text">版本 {{version}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1 +1,303 @@
|
||||
/* pages/mine/index.wxss */
|
||||
page {
|
||||
background-color: #f5f6fa;
|
||||
color: #1a1a2e;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
|
||||
.set-page {
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.user-card {
|
||||
background-color: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
overflow: hidden;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 40rpx 32rpx;
|
||||
gap: 24rpx;
|
||||
}
|
||||
|
||||
.user-info.login-area {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
background: linear-gradient(135deg, #4c6ef5, #748ffc);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4rpx 12rpx rgba(76, 110, 245, 0.25);
|
||||
}
|
||||
|
||||
.user-avatar.default-avatar {
|
||||
background: #f3f4f6;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.avatar-text {
|
||||
font-size: 36rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.user-detail {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.user-phone {
|
||||
font-size: 26rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.login-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.login-desc {
|
||||
font-size: 24rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
padding: 12rpx 28rpx;
|
||||
background-color: rgba(255, 107, 107, 0.1);
|
||||
border-radius: 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logout-btn:active {
|
||||
transform: scale(0.95);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.logout-text {
|
||||
font-size: 24rpx;
|
||||
color: #ff6b6b;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
margin: 0;
|
||||
padding: 16rpx 32rpx;
|
||||
background: linear-gradient(135deg, #4c6ef5, #748ffc);
|
||||
border-radius: 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
line-height: 1;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.login-btn::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.login-btn:active {
|
||||
transform: scale(0.95);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.login-btn-text {
|
||||
font-size: 26rpx;
|
||||
color: #ffffff;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.menu-section {
|
||||
background-color: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
overflow: hidden;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.menu-list {
|
||||
padding: 0 32rpx;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 32rpx 0;
|
||||
border-bottom: 1rpx solid #f3f4f6;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.menu-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.menu-item:active {
|
||||
background-color: rgba(76, 110, 245, 0.05);
|
||||
}
|
||||
|
||||
.menu-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
font-size: 28rpx;
|
||||
color: #1a1a2e;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.menu-title.danger {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.menu-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.version-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40rpx 0;
|
||||
}
|
||||
|
||||
.version-text {
|
||||
font-size: 24rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
/* 登录弹窗 */
|
||||
.login-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.login-popup-content {
|
||||
width: 80%;
|
||||
max-width: 600rpx;
|
||||
background-color: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 32rpx 32rpx 0;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.popup-close {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.popup-close:active {
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
|
||||
.popup-body {
|
||||
padding: 32rpx;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.form-item:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
color: #6b7280;
|
||||
margin-bottom: 12rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background-color: #f5f6fa;
|
||||
border-radius: 16rpx;
|
||||
padding: 0 24rpx;
|
||||
font-size: 28rpx;
|
||||
color: #1a1a2e;
|
||||
box-sizing: border-box;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
border-color: #4c6ef5;
|
||||
}
|
||||
|
||||
.popup-footer {
|
||||
padding: 0 32rpx 32rpx;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: linear-gradient(135deg, #4c6ef5, #748ffc);
|
||||
border-radius: 44rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 4rpx 16rpx rgba(76, 110, 245, 0.25);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.submit-btn:active {
|
||||
transform: scale(0.98);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.submit-btn-text {
|
||||
font-size: 30rpx;
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user