更新
This commit is contained in:
@@ -74,7 +74,7 @@ return [
|
||||
],
|
||||
'members' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Member\Models\Member::class,
|
||||
'model' => Modules\Member\Models\Member::class,
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class Member extends Authenticatable implements JWTSubject {
|
||||
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'status'];
|
||||
protected $hidden = ['password', 'deleted_at'];
|
||||
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.
|
||||
@@ -75,23 +75,7 @@ class Member extends Authenticatable implements JWTSubject {
|
||||
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(){
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
\Modules\Member\Events\LoginBefore::class => [
|
||||
\Modules\Member\Listeners\UpMemberPaswd::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,10 +31,10 @@ class AuthService {
|
||||
$password = $request->input('password');
|
||||
LoginBefore::dispatch($username, $password);
|
||||
|
||||
$token = auth('api')->attempt(['mobile' => $username, 'password' => $password]);
|
||||
$token = auth('api')->attempt(['username' => $username, 'password' => $password]);
|
||||
|
||||
if (!$token) {
|
||||
throw new \Exception("登錄失敗!", 1000);
|
||||
throw new \Exception("登录失败!", 1000);
|
||||
}else{
|
||||
LoginEvent::dispatch(auth('api')->user(), $request->input('openid', ''), $request->input('type'));
|
||||
// 判断是否到期
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
@@ -18,12 +18,12 @@ class EventServiceProvider extends ServiceProvider
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
'Modules\Member\Events\LoginEvent' => [
|
||||
'Modules\Wechat\Listeners\LoginBind',
|
||||
],
|
||||
'Modules\Member\Events\Registered' => [
|
||||
'Modules\Wechat\Listeners\RegisterBind',
|
||||
],
|
||||
// 'Modules\Member\Events\LoginEvent' => [
|
||||
// 'Modules\Wechat\Listeners\LoginBind',
|
||||
// ],
|
||||
// 'Modules\Member\Events\Registered' => [
|
||||
// 'Modules\Wechat\Listeners\RegisterBind',
|
||||
// ],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
<script>
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
console.log('App Launch')
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
}
|
||||
import { setCurrentRoute } from '@/utils/auth.js'
|
||||
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
console.log('App Launch')
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
}
|
||||
}
|
||||
</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>
|
||||
|
||||
11
resources/mobile/api/index.js
Normal file
11
resources/mobile/api/index.js
Normal 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
|
||||
32
resources/mobile/api/modules/auth.js
Normal file
32
resources/mobile/api/modules/auth.js
Normal 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})
|
||||
}
|
||||
}
|
||||
}
|
||||
11
resources/mobile/api/modules/sms.js
Normal file
11
resources/mobile/api/modules/sms.js
Normal 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
22
resources/mobile/boot.js
Normal 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)
|
||||
}
|
||||
}
|
||||
168
resources/mobile/components/pages/pages.vue
Normal file
168
resources/mobile/components/pages/pages.vue
Normal 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>
|
||||
348
resources/mobile/components/tab-bar/tab-bar.vue
Normal file
348
resources/mobile/components/tab-bar/tab-bar.vue
Normal 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>
|
||||
3
resources/mobile/config/dev.config.js
Normal file
3
resources/mobile/config/dev.config.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
baseURL: 'http://localhost:8000/'
|
||||
}
|
||||
46
resources/mobile/config/index.js
Normal file
46
resources/mobile/config/index.js
Normal 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
|
||||
35
resources/mobile/mixins/auth.js
Normal file
35
resources/mobile/mixins/auth.js
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,13 @@
|
||||
"家庭记账"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": { "name": "molong", "email": "ycgpp@126.com" },
|
||||
"author": {
|
||||
"name": "molong",
|
||||
"email": "ycgpp@126.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-ui": "^1.5.11",
|
||||
"crypto-js": "^4.2.0",
|
||||
"luch-request": "^3.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
{
|
||||
"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": {
|
||||
"navigationBarTextStyle": "black",
|
||||
@@ -15,6 +38,7 @@
|
||||
"easycom": {
|
||||
"autoscan": true,
|
||||
"custom": {
|
||||
"^un-(.*)": "@/components/$1/$1.vue",
|
||||
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
|
||||
}
|
||||
},
|
||||
|
||||
46
resources/mobile/pages/account/bill/index.vue
Normal file
46
resources/mobile/pages/account/bill/index.vue
Normal 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>
|
||||
46
resources/mobile/pages/account/statistics/index.vue
Normal file
46
resources/mobile/pages/account/statistics/index.vue
Normal 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>
|
||||
@@ -1,52 +1,151 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<image class="logo" src="/static/logo.png"></image>
|
||||
<view class="text-area">
|
||||
<text class="title">{{title}}</text>
|
||||
<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="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>
|
||||
</un-pages>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
title: 'Hello'
|
||||
}
|
||||
export default {
|
||||
methods: {
|
||||
handleTabChange(path) {
|
||||
console.log('Tab changed to:', path)
|
||||
// tabbar组件已经处理了跳转,这里不需要额外处理
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
navigateTo(url) {
|
||||
uni.showToast({
|
||||
title: '功能开发中',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
<style lang="scss" scoped>
|
||||
.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;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 200rpx;
|
||||
width: 200rpx;
|
||||
margin-top: 200rpx;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: 50rpx;
|
||||
}
|
||||
&:last-child {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
}
|
||||
|
||||
.text-area {
|
||||
.action-title {
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.recent-section {
|
||||
margin-top: 40rpx;
|
||||
|
||||
.section-header {
|
||||
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 {
|
||||
font-size: 36rpx;
|
||||
color: #8f8f94;
|
||||
.empty-list {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 80rpx 40rpx;
|
||||
text-align: center;
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
356
resources/mobile/pages/ucenter/agreement/privacy.vue
Normal file
356
resources/mobile/pages/ucenter/agreement/privacy.vue
Normal 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>
|
||||
252
resources/mobile/pages/ucenter/agreement/user.vue
Normal file
252
resources/mobile/pages/ucenter/agreement/user.vue
Normal 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>
|
||||
204
resources/mobile/pages/ucenter/index/index.vue
Normal file
204
resources/mobile/pages/ucenter/index/index.vue
Normal 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>
|
||||
407
resources/mobile/pages/ucenter/login/index.vue
Normal file
407
resources/mobile/pages/ucenter/login/index.vue
Normal 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>
|
||||
401
resources/mobile/pages/ucenter/register/index.vue
Normal file
401
resources/mobile/pages/ucenter/register/index.vue
Normal 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>
|
||||
15
resources/mobile/store/index.js
Normal file
15
resources/mobile/store/index.js
Normal 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
|
||||
});
|
||||
56
resources/mobile/store/modules/user.js
Normal file
56
resources/mobile/store/modules/user.js
Normal 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'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
143
resources/mobile/utils/auth.js
Normal file
143
resources/mobile/utils/auth.js
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -1,208 +1,73 @@
|
||||
import http from 'luch-request'
|
||||
import Request from 'luch-request'
|
||||
import sysConfig from '@/config'
|
||||
import store from '@/store'
|
||||
|
||||
// 创建实例
|
||||
const httpInstance = http.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
|
||||
timeout: 10000,
|
||||
header: {
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
}
|
||||
const request = new Request()
|
||||
|
||||
// 错误码常量
|
||||
const ERROR_CODES = {
|
||||
TOKEN_EXPIRED: 2000,
|
||||
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
|
||||
})
|
||||
|
||||
// 请求拦截器
|
||||
httpInstance.interceptors.request.use(
|
||||
(config) => {
|
||||
// 从本地存储获取 token
|
||||
const token = uni.getStorageSync('token')
|
||||
if (token) {
|
||||
config.header = {
|
||||
...config.header,
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
request.interceptors.request.use((config) => {
|
||||
// 从本地存储获取 token
|
||||
const token = store.state.user.token || ''
|
||||
config.header.Authorization = `Bearer ${token}`
|
||||
|
||||
// 添加时间戳,防止缓存
|
||||
if (config.method === 'GET') {
|
||||
config.params = {
|
||||
...config.params,
|
||||
_t: Date.now()
|
||||
}
|
||||
}
|
||||
return config
|
||||
}, (error) => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// 显示加载提示
|
||||
if (config.loading !== false) {
|
||||
uni.showLoading({
|
||||
title: config.loadingText || '加载中...',
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
request.interceptors.response.use((response) => {
|
||||
const { code, message } = response.data || {}
|
||||
|
||||
return config
|
||||
},
|
||||
(config) => {
|
||||
return Promise.reject(config)
|
||||
}
|
||||
)
|
||||
// 处理 token 过期或无效
|
||||
if (code === ERROR_CODES.TOKEN_EXPIRED || code === ERROR_CODES.TOKEN_INVALID) {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: message || '登录已过期,请重新登录',
|
||||
duration: 1500
|
||||
})
|
||||
setTimeout(() => {
|
||||
store.dispatch('userLogout')
|
||||
}, 100)
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
|
||||
// 响应拦截器
|
||||
httpInstance.interceptors.response.use(
|
||||
(response) => {
|
||||
// 隐藏加载提示
|
||||
if (response.config.loading !== false) {
|
||||
uni.hideLoading()
|
||||
}
|
||||
return response.data
|
||||
}, (error) => {
|
||||
const { statusCode, errMsg } = error || {}
|
||||
const errorMessage = HTTP_ERROR_MESSAGES[statusCode] || errMsg || '请求失败,请稍后重试'
|
||||
|
||||
const { statusCode, data } = response
|
||||
if (statusCode === 401) {
|
||||
store.dispatch('userLogout')
|
||||
}
|
||||
|
||||
// HTTP 状态码判断
|
||||
if (statusCode !== 200) {
|
||||
showError('网络请求失败')
|
||||
return Promise.reject(response)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// 业务状态码判断
|
||||
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
|
||||
}
|
||||
export default request
|
||||
|
||||
207
resources/mobile/utils/tool.js
Normal file
207
resources/mobile/utils/tool.js
Normal 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
|
||||
Reference in New Issue
Block a user