This commit is contained in:
2026-01-18 17:42:46 +08:00
parent 836bdc9409
commit f038dbab41
42 changed files with 3068 additions and 575 deletions

View File

@@ -74,7 +74,7 @@ return [
], ],
'members' => [ 'members' => [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => App\Member\Models\Member::class, 'model' => Modules\Member\Models\Member::class,
], ],
], ],

View File

@@ -1,36 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Listeners;
use Modules\Member\Events\LoginBefore;
use Modules\Member\Models\Member;
class UpMemberPaswd {
/**
* @title 会员登录后更新用户信息
*
* @param LoginEvent $event
* @return void
*/
public function handle(LoginBefore $event) {
$username = $event->username;
$password = $event->password;
$member = Member::where('username', '=', $username)->whereNotNull('old_password')->first();
if($member){
if(md5($password . $member->salt) === $member->old_password){
$member->password = $password;
$member->old_password = '';
$member->salt = '';
$member->save();
}
}
}
}

View File

@@ -23,7 +23,7 @@ class Member extends Authenticatable implements JWTSubject {
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'status']; protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'status'];
protected $hidden = ['password', 'deleted_at']; protected $hidden = ['password', 'deleted_at'];
protected $dateFormat = 'Y-m-d H:i:s'; protected $dateFormat = 'Y-m-d H:i:s';
protected $with = ['invite:uid,nickname,username,level_id', 'extend', 'level', 'store', 'social', 'pm']; protected $with = ['invite:uid,nickname,username,level_id', 'extend', 'level'];
/** /**
* Get the identifier that will be stored in the subject claim of the JWT. * Get the identifier that will be stored in the subject claim of the JWT.
@@ -75,23 +75,7 @@ class Member extends Authenticatable implements JWTSubject {
return $this->hasOne(MemberExtends::class, 'member_id', 'uid'); return $this->hasOne(MemberExtends::class, 'member_id', 'uid');
} }
public function social(){
return $this->hasMany(\Modules\Wechat\Models\MemberSocial::class, 'member_id', 'uid');
}
public function level(){ public function level(){
return $this->hasOne(MemberLevel::class, 'id', 'level_id'); return $this->hasOne(MemberLevel::class, 'id', 'level_id');
} }
public function address(){
return $this->hasMany(MemberAddress::class, 'member_id', 'id');
}
public function pm(){
return $this->hasOne(Pm::class, 'member_id', 'pm_uid');
}
public function store(){
return $this->hasOne(Store::class, 'member_id', 'store_uid');
}
} }

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberAccount extends BaseModel {
protected $table = 'member_account';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberAddress extends BaseModel {
protected $table = 'member_address';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberBank extends BaseModel {
protected $table = 'member_bank';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberCoupon extends BaseModel {
protected $table = 'member_coupon';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberScore extends BaseModel {
protected $table = 'member_score';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberStore extends BaseModel {
protected $table = 'member_store';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class MemberWallet extends BaseModel {
protected $table = 'member_wallet';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
}

View File

@@ -1,22 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class Pm extends BaseModel {
protected $table = 'member_pm';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
public function members(){
return $this->belongsTo(Member::class, 'member_id', 'uid');
}
}

View File

@@ -1,22 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Member\Models;
use App\Models\BaseModel;
class Store extends BaseModel {
protected $table = 'member_store';
protected $fillable = [];
// protected $hidden = ['deleted_at'];
public function members(){
return $this->belongsTo(Member::class, 'member_id', 'uid');
}
}

View File

@@ -18,9 +18,6 @@ class EventServiceProvider extends ServiceProvider
* @var array<string, array<int, string>> * @var array<string, array<int, string>>
*/ */
protected $listen = [ protected $listen = [
\Modules\Member\Events\LoginBefore::class => [
\Modules\Member\Listeners\UpMemberPaswd::class,
],
]; ];
/** /**

View File

@@ -31,10 +31,10 @@ class AuthService {
$password = $request->input('password'); $password = $request->input('password');
LoginBefore::dispatch($username, $password); LoginBefore::dispatch($username, $password);
$token = auth('api')->attempt(['mobile' => $username, 'password' => $password]); $token = auth('api')->attempt(['username' => $username, 'password' => $password]);
if (!$token) { if (!$token) {
throw new \Exception("錄失敗", 1000); throw new \Exception("录失败", 1000);
}else{ }else{
LoginEvent::dispatch(auth('api')->user(), $request->input('openid', ''), $request->input('type')); LoginEvent::dispatch(auth('api')->user(), $request->input('openid', ''), $request->input('type'));
// 判断是否到期 // 判断是否到期

View File

@@ -1,72 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void {
Schema::table('member', function (Blueprint $table) {
$table->string('invite_code')->nullable()->after('login_count')->comment('推荐码');
$table->string('old_password')->nullable()->after('password')->comment('旧密码');
$table->string('salt')->nullable()->after('old_password')->comment('密码盐值');
$table->unsignedBigInteger('pm_uid')->nullable()->after('invite_code')->comment('健康管理师id');
$table->unsignedBigInteger('store_id')->nullable()->after('pm_uid')->comment('所属综合服务体');
});
Schema::create('member_pm', function (Blueprint $table) {
$table->id()->uniqid()->comment('主键id');
$table->unsignedBigInteger('member_id')->comment('用户id');
$table->tinyInteger('level')->default(1)->comment('等级');
$table->string('name')->nullable()->comment('名称');
$table->integer('sex')->default(0)->comment('内容');
$table->string('mobile')->nullable()->comment('电话');
$table->string('area')->nullable()->comment('区域');
$table->tinyInteger('store_id')->default(0)->comment('所属综合服务体');
$table->tinyInteger('status')->default(1)->comment('状态');
$table->bigInteger('end_time')->nullable()->comment('到期时间');
$table->timestamp('created_at')->nullable()->comment('创建时间');
$table->timestamp('updated_at')->nullable()->comment('更新时间');
$table->engine = 'InnoDB';
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
$table->comment('会员工作室表');
});
Schema::create('member_store', function (Blueprint $table) {
$table->id()->uniqid()->comment('主键id');
$table->unsignedBigInteger('member_id')->comment('用户id');
$table->string('name')->nullable()->comment('名称');
$table->string('logo')->nullable()->comment('logo');
$table->string('mobile')->nullable()->comment('电话');
$table->string('area')->nullable()->comment('区域');
$table->string('address')->nullable()->comment('地址');
$table->string('map')->nullable()->comment('地图坐标');
$table->string('license')->nullable()->comment('营业执照');
$table->tinyInteger('status')->default(1)->comment('状态');
$table->timestamp('created_at')->nullable()->comment('创建时间');
$table->timestamp('updated_at')->nullable()->comment('更新时间');
$table->engine = 'InnoDB';
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
$table->comment('会员综合服务体表');
});
}
/**
* Reverse the migrations.
*/
public function down(): void {
Schema::table('member', function (Blueprint $table) {
$table->dropColumn('invite_code');
$table->dropColumn('old_password');
$table->dropColumn('salt');
});
Schema::dropIfExists('member_pm');
Schema::dropIfExists('member_store');
}
};

View File

@@ -1,26 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('member', function (Blueprint $table) {
$table->string('date_type', 10)->default('lunar')->comment('会员生日类型')->after('birthday');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};

View File

@@ -18,12 +18,12 @@ class EventServiceProvider extends ServiceProvider
* @var array<string, array<int, string>> * @var array<string, array<int, string>>
*/ */
protected $listen = [ protected $listen = [
'Modules\Member\Events\LoginEvent' => [ // 'Modules\Member\Events\LoginEvent' => [
'Modules\Wechat\Listeners\LoginBind', // 'Modules\Wechat\Listeners\LoginBind',
], // ],
'Modules\Member\Events\Registered' => [ // 'Modules\Member\Events\Registered' => [
'Modules\Wechat\Listeners\RegisterBind', // 'Modules\Wechat\Listeners\RegisterBind',
], // ],
]; ];
/** /**

View File

@@ -1,13 +1,28 @@
<script> <script>
export default { import { setCurrentRoute } from '@/utils/auth.js'
onLaunch: function() {
console.log('App Launch') export default {
}, onLaunch: function() {
onShow: function() { console.log('App Launch')
console.log('App Show') },
}, onShow: function() {
onHide: function() { console.log('App Show')
console.log('App Hide') },
} onHide: function() {
console.log('App Hide')
} }
}
</script> </script>
<style lang="scss">
/* 全局样式 */
page {
background-color: #F8F8F8;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}
/* 去除button默认边框 */
button::after {
border: none;
}
</style>

View File

@@ -0,0 +1,11 @@
/**
* @description 自动import导入所有 api 模块
*/
const files = import.meta.glob('./modules/*.js', { eager: true })
const modules = {}
Object.keys(files).forEach(key => {
modules[key.replace(/^\.\/modules\/(.*)\.js$/g, '$1')] = files[key].default
})
export default modules

View File

@@ -0,0 +1,32 @@
import request from '@/utils/request'
export default {
login: {
url: '/api/member/login',
name: '用户登录',
post: async function(params) {
return request.post(this.url, params)
}
},
logout: {
url: '/api/member/logout',
name: '用户登出',
post: async function(params) {
return request.post(this.url, params)
}
},
register: {
url: '/api/member/register',
name: '用户注册',
post: async function(params) {
return request.post(this.url, params)
}
},
info: {
url: '/api/member/user',
name: '用户信息',
get: async function(params) {
return request.get(this.url, {params: params})
}
}
}

View File

@@ -0,0 +1,11 @@
import request from '@/utils/request'
export default {
sendCode: {
url: '/api/member/sms/send',
name: '发送验证码',
post: async function(params) {
return request.post(this.url, params)
}
}
}

22
resources/mobile/boot.js Normal file
View File

@@ -0,0 +1,22 @@
/**
* 应用启动引导文件
* 注册全局属性、工具方法和混入
*/
import api from '@/api/index'
import store from '@/store'
import config from './config'
import tool from '@/utils/tool'
import authMixin from '@/mixins/auth.js'
export default {
install(app) {
// 注册全局属性
app.config.globalProperties.$config = config
app.config.globalProperties.$api = api
app.config.globalProperties.$store = store
app.config.globalProperties.$tool = tool
// 全局混入登录验证
app.mixin(authMixin)
}
}

View File

@@ -0,0 +1,168 @@
<template>
<view class="un-pages-container">
<!-- 顶部导航栏 -->
<uni-nav-bar v-if="showNavBar" :fixed="true" :background-color="navBarBgColor" :color="navBarColor"
:status-bar="true" :border="navBarBorder" :left-icon="showBack ? 'left' : ''" :title="navBarTitle"
@click-left="handleBack">
<slot name="navbar-right" slot="right"></slot>
</uni-nav-bar>
<!-- 中间内容区域 -->
<scroll-view class="content-scroll" scroll-y :style="{ height: scrollHeight }" :show-scrollbar="showScrollbar">
<view class="content-wrapper">
<slot></slot>
</view>
</scroll-view>
<!-- 底部tabbar -->
<un-tab-bar v-if="showTabBar" :current-path="currentPath" @change="handleTabChange"></un-tab-bar>
</view>
</template>
<script>
export default {
name: 'UnPages',
props: {
// 是否显示顶部导航栏
showNavBar: {
type: Boolean,
default: true
},
// 导航栏标题
navBarTitle: {
type: String,
default: ''
},
// 导航栏背景色
navBarBgColor: {
type: String,
default: '#fff'
},
// 导航栏文字颜色
navBarColor: {
type: String,
default: '#333'
},
// 导航栏是否显示边框
navBarBorder: {
type: Boolean,
default: true
},
// 是否显示返回按钮
showBack: {
type: Boolean,
default: false
},
// 是否显示底部tabbar
showTabBar: {
type: Boolean,
default: false
},
// 是否显示滚动条
showScrollbar: {
type: Boolean,
default: false
}
},
data() {
return {
scrollHeight: 'calc(100vh - 44px)',
systemInfo: null,
currentPath: ''
}
},
mounted() {
this.calculateHeight()
// 获取当前页面路径
this.getCurrentPath()
// 监听窗口变化
uni.onWindowResize(() => {
this.calculateHeight()
})
},
methods: {
/**
* 计算滚动区域高度
*/
calculateHeight() {
try {
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 0
const navBarHeight = this.showNavBar ? 44 : 0
const tabBarHeight = this.showTabBar ? 50 : 0 // tabbar高度约50px
let height = systemInfo.windowHeight - navBarHeight - tabBarHeight
// 如果有tabbar加上安全区域
if (this.showTabBar && systemInfo.safeAreaInsets) {
height -= systemInfo.safeAreaInsets.bottom
}
this.scrollHeight = height + 'px'
} catch (e) {
console.error('计算高度失败:', e)
this.scrollHeight = 'calc(100vh - 44px)'
}
},
/**
* 处理返回按钮点击
*/
handleBack() {
uni.navigateBack({
delta: 1,
fail: () => {
// 如果无法返回,跳转到首页
uni.switchTab({
url: '/pages/index/index'
})
}
})
},
/**
* 获取当前页面路径
*/
getCurrentPath() {
try {
const pages = getCurrentPages()
if (pages && pages.length > 0) {
const currentPage = pages[pages.length - 1]
this.currentPath = '/' + currentPage.route
}
} catch (e) {
console.error('获取当前页面路径失败:', e)
}
},
/**
* 处理tab切换
*/
handleTabChange(path) {
this.$emit('tab-change', path)
}
}
}
</script>
<style lang="scss" scoped>
.un-pages-container {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
background: #F8F8F8;
overflow: hidden;
}
.content-scroll {
flex: 1;
width: 100%;
overflow-y: auto;
}
.content-wrapper {
width: 100%;
min-height: 100%;
}
</style>

View File

@@ -0,0 +1,348 @@
<template>
<view class="tab-bar-container" :style="{ paddingBottom: safeAreaBottom }">
<view
class="tab-bar-item"
v-for="(item, index) in tabbarList"
:key="index"
:class="{ 'active': currentPath === item.pagePath }"
@tap="switchTab(index, item.pagePath)"
>
<view class="icon-wrapper">
<uni-icons
:type="currentPath === item.pagePath ? item.activeIcon : item.icon"
:size="iconSize"
:color="currentPath === item.pagePath ? activeColor : inactiveColor"
:customStyle="{ transition: 'all 0.3s' }"
></uni-icons>
<view class="badge-wrapper">
<!-- 数字徽章 -->
<view class="badge badge-num" v-if="item.badge > 0">
{{ item.badge > 99 ? '99+' : item.badge }}
</view>
<!-- 红点徽章 -->
<view class="badge badge-dot" v-else-if="item.dot"></view>
</view>
</view>
<text class="tab-text" :style="{ color: currentPath === item.pagePath ? activeColor : inactiveColor }">
{{ item.text }}
</text>
<!-- 激活状态下划线 -->
<view class="active-line" v-if="currentPath === item.pagePath" :style="{ backgroundColor: activeColor }"></view>
</view>
</view>
</template>
<script>
import config from '@/config/index.js'
export default {
name: 'TabBar',
props: {
// 当前页面路径
currentPath: {
type: String,
default: ''
},
// 图标大小
iconSize: {
type: Number,
default: 24
},
// 激活状态颜色
activeColor: {
type: String,
default: '#667eea'
},
// 未激活状态颜色
inactiveColor: {
type: String,
default: '#999'
},
// 是否显示激活状态下划线
showActiveLine: {
type: Boolean,
default: true
}
},
data() {
return {
tabbarList: [],
safeAreaBottom: '0px'
}
},
created() {
// 从配置文件加载tabbar配置
this.tabbarList = config.tabbarList || []
// 获取安全区域底部高度
this.getSafeAreaBottom()
},
mounted() {
// 监听页面显示,重新获取安全区域
uni.onWindowResize(() => {
this.getSafeAreaBottom()
})
},
methods: {
/**
* 切换tab
* @param {Number} index - tab索引
* @param {String} path - 页面路径
*/
switchTab(index, path) {
// 如果点击的是当前页面,不执行跳转
if (this.currentPath === path) return
// 发送切换事件
this.$emit('change', path)
// 触发点击反馈
this.playClickFeedback()
// 使用reLaunch跳转到对应页面关闭所有页面打开新页面
this.navigateToPage(path)
},
/**
* 跳转到页面
* @param {String} path - 页面路径
*/
navigateToPage(path) {
// 使用reLaunch跳转因为这是自定义tabbar
uni.reLaunch({
url: path,
success: () => {
console.log('跳转成功:', path)
},
fail: (err) => {
console.error('跳转失败:', err)
this.handleNavigationError()
}
})
},
/**
* 处理跳转失败的情况
*/
handleNavigationError() {
uni.showToast({
title: '页面跳转失败',
icon: 'none',
duration: 2000
})
},
/**
* 点击反馈动画
*/
playClickFeedback() {
// 可以添加震动反馈
if (uni.vibrateShort) {
uni.vibrateShort({
success: () => {},
fail: () => {}
})
}
},
/**
* 获取安全区域底部高度
*/
getSafeAreaBottom() {
const systemInfo = uni.getSystemInfoSync()
this.safeAreaBottom = systemInfo.safeAreaInsets
? systemInfo.safeAreaInsets.bottom + 'px'
: '0px'
},
/**
* 设置数字徽章
* @param {Number} index - tab索引
* @param {Number} count - 徽章数量
*/
setBadge(index, count) {
if (this.tabbarList[index]) {
this.$set(this.tabbarList, index, {
...this.tabbarList[index],
badge: count,
dot: false
})
}
},
/**
* 设置红点徽章
* @param {Number} index - tab索引
* @param {Boolean} show - 是否显示红点
*/
setDot(index, show) {
if (this.tabbarList[index]) {
this.$set(this.tabbarList, index, {
...this.tabbarList[index],
dot: show,
badge: 0
})
}
},
/**
* 清除所有徽章
*/
clearAllBadges() {
this.tabbarList.forEach((item, index) => {
this.$set(this.tabbarList, index, {
...item,
badge: 0,
dot: false
})
})
},
/**
* 获取tabbar项
* @param {Number} index - tab索引
* @returns {Object} tabbar项
*/
getTabItem(index) {
return this.tabbarList[index] || null
}
}
}
</script>
<style lang="scss" scoped>
.tab-bar-container {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 999;
display: flex;
align-items: center;
justify-content: space-around;
height: 100rpx;
background: #fff;
border-top: 1rpx solid #eee;
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
transition: all 0.3s;
}
.tab-bar-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
height: 100%;
position: relative;
transition: all 0.3s;
cursor: pointer;
&:active {
opacity: 0.7;
transform: scale(0.98);
}
&.active {
.tab-text {
font-weight: 500;
transform: translateY(-2rpx);
}
.icon-wrapper {
transform: translateY(-2rpx);
}
}
}
.icon-wrapper {
position: relative;
width: 48rpx;
height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 6rpx;
transition: all 0.3s;
}
.badge-wrapper {
position: absolute;
top: 0;
right: -8rpx;
z-index: 10;
}
.badge {
position: absolute;
top: -8rpx;
right: -8rpx;
min-width: 32rpx;
height: 32rpx;
padding: 0 6rpx;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 20rpx;
font-weight: 500;
line-height: 1;
box-shadow: 0 2rpx 8rpx rgba(245, 108, 108, 0.4);
animation: badgeIn 0.3s ease-out;
&.badge-num {
background: linear-gradient(135deg, #f56c6c 0%, #f89898 100%);
border-radius: 16rpx;
border: 2rpx solid #fff;
}
&.badge-dot {
min-width: 16rpx;
height: 16rpx;
background: #f56c6c;
border-radius: 50%;
border: 2rpx solid #fff;
padding: 0;
}
}
@keyframes badgeIn {
0% {
transform: scale(0);
opacity: 0;
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
opacity: 1;
}
}
.tab-text {
font-size: 22rpx;
color: #999;
transition: all 0.3s;
line-height: 1.2;
}
.active-line {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 40rpx;
height: 4rpx;
border-radius: 2rpx;
animation: lineIn 0.3s ease-out;
}
@keyframes lineIn {
0% {
width: 0;
}
100% {
width: 40rpx;
}
}
</style>

View File

@@ -0,0 +1,3 @@
export default {
baseURL: 'http://localhost:8000/'
}

View File

@@ -0,0 +1,46 @@
const config = {
baseURL: 'http://localhost:8000/',
tabbarList: [
{
pagePath: "/pages/index/index",
text: "首页",
icon: "home",
activeIcon: "home-filled",
badge: 0
},
{
pagePath: "/pages/account/bill/index",
text: "账单",
icon: "list",
activeIcon: "list",
badge: 0
},
{
pagePath: "/pages/account/statistics/index",
text: "统计",
icon: "chart",
activeIcon: "chart",
badge: 0
},
{
pagePath: "/pages/ucenter/index/index",
text: "我的",
icon: "person",
activeIcon: "person-filled",
badge: 0
}
],
whitelist: [
'/pages/ucenter/login/index',
'/pages/ucenter/register/index',
'/pages/ucenter/agreement/user',
'/pages/ucenter/agreement/privacy',
]
}
import devConfig from './dev.config.js'
if (process.env.NODE_ENV === 'development') {
Object.assign(config, devConfig)
}
export default config

View File

@@ -0,0 +1,35 @@
import { checkLogin, isLogin } from '@/utils/auth.js'
export default {
onLoad() {
// 页面加载时检查登录状态
this.checkAuth()
},
onShow() {
// 页面显示时检查登录状态
this.checkAuth()
},
methods: {
/**
* 检查登录状态
* 如果页面设置了需要登录needLogin: true则进行登录验证
*/
checkAuth() {
// 如果页面明确标记不需要登录,则跳过检查
if (this.needLogin === false) {
return
}
// 默认需要登录验证
checkLogin()
},
/**
* 检查是否已登录
* @returns {boolean}
*/
isLoggedIn() {
return isLogin()
}
}
}

View File

@@ -7,9 +7,13 @@
"家庭记账" "家庭记账"
], ],
"license": "MIT", "license": "MIT",
"author": { "name": "molong", "email": "ycgpp@126.com" }, "author": {
"name": "molong",
"email": "ycgpp@126.com"
},
"dependencies": { "dependencies": {
"@dcloudio/uni-ui": "^1.5.11", "@dcloudio/uni-ui": "^1.5.11",
"crypto-js": "^4.2.0",
"luch-request": "^3.1.1" "luch-request": "^3.1.1"
} }
} }

View File

@@ -1,6 +1,29 @@
{ {
"pages": [ "pages": [
{ "path": "pages/index/index" } {
"path": "pages/index/index"
},
{
"path": "pages/account/bill/index"
},
{
"path": "pages/account/statistics/index"
},
{
"path": "pages/ucenter/index/index"
},
{
"path": "pages/ucenter/login/index"
},
{
"path": "pages/ucenter/register/index"
},
{
"path": "pages/ucenter/agreement/user"
},
{
"path": "pages/ucenter/agreement/privacy"
}
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
@@ -15,6 +38,7 @@
"easycom": { "easycom": {
"autoscan": true, "autoscan": true,
"custom": { "custom": {
"^un-(.*)": "@/components/$1/$1.vue",
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue" "^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
} }
}, },

View File

@@ -0,0 +1,46 @@
<template>
<un-pages
:show-nav-bar="true"
nav-bar-title="账单"
:show-back="false"
:show-tab-bar="true"
@tab-change="handleTabChange"
>
<view class="page-content">
<view class="empty-state">
<uni-icons type="list" size="100" color="#ddd"></uni-icons>
<text class="empty-text">账单功能开发中</text>
</view>
</view>
</un-pages>
</template>
<script>
export default {
methods: {
handleTabChange(path) {
console.log('Tab changed to:', path)
}
}
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 40rpx 30rpx;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 200rpx 0;
.empty-text {
font-size: 28rpx;
color: #999;
margin-top: 40rpx;
}
}
</style>

View File

@@ -0,0 +1,46 @@
<template>
<un-pages
:show-nav-bar="true"
nav-bar-title="统计"
:show-back="false"
:show-tab-bar="true"
@tab-change="handleTabChange"
>
<view class="page-content">
<view class="empty-state">
<uni-icons type="chart" size="100" color="#ddd"></uni-icons>
<text class="empty-text">统计功能开发中</text>
</view>
</view>
</un-pages>
</template>
<script>
export default {
methods: {
handleTabChange(path) {
console.log('Tab changed to:', path)
}
}
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 40rpx 30rpx;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 200rpx 0;
.empty-text {
font-size: 28rpx;
color: #999;
margin-top: 40rpx;
}
}
</style>

View File

@@ -1,52 +1,151 @@
<template> <template>
<view class="content"> <un-pages
<image class="logo" src="/static/logo.png"></image> :show-nav-bar="true"
<view class="text-area"> nav-bar-title="首页"
<text class="title">{{title}}</text> :show-back="false"
:show-tab-bar="true"
@tab-change="handleTabChange"
>
<view class="page-content">
<view class="welcome-section">
<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
<text class="welcome-title">欢迎使用家庭记账</text>
<text class="welcome-desc">简单好用的家庭记账助手</text>
</view>
<view class="quick-actions">
<view class="action-card" @tap="navigateTo('/pages/account/bill/add')">
<uni-icons type="plus" size="40" color="#667eea"></uni-icons>
<text class="action-title">记一笔</text>
</view>
<view class="action-card" @tap="navigateTo('/pages/account/bill/index')">
<uni-icons type="list" size="40" color="#f093fb"></uni-icons>
<text class="action-title">账单</text>
</view>
</view>
<view class="recent-section">
<view class="section-header">
<text class="section-title">最近记录</text>
<text class="section-more" @tap="navigateTo('/pages/account/bill/index')">查看更多 ></text>
</view>
<view class="empty-list">
<text class="empty-text">暂无记录</text>
</view>
</view>
</view> </view>
</view> </un-pages>
</template> </template>
<script> <script>
export default { export default {
data() { methods: {
return { handleTabChange(path) {
title: 'Hello' console.log('Tab changed to:', path)
} // tabbar组件已经处理了跳转这里不需要额外处理
}, },
onLoad() { navigateTo(url) {
uni.showToast({
}, title: '功能开发中',
methods: { icon: 'none',
duration: 2000
})
} }
} }
}
</script> </script>
<style> <style lang="scss" scoped>
.content { .page-content {
padding: 40rpx 30rpx;
}
.welcome-section {
display: flex;
flex-direction: column;
align-items: center;
padding: 60rpx 0;
.logo {
width: 160rpx;
height: 160rpx;
margin-bottom: 30rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.9);
padding: 20rpx;
}
.welcome-title {
font-size: 44rpx;
font-weight: bold;
color: #333;
margin-bottom: 16rpx;
}
.welcome-desc {
font-size: 28rpx;
color: #999;
}
}
.quick-actions {
display: flex;
justify-content: space-between;
margin: 60rpx 0;
.action-card {
flex: 1;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 20rpx;
padding: 40rpx 20rpx;
margin: 0 10rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center;
}
.logo { &:last-child {
height: 200rpx; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
width: 200rpx; }
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area { .action-title {
font-size: 28rpx;
color: #fff;
margin-top: 20rpx;
}
}
}
.recent-section {
margin-top: 40rpx;
.section-header {
display: flex; display: flex;
justify-content: center; justify-content: space-between;
align-items: center;
margin-bottom: 30rpx;
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.section-more {
font-size: 26rpx;
color: #667eea;
}
} }
.title { .empty-list {
font-size: 36rpx; background: #fff;
color: #8f8f94; border-radius: 20rpx;
padding: 80rpx 40rpx;
text-align: center;
.empty-text {
font-size: 28rpx;
color: #999;
}
} }
}
</style> </style>

View File

@@ -0,0 +1,356 @@
<template>
<view class="agreement-container">
<!-- 顶部导航栏 -->
<view class="nav-bar">
<view class="nav-back" @tap="goBack">
<uni-icons type="left" size="24" color="#333"></uni-icons>
</view>
<view class="nav-title">隐私政策</view>
<view class="nav-placeholder"></view>
</view>
<!-- 内容区域 -->
<scroll-view class="content-scroll" scroll-y>
<view class="agreement-content">
<view class="agreement-title">家庭记账隐私政策</view>
<view class="agreement-intro">
<text class="intro-text">
我们非常重视您的隐私保护本隐私政策旨在向您说明我们如何收集使用存储和保护您的个人信息使用我们的服务即表示您同意本隐私政策的条款
</text>
</view>
<view class="agreement-section">
<text class="section-title">1. 信息收集</text>
<text class="section-text">
1.1 我们收集的信息包括
</text>
<text class="section-text">
1账户信息您在注册时提供的用户名密码昵称等
</text>
<text class="section-text">
2使用信息您使用应用的功能频率偏好等使用数据
</text>
<text class="section-text">
3设备信息设备型号操作系统版本唯一设备标识符等
</text>
<text class="section-text">
4日志信息访问时间页面浏览记录错误日志等
</text>
<text class="section-text">
1.2 我们仅在为您提供服务和改进产品时收集必要的信息绝不会收集与提供服务无关的信息
</text>
</view>
<view class="agreement-section">
<text class="section-title">2. 信息使用</text>
<text class="section-text">
2.1 我们可能使用收集的信息用于
</text>
<text class="section-text">
1提供维护和改进我们的服务
</text>
<text class="section-text">
2处理您的请求和交易
</text>
<text class="section-text">
3向您发送与服务相关的通知和更新
</text>
<text class="section-text">
4分析使用情况优化用户体验
</text>
<text class="section-text">
5防止欺诈滥用和安全威胁
</text>
<text class="section-text">
6遵守法律法规要求
</text>
</view>
<view class="agreement-section">
<text class="section-title">3. 信息共享</text>
<text class="section-text">
3.1 除以下情况外我们不会与第三方共享您的个人信息
</text>
<text class="section-text">
1获得您的明确同意
</text>
<text class="section-text">
2履行法律义务或响应法律要求
</text>
<text class="section-text">
3保护我们的权利财产或安全
</text>
<text class="section-text">
4与提供服务的合作伙伴共享但仅限于必要范围
</text>
<text class="section-text">
5业务转让或合并时涉及用户信息转移
</text>
<text class="section-text">
3.2 所有共享的信息都会受到严格的保密协议和隐私保护
</text>
</view>
<view class="agreement-section">
<text class="section-title">4. 信息存储与安全</text>
<text class="section-text">
4.1 我们采取合理的技术措施保护您的信息安全包括但不限于
</text>
<text class="section-text">
1数据加密传输和存储
</text>
<text class="section-text">
2访问权限控制
</text>
<text class="section-text">
3定期安全审计和风险评估
</text>
<text class="section-text">
4员工保密培训和责任制度
</text>
<text class="section-text">
4.2 我们在中华人民共和国境内存储您的个人信息
</text>
<text class="section-text">
4.3 如发生信息泄露我们将及时采取补救措施并通知您
</text>
</view>
<view class="agreement-section">
<text class="section-title">5. Cookie和类似技术</text>
<text class="section-text">
5.1 我们可能使用Cookie和类似技术来收集和存储信息以改善用户体验
</text>
<text class="section-text">
5.2 您可以通过浏览器设置管理Cookie但这可能影响某些功能的使用
</text>
</view>
<view class="agreement-section">
<text class="section-title">6. 您的权利</text>
<text class="section-text">
6.1 您对个人信息享有以下权利
</text>
<text class="section-text">
1访问更正删除您的个人信息
</text>
<text class="section-text">
2撤回对信息处理的同意
</text>
<text class="section-text">
3获取个人信息副本
</text>
<text class="section-text">
4限制信息处理
</text>
<text class="section-text">
5数据可携带权
</text>
<text class="section-text">
6反对信息处理
</text>
<text class="section-text">
7向监管机构投诉
</text>
<text class="section-text">
6.2 您可以通过应用内设置或联系我们来行使这些权利
</text>
</view>
<view class="agreement-section">
<text class="section-title">7. 信息保留</text>
<text class="section-text">
7.1 我们仅在实现收集目的所必需的期间内保留您的个人信息
</text>
<text class="section-text">
7.2 当账户注销或收集目的实现后我们将删除或匿名化处理您的信息法律法规另有规定的除外
</text>
</view>
<view class="agreement-section">
<text class="section-title">8. 未成年人保护</text>
<text class="section-text">
8.1 我们的服务主要面向成年人如果您未满18周岁请在监护人的陪同下使用本服务
</text>
<text class="section-text">
8.2 如发现未经未成年人监护人同意收集未成年人信息的情况请立即联系我们我们将及时删除相关信息
</text>
</view>
<view class="agreement-section">
<text class="section-title">9. 隐私政策的变更</text>
<text class="section-text">
9.1 我们可能不时更新本隐私政策
</text>
<text class="section-text">
9.2 更新后的政策将在应用内公布重大变更时我们会通过适当方式通知您
</text>
<text class="section-text">
9.3 继续使用服务即表示您接受更新后的隐私政策
</text>
</view>
<view class="agreement-section">
<text class="section-title">10. 联系我们</text>
<text class="section-text">
如对本隐私政策有任何疑问意见或请求请通过以下方式联系我们
</text>
<text class="section-text">
邮箱privacy@familyaccount.com
</text>
<text class="section-text">
电话400-XXX-XXXX
</text>
<text class="section-text">
地址中国XX省XX市XX区XX路XX号
</text>
</view>
<view class="agreement-section">
<text class="section-title">11. 适用法律</text>
<text class="section-text">
11.1 本隐私政策的订立执行和解释均适用中华人民共和国法律
</text>
<text class="section-text">
11.2 我们严格遵守中华人民共和国个人信息保护法网络安全法等相关法律法规的规定
</text>
</view>
<view class="agreement-footer">
<text class="footer-text">更新日期2024年1月</text>
<text class="footer-text">生效日期2024年1月1日</text>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
data() {
return {
// 不需要登录验证
needLogin: false
}
},
methods: {
// 返回上一页
goBack() {
uni.navigateBack()
}
}
}
</script>
<style lang="scss" scoped>
.agreement-container {
min-height: 100vh;
background: #F8F8F8;
display: flex;
flex-direction: column;
}
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
height: 88rpx;
padding: 0 30rpx;
background: #fff;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
position: sticky;
top: 0;
z-index: 100;
}
.nav-back {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
}
.nav-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
}
.nav-placeholder {
width: 60rpx;
}
.content-scroll {
flex: 1;
height: calc(100vh - 88rpx);
}
.agreement-content {
padding: 40rpx 30rpx;
background: #fff;
}
.agreement-title {
font-size: 40rpx;
font-weight: bold;
color: #333;
text-align: center;
margin-bottom: 40rpx;
}
.agreement-intro {
background: #f5f5f5;
padding: 30rpx;
border-radius: 10rpx;
margin-bottom: 40rpx;
}
.intro-text {
display: block;
font-size: 28rpx;
color: #666;
line-height: 1.8;
text-align: justify;
}
.agreement-section {
margin-bottom: 50rpx;
}
.section-title {
display: block;
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
}
.section-text {
display: block;
font-size: 28rpx;
color: #666;
line-height: 1.8;
margin-bottom: 20rpx;
text-align: justify;
}
.agreement-footer {
margin-top: 60rpx;
padding-top: 30rpx;
border-top: 1rpx solid #eee;
text-align: center;
}
.footer-text {
display: block;
font-size: 24rpx;
color: #999;
margin-bottom: 10rpx;
&:last-child {
margin-bottom: 0;
}
}
</style>

View File

@@ -0,0 +1,252 @@
<template>
<view class="agreement-container">
<!-- 顶部导航栏 -->
<view class="nav-bar">
<view class="nav-back" @tap="goBack">
<uni-icons type="left" size="24" color="#333"></uni-icons>
</view>
<view class="nav-title">用户协议</view>
<view class="nav-placeholder"></view>
</view>
<!-- 内容区域 -->
<scroll-view class="content-scroll" scroll-y>
<view class="agreement-content">
<view class="agreement-title">家庭记账用户协议</view>
<view class="agreement-section">
<text class="section-title">1. 服务条款的接受</text>
<text class="section-text">
欢迎使用家庭记账应用通过下载安装或使用本应用即表示您同意遵守本用户协议的所有条款和条件如果您不同意这些条款请不要使用本应用
</text>
</view>
<view class="agreement-section">
<text class="section-title">2. 服务说明</text>
<text class="section-text">
2.1 家庭记账是一款为用户提供记账账单管理等服务的移动应用程序
</text>
<text class="section-text">
2.2 我们保留随时修改或中断服务而不需通知用户的权利
</text>
<text class="section-text">
2.3 用户需自行承担使用本服务所产生的风险包括但不限于因使用本服务而导致的计算机系统损坏或数据丢失
</text>
</view>
<view class="agreement-section">
<text class="section-title">3. 用户账号</text>
<text class="section-text">
3.1 用户注册成功后将获得一个账号和密码用户应妥善保管账号和密码并对使用该账号和密码进行的所有活动承担责任
</text>
<text class="section-text">
3.2 用户不得将账号转让出借或以其他方式提供给他人使用
</text>
<text class="section-text">
3.3 如发现任何非法使用账号的情况应立即通知我们
</text>
</view>
<view class="agreement-section">
<text class="section-title">4. 用户行为规范</text>
<text class="section-text">
4.1 用户在使用本服务时必须遵守相关法律法规不得利用本服务从事任何违法或不当行为
</text>
<text class="section-text">
4.2 禁止用户
</text>
<text class="section-text">
1发布或传输任何违法有害威胁辱骂骚扰诽谤侵犯隐私的信息
</text>
<text class="section-text">
2侵犯他人的知识产权商业秘密或其他合法权利
</text>
<text class="section-text">
3干扰或破坏本服务的正常运行
</text>
<text class="section-text">
4传播病毒木马或其他恶意代码
</text>
</view>
<view class="agreement-section">
<text class="section-title">5. 隐私保护</text>
<text class="section-text">
我们重视用户的隐私保护关于个人信息收集使用和保护的具体内容请参阅我们的隐私政策
</text>
</view>
<view class="agreement-section">
<text class="section-title">6. 知识产权</text>
<text class="section-text">
6.1 本应用的所有内容包括但不限于文字图片音频视频软件程序版面设计等均受知识产权法保护
</text>
<text class="section-text">
6.2 用户在使用本服务过程中产生的内容用户保留其知识产权但授权我们在服务范围内使用该内容
</text>
</view>
<view class="agreement-section">
<text class="section-title">7. 免责声明</text>
<text class="section-text">
7.1 本服务按"现状"提供不提供任何明示或暗示的保证
</text>
<text class="section-text">
7.2 我们不对以下情况承担责任
</text>
<text class="section-text">
1因用户使用本服务而产生的任何直接或间接损失
</text>
<text class="section-text">
2因不可抗力网络故障系统维护等原因导致的服务中断
</text>
<text class="section-text">
3第三方提供的内容或服务
</text>
</view>
<view class="agreement-section">
<text class="section-title">8. 协议的修改</text>
<text class="section-text">
我们有权随时修改本协议的条款修改后的协议一旦公布即代替原协议用户如不同意修改后的协议可以停止使用本服务继续使用本服务即视为用户接受修改后的协议
</text>
</view>
<view class="agreement-section">
<text class="section-title">9. 法律适用与争议解决</text>
<text class="section-text">
9.1 本协议的订立执行和解释均适用中华人民共和国法律
</text>
<text class="section-text">
9.2 如发生争议双方应友好协商解决协商不成的任何一方均可向被告所在地人民法院提起诉讼
</text>
</view>
<view class="agreement-section">
<text class="section-title">10. 联系我们</text>
<text class="section-text">
如对本协议有任何疑问或建议请通过以下方式联系我们
</text>
<text class="section-text">
邮箱support@familyaccount.com
</text>
<text class="section-text">
电话400-XXX-XXXX
</text>
</view>
<view class="agreement-footer">
<text class="footer-text">更新日期2024年1月</text>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
data() {
return {
// 不需要登录验证
needLogin: false
}
},
methods: {
// 返回上一页
goBack() {
uni.navigateBack()
}
}
}
</script>
<style lang="scss" scoped>
.agreement-container {
min-height: 100vh;
background: #F8F8F8;
display: flex;
flex-direction: column;
}
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
height: 88rpx;
padding: 0 30rpx;
background: #fff;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
position: sticky;
top: 0;
z-index: 100;
}
.nav-back {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
}
.nav-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
}
.nav-placeholder {
width: 60rpx;
}
.content-scroll {
flex: 1;
height: calc(100vh - 88rpx);
}
.agreement-content {
padding: 40rpx 30rpx;
background: #fff;
}
.agreement-title {
font-size: 40rpx;
font-weight: bold;
color: #333;
text-align: center;
margin-bottom: 50rpx;
}
.agreement-section {
margin-bottom: 50rpx;
}
.section-title {
display: block;
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
}
.section-text {
display: block;
font-size: 28rpx;
color: #666;
line-height: 1.8;
margin-bottom: 20rpx;
text-align: justify;
}
.agreement-footer {
margin-top: 60rpx;
padding-top: 30rpx;
border-top: 1rpx solid #eee;
text-align: center;
}
.footer-text {
font-size: 24rpx;
color: #999;
}
</style>

View File

@@ -0,0 +1,204 @@
<template>
<un-pages
:show-nav-bar="true"
nav-bar-title="我的"
:show-back="false"
:show-tab-bar="true"
@tab-change="handleTabChange"
>
<view class="page-content">
<!-- 用户信息头部 -->
<view class="user-header">
<view class="user-avatar">
<uni-icons type="person-filled" size="60" color="#fff"></uni-icons>
</view>
<view class="user-info">
<text class="user-name">{{ userInfo.nickname || '未登录' }}</text>
<text class="user-desc">{{ userInfo.username || '点击登录' }}</text>
</view>
</view>
<!-- 功能菜单 -->
<view class="menu-section">
<view class="menu-item" @tap="navigateTo('/pages/ucenter/profile')">
<view class="menu-left">
<uni-icons type="gear" size="20" color="#667eea"></uni-icons>
<text class="menu-text">个人设置</text>
</view>
<uni-icons type="right" size="16" color="#ccc"></uni-icons>
</view>
<view class="menu-item" @tap="navigateTo('/pages/ucenter/help')">
<view class="menu-left">
<uni-icons type="help" size="20" color="#667eea"></uni-icons>
<text class="menu-text">帮助中心</text>
</view>
<uni-icons type="right" size="16" color="#ccc"></uni-icons>
</view>
<view class="menu-item" @tap="navigateTo('/pages/ucenter/about')">
<view class="menu-left">
<uni-icons type="info" size="20" color="#667eea"></uni-icons>
<text class="menu-text">关于我们</text>
</view>
<uni-icons type="right" size="16" color="#ccc"></uni-icons>
</view>
</view>
<!-- 退出登录按钮 -->
<view class="logout-section" v-if="isLogin">
<button class="logout-btn" @tap="handleLogout">退出登录</button>
</view>
</view>
</un-pages>
</template>
<script>
import { isLogin, logout } from '@/utils/auth.js'
export default {
data() {
return {
userInfo: {},
isLogin: false
}
},
onLoad() {
this.checkLoginStatus()
},
onShow() {
this.checkLoginStatus()
},
methods: {
// 检查登录状态
checkLoginStatus() {
this.isLogin = isLogin()
this.userInfo = uni.getStorageSync('userInfo') || {}
},
// 页面跳转
navigateTo(url) {
if (!this.isLogin) {
uni.navigateTo({
url: '/pages/ucenter/login/index'
})
return
}
uni.showToast({
title: '功能开发中',
icon: 'none',
duration: 2000
})
},
// 退出登录
handleLogout() {
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
logout()
}
}
})
},
// Tab切换
handleTabChange(path) {
console.log('Tab changed to:', path)
}
}
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 40rpx 30rpx;
}
.user-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 20rpx;
padding: 60rpx 40rpx;
margin: 40rpx 0;
display: flex;
align-items: center;
.user-avatar {
width: 120rpx;
height: 120rpx;
background: rgba(255, 255, 255, 0.3);
border-radius: 60rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 30rpx;
}
.user-info {
flex: 1;
display: flex;
flex-direction: column;
.user-name {
font-size: 36rpx;
font-weight: bold;
color: #fff;
margin-bottom: 16rpx;
}
.user-desc {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
}
}
}
.menu-section {
background: #fff;
border-radius: 20rpx;
overflow: hidden;
.menu-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx 40rpx;
border-bottom: 1rpx solid #f5f5f5;
&:last-child {
border-bottom: none;
}
.menu-left {
display: flex;
align-items: center;
.menu-text {
font-size: 32rpx;
color: #333;
margin-left: 20rpx;
}
}
}
}
.logout-section {
margin-top: 60rpx;
.logout-btn {
width: 100%;
height: 90rpx;
line-height: 90rpx;
border-radius: 45rpx;
background: #fff;
color: #f56c6c;
font-size: 32rpx;
border: 2rpx solid #f56c6c;
&::after {
border: none;
}
}
}
</style>

View File

@@ -0,0 +1,407 @@
<template>
<view class="login-container">
<view class="login-content">
<!-- Logo 区域 -->
<view class="logo-section">
<image src="/static/logo.png" class="logo" mode="aspectFit"></image>
<text class="app-name">家庭记账</text>
<text class="welcome-text">欢迎使用家庭记账</text>
</view>
<!-- 表单区域 -->
<view class="form-section">
<view class="form-item">
<uni-icons type="person" size="20" color="#999"></uni-icons>
<input class="input" type="text" v-model="formData.username" placeholder="请输入用户名"
placeholder-class="input-placeholder" maxlength="30" />
</view>
<view class="form-item">
<uni-icons type="locked" size="20" color="#999"></uni-icons>
<input class="input" :type="showPassword ? 'text' : 'password'" v-model="formData.password"
placeholder="请输入密码" placeholder-class="input-placeholder" />
<uni-icons :type="showPassword ? 'eye-slash' : 'eye'" size="20" color="#999"
@tap="togglePassword"></uni-icons>
</view>
<view class="form-options">
<view class="checkbox-item" @tap="toggleRemember">
<uni-icons :type="formData.remember ? 'checkbox-filled' : 'circle'"
:color="formData.remember ? '#4CAF50' : '#999'" size="20"></uni-icons>
<text class="checkbox-text">记住密码</text>
</view>
<text class="forget-password" @tap="handleForgetPassword">忘记密码?</text>
</view>
<button class="login-btn" type="primary" @tap="handleLogin" :loading="loading">
{{ loading ? '登录中...' : '登录' }}
</button>
<view class="register-tip">
<text class="tip-text">还没有账号</text>
<text class="register-link" @tap="goToRegister">立即注册</text>
</view>
</view>
<!-- 其他登录方式 -->
<view class="other-login" v-if="false">
<view class="divider">
<text class="divider-text">其他登录方式</text>
</view>
<view class="social-login">
<view class="social-item" @tap="handleWechatLogin">
<uni-icons type="weixin" size="32" color="#07C160"></uni-icons>
<text class="social-text">微信登录</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import authApi from '@/api/modules/auth'
export default {
data() {
return {
// 不需要登录验证
needLogin: false,
formData: {
username: '',
password: '',
remember: false
},
showPassword: false,
loading: false
}
},
onLoad() {
// 检查是否有记住的密码
const savedUsername = uni.getStorageSync('savedUsername')
const savedPassword = uni.getStorageSync('savedPassword')
if (savedUsername && savedPassword) {
this.formData.username = savedUsername
this.formData.password = savedPassword
this.formData.remember = true
}
},
methods: {
// 切换密码显示/隐藏
togglePassword() {
this.showPassword = !this.showPassword
},
// 切换记住密码
toggleRemember() {
this.formData.remember = !this.formData.remember
},
// 登录
async handleLogin() {
// 表单验证
if (!this.validateForm()) {
return
}
try {
this.loading = true
// 调用登录接口
const result = await authApi.login.post({
username: this.formData.username,
password: this.formData.password
})
// 保存 token 和用户信息
if (result.code == 1) {
this.$store.commit('setUserLogin', result.data)
const user = await authApi.info.get()
this.$store.commit('setUserInfo', user.data)
// 记住密码
if (this.formData.remember) {
uni.setStorageSync('savedUsername', this.formData.username)
uni.setStorageSync('savedPassword', this.formData.password)
} else {
uni.removeStorageSync('savedUsername')
uni.removeStorageSync('savedPassword')
}
uni.showToast({
title: '登录成功',
icon: 'success',
duration: 1500
})
// 跳转到首页
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index'
})
}, 1500)
} else {
uni.showToast({
title: result.message,
icon: 'success',
duration: 1500
})
}
} catch (error) {
console.error('登录失败:', error)
} finally {
this.loading = false
}
},
// 表单验证
validateForm() {
const { username, password } = this.formData
if (!username) {
uni.showToast({
title: '请输入用户名',
icon: 'none',
duration: 2000
})
return false
}
if (username.length < 3) {
uni.showToast({
title: '用户名至少3个字符',
icon: 'none',
duration: 2000
})
return false
}
if (!password) {
uni.showToast({
title: '请输入密码',
icon: 'none',
duration: 2000
})
return false
}
if (password.length < 6) {
uni.showToast({
title: '密码长度不能少于6位',
icon: 'none',
duration: 2000
})
return false
}
return true
},
// 忘记密码
handleForgetPassword() {
uni.showToast({
title: '功能开发中',
icon: 'none',
duration: 2000
})
},
// 跳转到注册页
goToRegister() {
uni.navigateTo({
url: '/pages/ucenter/register/index'
})
},
// 微信登录
handleWechatLogin() {
uni.showToast({
title: '微信登录功能开发中',
icon: 'none',
duration: 2000
})
}
}
}
</script>
<style lang="scss" scoped>
.login-container {
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 0 60rpx;
box-sizing: border-box;
}
.login-content {
padding-top: 120rpx;
}
.logo-section {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 80rpx;
.logo {
width: 160rpx;
height: 160rpx;
margin-bottom: 30rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.9);
padding: 20rpx;
}
.app-name {
font-size: 48rpx;
font-weight: bold;
color: #fff;
margin-bottom: 20rpx;
}
.welcome-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
}
}
.form-section {
.form-item {
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.95);
border-radius: 16rpx;
padding: 30rpx 40rpx;
margin-bottom: 30rpx;
.input {
flex: 1;
margin-left: 20rpx;
margin-right: 20rpx;
font-size: 32rpx;
color: #333;
}
.input-placeholder {
color: #999;
}
}
.form-options {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 40rpx;
padding: 0 10rpx;
.checkbox-item {
display: flex;
align-items: center;
.checkbox-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
margin-left: 10rpx;
}
}
.forget-password {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
}
}
.login-btn {
width: 100%;
height: 100rpx;
line-height: 100rpx;
border-radius: 50rpx;
background: linear-gradient(90deg, #f093fb 0%, #f5576c 100%);
color: #fff;
font-size: 36rpx;
font-weight: bold;
border: none;
box-shadow: 0 8rpx 20rpx rgba(245, 87, 108, 0.4);
margin-bottom: 40rpx;
&::after {
border: none;
}
}
.register-tip {
display: flex;
justify-content: center;
align-items: center;
.tip-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
}
.register-link {
font-size: 28rpx;
color: #fff;
font-weight: bold;
margin-left: 10rpx;
text-decoration: underline;
}
}
}
.other-login {
margin-top: 100rpx;
.divider {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 60rpx;
position: relative;
&::before,
&::after {
content: '';
position: absolute;
width: 200rpx;
height: 1rpx;
background: rgba(255, 255, 255, 0.3);
}
&::before {
left: 0;
}
&::after {
right: 0;
}
.divider-text {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.6);
padding: 0 20rpx;
}
}
.social-login {
display: flex;
justify-content: center;
.social-item {
display: flex;
flex-direction: column;
align-items: center;
.social-text {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.9);
margin-top: 20rpx;
}
}
}
}
</style>

View File

@@ -0,0 +1,401 @@
<template>
<view class="register-container">
<view class="register-content">
<!-- Logo 区域 -->
<view class="logo-section">
<image src="/static/logo.png" class="logo" mode="aspectFit"></image>
<text class="app-name">用户注册</text>
<text class="welcome-text">创建您的家庭记账账号</text>
</view>
<!-- 表单区域 -->
<view class="form-section">
<view class="form-item">
<uni-icons type="person" size="20" color="#999"></uni-icons>
<input
class="input"
type="text"
v-model="formData.username"
placeholder="请输入用户名"
placeholder-class="input-placeholder"
maxlength="30"
/>
</view>
<view class="form-item">
<uni-icons type="locked" size="20" color="#999"></uni-icons>
<input
class="input"
:type="showPassword ? 'text' : 'password'"
v-model="formData.password"
placeholder="请设置密码6-20位"
placeholder-class="input-placeholder"
/>
<uni-icons
:type="showPassword ? 'eye-slash' : 'eye'"
size="20"
color="#999"
@tap="togglePassword"
></uni-icons>
</view>
<view class="form-item">
<uni-icons type="locked" size="20" color="#999"></uni-icons>
<input
class="input"
:type="showConfirmPassword ? 'text' : 'password'"
v-model="formData.confirmPassword"
placeholder="请再次输入密码"
placeholder-class="input-placeholder"
/>
<uni-icons
:type="showConfirmPassword ? 'eye-slash' : 'eye'"
size="20"
color="#999"
@tap="toggleConfirmPassword"
></uni-icons>
</view>
<view class="form-item">
<uni-icons type="info" size="20" color="#999"></uni-icons>
<input
class="input"
type="text"
v-model="formData.nickname"
placeholder="请设置昵称"
placeholder-class="input-placeholder"
maxlength="20"
/>
</view>
<view class="agreement-item">
<uni-icons
:type="formData.agreed ? 'checkbox-filled' : 'circle'"
:color="formData.agreed ? '#4CAF50' : '#999'"
size="20"
@tap="toggleAgreement"
></uni-icons>
<text class="agreement-text">
我已阅读并同意
<text class="agreement-link" @tap="handleAgreement('user')">用户协议</text>
<text class="agreement-link" @tap="handleAgreement('privacy')">隐私政策</text>
</text>
</view>
<button class="register-btn" type="primary" @tap="handleRegister" :loading="loading">
{{ loading ? '注册中...' : '立即注册' }}
</button>
<view class="login-tip">
<text class="tip-text">已有账号</text>
<text class="login-link" @tap="goToLogin">立即登录</text>
</view>
</view>
</view>
</view>
</template>
<script>
import authApi from '@/api/modules/auth'
export default {
data() {
return {
// 不需要登录验证
needLogin: false,
formData: {
username: '',
password: '',
confirmPassword: '',
nickname: '',
agreed: false
},
showPassword: false,
showConfirmPassword: false,
loading: false
}
},
methods: {
// 切换密码显示/隐藏
togglePassword() {
this.showPassword = !this.showPassword
},
toggleConfirmPassword() {
this.showConfirmPassword = !this.showConfirmPassword
},
// 切换协议同意
toggleAgreement() {
this.formData.agreed = !this.formData.agreed
},
// 注册
async handleRegister() {
// 表单验证
if (!this.validateForm()) {
return
}
try {
this.loading = true
// 调用注册接口
const result = await authApi.register.post({
username: this.formData.username,
password: this.formData.password,
nickname: this.formData.nickname
})
uni.showToast({
title: '注册成功',
icon: 'success',
duration: 1500
})
// 跳转到登录页
setTimeout(() => {
uni.redirectTo({
url: '/pages/ucenter/login/index'
})
}, 1500)
} catch (error) {
console.error('注册失败:', error)
} finally {
this.loading = false
}
},
// 表单验证
validateForm() {
const { username, password, confirmPassword, nickname, agreed } = this.formData
// 验证用户名
if (!username) {
uni.showToast({
title: '请输入用户名',
icon: 'none',
duration: 2000
})
return false
}
if (username.length < 3) {
uni.showToast({
title: '用户名至少3个字符',
icon: 'none',
duration: 2000
})
return false
}
// 验证密码
if (!password) {
uni.showToast({
title: '请设置密码',
icon: 'none',
duration: 2000
})
return false
}
if (password.length < 6 || password.length > 20) {
uni.showToast({
title: '密码长度为6-20位',
icon: 'none',
duration: 2000
})
return false
}
// 验证确认密码
if (!confirmPassword) {
uni.showToast({
title: '请再次输入密码',
icon: 'none',
duration: 2000
})
return false
}
if (password !== confirmPassword) {
uni.showToast({
title: '两次输入的密码不一致',
icon: 'none',
duration: 2000
})
return false
}
// 验证昵称
if (!nickname) {
uni.showToast({
title: '请设置昵称',
icon: 'none',
duration: 2000
})
return false
}
// 验证协议
if (!agreed) {
uni.showToast({
title: '请阅读并同意用户协议和隐私政策',
icon: 'none',
duration: 2000
})
return false
}
return true
},
// 查看协议
handleAgreement(type) {
let url = ''
if (type === 'user') {
url = '/pages/ucenter/agreement/user'
} else if (type === 'privacy') {
url = '/pages/ucenter/agreement/privacy'
}
if (url) {
uni.navigateTo({
url: url
})
}
},
// 跳转到登录页
goToLogin() {
uni.navigateBack()
}
}
}
</script>
<style lang="scss" scoped>
.register-container {
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 0 60rpx;
box-sizing: border-box;
}
.register-content {
padding-top: 80rpx;
}
.logo-section {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 60rpx;
.logo {
width: 140rpx;
height: 140rpx;
margin-bottom: 30rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.9);
padding: 20rpx;
}
.app-name {
font-size: 44rpx;
font-weight: bold;
color: #fff;
margin-bottom: 16rpx;
}
.welcome-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
}
}
.form-section {
.form-item {
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.95);
border-radius: 16rpx;
padding: 30rpx 40rpx;
margin-bottom: 24rpx;
.input {
flex: 1;
margin-left: 20rpx;
margin-right: 20rpx;
font-size: 32rpx;
color: #333;
}
.input-placeholder {
color: #999;
}
}
.agreement-item {
display: flex;
align-items: flex-start;
margin-bottom: 30rpx;
padding: 0 10rpx;
.agreement-text {
flex: 1;
font-size: 26rpx;
color: rgba(255, 255, 255, 0.9);
line-height: 1.6;
margin-left: 10rpx;
.agreement-link {
color: #fff;
font-weight: bold;
text-decoration: underline;
}
}
}
.register-btn {
width: 100%;
height: 100rpx;
line-height: 100rpx;
border-radius: 50rpx;
background: linear-gradient(90deg, #f093fb 0%, #f5576c 100%);
color: #fff;
font-size: 36rpx;
font-weight: bold;
border: none;
box-shadow: 0 8rpx 20rpx rgba(245, 87, 108, 0.4);
margin-bottom: 40rpx;
&::after {
border: none;
}
}
.login-tip {
display: flex;
justify-content: center;
align-items: center;
.tip-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.9);
}
.login-link {
font-size: 28rpx;
color: #fff;
font-weight: bold;
margin-left: 10rpx;
text-decoration: underline;
}
}
}
</style>

View File

@@ -0,0 +1,15 @@
/**
* @description 自动import导入所有 vuex 模块
*/
import { createStore } from 'vuex';
const files = import.meta.glob('./modules/*.js', { eager: true })
const modules = {}
Object.keys(files).forEach(key => {
modules[key.replace(/^\.\/modules\/(.*)\.js$/g, '$1')] = files[key].default
})
export default createStore({
modules
});

View File

@@ -0,0 +1,56 @@
import tool from '../../utils/tool'
export default{
state: {
isLogin: tool.data.get('is-login') || false,
token: tool.data.get('token') || '',
userInfo: tool.data.get('userInfo') || {name: '', avatar: ''},
userPermissions: tool.data.get('userPermissions') || []
},
mutations:{
setUserLogin(state, data){
if(data){
tool.data.set('is-login', true);
state.isLogin = true;
tool.data.set('token', data.access_token);
state.token = data.access_token;
}else{
tool.data.set('is-login', false);
tool.data.set('token', '');
state.isLogin = false;
}
},
setUserInfo(state, data){
if(data){
tool.data.set('userInfo', data)
state.userInfo = data
}else{
tool.data.set('userInfo', {})
state.userInfo = {}
}
},
setUserPermissions(state, data){
tool.data.set('userPermissions', data)
state.userPermissions = data
},
setUserLogout(state, data){
tool.data.set('is-login', false);
state.isLogin = false;
tool.data.set('token', '');
state.token = '';
tool.data.set('userInfo', {})
state.userInfo = {}
}
},
getters:{},
actions:{
userLogout({commit}){
commit('setUserLogin', false);
let pages = getCurrentPages()
tool.data.set('beforLoginUrl', {route: pages[pages.length - 1].route, options: pages[pages.length - 1].options})
uni.reLaunch({
url: '/pages/ucenter/login/index'
})
}
}
}

View File

@@ -0,0 +1,143 @@
import config from '@/config/index.js'
// 全局存储当前路由
let currentRoute = ''
/**
* 设置当前路由
* @param {string} route
*/
export function setCurrentRoute(route) {
currentRoute = route
}
/**
* 检查是否已登录
* @returns {boolean}
*/
export function isLogin() {
try {
const token = uni.getStorageSync('token')
return !!token
} catch (e) {
console.error('检查登录状态失败:', e)
return false
}
}
/**
* 获取当前页面路径
* @returns {string}
*/
export function getCurrentRoute() {
try {
// 如果有存储的路由,优先使用
if (currentRoute) {
return currentRoute
}
const pages = getCurrentPages()
if (pages && pages.length > 0) {
const currentPage = pages[pages.length - 1]
const route = currentPage ? `/${currentPage.route}` : ''
currentRoute = route
return route
}
return ''
} catch (e) {
console.error('获取当前路由失败:', e)
return ''
}
}
/**
* 检查当前路由是否在白名单中
* @returns {boolean}
*/
export function isInWhitelist(route) {
try {
const currentRoute = route || getCurrentRoute()
if (!currentRoute) return false
return config.whitelist.some(path => currentRoute.includes(path))
} catch (e) {
console.error('检查白名单失败:', e)
return false
}
}
/**
* 检查登录状态,未登录则跳转到登录页
* @returns {boolean} 是否已登录
*/
export function checkLogin() {
try {
const currentRoute = getCurrentRoute()
// 如果当前路由为空,可能是页面刚初始化,暂不检查
if (!currentRoute) {
return true
}
// 如果在白名单中,不检查登录状态
if (isInWhitelist(currentRoute)) {
return true
}
// 检查是否已登录
if (isLogin()) {
return true
}
// 未登录,跳转到登录页
if (currentRoute !== '/pages/ucenter/login/index') {
uni.showToast({
title: '请先登录',
icon: 'none',
duration: 2000
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/ucenter/login/index',
fail: (err) => {
console.error('跳转登录页失败:', err)
}
})
}, 1500)
}
return false
} catch (e) {
console.error('检查登录失败:', e)
return false
}
}
/**
* 退出登录
*/
export function logout() {
try {
uni.removeStorageSync('token')
uni.removeStorageSync('userInfo')
uni.showToast({
title: '已退出登录',
icon: 'success',
duration: 1500
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/ucenter/login/index',
fail: (err) => {
console.error('跳转登录页失败:', err)
}
})
}, 1500)
} catch (e) {
console.error('退出登录失败:', e)
}
}

View File

@@ -1,208 +1,73 @@
import http from 'luch-request' import Request from 'luch-request'
import sysConfig from '@/config'
import store from '@/store'
// 创建实例 const request = new Request()
const httpInstance = http.create({
baseURL: import.meta.env.VITE_API_BASE_URL || '/api', // 错误码常量
timeout: 10000, const ERROR_CODES = {
header: { TOKEN_EXPIRED: 2000,
'Content-Type': 'application/json;charset=UTF-8' TOKEN_INVALID: 2001
} }
// HTTP状态码处理映射
const HTTP_ERROR_MESSAGES = {
400: '请求参数错误',
401: '未授权,请重新登录',
403: '拒绝访问',
404: '请求地址不存在',
500: '服务器内部错误',
502: '网络连接失败',
503: '服务不可用',
504: '网关超时'
}
request.setConfig((config) => {
config.baseURL = sysConfig.baseURL
config.header = {
'content-type': 'application/json',
}
config.timeout = 30000
config.sslVerify = false
return config
}) })
// 请求拦截器 request.interceptors.request.use((config) => {
httpInstance.interceptors.request.use( // 从本地存储获取 token
(config) => { const token = store.state.user.token || ''
// 从本地存储获取 token config.header.Authorization = `Bearer ${token}`
const token = uni.getStorageSync('token')
if (token) {
config.header = {
...config.header,
'Authorization': `Bearer ${token}`
}
}
// 添加时间戳,防止缓存 return config
if (config.method === 'GET') { }, (error) => {
config.params = { return Promise.reject(error)
...config.params, })
_t: Date.now()
}
}
// 显示加载提示 request.interceptors.response.use((response) => {
if (config.loading !== false) { const { code, message } = response.data || {}
uni.showLoading({
title: config.loadingText || '加载中...',
mask: true
})
}
return config // 处理 token 过期或无效
}, if (code === ERROR_CODES.TOKEN_EXPIRED || code === ERROR_CODES.TOKEN_INVALID) {
(config) => { uni.showToast({
return Promise.reject(config) icon: 'none',
} title: message || '登录已过期,请重新登录',
) duration: 1500
})
setTimeout(() => {
store.dispatch('userLogout')
}, 100)
return Promise.reject(response.data)
}
// 响应拦截器 return response.data
httpInstance.interceptors.response.use( }, (error) => {
(response) => { const { statusCode, errMsg } = error || {}
// 隐藏加载提示 const errorMessage = HTTP_ERROR_MESSAGES[statusCode] || errMsg || '请求失败,请稍后重试'
if (response.config.loading !== false) {
uni.hideLoading()
}
const { statusCode, data } = response if (statusCode === 401) {
store.dispatch('userLogout')
}
// HTTP 状态码判断 return Promise.reject(error)
if (statusCode !== 200) { })
showError('网络请求失败')
return Promise.reject(response)
}
// 业务状态码判断 export default request
if (data.code !== undefined) {
// 成功响应
if (data.code === 0 || data.code === 200 || data.code === 1) {
return data.data !== undefined ? data.data : data
}
// 业务错误处理
if (data.code === 401) {
// token 失效,跳转登录页
uni.removeStorageSync('token')
uni.removeStorageSync('userInfo')
uni.showToast({
title: '登录已过期,请重新登录',
icon: 'none',
duration: 2000
})
setTimeout(() => {
uni.navigateTo({
url: '/pages/login/index'
})
}, 2000)
return Promise.reject(data)
}
// 其他业务错误
showError(data.message || data.msg || '请求失败')
return Promise.reject(data)
}
return data
},
(error) => {
// 隐藏加载提示
if (error.config && error.config.loading !== false) {
uni.hideLoading()
}
let errorMessage = '网络请求失败'
if (error.response) {
const { statusCode, data } = error.response
switch (statusCode) {
case 400:
errorMessage = data?.message || '请求参数错误'
break
case 401:
errorMessage = '登录已过期,请重新登录'
uni.removeStorageSync('token')
uni.removeStorageSync('userInfo')
setTimeout(() => {
uni.navigateTo({
url: '/pages/login/index'
})
}, 2000)
break
case 403:
errorMessage = '没有权限访问'
break
case 404:
errorMessage = '请求的资源不存在'
break
case 500:
errorMessage = '服务器内部错误'
break
case 502:
errorMessage = '网关错误'
break
case 503:
errorMessage = '服务不可用'
break
case 504:
errorMessage = '网关超时'
break
default:
errorMessage = data?.message || `请求失败 (${statusCode})`
}
} else if (error.errMsg) {
// 网络错误
if (error.errMsg.includes('timeout')) {
errorMessage = '请求超时,请检查网络连接'
} else if (error.errMsg.includes('network')) {
errorMessage = '网络连接失败,请检查网络'
}
}
showError(errorMessage)
return Promise.reject(error)
}
)
// 显示错误提示
function showError(message) {
uni.showToast({
title: message,
icon: 'none',
duration: 3000
})
}
// 封装常用请求方法
export default {
// GET 请求
get(url, params = {}, config = {}) {
return httpInstance.get(url, {
params,
...config
})
},
// POST 请求
post(url, data = {}, config = {}) {
return httpInstance.post(url, data, config)
},
// PUT 请求
put(url, data = {}, config = {}) {
return httpInstance.put(url, data, config)
},
// DELETE 请求
delete(url, data = {}, config = {}) {
return httpInstance.delete(url, {
data,
...config
})
},
// 文件上传
upload(url, filePath, formData = {}, config = {}) {
return httpInstance.upload(url, {
filePath,
formData,
name: 'file',
...config
})
},
// 文件下载
download(url, config = {}) {
return httpInstance.download(url, config)
},
// 原始实例,用于特殊场景
instance: httpInstance
}

View File

@@ -0,0 +1,207 @@
/*
* @Descripttion: 工具集
* @version: 1.2
* @LastEditors: sakuya
* @LastEditTime: 2022年5月24日00:28:56
*/
import CryptoJS from 'crypto-js';
import sysConfig from "@/config";
const tool = {}
/* localStorage */
tool.data = {
set(key, data, datetime = 0) {
//加密
if(sysConfig.LS_ENCRYPTION == "AES"){
data = tool.crypto.AES.encrypt(JSON.stringify(data), sysConfig.LS_ENCRYPTION_key)
}
let cacheValue = {
content: data,
datetime: parseInt(datetime) === 0 ? 0 : new Date().getTime() + parseInt(datetime) * 1000
}
return uni.setStorageSync(key, JSON.stringify(cacheValue))
},
get(key) {
try {
const value = JSON.parse(uni.getStorageSync(key))
if (value) {
let nowTime = new Date().getTime()
if (nowTime > value.datetime && value.datetime != 0) {
uni.removeStorageSync(key)
return null;
}
//解密
if(sysConfig.LS_ENCRYPTION == "AES"){
value.content = JSON.parse(tool.crypto.AES.decrypt(value.content, sysConfig.LS_ENCRYPTION_key))
}
return value.content
}
return null
} catch (err) {
return null
}
},
remove(key) {
return uni.removeStorageSync(key)
},
clear() {
return uni.clearStorageSync()
}
}
/*sessionStorage - 仅在 H5 环境下可用*/
// #ifdef H5
tool.session = {
set(table, settings) {
const _set = JSON.stringify(settings)
return sessionStorage.setItem(table, _set)
},
get(table) {
const data = sessionStorage.getItem(table)
try {
return JSON.parse(data)
} catch (err) {
return null
}
},
remove(table) {
return sessionStorage.removeItem(table)
},
clear() {
return sessionStorage.clear()
}
}
/*cookie - 仅在 H5 环境下可用*/
tool.cookie = {
set(name, value, config = {}) {
const cfg = {
expires: null,
path: null,
domain: null,
secure: false,
httpOnly: false,
...config
}
let cookieStr = `${name}=${encodeURIComponent(value)}`
if (cfg.expires) {
const exp = new Date()
exp.setTime(exp.getTime() + parseInt(cfg.expires) * 1000)
cookieStr += `;expires=${exp.toUTCString()}`
}
if (cfg.path) {
cookieStr += `;path=${cfg.path}`
}
if (cfg.domain) {
cookieStr += `;domain=${cfg.domain}`
}
document.cookie = cookieStr
},
get(name) {
const arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"))
if (arr != null) {
return decodeURIComponent(arr[2])
}
return null
},
remove(name) {
const exp = new Date()
exp.setTime(exp.getTime() - 1)
document.cookie = `${name}=;expires=${exp.toUTCString()}`
}
}
// #endif
// #ifndef H5
// 非 H5 环境下提供空实现,避免调用报错
tool.session = {
set() { console.warn('sessionStorage 仅在 H5 环境下可用') },
get() { return null },
remove() {},
clear() {}
}
tool.cookie = {
set() { console.warn('cookie 仅在 H5 环境下可用') },
get() { return null },
remove() {}
}
// #endif
/* 复制对象 */
tool.objCopy = function (obj) {
return JSON.parse(JSON.stringify(obj));
}
/* 日期格式化 */
tool.dateFormat = function (date, fmt='yyyy-MM-dd hh:mm:ss') {
date = new Date(date)
var o = {
"M+" : date.getMonth()+1, //月份
"d+" : date.getDate(), //日
"h+" : date.getHours(), //小时
"m+" : date.getMinutes(), //分
"s+" : date.getSeconds(), //秒
"q+" : Math.floor((date.getMonth()+3)/3), //季度
"S" : date.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
}
/* 千分符 */
tool.groupSeparator = function (num) {
num = num + '';
if(!num.includes('.')){
num += '.'
}
return num.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
return $1 + ',';
}).replace(/\.$/, '');
}
/* 常用加解密 */
tool.crypto = {
//MD5加密
MD5(data){
return CryptoJS.MD5(data).toString()
},
//BASE64加解密
BASE64: {
encrypt(data){
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
},
decrypt(cipher){
return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
}
},
//AES加解密
AES: {
encrypt(data, secretKey, config={}){
if(secretKey.length % 8 != 0){
console.warn("[SCUI error]: 秘钥长度需为8的倍数否则解密将会失败。")
}
const result = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(secretKey), {
iv: CryptoJS.enc.Utf8.parse(config.iv || ""),
mode: CryptoJS.mode[config.mode || "ECB"],
padding: CryptoJS.pad[config.padding || "Pkcs7"]
})
return result.toString()
},
decrypt(cipher, secretKey, config={}){
const result = CryptoJS.AES.decrypt(cipher, CryptoJS.enc.Utf8.parse(secretKey), {
iv: CryptoJS.enc.Utf8.parse(config.iv || ""),
mode: CryptoJS.mode[config.mode || "ECB"],
padding: CryptoJS.pad[config.padding || "Pkcs7"]
})
return CryptoJS.enc.Utf8.stringify(result);
}
}
}
export default tool