增加远程测试数据库,优化登录页面,优化用户信息设置
This commit is contained in:
parent
a2b228d223
commit
5affae8a17
2
.hvigor/cache/file-cache.json
vendored
2
.hvigor/cache/file-cache.json
vendored
File diff suppressed because one or more lines are too long
2
.hvigor/cache/task-cache.json
vendored
2
.hvigor/cache/task-cache.json
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -3,13 +3,11 @@
|
|||||||
"MODULES": [
|
"MODULES": [
|
||||||
{
|
{
|
||||||
"MODULE_NAME": "1043bfc77febe75fafec0c4309faccf1",
|
"MODULE_NAME": "1043bfc77febe75fafec0c4309faccf1",
|
||||||
"API_TYPE": "stageMode",
|
"API_TYPE": "stageMode"
|
||||||
"INCREMENTAL_TASKS": {
|
|
||||||
"COMPILE_ARKTS": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"BUILD_MODE": "debug"
|
"BUILD_MODE": "debug",
|
||||||
|
"USE_NORMALIZED_OHMURL": true
|
||||||
},
|
},
|
||||||
"HVIGOR": {
|
"HVIGOR": {
|
||||||
"IS_INCREMENTAL": true,
|
"IS_INCREMENTAL": true,
|
||||||
@ -18,21 +16,19 @@
|
|||||||
"IS_HVIGORFILE_TYPE_CHECK": false,
|
"IS_HVIGORFILE_TYPE_CHECK": false,
|
||||||
"TASK_TIME": {
|
"TASK_TIME": {
|
||||||
"1043bfc77febe75fafec0c4309faccf1": {
|
"1043bfc77febe75fafec0c4309faccf1": {
|
||||||
"ConfigureCmake": 129292,
|
"ConfigureCmake": 289167,
|
||||||
"PreCheckSyscap": 310583,
|
"PreCheckSyscap": 444958,
|
||||||
"ProcessIntegratedHsp": 846000,
|
"ProcessIntegratedHsp": 1675875,
|
||||||
"BuildNativeWithCmake": 322417,
|
"BuildNativeWithCmake": 269250,
|
||||||
"SyscapTransform": 1217000,
|
"SyscapTransform": 591917,
|
||||||
"BuildNativeWithNinja": 583334,
|
"BuildNativeWithNinja": 708666,
|
||||||
"BuildJS": 1090333,
|
"BuildJS": 1348583,
|
||||||
"CompileArkTS": 914758125,
|
"SignHap": 572375,
|
||||||
"PackageHap": 388569166,
|
"CollectDebugSymbol": 1221042,
|
||||||
"SignHap": 578792,
|
"assembleHap": 62917
|
||||||
"CollectDebugSymbol": 1703250,
|
|
||||||
"assembleHap": 169458
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"TOTAL_TIME": 1674071250,
|
"TOTAL_TIME": 439641458,
|
||||||
"BUILD_ID": "202503312145043260"
|
"BUILD_ID": "202504011357556550"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
// 导入日志管理器 - 仅用于获取版本号
|
// 导入日志管理器 - 仅用于获取版本号
|
||||||
import logManager, { LogCategory, LogEventType, VersionLogItem } from './logtext';
|
import logManager, { LogCategory, LogEventType, VersionLogItem } from './logtext';
|
||||||
|
import { UserModel, DatabaseService } from './DatabaseService';
|
||||||
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||||
|
|
||||||
// 可选的主题颜色
|
// 可选的主题颜色
|
||||||
export enum ThemeColor {
|
export enum ThemeColor {
|
||||||
@ -16,19 +18,28 @@ export enum Language {
|
|||||||
ENGLISH = 'English'
|
ENGLISH = 'English'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户信息模型
|
// 用户信息模型 - 更新为从数据库获取
|
||||||
@Observed
|
@Observed
|
||||||
export class UserInfoModel {
|
export class UserInfoModel {
|
||||||
avatar: string;
|
account: string = '';
|
||||||
name: string;
|
avatar: string = '';
|
||||||
email: string;
|
name: string = '';
|
||||||
|
email: string = '';
|
||||||
|
phone: string = '';
|
||||||
|
category: string = '';
|
||||||
|
|
||||||
constructor(avatar: string = 'avatar-placeholder.png',
|
constructor(account: string = '',
|
||||||
name: string = '张三',
|
avatar: string = '',
|
||||||
email: string = 'zhangsan@example.com') {
|
name: string = '',
|
||||||
this.avatar = avatar;
|
email: string = '',
|
||||||
|
phone: string = '',
|
||||||
|
category: string = '') {
|
||||||
|
this.account = account;
|
||||||
|
this.avatar = avatar || 'http://139.155.155.67:2342/images/default_avatar.png';
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
|
this.phone = phone;
|
||||||
|
this.category = category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +192,10 @@ export class SettingsService {
|
|||||||
private settings: SettingsModel;
|
private settings: SettingsModel;
|
||||||
// 添加用户信息存储
|
// 添加用户信息存储
|
||||||
private userInfo: UserInfoModel;
|
private userInfo: UserInfoModel;
|
||||||
|
// 当前登录账号
|
||||||
|
private currentAccount: string = '';
|
||||||
|
// 数据库服务实例
|
||||||
|
private dbService: DatabaseService = DatabaseService.getInstance();
|
||||||
// 语言变化的回调函数
|
// 语言变化的回调函数
|
||||||
private languageChangeCallbacks: (() => void)[] = [];
|
private languageChangeCallbacks: (() => void)[] = [];
|
||||||
// 颜色
|
// 颜色
|
||||||
@ -195,6 +210,11 @@ export class SettingsService {
|
|||||||
this.settings = new SettingsModel();
|
this.settings = new SettingsModel();
|
||||||
// 初始化默认用户信息
|
// 初始化默认用户信息
|
||||||
this.userInfo = new UserInfoModel();
|
this.userInfo = new UserInfoModel();
|
||||||
|
|
||||||
|
// 注册数据库用户数据变化回调
|
||||||
|
this.dbService.registerUserDataChangeCallback(() => {
|
||||||
|
this.refreshUserInfo();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前最新版本号 - 与版本日志同步
|
// 获取当前最新版本号 - 与版本日志同步
|
||||||
@ -230,20 +250,53 @@ export class SettingsService {
|
|||||||
return this.userInfo;
|
return this.userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新用户邮箱
|
// 设置当前用户账号
|
||||||
public updateUserEmail(email: string): void {
|
public setCurrentAccount(account: string): void {
|
||||||
if (email && email.trim() !== '') {
|
this.currentAccount = account;
|
||||||
const oldEmail = this.userInfo.email;
|
this.refreshUserInfo();
|
||||||
this.userInfo.email = email.trim();
|
}
|
||||||
|
|
||||||
// 记录用户邮箱变更
|
// 刷新用户信息
|
||||||
logManager.info(LogCategory.USER, LogEventType.DATA_UPDATE, `Email updated: ${email}`);
|
private refreshUserInfo(): void {
|
||||||
logManager.debug(LogCategory.USER, LogEventType.SETTING_CHANGE, 'userEmail', oldEmail, email);
|
if (this.currentAccount) {
|
||||||
|
const user = this.dbService.getUserByAccount(this.currentAccount);
|
||||||
|
if (user) {
|
||||||
|
this.userInfo.account = user.account;
|
||||||
|
this.userInfo.name = user.nickname;
|
||||||
|
this.userInfo.email = user.email;
|
||||||
|
this.userInfo.phone = user.phone;
|
||||||
|
this.userInfo.avatar = user.photo;
|
||||||
|
this.userInfo.category = user.category;
|
||||||
|
|
||||||
this.notifyUserInfoChange();
|
// 通知用户信息发生变化
|
||||||
|
this.notifyUserInfoChange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新用户邮箱
|
||||||
|
public async updateUserEmail(newEmail: string): Promise<boolean> {
|
||||||
|
// 验证邮箱格式
|
||||||
|
if (!this.dbService.validateEmailFormat(newEmail)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新数据库 (使用await处理异步调用)
|
||||||
|
if (this.currentAccount) {
|
||||||
|
const updated = await this.dbService.updateUserEmail(this.currentAccount, newEmail);
|
||||||
|
if (updated) {
|
||||||
|
// 更新本地用户信息
|
||||||
|
this.userInfo.email = newEmail;
|
||||||
|
|
||||||
|
// 通知用户信息发生变化
|
||||||
|
this.notifyUserInfoChange();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 更新用户名称
|
// 更新用户名称
|
||||||
public updateUserName(name: string): void {
|
public updateUserName(name: string): void {
|
||||||
if (name && name.trim() !== '') {
|
if (name && name.trim() !== '') {
|
||||||
@ -378,6 +431,59 @@ export class SettingsService {
|
|||||||
const texts = this.getTextResources();
|
const texts = this.getTextResources();
|
||||||
return this.settings.notificationEnabled ? texts.enabled : texts.disabled;
|
return this.settings.notificationEnabled ? texts.enabled : texts.disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证用户登录 - 为了兼容性保留的同步方法
|
||||||
|
public validateUser(account: string, password: string): boolean {
|
||||||
|
// 降级为同步模式 - 仅用于紧急情况
|
||||||
|
try {
|
||||||
|
// 进行最简单的验证
|
||||||
|
if (account === '2' || account === '9222' || account === '0') {
|
||||||
|
return password === '1';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (error) {
|
||||||
|
hilog.error(0, 'ClassMG', `Error in legacy validateUser: ${error}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 异步验证用户登录 - 推荐使用此方法
|
||||||
|
public async validateUserAsync(account: string, password: string): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
const result = await this.dbService.validateUser(account, password);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
hilog.error(0, 'ClassMG', `Error in validateUserAsync: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户昵称
|
||||||
|
public getUserNickname(): string {
|
||||||
|
return this.userInfo.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户信息异步方法
|
||||||
|
public async refreshUserInfoAsync(account: string): Promise<void> {
|
||||||
|
if (!account) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await this.dbService.getUserByAccountAsync(account);
|
||||||
|
if (user !== null) {
|
||||||
|
this.userInfo.account = user.account;
|
||||||
|
this.userInfo.name = user.nickname;
|
||||||
|
this.userInfo.email = user.email;
|
||||||
|
this.userInfo.phone = user.phone;
|
||||||
|
this.userInfo.avatar = user.photo;
|
||||||
|
this.userInfo.category = user.category;
|
||||||
|
|
||||||
|
// 通知用户信息发生变化
|
||||||
|
this.notifyUserInfoChange();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
hilog.error(0, 'ClassMG', `Error refreshing user info: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出默认实例
|
// 导出默认实例
|
||||||
|
@ -41,7 +41,9 @@ export enum LogEventType {
|
|||||||
PAGE_SHOW = 'PAGE_SHOW',
|
PAGE_SHOW = 'PAGE_SHOW',
|
||||||
PAGE_HIDE = 'PAGE_HIDE',
|
PAGE_HIDE = 'PAGE_HIDE',
|
||||||
PAGE_BACK = 'PAGE_BACK',
|
PAGE_BACK = 'PAGE_BACK',
|
||||||
SYSTEM_INFO = 'SYSTEM_INFO'
|
SYSTEM_INFO = 'SYSTEM_INFO',
|
||||||
|
USER_LOGIN = 'USER_LOGIN',
|
||||||
|
USER_LOGIN_FAIL = 'USER_LOGIN_FAIL'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,8 +152,9 @@ export class LogManager {
|
|||||||
*/
|
*/
|
||||||
private initVersionLogs(): void {
|
private initVersionLogs(): void {
|
||||||
this.versionLogs = [
|
this.versionLogs = [
|
||||||
|
new VersionLogItem("1.0.0", "2025-2-10", ["初始版本发布", "实现基本功能界面", "添加用户信息管理", "支持主题色切换", "支持中英文切换"]),
|
||||||
new VersionLogItem("1.1.0", "2025-3-31", ["添加用户信息编辑功能", "增加版本日志功能", "改进主题颜色切换效果","添加公告栏","修复已知问题"]),
|
new VersionLogItem("1.1.0", "2025-3-31", ["添加用户信息编辑功能", "增加版本日志功能", "改进主题颜色切换效果","添加公告栏","修复已知问题"]),
|
||||||
new VersionLogItem("1.0.0", "2025-2-10", ["初始版本发布", "实现基本功能界面", "添加用户信息管理", "支持主题色切换", "支持中英文切换"])
|
new VersionLogItem("1.1.5","2025-4-1",["增加远程测试数据库","优化登录页面","优化用户信息设置"])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ struct HomePage {
|
|||||||
step: 6, // 降低步长,使滚动更慢
|
step: 6, // 降低步长,使滚动更慢
|
||||||
loop: -1,
|
loop: -1,
|
||||||
fromStart: true,
|
fromStart: true,
|
||||||
src: "欢迎使用【智能教室管理系统】,本项目由【922213102班第一组】制作,相关服务正在完善,欢迎您的使用!!"
|
src: "欢迎使用【智能教室管理系统】,本项目由【922213102班鸿蒙第一组】制作,相关服务正在完善,欢迎您的使用!!"
|
||||||
})
|
})
|
||||||
.width('90%')
|
.width('90%')
|
||||||
.height(30)
|
.height(30)
|
||||||
@ -84,6 +84,7 @@ struct HomePage {
|
|||||||
})
|
})
|
||||||
.margin({ top: 16, bottom: 16 })
|
.margin({ top: 16, bottom: 16 })
|
||||||
|
|
||||||
|
|
||||||
// 综合上课数据卡片
|
// 综合上课数据卡片
|
||||||
Card({
|
Card({
|
||||||
title: this.texts.comprehensiveData,
|
title: this.texts.comprehensiveData,
|
||||||
@ -188,7 +189,7 @@ struct Card {
|
|||||||
|
|
||||||
// 图表内容
|
// 图表内容
|
||||||
Column() {
|
Column() {
|
||||||
Text('图表内容')
|
Text('图表内容1')
|
||||||
.fontSize(16)
|
.fontSize(16)
|
||||||
.fontColor('#999')
|
.fontColor('#999')
|
||||||
.height(150)
|
.height(150)
|
||||||
|
@ -198,181 +198,222 @@ struct UserCard {
|
|||||||
// 邮箱更新回调
|
// 邮箱更新回调
|
||||||
updateEmail: (newEmail: string) => void = () => {};
|
updateEmail: (newEmail: string) => void = () => {};
|
||||||
|
|
||||||
aboutToAppear() {
|
|
||||||
// 初始化临时邮箱值
|
|
||||||
this.tempEmail = this.user.email;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证邮箱格式
|
// 验证邮箱格式
|
||||||
private validateEmail(email: string): boolean {
|
private validateEmail(email: string): boolean {
|
||||||
// 基本的邮箱格式验证正则表达式
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
||||||
return emailRegex.test(email);
|
return emailRegex.test(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理保存邮箱
|
// 保存邮箱
|
||||||
private handleSaveEmail(): void {
|
private saveEmail(): void {
|
||||||
// 验证邮箱格式
|
// 验证邮箱格式
|
||||||
if (!this.validateEmail(this.tempEmail)) {
|
if (!this.validateEmail(this.tempEmail)) {
|
||||||
this.emailError = true;
|
this.emailError = true;
|
||||||
this.errorMessage = '邮箱格式无效';
|
this.errorMessage = '请输入有效的邮箱地址';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置错误状态
|
// 更新邮箱
|
||||||
this.emailError = false;
|
|
||||||
this.errorMessage = '';
|
|
||||||
|
|
||||||
// 调用更新回调
|
|
||||||
this.updateEmail(this.tempEmail);
|
this.updateEmail(this.tempEmail);
|
||||||
|
|
||||||
// 退出编辑模式
|
// 退出编辑模式
|
||||||
this.isEditingEmail = false;
|
this.isEditingEmail = false;
|
||||||
|
this.emailError = false;
|
||||||
|
this.errorMessage = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
|
// 用户信息标题
|
||||||
Row() {
|
Row() {
|
||||||
Stack({ alignContent: Alignment.BottomEnd }) {
|
Text("用户信息")
|
||||||
Image(this.user.avatar)
|
.fontSize(18)
|
||||||
.width(84)
|
.fontWeight(FontWeight.Bold)
|
||||||
.height(84)
|
.fontColor('#333')
|
||||||
.borderRadius(42)
|
}
|
||||||
.border({ width: 4, color: Color.White, style: BorderStyle.Solid })
|
.width('100%')
|
||||||
.shadow({ radius: 12, color: 'rgba(0, 0, 0, 0.1)', offsetX: 0, offsetY: 4 })
|
.padding({ top: 8, bottom: 16 })
|
||||||
|
|
||||||
|
// 头像和用户信息
|
||||||
|
Row() {
|
||||||
|
// 头像 - 圆形设计
|
||||||
|
Stack() {
|
||||||
|
// 圆形背景
|
||||||
|
Circle()
|
||||||
|
.width(88)
|
||||||
|
.height(88)
|
||||||
|
.fill('#f5f5f5')
|
||||||
|
|
||||||
|
// 用户头像
|
||||||
|
Image(this.user.avatar || 'http://139.155.155.67:2342/images/default_avatar.png')
|
||||||
|
.width(80)
|
||||||
|
.height(80)
|
||||||
|
.borderRadius(40)
|
||||||
.objectFit(ImageFit.Cover)
|
.objectFit(ImageFit.Cover)
|
||||||
.scale({ x: this.avatarScale, y: this.avatarScale })
|
.scale({ x: this.avatarScale, y: this.avatarScale })
|
||||||
.animation({
|
.onHover((isHover: boolean) => {
|
||||||
duration: 300,
|
animateTo({ duration: 300, curve: Curve.EaseOut }, () => {
|
||||||
curve: Curve.EaseOut
|
this.avatarScale = isHover ? 1.05 : 1;
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.onClick(() => {
|
|
||||||
// 点击头像添加缩放动画效果
|
|
||||||
this.avatarScale = 0.92;
|
|
||||||
setTimeout(() => {
|
|
||||||
this.avatarScale = 1;
|
|
||||||
}, 150);
|
|
||||||
})
|
|
||||||
|
|
||||||
// 状态指示点
|
|
||||||
Circle({ width: 20, height: 20 })
|
|
||||||
.fill('#4CAF50')
|
|
||||||
.border({ width: 3, color: Color.White, style: BorderStyle.Solid })
|
|
||||||
.margin({ bottom: 2, right: 2 })
|
|
||||||
}
|
}
|
||||||
|
.margin({ right: 24 })
|
||||||
|
|
||||||
|
// 用户基本信息
|
||||||
Column() {
|
Column() {
|
||||||
Text(this.user.name)
|
// 用户名和用户类型
|
||||||
.fontSize(22)
|
Row() {
|
||||||
.fontWeight(FontWeight.Bold)
|
Text(this.user.name || '未设置昵称')
|
||||||
.fontColor('#333')
|
.fontSize(20)
|
||||||
.margin({ bottom: 8 })
|
.fontWeight(FontWeight.Bold)
|
||||||
|
.fontColor('#333')
|
||||||
|
|
||||||
// 邮箱信息 - 根据编辑状态显示不同内容
|
// 用户类型标签
|
||||||
if (this.isEditingEmail) {
|
if (this.user.category) {
|
||||||
Column() {
|
Text(this.user.category === 'student' ? '学生' : '教师')
|
||||||
Row() {
|
.fontSize(12)
|
||||||
TextInput({ text: this.tempEmail })
|
.backgroundColor(this.user.category === 'student' ? '#e6f7ff' : '#f6ffed')
|
||||||
.width('70%')
|
.fontColor(this.user.category === 'student' ? '#1890ff' : '#52c41a')
|
||||||
.height(36)
|
.borderRadius(4)
|
||||||
.fontSize(16)
|
.padding({ left: 8, right: 8, top: 2, bottom: 2 })
|
||||||
.fontColor('#333')
|
|
||||||
.backgroundColor('#f5f5f5')
|
|
||||||
.padding({ left: 8, right: 8 })
|
|
||||||
.borderRadius(8)
|
|
||||||
.onChange((value: string) => {
|
|
||||||
this.tempEmail = value;
|
|
||||||
// 输入时重置错误状态
|
|
||||||
if (this.emailError) {
|
|
||||||
this.emailError = false;
|
|
||||||
this.errorMessage = '';
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
Row({ space: 8 }) {
|
|
||||||
Button('保存')
|
|
||||||
.fontSize(14)
|
|
||||||
.height(32)
|
|
||||||
.width(60)
|
|
||||||
.backgroundColor(this.themeColor)
|
|
||||||
.onClick(() => {
|
|
||||||
// 保存并退出编辑模式
|
|
||||||
this.handleSaveEmail();
|
|
||||||
})
|
|
||||||
|
|
||||||
Button('取消')
|
|
||||||
.fontSize(14)
|
|
||||||
.height(32)
|
|
||||||
.width(60)
|
|
||||||
.backgroundColor('#f0f0f0')
|
|
||||||
.fontColor('#666')
|
|
||||||
.onClick(() => {
|
|
||||||
// 恢复原值并退出编辑模式
|
|
||||||
this.tempEmail = this.user.email;
|
|
||||||
this.emailError = false;
|
|
||||||
this.errorMessage = '';
|
|
||||||
this.isEditingEmail = false;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
.margin({ left: 8 })
|
.margin({ left: 8 })
|
||||||
}
|
|
||||||
.width('100%')
|
|
||||||
.justifyContent(FlexAlign.SpaceBetween)
|
|
||||||
|
|
||||||
// 错误提示信息
|
|
||||||
if (this.emailError) {
|
|
||||||
Text(this.errorMessage)
|
|
||||||
.fontSize(14)
|
|
||||||
.fontColor('#f56c6c')
|
|
||||||
.margin({ top: 4 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.width('100%')
|
|
||||||
} else {
|
|
||||||
Row() {
|
|
||||||
Text(this.user.email)
|
|
||||||
.fontSize(16)
|
|
||||||
.fontColor('#666')
|
|
||||||
.opacity(0.85)
|
|
||||||
|
|
||||||
// 编辑按钮
|
|
||||||
Image($r('app.media.edit'))
|
|
||||||
.width(16)
|
|
||||||
.height(16)
|
|
||||||
.fillColor(this.themeColor)
|
|
||||||
.margin({ left: 10 })
|
|
||||||
.opacity(0.8)
|
|
||||||
.scale({ x: this.editScale, y: this.editScale })
|
|
||||||
.animation({
|
|
||||||
duration: 200,
|
|
||||||
curve: Curve.EaseOut
|
|
||||||
})
|
|
||||||
.onClick(() => {
|
|
||||||
// 点击编辑按钮的动画效果
|
|
||||||
this.editScale = 0.8;
|
|
||||||
setTimeout(() => {
|
|
||||||
this.editScale = 1;
|
|
||||||
// 进入编辑模式并初始化临时邮箱
|
|
||||||
this.tempEmail = this.user.email;
|
|
||||||
this.isEditingEmail = true;
|
|
||||||
}, 100);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.width('100%')
|
||||||
|
.margin({ bottom: 10 })
|
||||||
|
|
||||||
|
// 账号信息
|
||||||
|
Row() {
|
||||||
|
Text("账号: ")
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
|
||||||
|
Text(this.user.account || '暂未配置')
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
}
|
||||||
|
.margin({ bottom: 6 })
|
||||||
|
|
||||||
|
// 手机号
|
||||||
|
Row() {
|
||||||
|
Text("手机: ")
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
|
||||||
|
Text(this.user.phone || '暂未配置')
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
}
|
||||||
|
.margin({ bottom: 6 })
|
||||||
}
|
}
|
||||||
.alignItems(HorizontalAlign.Start)
|
.alignItems(HorizontalAlign.Start)
|
||||||
.margin({ left: 24 })
|
|
||||||
.layoutWeight(1)
|
.layoutWeight(1)
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.padding({ top: 18, bottom: 18, left: 20, right: 20 })
|
|
||||||
.alignItems(VerticalAlign.Center)
|
.alignItems(VerticalAlign.Center)
|
||||||
|
.padding({ bottom: 20 })
|
||||||
|
|
||||||
|
// 邮箱信息 - 可编辑
|
||||||
|
Column() {
|
||||||
|
// 邮箱编辑区域
|
||||||
|
Row() {
|
||||||
|
Text("邮箱: ")
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
.width(50)
|
||||||
|
|
||||||
|
if (this.isEditingEmail) {
|
||||||
|
// 编辑模式 - 显示输入框
|
||||||
|
TextInput({
|
||||||
|
placeholder: '请输入邮箱',
|
||||||
|
text: this.tempEmail || this.user.email || ''
|
||||||
|
})
|
||||||
|
.width('60%')
|
||||||
|
.height(36)
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#333')
|
||||||
|
.backgroundColor('#f5f5f5')
|
||||||
|
.borderRadius(4)
|
||||||
|
.onChange((value: string) => {
|
||||||
|
this.tempEmail = value;
|
||||||
|
this.emailError = false;
|
||||||
|
})
|
||||||
|
|
||||||
|
// 保存按钮
|
||||||
|
Button("保存")
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor(Color.White)
|
||||||
|
.backgroundColor(this.themeColor)
|
||||||
|
.borderRadius(4)
|
||||||
|
.margin({ left: 10 })
|
||||||
|
.width(60)
|
||||||
|
.height(36)
|
||||||
|
.onClick(() => {
|
||||||
|
this.saveEmail();
|
||||||
|
})
|
||||||
|
|
||||||
|
// 取消按钮
|
||||||
|
Button("取消")
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
.backgroundColor('#f0f0f0')
|
||||||
|
.borderRadius(4)
|
||||||
|
.margin({ left: 10 })
|
||||||
|
.width(60)
|
||||||
|
.height(36)
|
||||||
|
.onClick(() => {
|
||||||
|
this.isEditingEmail = false;
|
||||||
|
this.emailError = false;
|
||||||
|
this.errorMessage = '';
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 显示模式 - 显示当前邮箱
|
||||||
|
Text(this.user.email || '暂未配置')
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666')
|
||||||
|
.layoutWeight(1)
|
||||||
|
|
||||||
|
// 编辑按钮
|
||||||
|
Button({ type: ButtonType.Circle }) {
|
||||||
|
Image($r('app.media.edit'))
|
||||||
|
.width(16)
|
||||||
|
.height(16)
|
||||||
|
.fillColor('#666')
|
||||||
|
}
|
||||||
|
.width(32)
|
||||||
|
.height(32)
|
||||||
|
.backgroundColor('#f5f5f5')
|
||||||
|
.scale({ x: this.editScale, y: this.editScale })
|
||||||
|
.onClick(() => {
|
||||||
|
this.isEditingEmail = true;
|
||||||
|
this.tempEmail = this.user.email || '';
|
||||||
|
})
|
||||||
|
.onHover((isHover: boolean) => {
|
||||||
|
animateTo({ duration: 300, curve: Curve.EaseOut }, () => {
|
||||||
|
this.editScale = isHover ? 1.1 : 1;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
.alignItems(VerticalAlign.Center)
|
||||||
|
|
||||||
|
// 邮箱错误提示
|
||||||
|
if (this.emailError) {
|
||||||
|
Text(this.errorMessage)
|
||||||
|
.fontSize(12)
|
||||||
|
.fontColor('#ff4d4f')
|
||||||
|
.margin({ top: 4, left: 50 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
.margin({ bottom: 10 })
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.backgroundColor(Color.White)
|
.backgroundColor(Color.White)
|
||||||
.borderRadius(16)
|
.borderRadius(12)
|
||||||
.padding(4) // 减小内边距,改用子组件控制
|
.padding(20)
|
||||||
.shadow({ radius: 15, color: 'rgba(0, 0, 0, 0.08)', offsetY: 2 })
|
.shadow({ radius: 6, color: '#eeeeee', offsetY: 2 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -736,7 +777,7 @@ struct SystemSettings {
|
|||||||
const currentVersion = settingsService.getCurrentVersion();
|
const currentVersion = settingsService.getCurrentVersion();
|
||||||
AlertDialog.show({
|
AlertDialog.show({
|
||||||
title: texts.about,
|
title: texts.about,
|
||||||
message: `v${currentVersion}\n© 第一组 版权所有`,
|
message: `v${currentVersion}\n© 922213102鸿蒙第一组 版权所有`,
|
||||||
confirm: {
|
confirm: {
|
||||||
value: currentLanguage === Language.CHINESE ? '确定' : 'OK',
|
value: currentLanguage === Language.CHINESE ? '确定' : 'OK',
|
||||||
action: () => {}
|
action: () => {}
|
||||||
|
@ -1,93 +1,233 @@
|
|||||||
import { router } from '@kit.ArkUI';
|
import { router } from '@kit.ArkUI';
|
||||||
import { BusinessError } from '@kit.BasicServicesKit';
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||||
|
import settingsService from '../common/SettingsService';
|
||||||
|
import { DatabaseService } from '../common/DatabaseService';
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
@Preview
|
@Preview
|
||||||
struct Login {
|
struct Login {
|
||||||
@State message: string = 'Hello World';
|
@State message: string = 'TD 智能教室管理系统';
|
||||||
@State username: string = ''; // 用户名
|
@State username: string = ''; // 用户名
|
||||||
@State password: string = ''; // 密码
|
@State password: string = ''; // 密码
|
||||||
|
@State isLoading: boolean = false; // 加载状态
|
||||||
|
@State errorMessage: string = ''; // 错误信息
|
||||||
|
|
||||||
|
// 获取数据库服务实例
|
||||||
|
private dbService: DatabaseService = DatabaseService.getInstance();
|
||||||
|
|
||||||
|
// 登录验证方法
|
||||||
|
private async handleLogin(): Promise<void> {
|
||||||
|
this.isLoading = true;
|
||||||
|
this.errorMessage = '';
|
||||||
|
|
||||||
|
// 用户名不能为空
|
||||||
|
if (!this.username || this.username.trim() === '') {
|
||||||
|
this.errorMessage = '请输入账号';
|
||||||
|
this.isLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 密码不能为空
|
||||||
|
if (!this.password || this.password.trim() === '') {
|
||||||
|
this.errorMessage = '请输入密码';
|
||||||
|
this.isLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 使用异步验证方法
|
||||||
|
const isValid = await this.dbService.validateUser(this.username, this.password);
|
||||||
|
|
||||||
|
if (isValid) {
|
||||||
|
// 设置当前用户
|
||||||
|
settingsService.setCurrentAccount(this.username);
|
||||||
|
|
||||||
|
// 记录登录日志
|
||||||
|
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN, `User logged in: ${this.username}`);
|
||||||
|
|
||||||
|
// 跳转到过渡页面
|
||||||
|
router.replaceUrl({
|
||||||
|
url: 'pages/TransitionPage'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.errorMessage = '账号或密码错误';
|
||||||
|
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN_FAIL, `Login failed: ${this.username}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.errorMessage = '登录失败,请稍后重试';
|
||||||
|
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN_FAIL, `Login error: ${error}`);
|
||||||
|
} finally {
|
||||||
|
this.isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column({space:10}){//列布局
|
Column({space: 20}) { // 增加行间距
|
||||||
Image('http://139.155.155.67:2342/images/tdcat.webp')
|
// 顶部标题和图标
|
||||||
.height(150)
|
Column() {
|
||||||
|
Image('http://139.155.155.67:2342/images/tdcat.webp')
|
||||||
|
.height(150)
|
||||||
|
.width(150)
|
||||||
|
.margin({ top: 40, bottom: 20 })
|
||||||
|
|
||||||
//分割线组件
|
Text(this.message)
|
||||||
Divider()
|
.fontColor('#333333')
|
||||||
|
.fontSize(28)
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
.margin({ bottom: 30 })
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
.alignItems(HorizontalAlign.Center)
|
||||||
|
|
||||||
Text("唱跳 rap 篮球").fontColor(Color.Green).fontSize(30)
|
// 登录表单
|
||||||
|
Column({ space: 30 }) {
|
||||||
|
// 账号输入框
|
||||||
|
Column({ space: 8 }) {
|
||||||
|
Text("账号")
|
||||||
|
.fontSize(16)
|
||||||
|
.fontColor('#666666')
|
||||||
|
.alignSelf(ItemAlign.Start)
|
||||||
|
|
||||||
Row(){
|
TextInput({ placeholder: '请输入账号' })
|
||||||
Text("用户名:")
|
.type(InputType.Normal)
|
||||||
TextInput({placeholder:'请输入账号'})//输入提示
|
.placeholderColor('#999999')
|
||||||
.width(250)
|
.placeholderFont({ size: 16 })
|
||||||
.onChange((value: string) => {
|
.caretColor('#2196F3')
|
||||||
this.username = value; // 绑定用户名输入
|
.width('100%')
|
||||||
|
.height(50)
|
||||||
|
.fontSize(16)
|
||||||
|
.fontColor('#333333')
|
||||||
|
.backgroundColor('#F5F5F5')
|
||||||
|
.borderRadius(8)
|
||||||
|
.padding({ left: 16, right: 16 })
|
||||||
|
.onChange((value: string) => {
|
||||||
|
this.username = value;
|
||||||
|
this.errorMessage = ''; // 清除错误信息
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
|
||||||
|
// 密码输入框
|
||||||
|
Column({ space: 8 }) {
|
||||||
|
Text("密码")
|
||||||
|
.fontSize(16)
|
||||||
|
.fontColor('#666666')
|
||||||
|
.alignSelf(ItemAlign.Start)
|
||||||
|
|
||||||
|
TextInput({ placeholder: '请输入密码' })
|
||||||
|
.type(InputType.Password)
|
||||||
|
.placeholderColor('#999999')
|
||||||
|
.placeholderFont({ size: 16 })
|
||||||
|
.caretColor('#2196F3')
|
||||||
|
.width('100%')
|
||||||
|
.height(50)
|
||||||
|
.fontSize(16)
|
||||||
|
.fontColor('#333333')
|
||||||
|
.backgroundColor('#F5F5F5')
|
||||||
|
.borderRadius(8)
|
||||||
|
.padding({ left: 16, right: 16 })
|
||||||
|
.onChange((value: string) => {
|
||||||
|
this.password = value;
|
||||||
|
this.errorMessage = ''; // 清除错误信息
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
|
||||||
|
// 错误信息提示
|
||||||
|
if (this.errorMessage !== '') {
|
||||||
|
Text(this.errorMessage)
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#FF0000')
|
||||||
|
.width('100%')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录按钮
|
||||||
|
Button("登录")
|
||||||
|
.width('100%')
|
||||||
|
.height(50)
|
||||||
|
.fontSize(18)
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.backgroundColor('#2196F3')
|
||||||
|
.borderRadius(8)
|
||||||
|
.fontColor(Color.White)
|
||||||
|
.stateEffect(true)
|
||||||
|
.enabled(!this.isLoading)
|
||||||
|
.opacity(this.isLoading ? 0.6 : 1)
|
||||||
|
.onClick(() => {
|
||||||
|
this.handleLogin();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
.width('90%')
|
||||||
|
.padding(20)
|
||||||
|
.backgroundColor(Color.White)
|
||||||
|
.borderRadius(16)
|
||||||
|
.shadow({ radius: 8, color: 'rgba(0,0,0,0.1)', offsetY: 4 })
|
||||||
|
|
||||||
|
// 底部提示
|
||||||
Row(){
|
Row() {
|
||||||
Text("密码:")
|
Button({ type: ButtonType.Capsule }) {
|
||||||
TextInput({placeholder:'请输入密码'})
|
Text("忘记密码?")
|
||||||
.type(InputType.Password)//输入模式
|
.fontSize(14)
|
||||||
.width(270)
|
.fontColor('#2196F3')
|
||||||
.onChange((value: string) => {
|
}
|
||||||
this.password = value; // 绑定密码输入
|
.backgroundColor(Color.Transparent)
|
||||||
})
|
.onClick(() => {
|
||||||
}
|
AlertDialog.show({
|
||||||
|
message: "忘记密码功能尚未开发,请联系管理员重置密码。",
|
||||||
Button("登录")
|
confirm: {
|
||||||
.onClick(()=>{
|
value: "确定",
|
||||||
if (this.username === '1' && this.password === '1') {
|
action: () => {}
|
||||||
router.pushUrl({url:'pages/HomePage'})
|
}
|
||||||
}else {
|
});
|
||||||
AlertDialog.show({message:'输入有误'})
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
.width('50%')
|
Blank(100)
|
||||||
|
|
||||||
|
Button({ type: ButtonType.Capsule }) {
|
||||||
Row(){//行布局
|
Text("注册")
|
||||||
Button("忘记密码?")
|
.fontSize(14)
|
||||||
.fontSize(15)
|
.fontColor('#2196F3')
|
||||||
.backgroundColor(Color.Gray)
|
}
|
||||||
.onClick(()=>{
|
.backgroundColor(Color.Transparent)
|
||||||
AlertDialog.show({message:"尚未开发"})
|
.onClick(() => {
|
||||||
})
|
AlertDialog.show({
|
||||||
|
message: "注册功能尚未开发,请联系管理员创建账号。",
|
||||||
Blank(150)//间隔
|
confirm: {
|
||||||
Button("注册")
|
value: "确定",
|
||||||
|
action: () => {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
.width('90%')
|
||||||
|
.margin({ top: 20 })
|
||||||
}
|
}
|
||||||
.height('100%')
|
.height('100%')
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.padding(20)
|
|
||||||
.alignItems(HorizontalAlign.Center)
|
.alignItems(HorizontalAlign.Center)
|
||||||
|
.backgroundColor('#F5F7FA') // 页面背景色
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面生命周期方法
|
// 页面生命周期方法
|
||||||
onPageShow(): void {// 页面显示时触发的生命周期方法
|
onPageShow(): void {
|
||||||
this.Log_LoginEvent('onPageShow');
|
this.Log_LoginEvent('onPageShow');
|
||||||
}
|
}
|
||||||
|
|
||||||
onPageHide(): void {// 页面隐藏时触发的生命周期方法
|
onPageHide(): void {
|
||||||
this.Log_LoginEvent('onPageHide');
|
this.Log_LoginEvent('onPageHide');
|
||||||
}
|
}
|
||||||
|
|
||||||
onBackPress(): void {// 页面返回按键按下时触发的生命周期方法
|
onBackPress(): void {
|
||||||
this.Log_LoginEvent('onBackPress');
|
this.Log_LoginEvent('onBackPress');
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToAppear(): void {// 页面即将显示时触发的生命周期方法
|
aboutToAppear(): void {
|
||||||
this.Log_LoginEvent('aboutToAppear');
|
this.Log_LoginEvent('aboutToAppear');
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToDisappear(): void {// 页面即将消失时触发的生命周期方法
|
aboutToDisappear(): void {
|
||||||
this.Log_LoginEvent('aboutToDisappear');
|
this.Log_LoginEvent('aboutToDisappear');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +254,6 @@ struct Login {
|
|||||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, `LoginPage: ${eventName}`);
|
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, `LoginPage: ${eventName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
interface User{
|
interface User{
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"src": [
|
"src": [
|
||||||
|
|
||||||
"pages/login",
|
"pages/login",
|
||||||
"pages/WelcomePage",
|
"pages/WelcomePage",
|
||||||
"pages/HomePage",
|
"pages/HomePage",
|
||||||
"pages/SettingsPage",
|
"pages/SettingsPage",
|
||||||
"pages/ClassPage"
|
"pages/ClassPage",
|
||||||
|
"pages/TransitionPage"
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user