Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
6251c6012a | |||
![]() |
a676fe8cd0 | ||
![]() |
3f5dd9ddaf | ||
![]() |
219dfe59e2 | ||
![]() |
8bdd4d957c | ||
![]() |
b431789d3a | ||
![]() |
21230d5a0d | ||
![]() |
463c47c5ea | ||
![]() |
f7fc2147b2 | ||
![]() |
e43a693a6e | ||
![]() |
eec890650d | ||
![]() |
b1420dcfeb | ||
![]() |
e996d46b79 | ||
![]() |
b6df80f859 | ||
![]() |
1c05922931 | ||
![]() |
ea6a10a588 | ||
![]() |
582343c437 | ||
![]() |
5d78bb86a3 | ||
![]() |
a2b8695327 | ||
![]() |
7faa9f1b35 | ||
![]() |
f1e7589344 |
71
.gitignore
vendored
@ -1,4 +1,67 @@
|
||||
build
|
||||
.preview
|
||||
.idea
|
||||
.hvigor
|
||||
# IDE和编辑器文件
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*.sublime-*
|
||||
|
||||
# 构建输出
|
||||
.hvigor/
|
||||
build/
|
||||
dist/
|
||||
.preview/
|
||||
out/
|
||||
release/
|
||||
|
||||
# 依赖目录
|
||||
node_modules/
|
||||
oh_modules/
|
||||
|
||||
# 日志文件
|
||||
*.log
|
||||
npm-debug.log*
|
||||
build.log
|
||||
*.log.*
|
||||
|
||||
# 系统文件
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
|
||||
# 临时文件
|
||||
*.tmp
|
||||
*.temp
|
||||
*.bak
|
||||
*.cache
|
||||
*.temp.*
|
||||
|
||||
# 测试文件
|
||||
*_test.md
|
||||
*_test.js
|
||||
*_test.ets
|
||||
classroom_test.md
|
||||
test/
|
||||
tests/
|
||||
|
||||
# 文档文件
|
||||
*.md
|
||||
!README.md
|
||||
docs/
|
||||
*.doc
|
||||
*.docx
|
||||
*.pdf
|
||||
|
||||
# 配置文件
|
||||
*.config.js
|
||||
api-*.js
|
||||
server.js
|
||||
*.env
|
||||
.env.*
|
||||
|
||||
# 其他
|
||||
*.zip
|
||||
*.rar
|
||||
*.7z
|
||||
*.tar
|
||||
*.gz
|
||||
*.tgz
|
1
.hvigor/cache/file-cache.json
vendored
1
.hvigor/cache/meta.json
vendored
@ -1 +0,0 @@
|
||||
{"compileSdkVersion":"5.0.2(14)","hvigorVersion":"5.14.3","toolChainsVersion":"5.0.2.126"}
|
1
.hvigor/cache/task-cache.json
vendored
@ -1 +0,0 @@
|
||||
{"basePath":"/Users/tian/Documents/DevEco/ClassMG/.hvigor/dependencyMap/dependencyMap.json5","rootDependency":"./oh-package.json5","dependencyMap":{"entry":"./entry/oh-package.json5"},"modules":[{"name":"entry","srcPath":"../../../entry"}]}
|
@ -1 +0,0 @@
|
||||
{"name":"entry","version":"1.0.0","description":"Please describe the basic information.","main":"","author":"","license":"","dependencies":{}}
|
@ -1 +0,0 @@
|
||||
{"modelVersion":"5.0.2","description":"Please describe the basic information.","dependencies":{},"devDependencies":{"@ohos/hypium":"1.0.21","@ohos/hamock":"1.0.0"}}
|
@ -1,38 +0,0 @@
|
||||
{
|
||||
"HVIGOR_OHOS_PLUGIN": {
|
||||
"MODULES": [
|
||||
{
|
||||
"MODULE_NAME": "1043bfc77febe75fafec0c4309faccf1",
|
||||
"API_TYPE": "stageMode",
|
||||
"INCREMENTAL_TASKS": {
|
||||
"COMPILE_ARKTS": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"BUILD_MODE": "debug"
|
||||
},
|
||||
"HVIGOR": {
|
||||
"IS_INCREMENTAL": true,
|
||||
"IS_DAEMON": true,
|
||||
"IS_PARALLEL": true,
|
||||
"IS_HVIGORFILE_TYPE_CHECK": false,
|
||||
"TASK_TIME": {
|
||||
"1043bfc77febe75fafec0c4309faccf1": {
|
||||
"ConfigureCmake": 303500,
|
||||
"PreCheckSyscap": 534625,
|
||||
"ProcessIntegratedHsp": 2304750,
|
||||
"BuildNativeWithCmake": 812250,
|
||||
"SyscapTransform": 2126459,
|
||||
"BuildNativeWithNinja": 1346958,
|
||||
"BuildJS": 2715708,
|
||||
"CompileArkTS": 2690421000,
|
||||
"PackageHap": 569532292,
|
||||
"SignHap": 836333,
|
||||
"CollectDebugSymbol": 2402750,
|
||||
"assembleHap": 185542
|
||||
}
|
||||
},
|
||||
"TOTAL_TIME": 3678888500,
|
||||
"BUILD_ID": "202504011919153050"
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"CACHE_SYNC_FILE_HASH":{"/Users/tian/Documents/DevEco/ClassMG/hvigorfile.ts":"9fcfc9a3e7dcbc1ff9995f87c81451a17a752746978695a53ea315b4b0923f08","/Users/tian/Documents/DevEco/ClassMG/oh-package.json5":"d15b2e6574c835be846438740580fdf0d07913cca0f9f2b81c0cd23fc0e8542f","/Users/tian/Documents/DevEco/ClassMG/.hvigor/outputs/sync/output.json":"356b666ffa752775d1c20e689fc6fc69e7db1eac58a99b059ca326e65edf38c8","/Users/tian/Documents/DevEco/ClassMG/entry/hvigorfile.ts":"9fcfc9a3e7dcbc1ff9995f87c81451a17a752746978695a53ea315b4b0923f08","/Users/tian/Documents/DevEco/ClassMG/entry/build-profile.json5":"e753bd3a2f1e3b9cd295cdaebd2aa42f48d3df182a195636e9c3f2cb784c2ceb","/Users/tian/Documents/DevEco/ClassMG/hvigor/hvigor-config.json5":"e381cc4e155e767588bdbd4bce1682e23850099dc7b861b35f2a98ac70699378","/Users/tian/Documents/DevEco/ClassMG/entry/oh-package.json5":"e5c96a2b6c40008639c515043adc6905ce28355164f58b419139eeaccaed5d86","/Users/tian/Documents/DevEco/ClassMG/build-profile.json5":"67a095cfb37136aba9f50f1ae51e82f2818dafb19b0011a78d4e0df536a67f42","SDK_LOCATION":"/Applications/DevEco-Studio.app/Contents/sdk"},"OHPM_INSTALL_FILE_HASH":{"/Users/tian/Documents/DevEco/ClassMG/oh-package.json5":"d15b2e6574c835be846438740580fdf0d07913cca0f9f2b81c0cd23fc0e8542f","/Users/tian/Documents/DevEco/ClassMG/oh_modules":true,"/Users/tian/Documents/DevEco/ClassMG/entry/oh_modules":false,"/Users/tian/Documents/DevEco/ClassMG/entry/oh-package.json5":"e5c96a2b6c40008639c515043adc6905ce28355164f58b419139eeaccaed5d86","/Users/tian/Documents/DevEco/ClassMG/oh_modules/.ohpm/lock.json5":"2d9515d008afdec55f0d658cc0d2a91a5c10ad7010c10462b39d3626b5f9ff99"}}
|
@ -1,174 +0,0 @@
|
||||
{
|
||||
"ohos-module-entry": {
|
||||
"SELECT_TARGET": "default",
|
||||
"MODULE_BUILD_DIR": "/Users/tian/Documents/DevEco/ClassMG/entry/build",
|
||||
"DEPENDENCY_INFO": {},
|
||||
"TARGETS": {
|
||||
"default": {
|
||||
"SOURCE_ROOT": "/Users/tian/Documents/DevEco/ClassMG/entry/src/main",
|
||||
"RESOURCES_PATH": [
|
||||
"/Users/tian/Documents/DevEco/ClassMG/entry/src/main/resources"
|
||||
],
|
||||
"BUILD_PATH": {
|
||||
"OUTPUT_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/outputs/default",
|
||||
"INTERMEDIA_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates",
|
||||
"JS_ASSETS_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/loader_out/default",
|
||||
"JS_LITE_ASSETS_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/loader_out_lite/default",
|
||||
"RES_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/res/default",
|
||||
"RES_PROFILE_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/res/default/resources/base/profile",
|
||||
"ETS_SUPER_VISUAL_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/cache/default/default@CompileArkTS/esmodule",
|
||||
"JS_SUPER_VISUAL_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/cache/default/default@CompileJS/jsbundle",
|
||||
"WORKER_LOADER": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/loader/default/loader.json",
|
||||
"MANIFEST_JSON": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/manifest/default",
|
||||
"OUTPUT_METADATA_JSON": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/hap_metadata/default/output_metadata.json",
|
||||
"SOURCE_MAP_DIR": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/source_map/default"
|
||||
},
|
||||
"BUILD_OPTION": {
|
||||
"debuggable": true
|
||||
}
|
||||
},
|
||||
"ohosTest": {
|
||||
"SOURCE_ROOT": "/Users/tian/Documents/DevEco/ClassMG/entry/src/ohosTest",
|
||||
"RESOURCES_PATH": [
|
||||
"/Users/tian/Documents/DevEco/ClassMG/entry/src/ohosTest/resources"
|
||||
],
|
||||
"BUILD_PATH": {
|
||||
"OUTPUT_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/outputs/ohosTest",
|
||||
"INTERMEDIA_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates",
|
||||
"JS_ASSETS_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/loader_out/ohosTest",
|
||||
"JS_LITE_ASSETS_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/loader_out_lite/ohosTest",
|
||||
"RES_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/res/ohosTest",
|
||||
"RES_PROFILE_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/res/ohosTest/resources/base/profile",
|
||||
"ETS_SUPER_VISUAL_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/cache/ohosTest/ohosTest@OhosTestCompileArkTS/esmodule",
|
||||
"JS_SUPER_VISUAL_PATH": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/cache/ohosTest/ohosTest@OhosTestCompileJS/jsbundle",
|
||||
"WORKER_LOADER": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/loader/ohosTest/loader.json",
|
||||
"MANIFEST_JSON": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/manifest/ohosTest",
|
||||
"OUTPUT_METADATA_JSON": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/hap_metadata/ohosTest/output_metadata.json",
|
||||
"SOURCE_MAP_DIR": "/Users/tian/Documents/DevEco/ClassMG/entry/build/default/intermediates/source_map/ohosTest"
|
||||
},
|
||||
"BUILD_OPTION": {
|
||||
"debuggable": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"BUILD_OPTION": {
|
||||
"default-default": {
|
||||
"debuggable": true,
|
||||
"copyFrom": "default",
|
||||
"strictMode": {
|
||||
"caseSensitiveCheck": true,
|
||||
"useNormalizedOHMUrl": true
|
||||
},
|
||||
"name": "debug"
|
||||
}
|
||||
},
|
||||
"BUILD_PROFILE_OPT": {
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {},
|
||||
"buildOptionSet": [
|
||||
{
|
||||
"name": "release",
|
||||
"arkOptions": {
|
||||
"obfuscation": {
|
||||
"ruleOptions": {
|
||||
"enable": false,
|
||||
"files": [
|
||||
"./obfuscation-rules.txt"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "default"
|
||||
},
|
||||
{
|
||||
"name": "debug"
|
||||
}
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest"
|
||||
}
|
||||
]
|
||||
},
|
||||
"BUILD_CACHE_DIR": ""
|
||||
},
|
||||
"ohos-project": {
|
||||
"SELECT_PRODUCT_NAME": "default",
|
||||
"MODULE_BUILD_DIR": "/Users/tian/Documents/DevEco/ClassMG/build",
|
||||
"BUNDLE_NAME": "com.example.myapplication",
|
||||
"BUILD_PATH": {
|
||||
"OUTPUT_PATH": "/Users/tian/Documents/DevEco/ClassMG/build/outputs/default"
|
||||
},
|
||||
"MODULES": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "/Users/tian/Documents/DevEco/ClassMG/entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
],
|
||||
"belongProjectPath": "/Users/tian/Documents/DevEco/ClassMG"
|
||||
}
|
||||
],
|
||||
"PROFILE_OPT": {
|
||||
"app": {
|
||||
"signingConfigs": [],
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"compatibleSdkVersion": "5.0.2(14)",
|
||||
"runtimeOS": "HarmonyOS",
|
||||
"buildOption": {
|
||||
"strictMode": {
|
||||
"caseSensitiveCheck": true,
|
||||
"useNormalizedOHMUrl": true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildModeSet": [
|
||||
{
|
||||
"name": "debug"
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"CONFIG_PROPERTIES": {
|
||||
"enableSignTask": true,
|
||||
"skipNativeIncremental": false,
|
||||
"hvigor.keepDependency": true
|
||||
},
|
||||
"OVERALL_PROJECT_PATHS": [
|
||||
"/Users/tian/Documents/DevEco/ClassMG"
|
||||
],
|
||||
"BUILD_CACHE_DIR": ""
|
||||
},
|
||||
"version": 1
|
||||
}
|
328
DATABASE_SETUP.md
Normal file
@ -0,0 +1,328 @@
|
||||
# 智慧教室管理系统数据库与API配置指南
|
||||
|
||||
本文档详细介绍如何在宝塔面板上配置MySQL数据库和Node.js API服务,以支持智慧教室管理系统的HarmonyOS应用。
|
||||
|
||||
## 一、宝塔面板安装与配置
|
||||
|
||||
### 1.1 安装宝塔面板
|
||||
|
||||
如果尚未安装宝塔面板,请参考[宝塔官方文档](https://www.bt.cn/bbs/thread-19376-1-1.html)进行安装。
|
||||
|
||||
### 1.2 安装必要软件
|
||||
|
||||
在宝塔面板中安装以下软件:
|
||||
- Nginx (用于Web服务器)
|
||||
- MySQL (用于数据库)
|
||||
- PHP (如需使用phpMyAdmin)
|
||||
- Node.js (用于API服务)
|
||||
|
||||
## 二、MySQL数据库配置
|
||||
|
||||
### 2.1 创建数据库
|
||||
|
||||
1. 在宝塔面板左侧找到"数据库"选项
|
||||
2. 点击"添加数据库"
|
||||
3. 填写以下信息:
|
||||
- 数据库名称:`hongm`
|
||||
- 用户名:`hongm`
|
||||
- 密码:`JsKJeG7CX2WnyArt` (或自定义安全密码)
|
||||
- 访问权限:选择"所有人" (开发环境)或指定IP (生产环境)
|
||||
4. 点击"提交"创建数据库
|
||||
|
||||
### 2.2 导入数据结构
|
||||
|
||||
1. 在数据库列表找到刚创建的`hongm`数据库
|
||||
2. 点击"管理"进入phpMyAdmin
|
||||
3. 选择"SQL"标签
|
||||
4. 复制并执行以下SQL语句:
|
||||
|
||||
```sql
|
||||
-- 创建用户信息表
|
||||
CREATE TABLE IF NOT EXISTS UserText (
|
||||
account VARCHAR(20) PRIMARY KEY,
|
||||
nickname VARCHAR(50) NOT NULL,
|
||||
email VARCHAR(100),
|
||||
phone VARCHAR(20),
|
||||
photo VARCHAR(255) DEFAULT NULL,
|
||||
category VARCHAR(20) NOT NULL,
|
||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- 创建用户密码表
|
||||
CREATE TABLE IF NOT EXISTS UserPassword (
|
||||
account VARCHAR(20) PRIMARY KEY,
|
||||
password VARCHAR(50) NOT NULL,
|
||||
FOREIGN KEY (account) REFERENCES UserText(account)
|
||||
);
|
||||
|
||||
-- 插入示例用户数据
|
||||
INSERT INTO UserText (account, nickname, email, phone, category) VALUES
|
||||
('2', '张三', 'student@qq.com', '17267383831', 'student'),
|
||||
('9222', '李华', 'student123@qq.com', '12345678901', 'student'),
|
||||
('0', '教师demo', 'teach@qq.com', NULL, 'teacher');
|
||||
|
||||
-- 插入密码(所有密码都是'1')
|
||||
INSERT INTO UserPassword (account, password) VALUES
|
||||
('2', '1'),
|
||||
('9222', '1'),
|
||||
('0', '1');
|
||||
```
|
||||
|
||||
## 三、Node.js API服务配置
|
||||
|
||||
### 3.1 创建网站
|
||||
|
||||
1. 在宝塔面板左侧找到"网站"选项
|
||||
2. 点击"添加站点"
|
||||
3. 填写以下信息:
|
||||
- 域名:`api.yourdomain.com` (或您的服务器IP地址)
|
||||
- 备注:`智慧教室管理系统API服务`
|
||||
- PHP版本:纯静态
|
||||
4. 点击"提交"创建网站
|
||||
|
||||
### 3.2 上传API服务代码
|
||||
|
||||
1. 在网站目录中创建`app.js`文件
|
||||
2. 将以下代码复制到`app.js`中:
|
||||
|
||||
```javascript
|
||||
const express = require('express');
|
||||
const mysql = require('mysql2');
|
||||
const cors = require('cors');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// 启用CORS和JSON解析
|
||||
app.use(cors());
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// 数据库连接配置
|
||||
const dbConfig = {
|
||||
host: 'localhost',
|
||||
port: 3306, // MySQL默认端口,根据您的配置可能需要修改
|
||||
user: 'hongm',
|
||||
password: 'JsKJeG7CX2WnyArt',
|
||||
database: 'hongm'
|
||||
};
|
||||
|
||||
// 创建数据库连接池
|
||||
const pool = mysql.createPool(dbConfig);
|
||||
const promisePool = pool.promise();
|
||||
|
||||
// 验证用户登录API
|
||||
app.post('/api/login', async (req, res) => {
|
||||
try {
|
||||
const { account, password } = req.body;
|
||||
|
||||
// 查询密码
|
||||
const [passwordRows] = await promisePool.query(
|
||||
'SELECT password FROM UserPassword WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (passwordRows.length === 0) {
|
||||
return res.status(401).json({ success: false, message: '账号不存在' });
|
||||
}
|
||||
|
||||
const storedPassword = passwordRows[0].password;
|
||||
|
||||
if (password !== storedPassword) {
|
||||
return res.status(401).json({ success: false, message: '密码错误' });
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
const [userRows] = await promisePool.query(
|
||||
'SELECT * FROM UserText WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (userRows.length === 0) {
|
||||
return res.status(401).json({ success: false, message: '用户信息不存在' });
|
||||
}
|
||||
|
||||
const user = userRows[0];
|
||||
|
||||
// 返回成功登录信息和用户数据
|
||||
res.json({
|
||||
success: true,
|
||||
message: '登录成功',
|
||||
user: {
|
||||
account: user.account,
|
||||
nickname: user.nickname,
|
||||
email: user.email,
|
||||
phone: user.phone,
|
||||
photo: user.photo || 'http://139.155.155.67:2342/images/default_avatar.png',
|
||||
category: user.category
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('登录错误:', error);
|
||||
res.status(500).json({ success: false, message: '服务器错误' });
|
||||
}
|
||||
});
|
||||
|
||||
// 获取用户信息API
|
||||
app.get('/api/user/:account', async (req, res) => {
|
||||
try {
|
||||
const { account } = req.params;
|
||||
|
||||
// 查询用户信息
|
||||
const [userRows] = await promisePool.query(
|
||||
'SELECT * FROM UserText WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (userRows.length === 0) {
|
||||
return res.status(404).json({ success: false, message: '用户不存在' });
|
||||
}
|
||||
|
||||
const user = userRows[0];
|
||||
|
||||
// 返回用户数据
|
||||
res.json({
|
||||
success: true,
|
||||
user: {
|
||||
account: user.account,
|
||||
nickname: user.nickname,
|
||||
email: user.email,
|
||||
phone: user.phone,
|
||||
photo: user.photo || 'http://139.155.155.67:2342/images/default_avatar.png',
|
||||
category: user.category
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('获取用户信息错误:', error);
|
||||
res.status(500).json({ success: false, message: '服务器错误' });
|
||||
}
|
||||
});
|
||||
|
||||
// 更新用户邮箱API
|
||||
app.put('/api/user/:account/email', async (req, res) => {
|
||||
try {
|
||||
const { account } = req.params;
|
||||
const { email } = req.body;
|
||||
|
||||
// 验证邮箱格式
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
return res.status(400).json({ success: false, message: '邮箱格式无效' });
|
||||
}
|
||||
|
||||
// 更新邮箱
|
||||
const [result] = await promisePool.query(
|
||||
'UPDATE UserText SET email = ? WHERE account = ?',
|
||||
[email, account]
|
||||
);
|
||||
|
||||
if (result.affectedRows === 0) {
|
||||
return res.status(404).json({ success: false, message: '用户不存在' });
|
||||
}
|
||||
|
||||
res.json({ success: true, message: '邮箱更新成功' });
|
||||
} catch (error) {
|
||||
console.error('更新邮箱错误:', error);
|
||||
res.status(500).json({ success: false, message: '服务器错误' });
|
||||
}
|
||||
});
|
||||
|
||||
// 启动服务器
|
||||
app.listen(port, () => {
|
||||
console.log(`API服务运行在端口 ${port}`);
|
||||
});
|
||||
```
|
||||
|
||||
### 3.3 安装依赖并启动服务
|
||||
|
||||
1. 通过SSH连接到服务器,进入网站目录:
|
||||
```bash
|
||||
cd /www/wwwroot/your_website_directory
|
||||
```
|
||||
|
||||
2. 初始化项目并安装依赖:
|
||||
```bash
|
||||
npm init -y
|
||||
npm install express mysql2 cors body-parser
|
||||
```
|
||||
|
||||
3. 安装PM2并启动服务:
|
||||
```bash
|
||||
npm install -g pm2
|
||||
pm2 start app.js --name "classmg-api"
|
||||
pm2 startup
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### 3.4 配置Nginx反向代理 (可选)
|
||||
|
||||
为了使API更安全和易于访问,可以配置Nginx反向代理:
|
||||
|
||||
1. 在宝塔面板中,找到您的网站,点击"设置"
|
||||
2. 点击"反向代理",添加新的反向代理
|
||||
3. 填写以下信息:
|
||||
- 名称:`API反向代理`
|
||||
- 目标URL:`http://127.0.0.1:3000`
|
||||
- 发送域名:勾选
|
||||
4. 点击"提交"
|
||||
|
||||
现在您可以通过 `http://your_domain/api/` 访问API服务。
|
||||
|
||||
### 3.5 配置防火墙
|
||||
|
||||
确保服务器防火墙允许访问3000端口(如果直接使用Node.js)或80/443端口(如果使用Nginx反向代理)。
|
||||
|
||||
## 四、HarmonyOS应用配置
|
||||
|
||||
### 4.1 修改API地址
|
||||
|
||||
在HarmonyOS应用的`DatabaseService.ets`文件中,确保API地址正确配置:
|
||||
|
||||
```typescript
|
||||
// 定义API服务配置
|
||||
const API_CONFIG: ApiConfig = {
|
||||
// 修改为您的实际服务器地址
|
||||
baseUrl: 'http://your_server_ip:3000/api',
|
||||
timeout: 10000
|
||||
};
|
||||
```
|
||||
|
||||
### 4.2 构建并测试应用
|
||||
|
||||
1. 在DevEco Studio中构建应用
|
||||
2. 在模拟器或真机上测试登录功能
|
||||
3. 尝试使用示例账号登录:
|
||||
- 账号:`2`或`9222`或`0`
|
||||
- 密码:`1`
|
||||
|
||||
## 五、生产环境安全建议
|
||||
|
||||
1. 启用HTTPS:为API服务配置SSL证书
|
||||
2. 实现更安全的密码存储:使用加盐哈希而不是明文存储
|
||||
3. 添加JWT认证:实现令牌机制进行会话管理
|
||||
4. 限制请求频率:防止暴力破解攻击
|
||||
5. 日志记录:记录所有API调用以便审计
|
||||
6. 定期备份数据库:防止数据丢失
|
||||
|
||||
## 六、故障排除
|
||||
|
||||
### 6.1 API连接问题
|
||||
|
||||
如果应用无法连接到API:
|
||||
1. 检查服务器IP和端口是否正确
|
||||
2. 确认防火墙设置允许连接
|
||||
3. 验证API服务是否正在运行 (`pm2 status`)
|
||||
4. 检查服务器日志 (`pm2 logs classmg-api`)
|
||||
|
||||
### 6.2 数据库问题
|
||||
|
||||
如果API服务无法连接到数据库:
|
||||
1. 确认数据库用户名和密码正确
|
||||
2. 检查数据库用户权限
|
||||
3. 验证数据库服务是否正在运行
|
||||
|
||||
### 6.3 降级模式
|
||||
|
||||
应用内已实现降级模式,当无法连接到API服务时,将使用本地模拟数据:
|
||||
- 账号:`2`、`9222`、`0`
|
||||
- 密码:`1`
|
232
LICENSE
Normal file
@ -0,0 +1,232 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
“This License” refers to version 3 of the GNU General Public License.
|
||||
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
||||
|
||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
||||
|
||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
||||
|
||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
IOS_Study_BossDemo
|
||||
Copyright (C) 2025 cc
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
IOS_Study_BossDemo Copyright (C) 2025 cc
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.
|
144
README.md
Normal file
@ -0,0 +1,144 @@
|
||||
# ClassMG - Interactive Classroom Management System
|
||||
|
||||
[English (Current)](README.md) | [中文版](README_CN.md)
|
||||
|
||||
## Overview
|
||||
|
||||
ClassMG is a comprehensive classroom management application designed for interactive teaching and learning. The system enables real-time communication between teachers and students, interactive question sessions, and immediate feedback mechanisms, all within a unified digital classroom environment.
|
||||
|
||||
## System Architecture
|
||||
|
||||
ClassMG is built on a client-server architecture:
|
||||
|
||||
- **Client Application**: Developed using HarmonyOS ArkTS for cross-device compatibility
|
||||
- **Communication Server**: Node.js based server that enables real-time message passing and state synchronization
|
||||
- **Local Data Storage**: Secure local storage for user credentials and session data
|
||||
|
||||
## Core Features
|
||||
|
||||
### 1. Classroom Management
|
||||
- **Create Classroom**: Teachers can create virtual classrooms with unique access codes
|
||||
- **Join Classroom**: Students can join using classroom codes
|
||||
- ~~**Classroom Status**: Real-time monitoring of active participants~~
|
||||
- **End Classroom**: Teachers can terminate sessions with proper notification to all participants
|
||||
|
||||
### ~~2. Real-time Communication~~
|
||||
- **Instant Messaging**: Bi-directional communication between teachers and students
|
||||
- **Message Synchronization**: Robust message delivery with automatic retry mechanisms
|
||||
- **Connection Status**: Visual indicators for connection status with troubleshooting options
|
||||
|
||||
### 3. Interactive Questions
|
||||
- **Question Publishing**: Teachers can create and publish multiple-choice questions
|
||||
- **Timed Responses**: Configurable time limits for answering questions
|
||||
- **Answer Submission**: Students can submit answers with immediate confirmation
|
||||
- **Result Analysis**: Visual presentation of response statistics and correctness rates
|
||||
|
||||
### 4. User Experience
|
||||
- **Adaptive Layout**: Responsive interface that works across different screen sizes
|
||||
- **Visual Feedback**: Clear status indicators for all operations
|
||||
- **Error Handling**: Comprehensive error notifications with recovery options
|
||||
- **Theme Customization**: Personalized visual appearance settings
|
||||
|
||||
## Operation Logic
|
||||
|
||||
### Authentication Flow
|
||||
1. Users register with username and password (stored securely)
|
||||
2. Login verification against local credentials
|
||||
3. Role assignment (teacher or student) determines available features
|
||||
|
||||
### Classroom Session Flow
|
||||
1. Teacher creates a classroom with a unique code
|
||||
2. Students join using the provided code
|
||||
3. Real-time synchronization establishes the classroom environment
|
||||
4. Teacher and students can exchange messages and participate in question sessions
|
||||
5. Teacher can end the classroom session, which notifies all participants
|
||||
|
||||
### Messaging System
|
||||
1. Messages are composed and sent from the input area
|
||||
2. Local preview appears immediately for responsive UX
|
||||
3. Messages are transmitted to the server
|
||||
4. Server broadcasts messages to all connected devices
|
||||
5. Polling mechanism ensures message delivery, even after temporary disconnections
|
||||
|
||||
### Question Management
|
||||
1. Teacher creates questions with multiple-choice options
|
||||
2. Students receive questions with configurable countdown timers
|
||||
3. Responses are collected and synchronized across devices
|
||||
4. Results are computed and displayed after the question ends
|
||||
5. Teachers can view detailed statistics while students see personal results
|
||||
|
||||
## Technical Implementation
|
||||
|
||||
### Communication Protocol
|
||||
- HTTP-based API for classroom operations
|
||||
- Polling mechanism for state synchronization
|
||||
- JSON message format for data exchange
|
||||
|
||||
### Data Security
|
||||
- Local credential storage with encryption
|
||||
- Classroom access controlled via unique codes
|
||||
- Session validation for all operations
|
||||
|
||||
### Synchronization Mechanism
|
||||
- Server maintains the source of truth for classroom state
|
||||
- Client polling ensures data consistency
|
||||
- Conflict resolution strategies for concurrent operations
|
||||
|
||||
### Error Handling
|
||||
- Connection status monitoring
|
||||
- Automatic reconnection attempts
|
||||
- User-friendly error messages with recovery options
|
||||
|
||||
## Server Setup
|
||||
|
||||
### Prerequisites
|
||||
- Node.js (v12 or higher)
|
||||
- NPM (Node Package Manager)
|
||||
|
||||
### Installation
|
||||
1. Install Node.js and NPM
|
||||
2. Clone or download the repository
|
||||
3. Install dependencies with `npm install`
|
||||
|
||||
### Running the Server
|
||||
1. Start with `npm start` or `node server.js`
|
||||
2. Server will run on port 5243 by default
|
||||
3. Note your computer's IP address for client configuration
|
||||
|
||||
## Client Configuration
|
||||
|
||||
### Development Environment
|
||||
- DevEco Studio (recommended)
|
||||
- HarmonyOS SDK
|
||||
|
||||
### Connection Setup
|
||||
1. Ensure all devices are on the same network
|
||||
2. Configure the server address in the client application
|
||||
3. Compile and deploy to testing devices
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Connection Issues
|
||||
- Verify all devices are on the same network
|
||||
- Check server IP address and port configuration
|
||||
- Use the built-in connection status checker in the application
|
||||
|
||||
### Message Synchronization
|
||||
- If messages aren't appearing across devices, check connection status
|
||||
- Verify server is running properly
|
||||
- Try reconnecting using the in-app troubleshooting button
|
||||
|
||||
### Layout Problems
|
||||
- If UI elements are misaligned or appear off-screen, restart the application
|
||||
- Different device screen sizes may require application restart after significant layout changes
|
||||
|
||||
## Notes for Developers
|
||||
|
||||
- The system uses a polling mechanism rather than WebSockets for compatibility reasons
|
||||
- Message deduplication is implemented to handle potential duplicate delivery
|
||||
- UI layouts are optimized for both tablet and smartphone form factors
|
||||
- Debug logging can be enabled for troubleshooting purposes
|
||||
|
||||
---
|
||||
|
||||
**Note**: This document provides an overview of the ClassMG system. For detailed API documentation and developer guides, please refer to the technical documentation.
|
347
api-app.js
Normal file
@ -0,0 +1,347 @@
|
||||
const express = require('express');
|
||||
const mysql = require('mysql2');
|
||||
const cors = require('cors');
|
||||
const bodyParser = require('body-parser');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 创建Express应用
|
||||
const app = express();
|
||||
const port = 2342;
|
||||
|
||||
// 启用CORS和JSON解析
|
||||
app.use(cors());
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// 创建logs目录(如果不存在)
|
||||
const logsDir = path.join(__dirname, 'logs');
|
||||
if (!fs.existsSync(logsDir)) {
|
||||
fs.mkdirSync(logsDir);
|
||||
}
|
||||
|
||||
// 简单日志函数
|
||||
function logToFile(message) {
|
||||
const logFile = path.join(logsDir, 'api.log');
|
||||
const timestamp = new Date().toISOString();
|
||||
fs.appendFileSync(logFile, `${timestamp} - ${message}\n`);
|
||||
console.log(`${timestamp} - ${message}`);
|
||||
}
|
||||
|
||||
// 数据库连接配置
|
||||
const dbConfig = {
|
||||
host: 'localhost',
|
||||
port: 25342, // 修改为正确的MySQL端口
|
||||
user: 'hongm', // 替换为您的数据库用户名
|
||||
password: 'JsKJeG7CX2WnyArt', // 替换为您的数据库密码
|
||||
database: 'hongm',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
};
|
||||
|
||||
// 创建数据库连接池
|
||||
const pool = mysql.createPool(dbConfig);
|
||||
const promisePool = pool.promise();
|
||||
|
||||
// 检查数据库连接
|
||||
async function checkDbConnection() {
|
||||
try {
|
||||
const connection = await promisePool.getConnection();
|
||||
logToFile('数据库连接成功');
|
||||
connection.release();
|
||||
return true;
|
||||
} catch (error) {
|
||||
logToFile(`数据库连接失败: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 在启动时测试数据库连接
|
||||
checkDbConnection();
|
||||
|
||||
// 创建一个简单的首页响应
|
||||
app.get('/', (req, res) => {
|
||||
res.send('智能教室管理系统API服务正在运行');
|
||||
});
|
||||
|
||||
// 创建一个图片目录路由
|
||||
app.use('/images', express.static(path.join(__dirname, 'images')));
|
||||
|
||||
// API: 用户登录验证
|
||||
app.post('/api/login', async (req, res) => {
|
||||
try {
|
||||
logToFile(`收到登录请求: ${JSON.stringify(req.body)}`);
|
||||
const { account, password } = req.body;
|
||||
|
||||
if (!account || !password) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '账号和密码不能为空'
|
||||
});
|
||||
}
|
||||
|
||||
// 查询密码
|
||||
const [passwordRows] = await promisePool.query(
|
||||
'SELECT password FROM UserPassword WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (passwordRows.length === 0) {
|
||||
logToFile(`登录失败: 账号 ${account} 不存在`);
|
||||
return res.status(401).json({
|
||||
success: false,
|
||||
message: '账号不存在'
|
||||
});
|
||||
}
|
||||
|
||||
const storedPassword = passwordRows[0].password;
|
||||
|
||||
if (password !== storedPassword) {
|
||||
logToFile(`登录失败: 账号 ${account} 密码错误`);
|
||||
return res.status(401).json({
|
||||
success: false,
|
||||
message: '密码错误'
|
||||
});
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
const [userRows] = await promisePool.query(
|
||||
'SELECT * FROM UserText WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (userRows.length === 0) {
|
||||
logToFile(`登录异常: 账号 ${account} 存在但用户信息丢失`);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: '用户信息不存在'
|
||||
});
|
||||
}
|
||||
|
||||
const user = userRows[0];
|
||||
logToFile(`登录成功: 账号 ${account}, 用户名 ${user.nickname}`);
|
||||
|
||||
// 返回成功登录信息和用户数据
|
||||
res.json({
|
||||
success: true,
|
||||
message: '登录成功',
|
||||
user: {
|
||||
account: user.account,
|
||||
nickname: user.nickname,
|
||||
email: user.email || '',
|
||||
phone: user.phone || '',
|
||||
photo: user.photo || 'http://139.155.155.67:2342/images/default_avatar.png',
|
||||
category: user.category
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
logToFile(`登录错误: ${error.message}`);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '服务器错误',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// API: 获取用户信息
|
||||
app.get('/api/user/:account', async (req, res) => {
|
||||
try {
|
||||
const { account } = req.params;
|
||||
logToFile(`获取用户信息请求: 账号 ${account}`);
|
||||
|
||||
// 查询用户信息
|
||||
const [userRows] = await promisePool.query(
|
||||
'SELECT * FROM UserText WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (userRows.length === 0) {
|
||||
logToFile(`获取用户信息失败: 账号 ${account} 不存在`);
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: '用户不存在'
|
||||
});
|
||||
}
|
||||
|
||||
const user = userRows[0];
|
||||
logToFile(`获取用户信息成功: 账号 ${account}, 用户名 ${user.nickname}`);
|
||||
|
||||
// 返回用户数据
|
||||
res.json({
|
||||
success: true,
|
||||
user: {
|
||||
account: user.account,
|
||||
nickname: user.nickname,
|
||||
email: user.email || '',
|
||||
phone: user.phone || '',
|
||||
photo: user.photo || 'http://139.155.155.67:2342/images/default_avatar.png',
|
||||
category: user.category
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
logToFile(`获取用户信息错误: ${error.message}`);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '服务器错误',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// API: 更新用户邮箱
|
||||
app.put('/api/user/:account/email', async (req, res) => {
|
||||
try {
|
||||
const { account } = req.params;
|
||||
const { email } = req.body;
|
||||
logToFile(`更新用户邮箱请求: 账号 ${account}, 新邮箱 ${email}`);
|
||||
|
||||
// 验证邮箱格式
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
logToFile(`更新邮箱失败: 邮箱格式无效 ${email}`);
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '邮箱格式无效'
|
||||
});
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
const [userCheck] = await promisePool.query(
|
||||
'SELECT account FROM UserText WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (userCheck.length === 0) {
|
||||
logToFile(`更新邮箱失败: 账号 ${account} 不存在`);
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: '用户不存在'
|
||||
});
|
||||
}
|
||||
|
||||
// 更新邮箱
|
||||
const [result] = await promisePool.query(
|
||||
'UPDATE UserText SET email = ? WHERE account = ?',
|
||||
[email, account]
|
||||
);
|
||||
|
||||
if (result.affectedRows === 0) {
|
||||
logToFile(`更新邮箱失败: 账号 ${account} 无法更新`);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: '更新邮箱失败'
|
||||
});
|
||||
}
|
||||
|
||||
logToFile(`更新邮箱成功: 账号 ${account}, 新邮箱 ${email}`);
|
||||
res.json({
|
||||
success: true,
|
||||
message: '邮箱更新成功'
|
||||
});
|
||||
} catch (error) {
|
||||
logToFile(`更新邮箱错误: ${error.message}`);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '服务器错误',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// API: 用户注册
|
||||
app.post('/api/register', async (req, res) => {
|
||||
try {
|
||||
const { account, password, nickname, email, phone, photo } = req.body;
|
||||
logToFile(`收到注册请求: ${JSON.stringify(req.body)}`);
|
||||
|
||||
// 验证必填字段
|
||||
if (!account || !password || !email) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '账号、密码和邮箱为必填项'
|
||||
});
|
||||
}
|
||||
|
||||
// 检查账号是否已存在
|
||||
const [existingUser] = await promisePool.query(
|
||||
'SELECT account FROM UserText WHERE account = ?',
|
||||
[account]
|
||||
);
|
||||
|
||||
if (existingUser.length > 0) {
|
||||
logToFile(`注册失败: 账号 ${account} 已存在`);
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '账号已存在'
|
||||
});
|
||||
}
|
||||
|
||||
// 检查邮箱是否已存在
|
||||
const [existingEmail] = await promisePool.query(
|
||||
'SELECT email FROM UserText WHERE email = ?',
|
||||
[email]
|
||||
);
|
||||
|
||||
if (existingEmail.length > 0) {
|
||||
logToFile(`注册失败: 邮箱 ${email} 已被使用`);
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '邮箱已被使用'
|
||||
});
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
const connection = await promisePool.getConnection();
|
||||
await connection.beginTransaction();
|
||||
|
||||
try {
|
||||
// 插入用户基本信息
|
||||
await connection.query(
|
||||
'INSERT INTO UserText (account, nickname, email, phone, photo, category) VALUES (?, ?, ?, ?, ?, ?)',
|
||||
[account, nickname || account, email, phone || null, photo || 'http://139.155.155.67:2342/images/default_avatar.png', 'user']
|
||||
);
|
||||
|
||||
// 插入用户密码
|
||||
await connection.query(
|
||||
'INSERT INTO UserPassword (account, password) VALUES (?, ?)',
|
||||
[account, password]
|
||||
);
|
||||
|
||||
// 提交事务
|
||||
await connection.commit();
|
||||
logToFile(`注册成功: 账号 ${account}, 昵称 ${nickname || account}`);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: '注册成功',
|
||||
user: {
|
||||
account,
|
||||
nickname: nickname || account,
|
||||
email,
|
||||
phone: phone || '',
|
||||
photo: photo || 'http://139.155.155.67:2342/images/default_avatar.png',
|
||||
category: 'user'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// 回滚事务
|
||||
await connection.rollback();
|
||||
throw error;
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
} catch (error) {
|
||||
logToFile(`注册错误: ${error.message}`);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '注册失败,请稍后重试',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 启动服务器
|
||||
app.listen(port, '0.0.0.0', () => {
|
||||
logToFile(`API服务运行在端口 ${port}`);
|
||||
});
|
16
api-package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "classmg-api",
|
||||
"version": "1.0.0",
|
||||
"description": "智能教室管理系统API服务",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
"dev": "nodemon app.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"mysql2": "^3.6.1"
|
||||
}
|
||||
}
|
11
build-script.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Cleaning project..."
|
||||
rm -rf build/
|
||||
rm -rf build-profile/
|
||||
|
||||
echo "Building project..."
|
||||
/Applications/DevEco-Studio.app/Contents/tools/node/bin/node /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw.js --mode module -p module=entry@default -p product=default -p requiredDeviceType=phone clean
|
||||
|
||||
echo "Rebuilding project..."
|
||||
/Applications/DevEco-Studio.app/Contents/tools/node/bin/node /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw.js --mode module -p module=entry@default -p product=default -p requiredDeviceType=phone assembleHap --analyze=normal --parallel --incremental --daemon
|
33
database_setup.sql
Normal file
@ -0,0 +1,33 @@
|
||||
-- Create the UserText table to store user information
|
||||
CREATE TABLE IF NOT EXISTS UserText (
|
||||
account VARCHAR(20) PRIMARY KEY,
|
||||
nickname VARCHAR(50) NOT NULL,
|
||||
email VARCHAR(100),
|
||||
phone VARCHAR(20),
|
||||
photo VARCHAR(255) DEFAULT NULL,
|
||||
category VARCHAR(20) NOT NULL,
|
||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Create the UserPassword table to store user account and password
|
||||
CREATE TABLE IF NOT EXISTS UserPassword (
|
||||
account VARCHAR(20) PRIMARY KEY,
|
||||
password VARCHAR(50) NOT NULL,
|
||||
FOREIGN KEY (account) REFERENCES UserText(account)
|
||||
);
|
||||
|
||||
-- Insert sample users as specified in the requirements
|
||||
-- Student users
|
||||
INSERT INTO UserText (account, nickname, email, phone, category) VALUES
|
||||
('2', '张三', 'student@qq.com', '17267383831', 'student'),
|
||||
('9222', '李华', 'student123@qq.com', '12345678901', 'student');
|
||||
|
||||
-- Teacher user
|
||||
INSERT INTO UserText (account, nickname, email, phone, category) VALUES
|
||||
('0', '教师demo', 'teach@qq.com', NULL, 'teacher');
|
||||
|
||||
-- Insert passwords (all passwords are '1')
|
||||
INSERT INTO UserPassword (account, password) VALUES
|
||||
('2', '1'),
|
||||
('9222', '1'),
|
||||
('0', '1');
|
10
entry/src/main/ets/common/App.ets
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
// 初始化应用
|
||||
export function initApp() {
|
||||
// Don't register routes during initialization
|
||||
// This should be handled by the UI components
|
||||
console.info('App initialized');
|
||||
}
|
1157
entry/src/main/ets/common/ClassRoomService.ets
Normal file
475
entry/src/main/ets/common/DatabaseService.ets
Normal file
@ -0,0 +1,475 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import prompt from '@ohos.promptAction';
|
||||
import http from '@ohos.net.http';
|
||||
|
||||
// User model for storing user information from database
|
||||
export class UserModel {
|
||||
account: string = '';
|
||||
nickname: string = '';
|
||||
email: string = '';
|
||||
phone: string = '';
|
||||
photo: string = '';
|
||||
category: string = '';
|
||||
|
||||
constructor(account: string = '',
|
||||
nickname: string = '',
|
||||
email: string = '',
|
||||
phone: string = '',
|
||||
photo: string = '',
|
||||
category: string = '') {
|
||||
this.account = account;
|
||||
this.nickname = nickname;
|
||||
this.email = email;
|
||||
this.phone = phone;
|
||||
this.photo = photo || 'http://139.155.155.67:2342/images/default_avatar.png'; // Default photo URL
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
||||
// API响应接口定义
|
||||
export interface ApiResponse {
|
||||
success: boolean;
|
||||
message?: string;
|
||||
user?: UserInfo;
|
||||
}
|
||||
|
||||
// User info returned from API
|
||||
export interface UserInfo {
|
||||
account: string;
|
||||
nickname: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
photo?: string;
|
||||
category: string;
|
||||
}
|
||||
|
||||
// API服务配置
|
||||
export interface ApiConfig {
|
||||
baseUrl: string;
|
||||
timeout: number;
|
||||
websocketDomain: string
|
||||
}
|
||||
|
||||
// 定义API服务配置
|
||||
const API_CONFIG: ApiConfig = {
|
||||
// 修改为用户实际使用的服务器地址
|
||||
baseUrl: 'http://139.155.155.67:2342/api',
|
||||
timeout: 10000, // 10秒超时
|
||||
websocketDomain: "139.155.155.67:4233",
|
||||
// websocketDomain: "198.18.0.1:8080",
|
||||
};
|
||||
|
||||
// 修正JSON响应类型处理
|
||||
export type JsonResponse = string | object | ArrayBuffer;
|
||||
|
||||
// 注册用户数据接口
|
||||
export interface RegisterUserData {
|
||||
account: string;
|
||||
password: string;
|
||||
nickname: string;
|
||||
email: string;
|
||||
phone?: string;
|
||||
photo?: string;
|
||||
}
|
||||
|
||||
// 真实API实现 - 连接到后端服务
|
||||
export class DatabaseService {
|
||||
private static instance: DatabaseService;
|
||||
// 缓存用户数据,减少API调用
|
||||
private userCache: Map<string, UserModel> = new Map();
|
||||
// 缓存验证结果
|
||||
private authCache: Map<string, boolean> = new Map();
|
||||
// Callbacks for user data changes
|
||||
private userDataChangeCallbacks: (() => void)[] = [];
|
||||
|
||||
private constructor() {
|
||||
// 初始化缓存
|
||||
hilog.info(0, 'ClassMG', 'Database Service Initialized');
|
||||
}
|
||||
|
||||
public static getInstance(): DatabaseService {
|
||||
if (!DatabaseService.instance) {
|
||||
DatabaseService.instance = new DatabaseService();
|
||||
}
|
||||
return DatabaseService.instance;
|
||||
}
|
||||
|
||||
public static getApiConfig():ApiConfig{
|
||||
return API_CONFIG;
|
||||
}
|
||||
|
||||
// 创建HTTP请求客户端
|
||||
private createHttpClient(): http.HttpRequest {
|
||||
let httpRequest = http.createHttp();
|
||||
httpRequest.on('headersReceive', (header) => {
|
||||
hilog.debug(0, 'ClassMG', `Headers received: ${JSON.stringify(header)}`);
|
||||
});
|
||||
return httpRequest;
|
||||
}
|
||||
|
||||
// 执行登录验证
|
||||
public async validateUser(account: string, password: string): Promise<boolean> {
|
||||
try {
|
||||
// 生成缓存键
|
||||
const cacheKey = `${account}:${password}`;
|
||||
|
||||
// 检查缓存
|
||||
if (this.authCache.has(cacheKey)) {
|
||||
const cachedResult = this.authCache.get(cacheKey);
|
||||
return cachedResult === true; // 确保返回布尔值
|
||||
}
|
||||
|
||||
// 创建HTTP客户端
|
||||
const httpRequest = this.createHttpClient();
|
||||
|
||||
// 准备登录数据
|
||||
let loginData = {} as Record<string, string>;
|
||||
loginData.account = account;
|
||||
loginData.password = password;
|
||||
|
||||
// 发送登录请求
|
||||
const response = await httpRequest.request(
|
||||
`${API_CONFIG.baseUrl}/login`,
|
||||
{
|
||||
method: http.RequestMethod.POST,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
extraData: JSON.stringify(loginData),
|
||||
connectTimeout: API_CONFIG.timeout,
|
||||
readTimeout: API_CONFIG.timeout
|
||||
}
|
||||
);
|
||||
|
||||
// 释放HTTP客户端
|
||||
httpRequest.destroy();
|
||||
|
||||
// 检查响应
|
||||
if (response.responseCode === 200) {
|
||||
// 使用显式类型转换处理JSON结果
|
||||
const jsonString: string = response.result ? response.result.toString() : '{}';
|
||||
try {
|
||||
const result: ApiResponse = JSON.parse(jsonString) as ApiResponse;
|
||||
|
||||
// 缓存结果
|
||||
const isValid = result.success === true;
|
||||
this.authCache.set(cacheKey, isValid);
|
||||
|
||||
// 如果登录成功且有用户数据,缓存用户信息
|
||||
if (isValid && result.user) {
|
||||
const user = new UserModel(
|
||||
result.user.account,
|
||||
result.user.nickname,
|
||||
result.user.email,
|
||||
result.user.phone,
|
||||
result.user.photo,
|
||||
result.user.category
|
||||
);
|
||||
this.userCache.set(account, user);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
} catch (parseError) {
|
||||
const errorMsg: string = parseError instanceof Error ? parseError.message : String(parseError);
|
||||
hilog.error(0, 'ClassMG', `Error parsing JSON response: ${errorMsg}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 默认返回false
|
||||
return false;
|
||||
} catch (error) {
|
||||
hilog.error(0, 'ClassMG', `Error validating user: ${error instanceof Error ? error.message : String(error)}`);
|
||||
|
||||
// 临时降级到模拟验证 - 仅用于开发/测试
|
||||
/* if (account === '2' || account === '9222' || account === '0') {
|
||||
return password === '1';
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户类别
|
||||
public getUserCategory(account: string): string {
|
||||
// 检查缓存
|
||||
if (this.userCache.has(account)) {
|
||||
const user = this.userCache.get(account);
|
||||
return user ? user.category : '';
|
||||
}
|
||||
|
||||
// 降级逻辑 - 当API不可用时
|
||||
if (account.includes('2')) {
|
||||
return 'student';
|
||||
} else if (account.includes('0')) {
|
||||
return 'teacher';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// 获取用户昵称
|
||||
public getUserNickname(account: string): string {
|
||||
// 检查缓存
|
||||
if (this.userCache.has(account)) {
|
||||
const user = this.userCache.get(account);
|
||||
return user ? user.nickname : '';
|
||||
}
|
||||
|
||||
// 默认值 - 仅用于开发/测试
|
||||
if (account === '2') {
|
||||
return '张三';
|
||||
}
|
||||
if (account === '9222') {
|
||||
return '李华';
|
||||
}
|
||||
if (account === '0') {
|
||||
return '教师demo';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// 异步获取用户信息
|
||||
public async getUserByAccountAsync(account: string): Promise<UserModel | null> {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (this.userCache.has(account)) {
|
||||
const cachedUser = this.userCache.get(account);
|
||||
return cachedUser || null;
|
||||
}
|
||||
|
||||
// 创建HTTP客户端
|
||||
const httpRequest = this.createHttpClient();
|
||||
|
||||
// 发送获取用户信息请求
|
||||
const response = await httpRequest.request(
|
||||
`${API_CONFIG.baseUrl}/user/${account}`,
|
||||
{
|
||||
method: http.RequestMethod.GET,
|
||||
connectTimeout: API_CONFIG.timeout,
|
||||
readTimeout: API_CONFIG.timeout
|
||||
}
|
||||
);
|
||||
|
||||
// 释放HTTP客户端
|
||||
httpRequest.destroy();
|
||||
|
||||
// 检查响应
|
||||
if (response.responseCode === 200) {
|
||||
// 使用显式类型转换处理JSON结果
|
||||
const jsonString: string = response.result ? response.result.toString() : '{}';
|
||||
try {
|
||||
const result: ApiResponse = JSON.parse(jsonString) as ApiResponse;
|
||||
|
||||
if (result.success && result.user) {
|
||||
const user = new UserModel(
|
||||
result.user.account,
|
||||
result.user.nickname,
|
||||
result.user.email,
|
||||
result.user.phone,
|
||||
result.user.photo,
|
||||
result.user.category
|
||||
);
|
||||
|
||||
// 更新缓存
|
||||
this.userCache.set(account, user);
|
||||
|
||||
return user;
|
||||
}
|
||||
} catch (parseError) {
|
||||
const errorMsg: string = parseError instanceof Error ? parseError.message : String(parseError);
|
||||
hilog.error(0, 'ClassMG', `Error parsing JSON response: ${errorMsg}`);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
hilog.error(0, 'ClassMG', `Error getting user: ${error instanceof Error ? error.message : String(error)}`);
|
||||
|
||||
// 降级到模拟数据 - 仅用于开发/测试
|
||||
/* if (account === '2') {
|
||||
return new UserModel('2', '张三', 'student@qq.com', '17267383831', '', 'student');
|
||||
} else if (account === '9222') {
|
||||
return new UserModel('9222', '李华', 'student123@qq.com', '12345678901', '', 'student');
|
||||
} else if (account === '0') {
|
||||
return new UserModel('0', '教师demo', 'teach@qq.com', '', '', 'teacher');
|
||||
}*/
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 为了兼容性保留的同步方法 - 使用缓存
|
||||
public getUserByAccount(account: string): UserModel | null {
|
||||
// 检查缓存
|
||||
if (this.userCache.has(account)) {
|
||||
const cachedUser = this.userCache.get(account);
|
||||
return cachedUser || null;
|
||||
}
|
||||
|
||||
// 如果缓存中没有,返回null并触发异步加载
|
||||
this.getUserByAccountAsync(account)
|
||||
.then((user: UserModel | null) => {
|
||||
if (user) {
|
||||
this.notifyUserDataChange();
|
||||
}
|
||||
})
|
||||
.catch((error: Error | string | Object) => {
|
||||
const errorMsg: string = error instanceof Error ? error.message : String(error);
|
||||
hilog.error(0, 'ClassMG', `Error in async user fetch: ${errorMsg}`);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新用户邮箱 - 连接API
|
||||
public async updateUserEmail(account: string, newEmail: string): Promise<boolean> {
|
||||
try {
|
||||
// 验证邮箱格式
|
||||
if (!this.validateEmailFormat(newEmail)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建HTTP客户端
|
||||
const httpRequest = this.createHttpClient();
|
||||
|
||||
// 准备更新数据
|
||||
let updateData = {} as Record<string, string>;
|
||||
updateData.email = newEmail;
|
||||
|
||||
// 发送更新请求
|
||||
const response = await httpRequest.request(
|
||||
`${API_CONFIG.baseUrl}/user/${account}/email`,
|
||||
{
|
||||
method: http.RequestMethod.PUT,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
extraData: JSON.stringify(updateData),
|
||||
connectTimeout: API_CONFIG.timeout,
|
||||
readTimeout: API_CONFIG.timeout
|
||||
}
|
||||
);
|
||||
|
||||
// 释放HTTP客户端
|
||||
httpRequest.destroy();
|
||||
|
||||
// 检查响应
|
||||
if (response.responseCode === 200) {
|
||||
// 使用显式类型转换处理JSON结果
|
||||
const jsonString: string = response.result ? response.result.toString() : '{}';
|
||||
try {
|
||||
const result: ApiResponse = JSON.parse(jsonString) as ApiResponse;
|
||||
|
||||
if (result.success) {
|
||||
// 更新本地缓存
|
||||
if (this.userCache.has(account)) {
|
||||
const user = this.userCache.get(account);
|
||||
if (user) {
|
||||
user.email = newEmail;
|
||||
this.userCache.set(account, user);
|
||||
}
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
this.notifyUserDataChange();
|
||||
|
||||
return true;
|
||||
}
|
||||
} catch (parseError) {
|
||||
const errorMsg: string = parseError instanceof Error ? parseError.message : String(parseError);
|
||||
hilog.error(0, 'ClassMG', `Error parsing JSON response: ${errorMsg}`);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
const errorMessage: string = error instanceof Error ? error.message : String(error);
|
||||
hilog.error(0, 'ClassMG', `Error updating user email: ${errorMessage}`);
|
||||
|
||||
// 降级到本地更新 - 仅用于开发/测试
|
||||
if (this.userCache.has(account)) {
|
||||
const user = this.userCache.get(account);
|
||||
if (user) {
|
||||
user.email = newEmail;
|
||||
this.userCache.set(account, user);
|
||||
this.notifyUserDataChange();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 注册数据变化回调
|
||||
public registerUserDataChangeCallback(callback: () => void): void {
|
||||
this.userDataChangeCallbacks.push(callback);
|
||||
}
|
||||
|
||||
// 通知所有回调
|
||||
private notifyUserDataChange(): void {
|
||||
this.userDataChangeCallbacks.forEach(callback => {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
// 验证邮箱格式
|
||||
public validateEmailFormat(email: string): boolean {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return emailRegex.test(email);
|
||||
}
|
||||
|
||||
// 清除缓存
|
||||
public clearCache(): void {
|
||||
this.userCache.clear();
|
||||
this.authCache.clear();
|
||||
}
|
||||
|
||||
// 注册用户
|
||||
public async registerUser(userData: RegisterUserData): Promise<boolean> {
|
||||
try {
|
||||
// 创建HTTP客户端
|
||||
const httpRequest = this.createHttpClient();
|
||||
|
||||
// 发送注册请求
|
||||
const response = await httpRequest.request(
|
||||
`${API_CONFIG.baseUrl}/register`,
|
||||
{
|
||||
method: http.RequestMethod.POST,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
extraData: JSON.stringify(userData),
|
||||
connectTimeout: API_CONFIG.timeout,
|
||||
readTimeout: API_CONFIG.timeout
|
||||
}
|
||||
);
|
||||
|
||||
// 释放HTTP客户端
|
||||
httpRequest.destroy();
|
||||
|
||||
// 检查响应
|
||||
if (response.responseCode === 200) {
|
||||
// 使用显式类型转换处理JSON结果
|
||||
const jsonString: string = response.result ? response.result.toString() : '{}';
|
||||
try {
|
||||
const result: ApiResponse = JSON.parse(jsonString) as ApiResponse;
|
||||
return result.success === true;
|
||||
} catch (parseError) {
|
||||
const errorMsg: string = parseError instanceof Error ? parseError.message : String(parseError);
|
||||
hilog.error(0, 'ClassMG', `Error parsing JSON response: ${errorMsg}`);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
hilog.error(0, 'ClassMG', `Error registering user: ${error instanceof Error ? error.message : String(error)}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
// 导入日志管理器 - 仅用于获取版本号
|
||||
import logManager, { LogCategory, LogEventType, VersionLogItem } from './logtext';
|
||||
import { UserModel, DatabaseService } from './DatabaseService';
|
||||
@ -128,7 +134,7 @@ chineseTexts.notificationSettings = '通知设置';
|
||||
chineseTexts.about = '关于';
|
||||
chineseTexts.versionInfo = '版本信息';
|
||||
// 版本日志相关
|
||||
chineseTexts.versionLog = '更新日志';
|
||||
chineseTexts.versionLog = '日志记录';
|
||||
chineseTexts.versionHistory = '版本历史';
|
||||
chineseTexts.latestVersion = '最新版本';
|
||||
chineseTexts.noVersionInfo = '没有版本信息';
|
||||
@ -256,6 +262,11 @@ export class SettingsService {
|
||||
this.refreshUserInfo();
|
||||
}
|
||||
|
||||
// 获取当前用户账号
|
||||
public getCurrentAccount(): string {
|
||||
return this.currentAccount;
|
||||
}
|
||||
|
||||
// 刷新用户信息
|
||||
private refreshUserInfo(): void {
|
||||
if (this.currentAccount) {
|
||||
@ -437,9 +448,9 @@ export class SettingsService {
|
||||
// 降级为同步模式 - 仅用于紧急情况
|
||||
try {
|
||||
// 进行最简单的验证
|
||||
if (account === '2' || account === '9222' || account === '0') {
|
||||
/* if (account === '2' || account === '9222' || account === '0') {
|
||||
return password === '1';
|
||||
}
|
||||
}*/
|
||||
return false;
|
||||
} catch (error) {
|
||||
hilog.error(0, 'ClassMG', `Error in legacy validateUser: ${error}`);
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
|
||||
// 日志域 - 应用程序的唯一标识符
|
||||
@ -43,7 +47,9 @@ export enum LogEventType {
|
||||
PAGE_BACK = 'PAGE_BACK',
|
||||
SYSTEM_INFO = 'SYSTEM_INFO',
|
||||
USER_LOGIN = 'USER_LOGIN',
|
||||
USER_LOGIN_FAIL = 'USER_LOGIN_FAIL'
|
||||
USER_LOGIN_FAIL = 'USER_LOGIN_FAIL',
|
||||
USER_REGISTER = 'USER_REGISTER',
|
||||
USER_REGISTER_FAIL = 'USER_REGISTER_FAIL'
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +59,7 @@ export class VersionLogItem {
|
||||
version: string = ''; // 版本号
|
||||
date: string = ''; // 发布日期
|
||||
changes: string[] = []; // 更新内容列表
|
||||
|
||||
|
||||
constructor(version: string = '', date: string = '', changes: string[] = []) {
|
||||
this.version = version;
|
||||
this.date = date;
|
||||
@ -78,11 +84,11 @@ export class LogManager {
|
||||
private versionLogs: VersionLogItem[] = [];
|
||||
// 当前语言
|
||||
private currentLanguage: string = '中文';
|
||||
|
||||
|
||||
private constructor() {
|
||||
this.initVersionLogs();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取LogManager实例
|
||||
*/
|
||||
@ -92,7 +98,7 @@ export class LogManager {
|
||||
}
|
||||
return LogManager.instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置当前语言
|
||||
* @param language 语言设置
|
||||
@ -101,7 +107,7 @@ export class LogManager {
|
||||
this.currentLanguage = language;
|
||||
logInfo(`日志管理器语言已设置为: ${language}`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 记录信息日志
|
||||
* @param category 日志类别
|
||||
@ -112,7 +118,7 @@ export class LogManager {
|
||||
const logMessage = `[${category}][${type}] ${message}`;
|
||||
hilog.info(LOG_DOMAIN, LOG_TAG, logMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 记录调试日志,带有更多上下文
|
||||
* @param category 日志类别
|
||||
@ -125,7 +131,7 @@ export class LogManager {
|
||||
const logMessage = `[${category}][${type}] ${key}: ${oldValue} -> ${newValue}`;
|
||||
hilog.debug(LOG_DOMAIN, LOG_TAG, logMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 记录警告日志
|
||||
* @param category 日志类别
|
||||
@ -135,7 +141,7 @@ export class LogManager {
|
||||
const logMessage = `[${category}][WARN] ${message}`;
|
||||
hilog.warn(LOG_DOMAIN, LOG_TAG, logMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 记录错误日志
|
||||
* @param category 日志类别
|
||||
@ -146,7 +152,7 @@ export class LogManager {
|
||||
const logMessage = `[${category}][ERROR] ${errorMessage}`;
|
||||
hilog.error(LOG_DOMAIN, LOG_TAG, logMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化版本日志数据
|
||||
*/
|
||||
@ -155,17 +161,22 @@ export class LogManager {
|
||||
new VersionLogItem("1.0.0", "2025-2-10", ["初始版本发布", "实现基本功能界面", "添加用户信息管理", "支持主题色切换", "支持中英文切换"]),
|
||||
new VersionLogItem("1.1.0", "2025-3-31", ["添加用户信息编辑功能", "增加版本日志功能", "改进主题颜色切换效果","添加公告栏","修复已知问题"]),
|
||||
new VersionLogItem("1.1.5","2025-4-1",["增加远程测试数据库","优化登录页面","优化用户信息设置","增加退出按钮"]),
|
||||
new VersionLogItem("1.1.7","2025-4-1",["添加测试按钮","修复已知问题"])
|
||||
new VersionLogItem("1.1.7","2025-4-1",["添加测试按钮","修复已知问题"]),
|
||||
new VersionLogItem("1.2.0","2025-4-2",["添加课堂功能","修改上课页面逻辑"]),
|
||||
new VersionLogItem("1.2.0 beta1.0","2025-4-3",["测试消息发送","修复已知问题"]),
|
||||
new VersionLogItem("1.2.0 beta1.1","2025-4-4",["更新说明文档","添加日志输出"]),
|
||||
new VersionLogItem("1.2.0 beta1.2","2025-4-8",["修改首页","添加网页"]),
|
||||
new VersionLogItem("1.2.0 beta2.0","2025-4-15",["修改登录逻辑","修复上课逻辑","添加注册功能测试","添加记住密码功能测试"]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有版本日志
|
||||
*/
|
||||
public getVersionLogs(): VersionLogItem[] {
|
||||
return this.versionLogs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取最新版本号
|
||||
*/
|
||||
@ -173,21 +184,14 @@ export class LogManager {
|
||||
if (this.versionLogs && this.versionLogs.length > 0) {
|
||||
// 先复制一份数组进行排序,确保不影响原数组
|
||||
const sortedLogs = [...this.versionLogs].sort((a, b) => {
|
||||
const vA = a.version.split('.').map(Number);
|
||||
const vB = b.version.split('.').map(Number);
|
||||
for (let i = 0; i < Math.max(vA.length, vB.length); i++) {
|
||||
const numA = i < vA.length ? vA[i] : 0;
|
||||
const numB = i < vB.length ? vB[i] : 0;
|
||||
if (numB - numA !== 0) return numB - numA;
|
||||
}
|
||||
return 0;
|
||||
return this.compareVersions(a.version, b.version);
|
||||
});
|
||||
// 返回排序后的第一个元素(最高版本)
|
||||
return sortedLogs[0].version;
|
||||
}
|
||||
return "1.0.0"; // 默认版本号
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加新版本日志
|
||||
* @param versionLog 版本日志项
|
||||
@ -205,19 +209,77 @@ export class LogManager {
|
||||
logInfo(`新版本日志已添加: ${versionLog.version}`);
|
||||
}
|
||||
|
||||
// 按版本号排序(假设版本号格式为x.y.z)
|
||||
// 按版本号排序(支持beta版本)
|
||||
this.versionLogs.sort((a, b) => {
|
||||
const vA = a.version.split('.').map(Number);
|
||||
const vB = b.version.split('.').map(Number);
|
||||
for (let i = 0; i < Math.max(vA.length, vB.length); i++) {
|
||||
const numA = i < vA.length ? vA[i] : 0;
|
||||
const numB = i < vB.length ? vB[i] : 0;
|
||||
if (numB - numA !== 0) return numB - numA;
|
||||
}
|
||||
return 0;
|
||||
return this.compareVersions(a.version, b.version);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较两个版本号
|
||||
* @param versionA 版本号A
|
||||
* @param versionB 版本号B
|
||||
* @returns 返回比较结果,负数表示A < B,正数表示A > B,0表示A == B
|
||||
*/
|
||||
public compareVersions(versionA: string, versionB: string): number {
|
||||
// 检查是否包含beta
|
||||
const isBetaA = versionA.toLowerCase().includes('beta');
|
||||
const isBetaB = versionB.toLowerCase().includes('beta');
|
||||
|
||||
// 如果一个是beta,一个是正式版本,beta版本排在后面
|
||||
if (isBetaA && !isBetaB) {
|
||||
return -1;
|
||||
} else if (!isBetaA && isBetaB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 分离主版本号和beta版本号
|
||||
let mainVersionA = versionA;
|
||||
let betaVersionA = '';
|
||||
let mainVersionB = versionB;
|
||||
let betaVersionB = '';
|
||||
|
||||
if (isBetaA) {
|
||||
const parts = versionA.split('beta');
|
||||
mainVersionA = parts[0].trim();
|
||||
betaVersionA = parts[1].trim();
|
||||
}
|
||||
|
||||
if (isBetaB) {
|
||||
const parts = versionB.split('beta');
|
||||
mainVersionB = parts[0].trim();
|
||||
betaVersionB = parts[1].trim();
|
||||
}
|
||||
|
||||
// 比较主版本号
|
||||
const mainPartsA = mainVersionA.split('.').map(part => parseInt(part) || 0);
|
||||
const mainPartsB = mainVersionB.split('.').map(part => parseInt(part) || 0);
|
||||
|
||||
for (let i = 0; i < Math.max(mainPartsA.length, mainPartsB.length); i++) {
|
||||
const numA = mainPartsA[i] || 0;
|
||||
const numB = mainPartsB[i] || 0;
|
||||
if (numA !== numB) {
|
||||
return numB - numA; // 降序排列,最新版本在前
|
||||
}
|
||||
}
|
||||
|
||||
// 如果主版本号相同且都有beta版本,比较beta版本号
|
||||
if (betaVersionA && betaVersionB) {
|
||||
const betaPartsA = betaVersionA.split('.').map(part => parseInt(part) || 0);
|
||||
const betaPartsB = betaVersionB.split('.').map(part => parseInt(part) || 0);
|
||||
|
||||
for (let i = 0; i < Math.max(betaPartsA.length, betaPartsB.length); i++) {
|
||||
const numA = betaPartsA[i] || 0;
|
||||
const numB = betaPartsB[i] || 0;
|
||||
if (numA !== numB) {
|
||||
return numB - numA; // 降序排列,beta2.0 > beta1.2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 导出单例实例
|
||||
export default LogManager.getInstance();
|
||||
export default LogManager.getInstance();
|
@ -1,21 +1,56 @@
|
||||
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { initApp } from '../common/App';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
let copyrightDisplayed = false;
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
||||
|
||||
this.displayCopyright();
|
||||
|
||||
// 初始化应用,注册路由
|
||||
initApp();
|
||||
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
}
|
||||
|
||||
private displayCopyright(): void {
|
||||
if (copyrightDisplayed) return;
|
||||
|
||||
const asciiArt = `
|
||||
███████╗███╗ ███╗ █████╗ ██████╗ ███████╗██████╗ ██████╗ ██╗ ██╗
|
||||
██╔════╝████╗ ████║██╔══██╗██╔══██╗██╔════╝██╔══██╗ ██╔══██╗██║ ██╔╝
|
||||
███████╗██╔████╔██║███████║██████╔╝█████╗ ██████╔╝ ██████╔╝█████╔╝
|
||||
╚════██║██║╚██╔╝██║██╔══██║██╔══██╗██╔══╝ ██╔══██╗ ██╔══██╗██╔═██╗
|
||||
███████║██║ ╚═╝ ██║██║ ██║██║ ██║███████╗██║ ██║ ██║ ██║██║ ██╗
|
||||
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝
|
||||
`;
|
||||
|
||||
console.info('==========================================');
|
||||
console.info(asciiArt);
|
||||
console.info('Copyright (c) 2025 TDCAT.CN');
|
||||
console.info('==========================================');
|
||||
|
||||
hilog.info(DOMAIN, 'COPYRIGHT', '==========================================');
|
||||
hilog.info(DOMAIN, 'COPYRIGHT', 'Copyright (c) 2025 TDCAT.CN');
|
||||
hilog.info(DOMAIN, 'COPYRIGHT', '==========================================');
|
||||
|
||||
hilog.info(DOMAIN, 'COPYRIGHT', '%{public}s', '==========================================');
|
||||
hilog.info(DOMAIN, 'COPYRIGHT', '%{public}s', 'Copyright (c) 2025 TDCAT.CN');
|
||||
hilog.info(DOMAIN, 'COPYRIGHT', '%{public}s', '==========================================');
|
||||
|
||||
copyrightDisplayed = true;
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/WelcomePage', (err) => {
|
||||
@ -28,17 +63,14 @@ export default class EntryAbility extends UIAbility {
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
}
|
229
entry/src/main/ets/pages/AccountPage.ets
Normal file
@ -0,0 +1,229 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import settingsService, { SettingsModel, TextResources } from '../common/SettingsService';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct AccountPage {
|
||||
@State settings: SettingsModel = settingsService.getSettings();
|
||||
@State texts: TextResources = settingsService.getTextResources();
|
||||
@State userName: string = settingsService.getCurrentAccount() || "用户";
|
||||
@State userEmail: string = "未设置邮箱";
|
||||
|
||||
aboutToAppear() {
|
||||
// 注册语言变化的回调
|
||||
settingsService.registerLanguageChangeCallback(() => {
|
||||
this.texts = settingsService.getTextResources();
|
||||
});
|
||||
|
||||
// 获取用户名
|
||||
this.userName = settingsService.getCurrentAccount() || "用户";
|
||||
|
||||
this.Log_Event('aboutToAppear');
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 顶部导航栏
|
||||
Row() {
|
||||
Text("我的账户").fontSize(22).fontColor(Color.White).fontWeight(FontWeight.Bold)
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.height(60)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.padding({ left: 20 })
|
||||
|
||||
// 页面内容区
|
||||
Scroll() {
|
||||
Column() {
|
||||
// 用户基本信息
|
||||
Column() {
|
||||
Image($r('app.media.tdcat'))
|
||||
.width(80)
|
||||
.height(80)
|
||||
.borderRadius(40)
|
||||
.margin({ top: 20, bottom: 10 })
|
||||
|
||||
Text(this.userName)
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 8 })
|
||||
|
||||
Text(this.userEmail)
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
.margin({ bottom: 20 })
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 账户选项列表
|
||||
Column() {
|
||||
// 账户信息
|
||||
this.AccountListItem("账户信息", "查看和编辑您的个人资料")
|
||||
|
||||
// 安全设置
|
||||
this.AccountListItem("安全设置", "修改密码和安全选项")
|
||||
|
||||
// 通知管理
|
||||
this.AccountListItem("通知管理", "管理您收到的通知")
|
||||
|
||||
// 隐私设置
|
||||
this.AccountListItem("隐私设置", "管理您的隐私选项")
|
||||
|
||||
// 退出登录
|
||||
Button("退出登录")
|
||||
.width('90%')
|
||||
.height(50)
|
||||
.fontSize(16)
|
||||
.backgroundColor('#FF5A5A')
|
||||
.fontColor(Color.White)
|
||||
.margin({ top: 40, bottom: 20 })
|
||||
.onClick(() => {
|
||||
this.logout();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.padding({ top: 20 })
|
||||
.backgroundColor('#FFFFFF')
|
||||
.borderRadius(16)
|
||||
.margin({ top: 20 })
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
}
|
||||
.width('100%')
|
||||
.padding({ left: 16, right: 16 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.scrollBar(BarState.Off)
|
||||
|
||||
// 底部导航栏
|
||||
this.BottomNavigationBar('account')
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('#F5F7FA')
|
||||
}
|
||||
|
||||
@Builder
|
||||
AccountListItem(title: string, description: string) {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(title)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
|
||||
Text(description)
|
||||
.fontSize(12)
|
||||
.fontColor('#999999')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
.layoutWeight(1)
|
||||
|
||||
Image($r('app.media.arrow_right'))
|
||||
.width(20)
|
||||
.height(20)
|
||||
.margin({ right: 10 })
|
||||
}
|
||||
.width('90%')
|
||||
.padding({ top: 16, bottom: 16 })
|
||||
.borderRadius(8)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.margin({ bottom: 12 })
|
||||
}
|
||||
|
||||
@Builder
|
||||
BottomNavigationBar(activePage: string) {
|
||||
Row() {
|
||||
// 首页
|
||||
Column() {
|
||||
Image($r('app.media.home'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.fillColor(activePage === 'home' ? this.settings.themeColor : '#999999')
|
||||
Text("首页")
|
||||
.fontSize(12)
|
||||
.fontColor(activePage === 'home' ? this.settings.themeColor : '#999999')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.onClick(() => {
|
||||
router.pushUrl({ url: 'pages/HomePage' });
|
||||
})
|
||||
|
||||
// 课程
|
||||
Column() {
|
||||
Image($r('app.media.class'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.fillColor(activePage === 'class' ? this.settings.themeColor : '#999999')
|
||||
Text("课程")
|
||||
.fontSize(12)
|
||||
.fontColor(activePage === 'class' ? this.settings.themeColor : '#999999')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.onClick(() => {
|
||||
router.pushUrl({ url: 'pages/ClassPage' });
|
||||
})
|
||||
|
||||
// 账户
|
||||
Column() {
|
||||
Image($r('app.media.info'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.fillColor(activePage === 'account' ? this.settings.themeColor : '#999999')
|
||||
Text("账户")
|
||||
.fontSize(12)
|
||||
.fontColor(activePage === 'account' ? this.settings.themeColor : '#999999')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
|
||||
// 设置
|
||||
Column() {
|
||||
Image($r('app.media.settings'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.fillColor(activePage === 'settings' ? this.settings.themeColor : '#999999')
|
||||
Text("设置")
|
||||
.fontSize(12)
|
||||
.fontColor(activePage === 'settings' ? this.settings.themeColor : '#999999')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.onClick(() => {
|
||||
router.pushUrl({ url: 'pages/SettingsPage' });
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height(60)
|
||||
.backgroundColor(Color.White)
|
||||
.padding({ top: 8, bottom: 8 })
|
||||
.justifyContent(FlexAlign.SpaceAround)
|
||||
.alignItems(VerticalAlign.Center)
|
||||
}
|
||||
|
||||
// 退出登录方法
|
||||
private logout() {
|
||||
settingsService.setCurrentAccount(""); // Clear the account by setting it empty
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, "User logged out");
|
||||
|
||||
// 跳转到登录页
|
||||
router.replaceUrl({
|
||||
url: 'pages/login'
|
||||
});
|
||||
}
|
||||
|
||||
// 日志记录方法
|
||||
private Log_Event(eventName: string): void {
|
||||
logManager.info(LogCategory.HOME, LogEventType.PAGE_APPEAR, `AccountPage: ${eventName}`);
|
||||
}
|
||||
}
|
||||
|
||||
export { AccountPage }
|
1655
entry/src/main/ets/pages/ClassLivePage.ets
Normal file
@ -1,8 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { MonitorDataType } from './HomePage';
|
||||
import settingsService, { SettingsModel, TextResources } from '../common/SettingsService';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
import { DatabaseService } from '../common/DatabaseService';
|
||||
import classRoomService, { ClassSessionModel, QuestionOption } from '../common/ClassRoomService';
|
||||
|
||||
// 用户角色类型
|
||||
enum UserRole {
|
||||
STUDENT = 'student',
|
||||
TEACHER = 'teacher',
|
||||
UNKNOWN = 'unknown'
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@ -13,7 +26,19 @@ struct ClassPage {
|
||||
time: '',
|
||||
content: '',
|
||||
status: false
|
||||
}; // Initialize with empty values
|
||||
};
|
||||
|
||||
// 新增状态
|
||||
@State userRole: UserRole = UserRole.UNKNOWN;
|
||||
@State classCode: string = '';
|
||||
@State className: string = '';
|
||||
@State showCreateClassDialog: boolean = false;
|
||||
@State showJoinClassDialog: boolean = false;
|
||||
@State errorMessage: string = '';
|
||||
@State isLoading: boolean = false;
|
||||
|
||||
// 数据库服务
|
||||
private dbService: DatabaseService = DatabaseService.getInstance();
|
||||
|
||||
// 从设置服务获取设置
|
||||
@State settings: SettingsModel = settingsService.getSettings();
|
||||
@ -31,60 +56,673 @@ struct ClassPage {
|
||||
this.settings = settingsService.getSettings();
|
||||
});
|
||||
|
||||
// 检查用户角色
|
||||
const currentAccount = settingsService.getCurrentAccount();
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, `当前用户账号: ${currentAccount}`);
|
||||
|
||||
const category = this.dbService.getUserCategory(currentAccount);
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, `用户类别: ${category}`);
|
||||
|
||||
if (category === 'student') {
|
||||
this.userRole = UserRole.STUDENT;
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, '用户角色设置为学生');
|
||||
} else if (category === 'teacher') {
|
||||
this.userRole = UserRole.TEACHER;
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, '用户角色设置为教师');
|
||||
} else {
|
||||
this.userRole = UserRole.UNKNOWN;
|
||||
logManager.warn(LogCategory.USER, '无法识别用户角色,设置为未知');
|
||||
|
||||
// 尝试使用账号号码进行识别(备用方案)
|
||||
if (currentAccount.includes('2')) {
|
||||
this.userRole = UserRole.STUDENT;
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, '通过账号号码识别为学生');
|
||||
} else if (currentAccount.includes('0')) {
|
||||
this.userRole = UserRole.TEACHER;
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, '通过账号号码识别为教师');
|
||||
}
|
||||
}
|
||||
|
||||
// 同步设置到课堂服务
|
||||
classRoomService.checkIsTeacher();
|
||||
|
||||
this.Log_Event('aboutToAppear');
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 顶部导航栏
|
||||
Row() {
|
||||
Text(this.texts.classPageTitle).fontSize(22).fontColor(Color.White).fontWeight(FontWeight.Bold)
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.height(60)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.padding({ left: 20 })
|
||||
|
||||
// 页面内容区
|
||||
Scroll() {
|
||||
Column() {
|
||||
// 当前课程信息
|
||||
Column() {
|
||||
Text(this.currentClassInfo.name).fontSize(24).fontWeight(FontWeight.Bold).margin({ bottom: 10 })
|
||||
Text(`${this.texts.teacher}: ${this.currentClassInfo.teacher}`).fontSize(16).fontColor('#666').margin({ bottom: 8 })
|
||||
Text(`${this.texts.classroom}: ${this.currentClassInfo.room}`).fontSize(16).fontColor('#666')
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(12)
|
||||
.padding(20)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
.margin({ top: 15, bottom: 15 })
|
||||
|
||||
// 上课数据卡片
|
||||
Card({
|
||||
title: this.texts.classData,
|
||||
data: this.classData,
|
||||
themeColor: this.settings.themeColor
|
||||
})
|
||||
Stack({ alignContent: Alignment.TopStart }) {
|
||||
Column() {
|
||||
// 顶部导航栏
|
||||
Row() {
|
||||
Text(this.texts.classPageTitle).fontSize(22).fontColor(Color.White).fontWeight(FontWeight.Bold)
|
||||
}
|
||||
.width('100%')
|
||||
.padding({ left: 16, right: 16 })
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.height(60)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.padding({ left: 20 })
|
||||
|
||||
// 页面内容区
|
||||
Scroll() {
|
||||
Column() {
|
||||
// 根据用户角色显示不同界面
|
||||
if (this.userRole === UserRole.STUDENT) {
|
||||
this.StudentView()
|
||||
} else if (this.userRole === UserRole.TEACHER) {
|
||||
this.TeacherView()
|
||||
} else {
|
||||
this.UnknownRoleView()
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.padding({ left: 16, right: 16 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.scrollBar(BarState.Off)
|
||||
|
||||
// 底部导航栏
|
||||
BottomNavigation({
|
||||
activePage: 'class',
|
||||
themeColor: this.settings.themeColor,
|
||||
texts: this.texts
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
||||
// 创建课堂对话框
|
||||
if (this.showCreateClassDialog) {
|
||||
this.CreateClassDialog()
|
||||
}
|
||||
|
||||
// 加入课堂对话框
|
||||
if (this.showJoinClassDialog) {
|
||||
this.JoinClassDialog()
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.scrollBar(BarState.Off)
|
||||
|
||||
// 底部导航栏
|
||||
BottomNavigation({
|
||||
activePage: 'class',
|
||||
themeColor: this.settings.themeColor,
|
||||
texts: this.texts
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
// 学生视图
|
||||
@Builder
|
||||
StudentView() {
|
||||
Column() {
|
||||
// 学生上课指引卡片
|
||||
Column() {
|
||||
Text("学生上课")
|
||||
.fontSize(24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
Text("请输入老师提供的课堂暗号进入课堂")
|
||||
.fontSize(16)
|
||||
.fontColor('#666')
|
||||
.margin({ bottom: 20 })
|
||||
|
||||
// 暗号输入框
|
||||
Column({ space: 8 }) {
|
||||
Text("课堂暗号")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入4-6位数字暗号' })
|
||||
.type(InputType.Number)
|
||||
.maxLength(6)
|
||||
.placeholderColor('#999999')
|
||||
.placeholderFont({ size: 16 })
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.backgroundColor('#F5F5F5')
|
||||
.borderRadius(8)
|
||||
.padding({ left: 16, right: 16 })
|
||||
.onChange((value: string) => {
|
||||
this.classCode = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
// 错误信息
|
||||
if (this.errorMessage !== '') {
|
||||
Text(this.errorMessage)
|
||||
.fontSize(14)
|
||||
.fontColor('#FF0000')
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
}
|
||||
|
||||
// 加入课堂按钮
|
||||
Button("加入课堂")
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.borderRadius(8)
|
||||
.fontColor(Color.White)
|
||||
.enabled(!this.isLoading)
|
||||
.opacity(this.isLoading ? 0.6 : 1)
|
||||
.onClick(() => {
|
||||
this.joinClass();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(12)
|
||||
.padding(20)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
.margin({ top: 20, bottom: 20 })
|
||||
|
||||
// 当前课程信息卡片(只在没有正在进行的课程时显示)
|
||||
Column() {
|
||||
Text("近期课程").fontSize(20).fontWeight(FontWeight.Bold).margin({ bottom: 16 })
|
||||
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.currentClassInfo.name)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
Text(`${this.texts.teacher}: ${this.currentClassInfo.teacher}`)
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ top: 8 })
|
||||
Text(`${this.texts.classroom}: ${this.currentClassInfo.room}`)
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
Column() {
|
||||
Text("未开始")
|
||||
.fontSize(14)
|
||||
.fontColor('#999')
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(12)
|
||||
.padding({ left: 12, right: 12, top: 6, bottom: 6 })
|
||||
}
|
||||
.justifyContent(FlexAlign.Center)
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.borderRadius(8)
|
||||
.backgroundColor('#f9f9f9')
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(12)
|
||||
.padding(20)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
}
|
||||
}
|
||||
|
||||
// 教师视图
|
||||
@Builder
|
||||
TeacherView() {
|
||||
Column() {
|
||||
// 教师上课指引卡片
|
||||
Column() {
|
||||
Text("教师上课")
|
||||
.fontSize(24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
Text("点击下方按钮创建新课堂")
|
||||
.fontSize(16)
|
||||
.fontColor('#666')
|
||||
.margin({ bottom: 20 })
|
||||
|
||||
// 创建课堂按钮
|
||||
Button("创建新课堂")
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.borderRadius(8)
|
||||
.fontColor(Color.White)
|
||||
.enabled(!this.isLoading)
|
||||
.opacity(this.isLoading ? 0.6 : 1)
|
||||
.onClick(() => {
|
||||
this.showCreateClassDialog = true;
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(12)
|
||||
.padding(20)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
.margin({ top: 20, bottom: 20 })
|
||||
|
||||
// 历史课堂记录
|
||||
Column() {
|
||||
Text("历史课堂").fontSize(20).fontWeight(FontWeight.Bold).margin({ bottom: 16 })
|
||||
|
||||
// 示例历史课堂卡片
|
||||
Row() {
|
||||
Column() {
|
||||
Text("高等数学")
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
Text("课堂暗号: 123456")
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ top: 8 })
|
||||
Text("2025-04-01 10:30")
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
Column() {
|
||||
Text("已结束")
|
||||
.fontSize(14)
|
||||
.fontColor('#999')
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(12)
|
||||
.padding({ left: 12, right: 12, top: 6, bottom: 6 })
|
||||
}
|
||||
.justifyContent(FlexAlign.Center)
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.borderRadius(8)
|
||||
.backgroundColor('#f9f9f9')
|
||||
.margin({ bottom: 12 })
|
||||
|
||||
// 示例历史课堂卡片
|
||||
Row() {
|
||||
Column() {
|
||||
Text("线性代数")
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
Text("课堂暗号: 654321")
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ top: 8 })
|
||||
Text("2025-03-30 14:30")
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
Column() {
|
||||
Text("已结束")
|
||||
.fontSize(14)
|
||||
.fontColor('#999')
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(12)
|
||||
.padding({ left: 12, right: 12, top: 6, bottom: 6 })
|
||||
}
|
||||
.justifyContent(FlexAlign.Center)
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.borderRadius(8)
|
||||
.backgroundColor('#f9f9f9')
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(12)
|
||||
.padding(20)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
}
|
||||
}
|
||||
|
||||
// 未知角色视图
|
||||
@Builder
|
||||
UnknownRoleView() {
|
||||
Column() {
|
||||
Text("用户角色未知")
|
||||
.fontSize(24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
Text("系统无法识别您的用户角色,请联系管理员或重新登录")
|
||||
.fontSize(16)
|
||||
.fontColor('#666')
|
||||
.margin({ bottom: 20 })
|
||||
|
||||
Button("返回登录")
|
||||
.width('60%')
|
||||
.height(50)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.borderRadius(8)
|
||||
.fontColor(Color.White)
|
||||
.onClick(() => {
|
||||
// 返回登录页
|
||||
router.replaceUrl({
|
||||
url: 'pages/login'
|
||||
});
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(12)
|
||||
.padding(20)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
.margin({ top: 20 })
|
||||
}
|
||||
|
||||
// 创建课堂对话框
|
||||
@Builder
|
||||
CreateClassDialog() {
|
||||
// 遮罩层
|
||||
Column() {
|
||||
// 对话框内容
|
||||
Column() {
|
||||
// 标题
|
||||
Text("创建新课堂")
|
||||
.fontSize(22)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 24 })
|
||||
|
||||
// 课堂名称
|
||||
Column({ space: 8 }) {
|
||||
Text("课堂名称")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入课堂名称' })
|
||||
.maxLength(20)
|
||||
.placeholderColor('#999999')
|
||||
.placeholderFont({ size: 16 })
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.backgroundColor('#F5F5F5')
|
||||
.borderRadius(8)
|
||||
.padding({ left: 16, right: 16 })
|
||||
.onChange((value: string) => {
|
||||
this.className = value;
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
// 课堂暗号
|
||||
Column({ space: 8 }) {
|
||||
Text("课堂暗号")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入4-6位数字暗号' })
|
||||
.type(InputType.Number)
|
||||
.maxLength(6)
|
||||
.placeholderColor('#999999')
|
||||
.placeholderFont({ size: 16 })
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.backgroundColor('#F5F5F5')
|
||||
.borderRadius(8)
|
||||
.padding({ left: 16, right: 16 })
|
||||
.onChange((value: string) => {
|
||||
this.classCode = value;
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
// 错误信息
|
||||
if (this.errorMessage !== '') {
|
||||
Text(this.errorMessage)
|
||||
.fontSize(14)
|
||||
.fontColor('#FF0000')
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
}
|
||||
|
||||
// 按钮组
|
||||
Row({ space: 20 }) {
|
||||
Button("取消")
|
||||
.width('45%')
|
||||
.height(45)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(8)
|
||||
.fontColor('#333')
|
||||
.onClick(() => {
|
||||
this.showCreateClassDialog = false;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
|
||||
Button("创建")
|
||||
.width('45%')
|
||||
.height(45)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.borderRadius(8)
|
||||
.fontColor(Color.White)
|
||||
.enabled(!this.isLoading)
|
||||
.opacity(this.isLoading ? 0.6 : 1)
|
||||
.onClick(() => {
|
||||
this.createClass();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.width('85%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(16)
|
||||
.padding(24)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('rgba(0,0,0,0.5)')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.onClick(() => {
|
||||
// 点击遮罩不关闭对话框
|
||||
// 只能通过按钮关闭
|
||||
})
|
||||
}
|
||||
|
||||
// 加入课堂对话框
|
||||
@Builder
|
||||
JoinClassDialog() {
|
||||
// 遮罩层
|
||||
Column() {
|
||||
// 对话框内容
|
||||
Column() {
|
||||
// 标题
|
||||
Text("加入课堂")
|
||||
.fontSize(22)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 24 })
|
||||
|
||||
// 课堂暗号
|
||||
Column({ space: 8 }) {
|
||||
Text("课堂暗号")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入4-6位数字暗号' })
|
||||
.type(InputType.Number)
|
||||
.maxLength(6)
|
||||
.placeholderColor('#999999')
|
||||
.placeholderFont({ size: 16 })
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.backgroundColor('#F5F5F5')
|
||||
.borderRadius(8)
|
||||
.padding({ left: 16, right: 16 })
|
||||
.onChange((value: string) => {
|
||||
this.classCode = value;
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
|
||||
// 错误信息
|
||||
if (this.errorMessage !== '') {
|
||||
Text(this.errorMessage)
|
||||
.fontSize(14)
|
||||
.fontColor('#FF0000')
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
}
|
||||
|
||||
// 按钮组
|
||||
Row({ space: 20 }) {
|
||||
Button("取消")
|
||||
.width('45%')
|
||||
.height(45)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(8)
|
||||
.fontColor('#333')
|
||||
.onClick(() => {
|
||||
this.showJoinClassDialog = false;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
|
||||
Button("加入")
|
||||
.width('45%')
|
||||
.height(45)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor(this.settings.themeColor)
|
||||
.borderRadius(8)
|
||||
.fontColor(Color.White)
|
||||
.enabled(!this.isLoading)
|
||||
.opacity(this.isLoading ? 0.6 : 1)
|
||||
.onClick(() => {
|
||||
this.joinClass();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.width('85%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(16)
|
||||
.padding(24)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('rgba(0,0,0,0.5)')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.onClick(() => {
|
||||
// 点击遮罩不关闭对话框
|
||||
// 只能通过按钮关闭
|
||||
})
|
||||
}
|
||||
|
||||
// 创建课堂方法
|
||||
private async createClass() {
|
||||
// 参数验证
|
||||
if (!this.className || this.className.trim() === '') {
|
||||
this.errorMessage = '请输入课堂名称';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.classCode || this.classCode.trim() === '') {
|
||||
this.errorMessage = '请输入课堂暗号';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^\d{4,6}$/.test(this.classCode)) {
|
||||
this.errorMessage = '课堂暗号必须是4-6位数字';
|
||||
return;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
|
||||
// 连接服务
|
||||
await classRoomService.connect();
|
||||
|
||||
// 创建课堂
|
||||
try {
|
||||
const classSession = await classRoomService.createClassSession(this.className, this.classCode);
|
||||
|
||||
if (classSession) {
|
||||
// 创建成功
|
||||
this.showCreateClassDialog = false;
|
||||
this.errorMessage = '';
|
||||
|
||||
// 跳转到教师上课页面
|
||||
router.pushUrl({
|
||||
url: 'pages/ClassLivePage',
|
||||
params: {
|
||||
mode: 'teacher'
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.errorMessage = '创建课堂失败,请稍后再试';
|
||||
}
|
||||
} catch (error) {
|
||||
this.errorMessage = '创建过程中发生错误,请稍后再试';
|
||||
logManager.error(LogCategory.CLASS, `Create class error: ${error}`);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 加入课堂方法
|
||||
private async joinClass() {
|
||||
// 参数验证
|
||||
if (!this.classCode || this.classCode.trim() === '') {
|
||||
this.errorMessage = '请输入课堂暗号';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^\d{4,6}$/.test(this.classCode)) {
|
||||
this.errorMessage = '课堂暗号必须是4-6位数字';
|
||||
return;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
|
||||
// 连接服务
|
||||
await classRoomService.connect();
|
||||
|
||||
// 加入课堂
|
||||
try {
|
||||
const result = await classRoomService.joinClassSession(this.classCode);
|
||||
|
||||
if (result) {
|
||||
// 加入成功
|
||||
this.showJoinClassDialog = false;
|
||||
this.errorMessage = '';
|
||||
|
||||
// 跳转到学生上课页面
|
||||
router.pushUrl({
|
||||
url: 'pages/ClassLivePage',
|
||||
params: {
|
||||
mode: 'student'
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.errorMessage = '加入课堂失败,请检查暗号是否正确';
|
||||
}
|
||||
} catch (error) {
|
||||
this.errorMessage = '加入过程中发生错误,请稍后再试';
|
||||
logManager.error(LogCategory.CLASS, `Join class error: ${error}`);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 页面生命周期方法
|
||||
onPageShow(): void {
|
||||
@ -256,10 +894,7 @@ struct BottomNavigation {
|
||||
.onClick(() => {
|
||||
if (this.activePage !== 'settings') {
|
||||
router.replaceUrl({
|
||||
url: 'pages/SettingsPage',
|
||||
params: {
|
||||
direction: 'right' // 从上课页向右切换到设置页
|
||||
}
|
||||
url: 'pages/SettingsPage'
|
||||
});
|
||||
}
|
||||
})
|
||||
@ -267,8 +902,12 @@ struct BottomNavigation {
|
||||
.width('100%')
|
||||
.height(60)
|
||||
.backgroundColor(Color.White)
|
||||
.border({ color: '#eeeeee', width: 1, style: BorderStyle.Solid })
|
||||
.borderWidth({ top: 0.5 })
|
||||
.borderColor('#eeeeee')
|
||||
.padding({ top: 8, bottom: 8 })
|
||||
}
|
||||
}
|
||||
|
||||
export { ClassPage }
|
||||
|
||||
|
||||
|
@ -1,40 +1,118 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
import settingsService, { SettingsModel, TextResources } from '../common/SettingsService';
|
||||
import web_webview from '@ohos.web.webview';
|
||||
|
||||
// 摄像头接口定义
|
||||
interface CameraType {
|
||||
name: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct HomePage {
|
||||
@State message: string = '智慧教室管理系统';
|
||||
@State classroomMonitorData: MonitorDataType = {
|
||||
roomId: '',
|
||||
temperature: 0,
|
||||
humidity: 0,
|
||||
occupancy: 0,
|
||||
status: ''
|
||||
roomId: 'A301',
|
||||
temperature: 25.5,
|
||||
humidity: 60,
|
||||
occupancy: 32,
|
||||
status: '正常'
|
||||
};
|
||||
@State comprehensiveClassData: ClassDataType = {
|
||||
classId: '',
|
||||
subjectName: '',
|
||||
teacherName: '',
|
||||
duration: 0,
|
||||
studentCount: 0
|
||||
classId: 'CS101',
|
||||
subjectName: '高等数学',
|
||||
teacherName: '张教授',
|
||||
duration: 95,
|
||||
studentCount: 45
|
||||
};
|
||||
|
||||
// 摄像头URL
|
||||
@State currentCameraUrl: string = 'https://www.skylinewebcams.com/webcam/maldives/lhaviyani-atoll/kuredu/kuredu-island-resort.html';
|
||||
|
||||
// 摄像头列表
|
||||
private cameras: Array<CameraType> = [
|
||||
{
|
||||
name: '马尔代夫库雷都岛',
|
||||
url: 'https://www.skylinewebcams.com/webcam/maldives/lhaviyani-atoll/kuredu/kuredu-island-resort.html'
|
||||
},
|
||||
{
|
||||
name: '意大利米兰大教堂',
|
||||
url: 'https://www.skylinewebcams.com/webcam/italia/lombardia/milano/duomo-milano.html'
|
||||
},
|
||||
{
|
||||
name: '埃及吉萨金字塔',
|
||||
url: 'https://www.skylinewebcams.com/webcam/egypt/cairo/cairo/pyramids-giza.html'
|
||||
}
|
||||
];
|
||||
|
||||
// 从设置服务获取设置
|
||||
@State settings: SettingsModel = settingsService.getSettings();
|
||||
// 获取文本资源
|
||||
@State texts: TextResources = settingsService.getTextResources();
|
||||
|
||||
//确保每次从EntryAbility传递过来的参数都能刷新到UI
|
||||
@StorageLink('userName') userName: string = AppStorage.get('userName') || '';
|
||||
|
||||
|
||||
aboutToAppear() {
|
||||
|
||||
/* // 确保在组件出现之前从AppStorage获取最新的值
|
||||
this.userName = AppStorage.get('userName') || '';*/
|
||||
|
||||
// 注册语言变化的回调
|
||||
settingsService.registerLanguageChangeCallback(() => {
|
||||
this.texts = settingsService.getTextResources();
|
||||
this.message = this.texts.title;
|
||||
});
|
||||
|
||||
// 获取当前用户名
|
||||
this.userName = settingsService.getUserNickname() || settingsService.getCurrentAccount() || '访客';
|
||||
|
||||
// 注册用户信息变化的回调
|
||||
settingsService.registerUserInfoChangeCallback(() => {
|
||||
this.userName = settingsService.getUserNickname() || settingsService.getCurrentAccount() || '访客';
|
||||
});
|
||||
|
||||
// 初始化文本
|
||||
this.message = this.texts.title;
|
||||
|
||||
// 注册摄像头选择事件
|
||||
this.registerCameraSelectorEvent();
|
||||
}
|
||||
|
||||
// 注册摄像头选择事件
|
||||
private registerCameraSelectorEvent() {
|
||||
getContext(this).eventHub.on('showCameraSelector', () => {
|
||||
this.showCameraSelector();
|
||||
});
|
||||
}
|
||||
|
||||
// 显示摄像头选择对话框
|
||||
private showCameraSelector() {
|
||||
// 创建一个CustomDialogController
|
||||
let dialogController = new CustomDialogController({
|
||||
builder: CameraDialogBuilder({
|
||||
cameras: this.cameras,
|
||||
onSelect: (url: string, name: string) => {
|
||||
this.currentCameraUrl = url;
|
||||
console.info(`选择了摄像头: ${name}`);
|
||||
}
|
||||
}),
|
||||
cancel: () => {
|
||||
console.info('取消选择摄像头');
|
||||
},
|
||||
autoCancel: true,
|
||||
alignment: DialogAlignment.Center
|
||||
});
|
||||
|
||||
// 显示对话框
|
||||
dialogController.open();
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -61,7 +139,7 @@ struct HomePage {
|
||||
step: 6, // 降低步长,使滚动更慢
|
||||
loop: -1,
|
||||
fromStart: true,
|
||||
src: "欢迎使用【智能教室管理系统】,本项目由【922213102班鸿蒙第一组】制作,相关服务正在完善,欢迎您的使用!!"
|
||||
src: "欢迎【" + this.userName + "】,使用【智能教室管理系统】,本项目由【922213102班鸿蒙第一组】制作,相关服务正在完善,欢迎您的使用!!"
|
||||
})
|
||||
.width('90%')
|
||||
.height(30)
|
||||
@ -80,7 +158,8 @@ struct HomePage {
|
||||
Card({
|
||||
title: this.texts.classroomMonitor,
|
||||
data: this.classroomMonitorData,
|
||||
themeColor: this.settings.themeColor
|
||||
themeColor: this.settings.themeColor,
|
||||
cameraUrl: this.currentCameraUrl
|
||||
})
|
||||
.margin({ top: 16, bottom: 16 })
|
||||
|
||||
@ -89,7 +168,8 @@ struct HomePage {
|
||||
Card({
|
||||
title: this.texts.comprehensiveData,
|
||||
data: this.comprehensiveClassData,
|
||||
themeColor: this.settings.themeColor
|
||||
themeColor: this.settings.themeColor,
|
||||
cameraUrl: this.currentCameraUrl
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
@ -174,7 +254,10 @@ struct Card {
|
||||
title: string = '';
|
||||
data: MonitorDataType | ClassDataType = {} as MonitorDataType;
|
||||
themeColor: string = '#409eff';
|
||||
|
||||
|
||||
// 接收摄像头URL
|
||||
@Link cameraUrl: string;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 卡片标题
|
||||
@ -188,17 +271,13 @@ struct Card {
|
||||
.padding({ top: 8, bottom: 16 })
|
||||
|
||||
// 图表内容
|
||||
Column() {
|
||||
Text('图表内容1')
|
||||
.fontSize(16)
|
||||
.fontColor('#999')
|
||||
.height(150)
|
||||
.width('100%')
|
||||
.textAlign(TextAlign.Center)
|
||||
if (this.isMonitorData()) {
|
||||
// 教室监控数据显示
|
||||
this.MonitorDataChart()
|
||||
} else {
|
||||
// 综合上课数据显示
|
||||
this.ClassDataChart()
|
||||
}
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(8)
|
||||
.width('100%')
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
@ -206,6 +285,241 @@ struct Card {
|
||||
.padding(16)
|
||||
.shadow({ radius: 6, color: '#eeeeee' })
|
||||
}
|
||||
|
||||
// 判断是否为监控数据类型
|
||||
private isMonitorData(): boolean {
|
||||
// 使用特有属性进行区分
|
||||
return (this.data as MonitorDataType).temperature !== undefined;
|
||||
}
|
||||
|
||||
// 教室监控数据图表
|
||||
@Builder
|
||||
MonitorDataChart() {
|
||||
Column() {
|
||||
// 监控摄像头视频
|
||||
Column() {
|
||||
Web({ src: this.cameraUrl, controller: new web_webview.WebviewController() })
|
||||
.width('100%')
|
||||
.height(200)
|
||||
.zoomAccess(false) // 禁用缩放
|
||||
.onPageBegin(() => {
|
||||
console.info('网页开始加载');
|
||||
})
|
||||
.onPageEnd(() => {
|
||||
console.info('网页加载完成');
|
||||
})
|
||||
.onErrorReceive((event) => {
|
||||
console.error('网页加载失败', event);
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
// 传感器数据展示
|
||||
Row() {
|
||||
// 温度展示
|
||||
Column() {
|
||||
Text('温度')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Row() {
|
||||
Text((this.data as MonitorDataType).temperature.toString())
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(this.themeColor)
|
||||
Text('°C')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ left: 4 })
|
||||
}
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 湿度展示
|
||||
Column() {
|
||||
Text('湿度')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Row() {
|
||||
Text((this.data as MonitorDataType).humidity.toString())
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(this.themeColor)
|
||||
Text('%')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ left: 4 })
|
||||
}
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 人数展示
|
||||
Column() {
|
||||
Text('人数')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Text((this.data as MonitorDataType).occupancy.toString())
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(this.themeColor)
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 8 })
|
||||
|
||||
// 状态和操作按钮
|
||||
Row() {
|
||||
// 状态展示
|
||||
Column() {
|
||||
Text('状态')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Text((this.data as MonitorDataType).status || '正常')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor(this.getStatusColor((this.data as MonitorDataType).status))
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
// 切换摄像头按钮
|
||||
Button('切换摄像头', { type: ButtonType.Capsule })
|
||||
.fontSize(14)
|
||||
.height(32)
|
||||
.backgroundColor(this.themeColor)
|
||||
.onClick(() => {
|
||||
// 显示摄像头选择对话框
|
||||
this.showCameraSelector();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.SpaceBetween)
|
||||
}
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(8)
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
}
|
||||
|
||||
// 显示摄像头选择器
|
||||
private showCameraSelector() {
|
||||
if (getContext(this) && getContext(this).eventHub) {
|
||||
// 触发自定义事件,在HomePage中处理
|
||||
getContext(this).eventHub.emit('showCameraSelector', {});
|
||||
}
|
||||
}
|
||||
|
||||
// 综合上课数据图表
|
||||
@Builder
|
||||
ClassDataChart() {
|
||||
Column() {
|
||||
// 课程信息
|
||||
Row() {
|
||||
Column() {
|
||||
Text('课程')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Text((this.data as ClassDataType).subjectName || '未指定')
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor('#333')
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
Column() {
|
||||
Text('教师')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Text((this.data as ClassDataType).teacherName || '未指定')
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor('#333')
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 20 })
|
||||
|
||||
// 课堂数据
|
||||
Row() {
|
||||
// 课堂时长
|
||||
Column() {
|
||||
Text('时长')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Row() {
|
||||
Text(this.formatDuration((this.data as ClassDataType).duration))
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(this.themeColor)
|
||||
}
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 学生人数
|
||||
Column() {
|
||||
Text('学生人数')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
Row() {
|
||||
Text((this.data as ClassDataType).studentCount.toString())
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(this.themeColor)
|
||||
Text('人')
|
||||
.fontSize(14)
|
||||
.fontColor('#666')
|
||||
.margin({ left: 4 })
|
||||
}
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(8)
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
}
|
||||
|
||||
// 获取状态对应的颜色
|
||||
private getStatusColor(status: string): string {
|
||||
switch (status) {
|
||||
case '警告':
|
||||
return '#E6A23C';
|
||||
case '危险':
|
||||
return '#F56C6C';
|
||||
case '正常':
|
||||
default:
|
||||
return '#67C23A';
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化时长(分钟转为小时和分钟)
|
||||
private formatDuration(minutes: number): string {
|
||||
if (!minutes) return '0分钟';
|
||||
|
||||
if (minutes < 60) {
|
||||
return `${minutes}分钟`;
|
||||
}
|
||||
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const remainingMinutes = minutes % 60;
|
||||
|
||||
if (remainingMinutes === 0) {
|
||||
return `${hours}小时`;
|
||||
}
|
||||
|
||||
return `${hours}小时${remainingMinutes}分钟`;
|
||||
}
|
||||
}
|
||||
|
||||
// 底部导航栏组件
|
||||
@ -288,4 +602,66 @@ struct BottomNavigation {
|
||||
.backgroundColor(Color.White)
|
||||
.border({ color: '#eeeeee', width: 1, style: BorderStyle.Solid })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义摄像头选择对话框
|
||||
@CustomDialog
|
||||
struct CameraDialogBuilder {
|
||||
controller: CustomDialogController;
|
||||
@Prop cameras: Array<CameraType> = [];
|
||||
@Prop onSelect: (url: string, name: string) => void = () => {};
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Text('选择监控摄像头')
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ top: 20, bottom: 16 })
|
||||
|
||||
List() {
|
||||
ForEach(this.cameras, (camera: CameraType) => {
|
||||
ListItem() {
|
||||
Row() {
|
||||
Text(camera.name)
|
||||
.fontSize(16)
|
||||
.fontColor('#333')
|
||||
|
||||
Blank()
|
||||
|
||||
Button('选择')
|
||||
.fontSize(14)
|
||||
.height(32)
|
||||
.backgroundColor('#409eff')
|
||||
.onClick(() => {
|
||||
this.onSelect(camera.url, camera.name);
|
||||
this.controller.close();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.padding(12)
|
||||
.justifyContent(FlexAlign.SpaceBetween)
|
||||
}
|
||||
.backgroundColor('#f5f5f5')
|
||||
.borderRadius(8)
|
||||
.margin({ bottom: 8 })
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.layoutWeight(1)
|
||||
|
||||
Button('取消')
|
||||
.fontSize(16)
|
||||
.width('40%')
|
||||
.margin({ top: 16, bottom: 20 })
|
||||
.onClick(() => {
|
||||
this.controller.close();
|
||||
})
|
||||
}
|
||||
.width('80%')
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(16)
|
||||
.padding(16)
|
||||
}
|
||||
}
|
||||
|
||||
export { HomePage }
|
31
entry/src/main/ets/pages/Index.ets
Normal file
@ -0,0 +1,31 @@
|
||||
import router from '@ohos.router';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
build() {
|
||||
Column() {
|
||||
Text('Welcome to ClassMG')
|
||||
.fontSize(24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 20 })
|
||||
|
||||
Text('This is the default index page')
|
||||
.fontSize(16)
|
||||
.margin({ bottom: 40 })
|
||||
|
||||
Button('Go to Login')
|
||||
.onClick(() => {
|
||||
router.pushUrl({ url: 'pages/login' });
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
}
|
||||
}
|
||||
|
||||
export default function DefaultIndex() {
|
||||
return;
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import settingsService, { ThemeColor, Language, SettingsModel, TextResources, UserInfoModel } from '../common/SettingsService';
|
||||
@ -177,6 +181,8 @@ struct SettingsPage {
|
||||
}
|
||||
}
|
||||
|
||||
export { SettingsPage }
|
||||
|
||||
// 用户信息卡片组件 - 美化版
|
||||
@Component
|
||||
struct UserCard {
|
||||
@ -600,7 +606,7 @@ struct SystemSettings {
|
||||
|
||||
// 添加日志记录设置项
|
||||
SettingItem({
|
||||
title: this.texts.versionLog || '更新日志',
|
||||
title: this.texts.versionLog || '日志记录',
|
||||
value: '点一点',
|
||||
refreshTrigger: this.refreshTrigger,
|
||||
themeColor: this.themeColor,
|
||||
@ -813,16 +819,9 @@ struct SystemSettings {
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保版本日志按版本号降序排列
|
||||
// 使用LogManager的版本比较逻辑进行排序
|
||||
const sortedLogs = [...versionLogs].sort((a, b) => {
|
||||
const vA = a.version.split('.').map(Number);
|
||||
const vB = b.version.split('.').map(Number);
|
||||
for (let i = 0; i < Math.max(vA.length, vB.length); i++) {
|
||||
const numA = i < vA.length ? vA[i] : 0;
|
||||
const numB = i < vB.length ? vB[i] : 0;
|
||||
if (numB - numA !== 0) return numB - numA;
|
||||
}
|
||||
return 0;
|
||||
return logManager.compareVersions(a.version, b.version);
|
||||
});
|
||||
|
||||
// 构建版本日志内容
|
||||
@ -837,7 +836,7 @@ struct SystemSettings {
|
||||
|
||||
// 显示对话框
|
||||
AlertDialog.show({
|
||||
title: '更新日志',
|
||||
title: '日志记录',
|
||||
message: message,
|
||||
confirm: {
|
||||
value: this.currentLanguage === Language.CHINESE ? '确定' : 'OK',
|
||||
|
55
entry/src/main/ets/pages/StartPage.ets
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import settingsService from '../common/SettingsService';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct StartPage {
|
||||
@State isLoggedIn: boolean = false;
|
||||
|
||||
aboutToAppear() {
|
||||
// Check if user is logged in
|
||||
const currentAccount = settingsService.getCurrentAccount();
|
||||
this.isLoggedIn = !!currentAccount;
|
||||
|
||||
// Auto navigate after checking login status
|
||||
setTimeout(() => {
|
||||
if (this.isLoggedIn) {
|
||||
router.replaceUrl({
|
||||
url: 'pages/HomePage'
|
||||
});
|
||||
} else {
|
||||
router.replaceUrl({
|
||||
url: 'pages/login'
|
||||
});
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Image($r('app.media.tdcat'))
|
||||
.width(150)
|
||||
.height(150)
|
||||
.margin({ bottom: 20 })
|
||||
Text('智能教室管理系统')
|
||||
.fontSize(24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 40 })
|
||||
LoadingProgress()
|
||||
.width(50)
|
||||
.height(50)
|
||||
.color('#2196F3')
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('#FFFFFF')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
}
|
||||
}
|
||||
|
||||
export { StartPage }
|
264
entry/src/main/ets/pages/TransitionPage.ets
Normal file
@ -0,0 +1,264 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import settingsService from '../common/SettingsService';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
|
||||
// 粒子信息类型
|
||||
class ParticleInfo {
|
||||
x: number = 0;
|
||||
y: number = 0;
|
||||
size: number = 0;
|
||||
opacity: number = 0;
|
||||
speed: number = 0;
|
||||
color: string = '#ffffff';
|
||||
|
||||
constructor(x: number = 0,
|
||||
y: number = 0,
|
||||
size: number = 0,
|
||||
opacity: number = 0,
|
||||
speed: number = 0,
|
||||
color: string = '#ffffff') {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.size = size;
|
||||
this.opacity = opacity;
|
||||
this.speed = speed;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TransitionPage {
|
||||
@State userName: string = '';
|
||||
@State welcomeMessage: string = '欢迎使用智慧教室管理系统';
|
||||
@State contentOpacity: number = 0;
|
||||
@State scaleValue: number = 0.8;
|
||||
@State rotationAngle: number = -10;
|
||||
@State translateYValue: number = 100;
|
||||
|
||||
// 为粒子动画定义状态
|
||||
@State particles: ParticleInfo[] = [];
|
||||
private particleCount: number = 30; // 降低粒子数量避免性能问题
|
||||
private particleTimer: number = 0;
|
||||
private bgColorStop: number = 0;
|
||||
@State backgroundGradient: string = 'linear-gradient(45deg, #4c71f2, #42a7f0)';
|
||||
|
||||
// 创建粒子
|
||||
private createParticles() {
|
||||
let newParticles: ParticleInfo[] = [];
|
||||
for (let i = 0; i < this.particleCount; i++) {
|
||||
let particle = new ParticleInfo(
|
||||
Math.random() * 100, // x位置 (百分比)
|
||||
Math.random() * 100, // y位置 (百分比)
|
||||
Math.random() * 8 + 2, // 粒子大小
|
||||
Math.random() * 0.6 + 0.1, // 初始透明度
|
||||
Math.random() * 0.5 + 0.1, // 移动速度
|
||||
i % 3 === 0 ? '#ffffff' : (i % 3 === 1 ? '#aaccff' : '#77aaff') // 随机颜色
|
||||
);
|
||||
newParticles.push(particle);
|
||||
}
|
||||
this.particles = newParticles;
|
||||
}
|
||||
|
||||
// 更新粒子动画
|
||||
private updateParticles() {
|
||||
this.particleTimer = setInterval(() => {
|
||||
let updatedParticles: ParticleInfo[] = [];
|
||||
|
||||
for (let i = 0; i < this.particles.length; i++) {
|
||||
let p = this.particles[i];
|
||||
// 更新位置
|
||||
let newY = p.y - p.speed;
|
||||
if (newY < -5) {
|
||||
newY = 105; // 当粒子移出屏幕顶部时,从底部重新进入
|
||||
p.x = Math.random() * 100;
|
||||
}
|
||||
|
||||
let newOpacity = p.opacity + (Math.random() * 0.1 - 0.05);
|
||||
// 确保透明度在合理范围内
|
||||
if (newOpacity < 0.1) newOpacity = 0.1;
|
||||
if (newOpacity > 0.8) newOpacity = 0.8;
|
||||
|
||||
// 创建更新后的粒子对象
|
||||
let updatedParticle = new ParticleInfo(
|
||||
p.x,
|
||||
newY,
|
||||
p.size,
|
||||
newOpacity,
|
||||
p.speed,
|
||||
p.color
|
||||
);
|
||||
|
||||
updatedParticles.push(updatedParticle);
|
||||
}
|
||||
|
||||
this.particles = updatedParticles;
|
||||
|
||||
// 更新背景渐变
|
||||
this.bgColorStop = (this.bgColorStop + 0.005) % 1;
|
||||
const hue1 = Math.floor((220 + Math.sin(this.bgColorStop * Math.PI * 2) * 20) % 360);
|
||||
const hue2 = Math.floor((190 + Math.cos(this.bgColorStop * Math.PI * 2) * 20) % 360);
|
||||
this.backgroundGradient = `linear-gradient(45deg, hsl(${hue1}, 70%, 60%), hsl(${hue2}, 70%, 60%))`;
|
||||
|
||||
}, 50);
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
// 设置用户名称
|
||||
this.userName = settingsService.getUserNickname();
|
||||
|
||||
// 创建并开始粒子动画
|
||||
this.createParticles();
|
||||
this.updateParticles();
|
||||
|
||||
// 第一阶段动画:元素进入
|
||||
animateTo({ duration: 1000, curve: Curve.Ease }, () => {
|
||||
this.contentOpacity = 1;
|
||||
this.scaleValue = 1;
|
||||
this.rotationAngle = 0;
|
||||
this.translateYValue = 0;
|
||||
});
|
||||
|
||||
// 3秒后开始退出动画
|
||||
setTimeout(() => {
|
||||
// 第二阶段动画:放大效果
|
||||
animateTo({ duration: 300, curve: Curve.EaseIn }, () => {
|
||||
this.scaleValue = 1.1;
|
||||
this.rotationAngle = 0;
|
||||
});
|
||||
|
||||
// 第三阶段动画:淡出效果
|
||||
setTimeout(() => {
|
||||
animateTo({ duration: 700, curve: Curve.EaseOut }, () => {
|
||||
this.contentOpacity = 0;
|
||||
this.scaleValue = 0.5;
|
||||
this.translateYValue = -50;
|
||||
});
|
||||
|
||||
// 等待动画结束后跳转
|
||||
setTimeout(() => {
|
||||
// 停止粒子动画定时器
|
||||
clearInterval(this.particleTimer);
|
||||
router.pushUrl({
|
||||
url: 'pages/HomePage'
|
||||
});
|
||||
}, 700);
|
||||
}, 300);
|
||||
}, 3000);
|
||||
|
||||
// 记录过渡
|
||||
this.Log_Event('aboutToAppear');
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
// 清除粒子动画定时器
|
||||
if (this.particleTimer) {
|
||||
clearInterval(this.particleTimer);
|
||||
}
|
||||
this.Log_Event('aboutToDisappear');
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 粒子动画层
|
||||
Stack() {
|
||||
// 渐变背景
|
||||
Column()
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundImage(this.backgroundGradient)
|
||||
|
||||
// 粒子效果
|
||||
ForEach(this.particles, (item: ParticleInfo) => {
|
||||
Circle()
|
||||
.fill(item.color)
|
||||
.width(item.size)
|
||||
.height(item.size)
|
||||
.position({ x: `${item.x}%`, y: `${item.y}%` })
|
||||
.opacity(item.opacity)
|
||||
})
|
||||
|
||||
// 内容层
|
||||
Column() {
|
||||
Image('http://139.155.155.67:2342/images/default_avatar.png')
|
||||
.width(120)
|
||||
.height(120)
|
||||
.borderRadius(60)
|
||||
.margin({ bottom: 40 })
|
||||
|
||||
Text(this.userName)
|
||||
.fontSize(42)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor('#FFFFFF')
|
||||
.margin({ bottom: 20 })
|
||||
|
||||
Text(this.welcomeMessage)
|
||||
.fontSize(26)
|
||||
.fontColor('rgba(255, 255, 255, 0.9)')
|
||||
|
||||
Row()
|
||||
.width(150)
|
||||
.height(4)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.borderRadius(2)
|
||||
.margin({ top: 30 })
|
||||
.opacity(0.7)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.opacity(this.contentOpacity)
|
||||
.scale({ x: this.scaleValue, y: this.scaleValue })
|
||||
.rotate({ angle: this.rotationAngle })
|
||||
.translate({ y: this.translateYValue })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
// 页面生命周期方法
|
||||
onPageShow(): void {
|
||||
this.Log_Event('onPageShow');
|
||||
}
|
||||
|
||||
onPageHide(): void {
|
||||
this.Log_Event('onPageHide');
|
||||
}
|
||||
|
||||
onBackPress(): boolean {
|
||||
this.Log_Event('onBackPress');
|
||||
return true; // 防止返回
|
||||
}
|
||||
|
||||
// 日志记录方法
|
||||
public Log_Event(eventName: string): void {
|
||||
// 根据事件名称选择合适的日志事件类型
|
||||
switch (eventName) {
|
||||
case 'aboutToAppear':
|
||||
logManager.info(LogCategory.USER, LogEventType.PAGE_APPEAR, 'TransitionPage');
|
||||
break;
|
||||
case 'aboutToDisappear':
|
||||
logManager.info(LogCategory.USER, LogEventType.PAGE_DISAPPEAR, 'TransitionPage');
|
||||
break;
|
||||
case 'onPageShow':
|
||||
logManager.info(LogCategory.USER, LogEventType.PAGE_SHOW, 'TransitionPage');
|
||||
break;
|
||||
case 'onPageHide':
|
||||
logManager.info(LogCategory.USER, LogEventType.PAGE_HIDE, 'TransitionPage');
|
||||
break;
|
||||
case 'onBackPress':
|
||||
logManager.info(LogCategory.USER, LogEventType.PAGE_BACK, 'TransitionPage');
|
||||
break;
|
||||
default:
|
||||
logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, `TransitionPage: ${eventName}`);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
|
||||
|
184
entry/src/main/ets/pages/agreements/DataProcessingStatement.ets
Normal file
@ -0,0 +1,184 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct DataProcessingStatement {
|
||||
@State title: string = '数据处理声明';
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 顶部栏
|
||||
Row() {
|
||||
Image($r('app.media.back'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.margin({ left: 16 })
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
|
||||
Text(this.title)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.margin({ left: 16 })
|
||||
|
||||
Blank()
|
||||
}
|
||||
.width('100%')
|
||||
.height(56)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.alignItems(VerticalAlign.Center)
|
||||
|
||||
// 内容区域
|
||||
Scroll() {
|
||||
Column() {
|
||||
Text('智能教室管理系统数据处理声明')
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ top: 20, bottom: 20 })
|
||||
.textAlign(TextAlign.Center)
|
||||
.width('100%')
|
||||
|
||||
Text('最近更新日期:2025年04月15日\n文件编号:CMSDP-2025-001\n生效日期:2025年04月15日')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
.margin({ bottom: 20 })
|
||||
.width('100%')
|
||||
.textAlign(TextAlign.Center)
|
||||
|
||||
Text('总则')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('本数据处理声明(以下简称"本声明")阐述了数据猫(以下简称"我们")作为数据控制者和/或数据处理者如何处理通过智能教室管理系统(以下简称"本系统")收集的个人数据以及与数据处理相关的权利和责任。本声明是我们《用户服务协议》和《隐私政策》的补充文件,应当与前述文件一并阅读和理解。\n\n本声明基于《中华人民共和国个人信息保护法》、《中华人民共和国数据安全法》以及其他适用的法律法规制定。我们承诺以负责任、透明的方式处理您的个人数据,并尊重您的隐私权。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第一条 定义')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('在本声明中,除非另有规定,下列术语具有以下含义:\n\n1.1 "个人数据"或"个人信息":指与已识别或可识别的自然人("数据主体")相关的任何信息。可识别的自然人是指可以直接或间接地识别的人,特别是通过诸如姓名、身份证号码、位置数据、网上标识符或者一个或多个特定于该自然人的物理、生理、遗传、心理、经济、文化或社会身份的因素。\n\n1.2 "数据控制者":指单独或与他人共同决定处理个人数据的目的和方法的自然人或法人、公共机构、代理机构或其他团体。\n\n1.3 "数据处理者":指代表数据控制者处理个人数据的自然人或法人、公共机构、代理机构或其他团体。\n\n1.4 "处理":指对个人数据进行的任何操作或一系列操作,无论是否通过自动化手段,如收集、记录、组织、构造、存储、改编或修改、检索、咨询、使用、通过传输、传播或其他方式提供、对齐或组合、限制、删除或销毁。\n\n1.5 "数据主体":指个人数据所关联的自然人。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第二条 数据控制者和处理者')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('2.1 数据控制者\n\n公司名称:数据猫\n注册地址:重庆理工大学两江校区\n企业统一社会信用代码:XXXXXXXXXXXXXXXXXXXX\n负责人:数据保护官\n电子邮件:support@tdcat.cn\n\n2.2 数据处理者\n\n在某些情况下,我们会委托第三方服务提供商作为数据处理者处理部分个人数据。所有第三方处理者都必须遵守我们的数据保护标准和安全要求,并且仅能根据我们明确的书面指示处理个人数据。我们仅选择能够提供足够保证的数据处理者,这些保证应包括实施适当的技术和组织措施,确保数据处理符合适用的数据保护法律要求,并保护数据主体的权利。\n\n我们会与所有数据处理者签订符合法律要求的数据处理协议,明确其数据处理义务和责任。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第三条 数据处理的法律依据')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('我们处理个人数据的法律依据包括但不限于:\n\n3.1 合同必要性\n当处理对于履行我们与您之间的合同(如《用户服务协议》)必要时,或者根据您的请求在签订合同前采取措施时。例如,为了向您提供本系统的核心功能,我们需要处理您的账号信息和相关数据。\n\n3.2 法律义务\n当处理是遵守我们所适用的法律义务所必需时。例如,为了满足教育监管要求或保留特定时间段内的记录。\n\n3.3 合法权益\n当处理对于我们或第三方的合法权益所必需时,除非您的权益或基本权利和自由凌驾于这些权益之上。例如,为了维护系统安全性和改进服务质量,我们可能会分析用户使用模式和系统性能数据。\n\n3.4 同意\n在某些情况下,我们会根据您的明确同意处理特定的个人数据。在此情况下,您有权随时撤回您的同意。例如,我们在向您发送非必要服务通知前会征求您的同意。\n\n3.5 重要利益\n当处理对于保护数据主体或其他自然人的重要利益所必需时。例如,在紧急情况下为保障师生安全而处理位置信息。\n\n3.6 公共利益\n当处理对于执行公共利益或履行数据控制者被授予的官方权限所必需时。例如,为教育研究或行政管理目的进行的数据分析(通常采用去标识化处理)。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第四条 数据处理活动')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('4.1 用户账号管理\n处理目的:创建和管理用户账号,提供身份验证和授权。\n数据类别:用户名、密码(加密存储)、电子邮件地址、手机号码、账号状态信息。\n处理性质:电子存储、验证、检索、更新、备份。\n保留期限:账号存续期间,以及账号关闭后根据适用法律要求和合法业务需要保留的时间(通常不超过3年)。\n法律依据:合同必要性、合法权益。\n\n4.2 核心功能提供\n处理目的:提供教室预约、设备管理、课程安排、考勤管理等核心功能。\n数据类别:用户身份信息、预约记录、使用记录、课程信息、考勤数据、操作日志。\n处理性质:收集、存储、分析、检索、更新、传输。\n保留期限:服务期间及服务终止后的合理期限(通常为5年,部分教育管理相关数据可能根据教育法规要求保留更长时间)。\n法律依据:合同必要性、法律义务、合法权益。\n\n4.3 系统安全与运维\n处理目的:确保系统安全,防止欺诈,进行技术维护和故障排除。\n数据类别:日志数据、设备信息、网络数据、用户行为数据、错误报告。\n处理性质:自动收集、监控、分析、故障排除。\n保留期限:根据安全和合规要求,通常为6-24个月。\n法律依据:合法权益、法律义务。\n\n4.4 服务优化与分析\n处理目的:分析系统使用情况,改进服务质量和用户体验。\n数据类别:使用统计数据、功能使用频率、界面交互数据、用户反馈(通常为匿名化或假名化处理)。\n处理性质:统计分析、模式识别、聚合处理。\n保留期限:通常为2年,之后进行永久匿名化处理。\n法律依据:合法权益、同意(针对特定非必要分析)。\n\n4.5 沟通与通知\n处理目的:向用户发送服务相关通知、更新和重要信息。\n数据类别:联系信息、通知偏好设置、通知历史记录。\n处理性质:电子通信、推送通知、邮件发送。\n保留期限:账号存续期间及之后的合理期限(通常不超过1年)。\n法律依据:合同必要性、合法权益、同意(针对非必要通知)。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第五条 数据接收者')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('5.1 我们可能会将个人数据传输给以下类别的接收者:\n\n5.1.1 内部接收者\n• 我们的员工和授权代表(根据工作职责的需要和最小必要权限原则)\n• 关联公司和子公司(仅在必要时且遵循适当的数据保护标准)\n\n5.1.2 外部接收者\n• 云服务和托管服务提供商\n• IT和系统维护服务提供商\n• 分析和技术支持服务提供商\n• 客户支持服务提供商\n• 审计师和专业顾问(如法律顾问、税务顾问)\n• 教育主管部门(在法律要求的情况下)\n• 政府机构和执法部门(应法律要求)\n\n5.2 数据传输保障\n5.2.1 所有外部接收者都必须提供适当的数据安全保证,并签署数据处理协议或包含数据保护条款的服务协议。\n5.2.2 对于外部数据接收者,我们确保其仅在指定目的范围内处理数据,并遵守合同约定和适用法律的保密和安全要求。\n5.2.3 当与第三方共享数据时,我们会尽量限制共享的数据范围,优先采用匿名化或假名化处理。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第六条 数据安全')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('6.1 技术措施\n我们实施了适当的技术措施,包括但不限于:\n6.1.1 数据加密:使用行业标准的加密技术保护传输中的数据(TLS/SSL)和存储的敏感数据(AES-256等)。\n6.1.2 访问控制:实施基于角色的访问控制、多因素认证和最小权限原则。\n6.1.3 网络安全:部署防火墙、入侵检测/防御系统、DDoS防护措施。\n6.1.4 安全监控:实施7×24小时的系统监控,日志审计和异常检测。\n6.1.5 定期安全评估:进行漏洞扫描、渗透测试和安全审计。\n\n6.2 组织措施\n我们还实施了组织措施,包括但不限于:\n6.2.1 安全管理制度:建立全面的信息安全管理体系,定期更新安全政策。\n6.2.2 员工培训:定期对员工进行数据安全和隐私保护培训。\n6.2.3 访问管理:严格控制对个人数据的访问,实行职责分离。\n6.2.4 供应商管理:评估和监督第三方服务提供商的安全措施。\n6.2.5 安全事件响应:建立安全事件响应程序,确保及时处理数据泄露事件。\n\n6.3 持续改进\n我们定期审查和更新这些措施,以适应不断变化的技术环境和安全威胁。我们的安全措施遵循行业最佳实践和适用的安全标准,如ISO/IEC 27001、等级保护标准等。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第七条 数据跨境传输')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('7.1 数据本地化\n我们的服务器和数据存储设施主要位于中国境内。我们收集的个人数据通常存储在中国境内,并遵守中国的数据保护法律。\n\n7.2 跨境传输情形\n在下列情形下,我们可能需要将您的个人数据传输到中国境外:\n7.2.1 法律法规明确规定;\n7.2.2 依法获得您的单独同意;\n7.2.3 为履行您作为一方当事人的合同所必需;\n7.2.4 为了保护自然人的生命、健康和财产安全等重大合法权益所必需;\n7.2.5 法律、行政法规规定的其他情形。\n\n7.3 跨境传输保障\n如需将您的个人数据传输至中国境外,我们将:\n7.3.1 依法进行个人信息出境评估或安全评估;\n7.3.2 确保接收方具备不低于中国法律规定的个人信息保护标准;\n7.3.3 采取加密等安全措施保护传输数据;\n7.3.4 通过合同或其他形式确保接收方履行数据保护义务。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第八条 数据主体权利')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('8.1 权利内容\n根据适用的数据保护法律,您作为数据主体享有以下权利:\n\n8.1.1 知情权\n您有权获取有关我们如何处理您的个人数据的信息,包括处理的目的、个人数据类别、保留期限等。\n\n8.1.2 访问权\n您有权获取我们是否处理您的个人数据的确认,以及在处理的情况下,访问该数据的副本。\n\n8.1.3 更正权\n您有权要求更正不准确的个人数据,并有权要求补充不完整的个人数据。\n\n8.1.4 删除权(被遗忘权)\n在特定情况下,您有权要求删除与您相关的个人数据,例如当数据不再必要或您撤回同意时。\n\n8.1.5 处理限制权\n在特定情况下,您有权限制我们处理您的个人数据,例如当您质疑数据准确性或处理合法性时。\n\n8.1.6 数据可携权\n您有权以结构化、常用的、机器可读的格式接收您提供给我们的个人数据,并有权将这些数据传输给另一个数据控制者。\n\n8.1.7 反对权\n基于与您的特定情况相关的理由,您有权随时反对处理您的个人数据。\n\n8.1.8 自动化决策权\n您有权不受完全基于自动化处理(包括分析)的决策约束,除非此类决策对合同履行必要或您明确同意。\n\n8.2 行使权利的方式\n8.2.1 您可以通过本声明第九条提供的联系方式向我们发送请求,行使上述权利。\n8.2.2 为保障安全,我们可能需要验证您的身份,然后才能处理您的请求。\n8.2.3 我们将在收到您的请求后的30天内做出回应。如需延长回应时间,我们将告知您延迟原因。\n8.2.4 在特定情况下,如请求明显无根据、重复或过度,我们可能会收取合理费用或拒绝处理请求,但我们会告知您拒绝的理由。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第九条 数据泄露通知')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('9.1 安全事件识别\n我们建立了全面的数据安全事件识别机制,通过安全监控系统和人工审核相结合的方式,及时发现可能的数据泄露事件。\n\n9.2 内部报告程序\n9.2.1 一旦识别到数据安全事件,我们的工作人员将按照内部安全事件响应程序,立即向安全响应团队和数据保护官报告。\n9.2.2 安全响应团队将评估事件性质、规模和可能的影响,确定事件的严重程度。\n\n9.3 监管机构通知\n9.3.1 如发生可能导致个人信息泄露的数据安全事件,我们将按照法律法规的要求,在规定时间内向相关监管机构报告。\n9.3.2 报告内容将包括但不限于:事件性质、涉及的个人数据类别和数量、可能产生的后果、我们已采取的补救措施、联系方式等。\n\n9.4 数据主体通知\n9.4.1 对于可能导致数据主体权利受到严重影响的数据泄露事件,我们将在事件确认后及时通知受影响的数据主体。\n9.4.2 通知方式可能包括:电子邮件、短信、电话、系统内通知或其他合适的方式。\n9.4.3 通知内容将包括:事件描述、可能的影响、我们已采取的措施、建议数据主体采取的措施以及联系方式。\n\n9.5 持续改进\n每次数据安全事件后,我们将进行全面的事后审查,分析事件根源,完善安全措施,避免类似事件再次发生。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第十条 联系方式')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('如果您对我们的数据处理有任何疑问,或希望行使数据主体权利,请通过以下方式联系我们:\n\n数据保护官:数据保护官\n数据保护团队:个人信息保护办公室\n电子邮件:support@tdcat.cn\n地址:重庆理工大学两江校区\n邮编:100080\n\n我们将尽快处理您的请求,通常会在收到请求后的30天内回复。如果由于特殊情况需要更长的处理时间,我们会告知您延迟的原因及预计回复时间。\n\n如果您对我们的回复不满意,您还可以向相关数据保护监管机构投诉或寻求司法救济。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 30 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('本声明最终解释权归数据猫所有。')
|
||||
.fontSize(14)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 30 })
|
||||
.textAlign(TextAlign.Center)
|
||||
}
|
||||
.width('90%')
|
||||
.padding({ bottom: 50 })
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.layoutWeight(1)
|
||||
.backgroundColor('#F5F7FA')
|
||||
.scrollBar(BarState.Auto)
|
||||
.edgeEffect(EdgeEffect.Spring)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
||||
export { DataProcessingStatement }
|
180
entry/src/main/ets/pages/agreements/PrivacyPolicy.ets
Normal file
@ -0,0 +1,180 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct PrivacyPolicy {
|
||||
@State title: string = '隐私政策';
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 顶部栏
|
||||
Row() {
|
||||
Image($r('app.media.back'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.margin({ left: 16 })
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
|
||||
Text(this.title)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.margin({ left: 16 })
|
||||
|
||||
Blank()
|
||||
}
|
||||
.width('100%')
|
||||
.height(56)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.alignItems(VerticalAlign.Center)
|
||||
|
||||
// 内容区域
|
||||
Scroll() {
|
||||
Column() {
|
||||
Text('智能教室管理系统隐私政策')
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ top: 20, bottom: 20 })
|
||||
.textAlign(TextAlign.Center)
|
||||
.width('100%')
|
||||
|
||||
Text('最近更新日期:2025年04月15日\n文件编号:CMSPP-2025-001\n生效日期:2025年04月15日')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
.margin({ bottom: 20 })
|
||||
.width('100%')
|
||||
.textAlign(TextAlign.Center)
|
||||
|
||||
Text('引言')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('数据猫(以下简称"我们")深知个人信息对您的重要性,我们非常重视您的个人隐私和个人信息保护。本隐私政策(以下简称"本政策")为智能教室管理系统所制定,阐明了我们如何收集、使用、存储、共享、转让、公开披露和保护您的个人信息,以及您享有的相关权利。在使用我们的服务前,请您务必仔细阅读并了解本政策的全部内容(特别是加粗或下划线标注的内容),以便做出适当的选择。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('如您是18周岁以下的未成年人,请在监护人的陪同下阅读本政策,并确保已征得监护人的同意后使用我们的服务。')
|
||||
.fontSize(14)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第一条 定义')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('1.1 个人信息:指以电子或者其他方式记录的能够单独或者与其他信息结合识别特定自然人身份或者反映特定自然人活动情况的各种信息。\n\n1.2 个人敏感信息:指一旦泄露、非法提供或滥用可能危害人身和财产安全,极易导致个人名誉、身心健康受到损害或歧视性待遇的个人信息,主要包括身份证件号码、个人生物识别信息、银行账号、通信内容、健康生理信息等。\n\n1.3 设备:指可用于访问智能教室管理系统服务的设备,例如台式电脑、笔记本电脑、平板电脑或智能手机。\n\n1.4 唯一设备标识符:指具有唯一性的设备标识符(有时称为通用唯一标识符或UUID),例如设备的IMEI号、MAC地址、软件安装列表等。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第二条 我们收集的信息')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('2.1 您提供的信息\n根据服务类型的不同,我们可能收集以下信息:\n\n2.1.1 账号信息:您在注册和使用本系统时提供的用户名、密码(以加密形式存储)、电子邮件地址、手机号码。\n2.1.2 个人资料:您在使用本系统中填写的姓名、职位、所属部门、学号/工号等信息。\n2.1.3 用户反馈:您在使用我们服务过程中向我们提供的反馈信息,包括但不限于问题报告、建议、调查问卷回复等。\n2.1.4 其他您选择提供的信息。\n\n2.2 我们自动收集的信息\n当您使用我们的服务时,我们可能会自动收集以下信息:\n\n2.2.1 设备信息:设备类型、操作系统及版本、唯一设备标识符、IP地址、设备设置等信息。\n2.2.2 日志信息:您使用本系统的详细情况,包括登录时间、使用时长、操作记录、搜索查询内容等使用服务的操作日志。\n2.2.3 位置信息:在您授权的情况下,我们可能会收集您的位置信息。您可以通过设备的设置功能随时关闭或开启定位功能。\n2.2.4 网络信息:网络类型、网络状态、连接状态、HTTP头等网络通信数据。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第三条 信息使用')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('我们严格遵循合法、正当、必要的原则,出于以下目的使用收集的信息:\n\n3.1 向您提供服务\n3.1.1 创建和管理您的账号。\n3.1.2 验证您的身份,确保系统安全。\n3.1.3 处理您的请求和交易,响应您的查询。\n3.1.4 提供、维护和改进我们的服务功能和质量。\n\n3.2 服务优化与安全\n3.2.1 开发新的服务或功能。\n3.2.2 分析用户如何使用我们的服务,以便改进用户体验。\n3.2.3 向您推送重要的通知,如系统更新、服务条款和政策变更等。\n3.2.4 防止、检测和调查欺诈、未授权或非法活动。\n3.2.5 保护我们和用户的合法权益。\n\n3.3 其他用途\n3.3.1 履行适用法律法规规定的义务。\n3.3.2 基于学术研究、公共利益目的进行统计分析(去标识化处理后)。\n3.3.3 根据您的授权或法律法规允许的其他用途。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第四条 信息共享')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('4.1 我们不会将您的个人信息出售给任何第三方。\n\n4.2 在以下情况下,我们可能会共享您的个人信息:\n4.2.1 经您明确同意的情况下。\n4.2.2 为完成合并、收购或资产出售而转让给其他实体,但我们会要求此类实体继续按照本政策处理个人信息。\n4.2.3 出于法律原因,如遵守适用的法律法规、法律程序或政府强制要求;保护我们或公众的权利、财产或安全;检测、防止和解决欺诈、安全或技术问题;保护我们或其他用户的合法权益免受损害等。\n4.2.4 与我们的第三方服务提供商共享,这些提供商需要访问这些信息来代表我们执行服务,例如云服务提供商、数据分析服务商、维护服务提供商等,但我们会确保他们遵守合同约定的保密和安全措施,并禁止他们将您的个人信息用于任何其他用途。\n\n4.3 在共享信息前,我们将确保接收方的数据安全能力,并签署严格的保密协议,要求他们按照本政策以及我们要求的其他适当的保密和安全措施来处理个人信息。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第五条 信息存储和安全')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('5.1 信息存储\n5.1.1 我们将在中华人民共和国境内收集和产生的个人信息存储在中国境内。\n5.1.2 我们将在实现本政策所述目的所需的期限内保留您的个人信息,除非法律要求或允许更长的保留期限。超出保留期限后,我们将对您的个人信息进行删除或匿名化处理,但以下情形除外:\n(a) 法律法规等有明确规定;\n(b) 取得您的明确授权;\n(c) 涉及国家安全、国防安全、公共安全、公共卫生、公共利益等。\n\n5.2 信息安全\n5.2.1 我们采取各种合理的物理、技术和管理措施,以保护您的个人信息免受未经授权的访问、使用或泄露。这些措施包括但不限于:\n(a) 数据加密:对传输中和存储的敏感数据进行加密;\n(b) 访问控制:严格限制有权访问个人信息的员工范围,并实施多重身份验证;\n(c) 安全培训:定期对员工进行数据安全培训;\n(d) 漏洞扫描:定期评估和更新安全措施,及时修补安全漏洞;\n(e) 数据备份:定期备份数据以防丢失。\n\n5.2.2 我们会尽力防止您的信息遭到泄露、破坏或丢失。尽管我们采取了合理的安全措施,但请注意,由于互联网环境并非百分之百安全,我们无法保证信息传输的绝对安全性。\n\n5.2.3 若发生个人信息安全事件,我们将按照法律法规的要求向您告知事件的基本情况、我们采取的处置措施以及您可自主防范和降低风险的建议措施等。我们将通过电子邮件、短信、电话等方式告知您,当难以逐一告知时,我们将采取合理、有效的方式进行告知。同时,我们还将按照监管部门要求,主动上报个人信息安全事件的处置情况。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第六条 您的权利')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('根据适用的法律法规,您享有以下权利:\n\n6.1 访问权\n您有权访问您的个人信息,包括获知我们处理您个人信息的情况,并获取我们持有的关于您的个人信息的副本。\n\n6.2 更正权\n当您发现我们处理的关于您的个人信息有错误或不完整时,您有权要求我们更正或补充。\n\n6.3 删除权\n在以下情形中,您可以向我们提出删除个人信息的请求:\n6.3.1 处理目的已实现、无法实现或不再需要;\n6.3.2 我们停止提供服务,或保存期限已届满;\n6.3.3 您撤回同意;\n6.3.4 我们违反法律法规或与您的约定收集、使用个人信息。\n\n6.4 撤回同意权\n对于基于您同意而收集和使用的个人信息,您有权随时撤回您的同意。但这不会影响我们在您撤回同意前基于您的同意所进行的个人信息处理的合法性。\n\n6.5 限制处理权\n在特定情况下,您有权要求我们暂停或限制对您个人信息的处理。\n\n6.6 数据可携权\n在技术可行的情况下,您有权要求我们以结构化、常用的、机器可读的格式提供您的个人信息,并有权将这些信息传输给另一个控制者。\n\n6.7 反对权\n在特定情况下,您有权基于与您的特定情况相关的理由,反对处理您的个人信息。\n\n行使上述权利时,请通过本政策第九条提供的联系方式与我们联系。我们将在收到您的请求后的30天内做出回复。如出于安全考虑,我们可能会要求您提供书面请求,或以其他方式证明您的身份。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第七条 儿童隐私')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('7.1 我们的服务主要面向成人。如您为未满14周岁的儿童,在使用我们的服务前,应当事先取得您的监护人的同意。\n\n7.2 对于经监护人同意收集的儿童个人信息,我们只会在法律允许、监护人明确同意或者为保护儿童所必要的情况下使用或披露。\n\n7.3 如果我们发现自己在未获得可证实的监护人同意的情况下收集了儿童的个人信息,则会设法尽快删除相关信息。\n\n7.4 若您是儿童的监护人,如您对您所监护的儿童的个人信息有任何疑问,请通过本政策第九条提供的联系方式与我们联系。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第八条 隐私政策更新')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('8.1 我们可能会不时更新本隐私政策,此类更新将构成本政策的一部分。政策更新后,我们会通过在智能教室管理系统相关页面发布通知、发送电子邮件或其他适当方式通知您更新的内容,并标明最新更新日期。\n\n8.2 对于重大变更,我们还会提供更为显著的通知(包括对于特定服务的通知,我们会通过电子邮件发送通知或以弹窗方式通知)。本政策所指的重大变更包括但不限于:\n8.2.1 我们的服务模式发生重大变化,如处理个人信息的目的、处理的个人信息类型、个人信息的使用方式等;\n8.2.2 我们在控制权、组织架构等方面发生重大变化,如业务调整、破产并购等引起的所有者变更等;\n8.2.3 个人信息共享、转让或公开披露的主要对象发生变化;\n8.2.4 您参与个人信息处理方面的权利及其行使方式发生重大变化;\n8.2.5 我们负责处理个人信息安全的责任部门、联络方式及投诉渠道发生变化。\n\n8.3 若您继续使用我们的服务,即表示您同意接受修订后的本政策的约束。我们鼓励您定期查看本隐私政策,以了解我们如何保护您的信息。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第九条 联系我们')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('如果您对本隐私政策有任何疑问、意见或建议,或者想行使您的权利,请通过以下方式联系我们:\n\n个人信息保护负责人:数据保护官\n联系部门:个人信息保护办公室\n电子邮件:support@tdcat.cn\n地址:重庆理工大学两江校区\n邮编:100080\n\n一般情况下,我们将在收到您的请求后30天内答复。如您不满意我们的回复,特别是我们的个人信息处理行为损害了您的合法权益,您还可以通过以下外部途径寻求解决方案:向所在地的人民法院提起诉讼。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 30 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('本政策最终解释权归数据猫所有。')
|
||||
.fontSize(14)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 30 })
|
||||
.textAlign(TextAlign.Center)
|
||||
}
|
||||
.width('90%')
|
||||
.padding({ bottom: 50 })
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.layoutWeight(1)
|
||||
.backgroundColor('#F5F7FA')
|
||||
.scrollBar(BarState.Auto)
|
||||
.edgeEffect(EdgeEffect.Spring)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
||||
export { PrivacyPolicy }
|
178
entry/src/main/ets/pages/agreements/UserAgreement.ets
Normal file
@ -0,0 +1,178 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct UserAgreement {
|
||||
@State title: string = '用户服务协议';
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 顶部栏
|
||||
Row() {
|
||||
Image($r('app.media.back'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.margin({ left: 16 })
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
|
||||
Text(this.title)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.margin({ left: 16 })
|
||||
|
||||
Blank()
|
||||
}
|
||||
.width('100%')
|
||||
.height(56)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.alignItems(VerticalAlign.Center)
|
||||
|
||||
// 内容区域
|
||||
Scroll() {
|
||||
Column() {
|
||||
Text('智能教室管理系统用户服务协议')
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ top: 20, bottom: 20 })
|
||||
.textAlign(TextAlign.Center)
|
||||
.width('100%')
|
||||
|
||||
Text('最近更新日期:2025年04月15日\n文件编号:CMSUSR-2025-001\n生效日期:2025年04月15日')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
.margin({ bottom: 20 })
|
||||
.width('100%')
|
||||
.textAlign(TextAlign.Center)
|
||||
|
||||
Text('前言')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('本协议是由智能教室管理系统(以下简称"本系统")的所有者与用户(以下简称"您")就本系统的使用等相关事宜所订立的有效合约。请您在使用本系统前,仔细阅读并充分理解本协议各条款。您使用本系统,即表示您已充分阅读并同意接受本协议的全部条款及其它与本系统相关的政策和规则。如您不同意本协议的任何内容,请勿注册或使用本系统服务。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第一条 定义')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('1.1 智能教室管理系统:指由数据猫开发并运营的教育信息管理软件系统,包括但不限于桌面应用、移动应用等各种形式的应用程序。\n\n1.2 用户:指注册、登录、使用本系统的个人或单位。\n\n1.3 账号:指用户为使用本系统服务而注册的登录凭证,包括用户名和密码等验证信息。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第二条 服务内容')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('2.1 本系统是为教育机构提供的一套智能化教室管理解决方案,包括但不限于教室预约、设备管理、课程安排、考勤管理等功能。具体服务内容以本系统实际提供的为准。\n\n2.2 本系统会不断努力提升服务质量,优化用户体验。本系统有权在必要时变更、中断或终止部分或全部网络服务,但会尽可能提前在相关页面进行通知。\n\n2.3 本系统仅提供相关的网络服务,除此之外与相关网络服务有关的设备(如个人电脑、手机等)及所需的费用(如为接入互联网而支付的电话费及上网费等)均由用户自行承担。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第三条 用户账号')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('3.1 注册资格\n用户应具有法定的相应权利能力和行为能力,能够独立承担法律责任。若用户不具备前述条件,则用户及用户的监护人应依照法律规定承担因此而导致的一切后果。\n\n3.2 账号获取\n用户可通过教育机构分配或自行注册等方式获取本系统账号。用户注册成功后,将获得一个用户账号及相应的密码,该账号和密码由用户负责保管。\n\n3.3 账号安全\n3.3.1 用户应对账号进行的所有活动和事件承担法律责任,包括用户所产生的任何数据和造成的后果,无论该使用是否经过用户授权。\n3.3.2 为维护账号安全,用户应自行加强密码安全性设置,不应将账号信息提供给他人使用。\n3.3.3 如发现有他人未经授权使用用户账号,或存在其他安全问题,用户应立即通知本系统。\n\n3.4 账号注销\n在符合本系统规定条件的情况下,用户可通过系统设置等方式申请注销账号。账号注销后,用户将无法使用该账号,也无法恢复和查询账号中的任何内容或信息。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第四条 用户行为规范')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('4.1 用户在使用本系统过程中必须遵循以下原则:\n4.1.1 遵守中华人民共和国有关的法律法规;\n4.1.2 不得为任何非法目的而使用本系统;\n4.1.3 遵守所有与网络服务有关的协议、规定和程序;\n4.1.4 不得利用本系统进行任何可能对互联网正常运转造成不利影响的行为;\n4.1.5 不得利用本系统传播任何非法、有害、骚扰、侵害、中伤、粗俗、猥亵或其他道德上令人反感的内容;\n4.1.6 不得侵犯他人知识产权或其他合法权益。\n\n4.2 如用户违反上述任何规定,本系统有权采取以下措施:\n4.2.1 立即终止向该用户提供服务;\n4.2.2 删除违反规定的内容;\n4.2.3 保存有关记录,并向有关政府部门报告;\n4.2.4 追究用户的法律责任。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第五条 知识产权')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('5.1 本系统所包含的所有内容,包括但不限于文本、图形、标志、按钮图标、图像、声音文件片段、数字下载、数据编译和软件,均为数据猫或内容提供者所有,受中华人民共和国著作权法、商标法、专利法及其他知识产权法律法规和国际公约的保护。\n\n5.2 未经数据猫事先书面同意,用户不得以任何方式使用、复制、修改、传播、展示、出版、发行本系统的任何内容,或创作与之相关的衍生作品。\n\n5.3 用户通过本系统上传、发布的内容,用户保证对该等内容拥有合法权利。用户同意授予数据猫非独占的、永久的、不可撤销的、全球范围内的、免费的许可使用权,数据猫有权为提供服务的目的使用、复制、修改、改编、出版、翻译、据以创作衍生作品、传播、表演和展示此等内容。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第六条 免责声明')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('6.1 本系统不担保服务一定能满足用户的所有要求,也不担保服务不会中断,对服务的及时性、安全性、准确性也不作担保。\n\n6.2 对于因下列任一情况导致的服务中断或受阻,本系统不承担任何法律责任:\n6.2.1 因计算机病毒、木马或其他恶意程序、黑客攻击、网络故障、系统故障、通讯故障、电力故障、罢工、暴乱、火灾、洪水、风暴、爆炸、战争、政府行为、司法行政机关的命令或第三方的不作为而造成的服务中断或延迟;\n6.2.2 用户或本系统的电脑软件、硬件、通信线路、Internet接入故障;\n6.2.3 用户操作不当;\n6.2.4 用户通过非本系统授权的方式使用本服务;\n6.2.5 其他本系统无法控制或合理预见的情形。\n\n6.3 用户理解,本系统需要定期或不定期对系统进行维护、升级,如因此类情况而造成服务在合理时间内的中断,本系统无需为此承担任何责任。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第七条 协议修改')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('7.1 数据猫保留随时修改本协议的权利,修改后的协议条款将在发布后生效。\n\n7.2 如用户不同意相关变更,请停止使用本系统服务。用户继续使用本系统服务,则视为用户已接受修改后的协议。\n\n7.3 本系统会在主要页面或修改的条款页面通过合理方式向用户提示修改内容。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第八条 适用法律与争议解决')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('8.1 本协议的订立、执行和解释及争议的解决均应适用中华人民共和国法律。\n\n8.2 如双方就本协议内容或其执行发生任何争议,应尽量友好协商解决;协商不成时,任何一方均有权将争议提交至北京市海淀区人民法院诉讼解决。\n\n8.3 本协议任何条款被有管辖权的法院认定为无效的,不应影响其他条款或其任何部分的效力。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('第九条 其他')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('9.1 本协议构成双方对本协议之约定事项及其他有关事宜的完整协议,除本协议规定的之外,未赋予本协议各方其他权利。\n\n9.2 如本协议中的任何条款无论因何种原因完全或部分无效或不具有执行力,本协议的其余条款仍应有效并且有约束力。\n\n9.3 本协议中的标题仅为方便而设,不具有法律或契约效果。\n\n9.4 数据猫未行使或执行本协议任何权利或规定,不构成对前述权利或权利之放弃。\n\n9.5 本协议内容同时包括本系统的隐私政策、数据处理声明等其他相关规则。上述内容一经正式发布,即为本协议不可分割的组成部分,用户同样应当遵守。')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 20 })
|
||||
.textAlign(TextAlign.Start)
|
||||
|
||||
Text('联系方式')
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 10 })
|
||||
|
||||
Text('如您对本协议或本系统服务有任何疑问,请通过以下方式与我们联系:\n\n名称:数据猫\n电子邮件:support@tdcat.cn\n地址:重庆理工大学两江校区\n邮编:100080')
|
||||
.fontSize(14)
|
||||
.margin({ bottom: 30 })
|
||||
.textAlign(TextAlign.Start)
|
||||
}
|
||||
.width('90%')
|
||||
.padding({ bottom: 50 })
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.layoutWeight(1)
|
||||
.backgroundColor('#F5F7FA')
|
||||
.scrollBar(BarState.Auto)
|
||||
.edgeEffect(EdgeEffect.Spring)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
||||
export { UserAgreement }
|
@ -1,8 +1,14 @@
|
||||
import { router } from '@kit.ArkUI';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
import settingsService from '../common/SettingsService';
|
||||
import { DatabaseService } from '../common/DatabaseService';
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@ -13,9 +19,12 @@ struct Login {
|
||||
@State password: string = ''; // 密码
|
||||
@State isLoading: boolean = false; // 加载状态
|
||||
@State errorMessage: string = ''; // 错误信息
|
||||
@State isAgreementChecked: boolean = false; // 是否同意条款
|
||||
@State isRememberPassword: boolean = false; // 是否记住密码
|
||||
|
||||
// 获取数据库服务实例
|
||||
private dbService: DatabaseService = DatabaseService.getInstance();
|
||||
private userpassFilePath: string = '';
|
||||
|
||||
// 登录验证方法
|
||||
private async handleLogin(): Promise<void> {
|
||||
@ -36,6 +45,13 @@ struct Login {
|
||||
return;
|
||||
}
|
||||
|
||||
// 必须同意条款才能登录
|
||||
if (!this.isAgreementChecked) {
|
||||
this.errorMessage = '请阅读并同意相关条款';
|
||||
this.isLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用异步验证方法
|
||||
const isValid = await this.dbService.validateUser(this.username, this.password);
|
||||
@ -44,193 +60,484 @@ struct Login {
|
||||
// 设置当前用户
|
||||
settingsService.setCurrentAccount(this.username);
|
||||
|
||||
// 如果勾选了记住密码,保存用户名密码到文件
|
||||
if (this.isRememberPassword) {
|
||||
this.saveUserCredentials();
|
||||
}
|
||||
|
||||
// 记录登录日志
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN, `User logged in: ${this.username}`);
|
||||
|
||||
// 跳转到过渡页面
|
||||
router.replaceUrl({
|
||||
url: 'pages/TransitionPage'
|
||||
//url: 'pages/TransitionPage'
|
||||
//取消过渡动画
|
||||
url: 'pages/HomePage'
|
||||
});
|
||||
} else {
|
||||
this.errorMessage = '账号或密码错误';
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN_FAIL, `Login failed: ${this.username}`);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
this.errorMessage = '登录失败,请稍后重试';
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN_FAIL, `Login error: ${error}`);
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN_FAIL, '登录过程中出现错误');
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存用户凭证到文件
|
||||
private saveUserCredentials(): void {
|
||||
try {
|
||||
const credentials: string = JSON.stringify({
|
||||
username: this.username,
|
||||
password: this.password
|
||||
});
|
||||
|
||||
// 写入文件前确保文件存在
|
||||
this.ensureFileExists();
|
||||
|
||||
// 写入文件
|
||||
try {
|
||||
const file = fileIo.openSync(this.userpassFilePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
|
||||
|
||||
// 将字符串转换为字节数组并写入
|
||||
const buffer = new ArrayBuffer(credentials.length * 2);
|
||||
const dataView = new DataView(buffer);
|
||||
for (let i = 0; i < credentials.length; i++) {
|
||||
dataView.setUint16(i * 2, credentials.charCodeAt(i), true);
|
||||
}
|
||||
|
||||
fileIo.writeSync(file.fd, buffer);
|
||||
fileIo.closeSync(file.fd);
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "已保存用户凭证");
|
||||
} catch {
|
||||
logManager.error(LogCategory.SYSTEM, "写入凭证失败");
|
||||
}
|
||||
} catch {
|
||||
logManager.error(LogCategory.SYSTEM, "保存凭证失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 清除保存的用户凭证
|
||||
private clearUserCredentials(): void {
|
||||
try {
|
||||
if (fileIo.accessSync(this.userpassFilePath)) {
|
||||
try {
|
||||
// 清空文件内容
|
||||
const file = fileIo.openSync(this.userpassFilePath, fileIo.OpenMode.WRITE_ONLY | fileIo.OpenMode.TRUNC);
|
||||
fileIo.closeSync(file.fd);
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "已清除用户凭证");
|
||||
} catch {
|
||||
logManager.error(LogCategory.SYSTEM, "清除凭证失败");
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 文件不存在,不需要清除
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "没有需要清除的凭证文件");
|
||||
}
|
||||
}
|
||||
|
||||
// 读取用户凭证
|
||||
private loadUserCredentials(): void {
|
||||
try {
|
||||
if (fileIo.accessSync(this.userpassFilePath)) {
|
||||
try {
|
||||
const file = fileIo.openSync(this.userpassFilePath, fileIo.OpenMode.READ_ONLY);
|
||||
const fileSize = fileIo.statSync(this.userpassFilePath).size;
|
||||
|
||||
if (fileSize > 0) {
|
||||
const buf = new ArrayBuffer(fileSize);
|
||||
fileIo.readSync(file.fd, buf);
|
||||
fileIo.closeSync(file.fd);
|
||||
|
||||
// 手动将字节数组转换为字符串
|
||||
const dataView = new DataView(buf);
|
||||
let content = '';
|
||||
|
||||
// 安全地读取字符
|
||||
for (let i = 0; i < Math.floor(fileSize / 2); i++) {
|
||||
content += String.fromCharCode(dataView.getUint16(i * 2, true));
|
||||
}
|
||||
|
||||
if (content && content.length > 0) {
|
||||
try {
|
||||
// 解析JSON内容并添加显式类型标注
|
||||
const jsonText: string = content;
|
||||
// 使用Record<string, string>类型替代any
|
||||
const parsed: Record<string, string> = JSON.parse(jsonText);
|
||||
|
||||
if (parsed && typeof parsed === 'object') {
|
||||
// 直接访问并检查属性
|
||||
if (parsed.username !== undefined && typeof parsed.username === 'string') {
|
||||
this.username = parsed.username;
|
||||
}
|
||||
|
||||
if (parsed.password !== undefined && typeof parsed.password === 'string') {
|
||||
this.password = parsed.password;
|
||||
}
|
||||
|
||||
this.isRememberPassword = true;
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "已加载保存的凭证");
|
||||
}
|
||||
} catch {
|
||||
logManager.error(LogCategory.SYSTEM, "解析凭证失败");
|
||||
}
|
||||
} else {
|
||||
// 文件存在但内容为空
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "凭证文件存在但为空");
|
||||
}
|
||||
} else {
|
||||
fileIo.closeSync(file.fd);
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "凭证文件为空");
|
||||
}
|
||||
} catch {
|
||||
logManager.error(LogCategory.SYSTEM, "读取凭证文件失败");
|
||||
}
|
||||
} else {
|
||||
// 文件不存在
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "凭证文件不存在");
|
||||
}
|
||||
} catch {
|
||||
// 文件不存在或无法访问
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "未找到保存的凭证");
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否启用记住密码但没有凭据
|
||||
private checkRememberPasswordStatus(): void {
|
||||
// 当用户勾选记住密码但没有已保存的凭据时显示提示
|
||||
if (this.isRememberPassword && (!this.username || !this.password)) {
|
||||
promptAction.showToast({
|
||||
message: '当前没有保存的密码',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 确保文件存在,不存在则创建
|
||||
private ensureFileExists(): void {
|
||||
try {
|
||||
// 检查文件是否存在
|
||||
if (!fileIo.accessSync(this.userpassFilePath)) {
|
||||
// 创建空文件
|
||||
const file = fileIo.openSync(this.userpassFilePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY);
|
||||
fileIo.closeSync(file.fd);
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "已创建凭证文件");
|
||||
}
|
||||
} catch {
|
||||
// 文件不存在,创建新文件
|
||||
try {
|
||||
const file = fileIo.openSync(this.userpassFilePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY);
|
||||
fileIo.closeSync(file.fd);
|
||||
logManager.info(LogCategory.SYSTEM, LogEventType.SYSTEM_INFO, "已创建凭证文件");
|
||||
} catch {
|
||||
logManager.error(LogCategory.SYSTEM, "创建凭证文件失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
Column({space: 20}) { // 增加行间距
|
||||
// 顶部标题和图标
|
||||
Column() {
|
||||
Image('http://139.155.155.67:2342/images/tdcat.webp')
|
||||
.height(150)
|
||||
.width(150)
|
||||
.margin({ top: 40, bottom: 20 })
|
||||
Stack() {
|
||||
// 原有登录页面内容
|
||||
Column({space: 20}) { // 增加行间距
|
||||
// 顶部标题和图标
|
||||
Column() {
|
||||
Image($r('app.media.logo'))
|
||||
.objectFit(ImageFit.Contain)
|
||||
.width('80%')
|
||||
.aspectRatio(1.5)
|
||||
.margin({ top: 40 })
|
||||
.borderRadius(8)
|
||||
|
||||
// Text(this.message)
|
||||
// .fontColor('#333333')
|
||||
// .fontSize(28)
|
||||
// .fontWeight(FontWeight.Bold)
|
||||
// .margin({ top: 20, bottom: 30 })
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 登录表单
|
||||
Column({ space: 30 }) {
|
||||
// 账号输入框
|
||||
Column({ space: 8 }) {
|
||||
Text("账号")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入账号' })
|
||||
.type(InputType.Normal)
|
||||
.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.username = value;
|
||||
this.errorMessage = ''; // 清除错误信息
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
Text(this.message)
|
||||
.fontColor('#333333')
|
||||
.fontSize(28)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.margin({ bottom: 30 })
|
||||
// 密码输入框
|
||||
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%')
|
||||
}
|
||||
|
||||
// 记住密码选项
|
||||
Row() {
|
||||
Checkbox()
|
||||
.select(this.isRememberPassword)
|
||||
.selectedColor('#2196F3')
|
||||
.width(20)
|
||||
.height(20)
|
||||
.margin({ right: 8 })
|
||||
.onChange((value: boolean) => {
|
||||
this.isRememberPassword = value;
|
||||
if (value) {
|
||||
this.checkRememberPasswordStatus();
|
||||
} else if (this.username && this.password) {
|
||||
// 用户取消勾选"记住密码"选项,询问是否清除已保存的密码
|
||||
AlertDialog.show({
|
||||
title: '提示',
|
||||
message: '是否清除已保存的密码?',
|
||||
primaryButton: {
|
||||
value: '取消',
|
||||
action: () => {
|
||||
// 用户取消,恢复勾选状态
|
||||
this.isRememberPassword = true;
|
||||
}
|
||||
},
|
||||
secondaryButton: {
|
||||
value: '确定',
|
||||
action: () => {
|
||||
// 用户确认,清除保存的密码
|
||||
this.clearUserCredentials();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
Text('记住密码')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ bottom: 16 })
|
||||
.alignItems(VerticalAlign.Center)
|
||||
|
||||
// 条款同意选项
|
||||
Row() {
|
||||
Checkbox()
|
||||
.select(this.isAgreementChecked)
|
||||
.selectedColor('#2196F3')
|
||||
.width(20)
|
||||
.height(20)
|
||||
.margin({ right: 8 })
|
||||
.onChange((value: boolean) => {
|
||||
this.isAgreementChecked = value;
|
||||
this.errorMessage = ''; // 清除错误信息
|
||||
})
|
||||
|
||||
Text() {
|
||||
Span('我已阅读并同意')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
|
||||
Span('《用户服务协议》')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/agreements/UserAgreement'
|
||||
});
|
||||
})
|
||||
|
||||
Span('、')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
|
||||
Span('《隐私政策》')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/agreements/PrivacyPolicy'
|
||||
});
|
||||
})
|
||||
|
||||
Span('和')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
|
||||
Span('《数据处理声明》')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/agreements/DataProcessingStatement'
|
||||
});
|
||||
})
|
||||
}
|
||||
.width('90%')
|
||||
.textAlign(TextAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ top: 16, bottom: 16 })
|
||||
.alignItems(VerticalAlign.Center)
|
||||
|
||||
// 忘记密码和注册按钮
|
||||
Row() {
|
||||
Text('忘记密码')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.onClick(() => {
|
||||
AlertDialog.show({
|
||||
message:"该功能尚未开发",
|
||||
confirm:{
|
||||
value:"确定",
|
||||
action:()=>{}
|
||||
}
|
||||
});
|
||||
//跳转忘记密码页面
|
||||
/* router.pushUrl({
|
||||
url: 'pages/forgot-password'
|
||||
});*/
|
||||
})
|
||||
|
||||
Blank()
|
||||
|
||||
Text('注册账号')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/register'
|
||||
});
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.SpaceBetween)
|
||||
.margin({ top: 10 })
|
||||
|
||||
// 登录按钮
|
||||
Button('登录')
|
||||
.type(ButtonType.Capsule)
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor('#2196F3')
|
||||
.onClick(() => {
|
||||
this.handleLogin();
|
||||
})
|
||||
.margin({ top: 20 })
|
||||
}
|
||||
.width('100%')
|
||||
.padding({ left: 30, right: 30 })
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 登录表单
|
||||
Column({ space: 30 }) {
|
||||
// 账号输入框
|
||||
Column({ space: 8 }) {
|
||||
Text("账号")
|
||||
.height('100%')
|
||||
|
||||
// 浮动测试按钮
|
||||
Button({ type: ButtonType.Circle }) {
|
||||
Row() {
|
||||
Image($r('app.media.ic_test'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.margin({ right: 4 })
|
||||
/* Text('测试')
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入账号' })
|
||||
.type(InputType.Normal)
|
||||
.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.username = value;
|
||||
this.errorMessage = ''; // 清除错误信息
|
||||
})
|
||||
.fontColor('#FFFFFF')*/
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.width(100)
|
||||
.height(40)
|
||||
.backgroundColor('#2196F3')
|
||||
.position({ x: '80%', y: 50 })
|
||||
.enabled(!this.isLoading)
|
||||
.onClick(() => {
|
||||
if (this.isLoading) return;
|
||||
this.isLoading = true;
|
||||
|
||||
// 密码输入框
|
||||
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();
|
||||
})
|
||||
|
||||
// 测试按钮 - 直接跳转到首页
|
||||
Button("测试直接进入")
|
||||
.width('100%')
|
||||
.height(40)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.backgroundColor('#4CAF50')
|
||||
.borderRadius(8)
|
||||
.fontColor(Color.White)
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
// 设置账户为测试用户
|
||||
settingsService.setCurrentAccount('test');
|
||||
|
||||
// 记录测试登录
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN, 'Test user logged in');
|
||||
|
||||
// 直接跳转到首页
|
||||
router.replaceUrl({
|
||||
// 使用测试账号直接登录
|
||||
this.dbService.validateUser('teststudent21', '123456').then((success: boolean) => {
|
||||
if (success) {
|
||||
// 设置当前用户
|
||||
settingsService.setCurrentAccount('teststudent21');
|
||||
// 记录登录成功日志
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_LOGIN, `Test login success: teststudent21`);
|
||||
// 跳转到主页
|
||||
router.pushUrl({
|
||||
url: 'pages/HomePage'
|
||||
});
|
||||
})
|
||||
}
|
||||
.width('90%')
|
||||
.padding(20)
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(16)
|
||||
.shadow({ radius: 8, color: 'rgba(0,0,0,0.1)', offsetY: 4 })
|
||||
|
||||
// 底部提示
|
||||
Row() {
|
||||
Button({ type: ButtonType.Capsule }) {
|
||||
Text("忘记密码?")
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
}
|
||||
.backgroundColor(Color.Transparent)
|
||||
.onClick(() => {
|
||||
AlertDialog.show({
|
||||
message: "忘记密码功能尚未开发,请联系管理员重置密码。",
|
||||
confirm: {
|
||||
value: "确定",
|
||||
action: () => {}
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
// 避免使用错误对象,直接记录测试登录失败
|
||||
logManager.error(LogCategory.USER, '测试登录失败');
|
||||
promptAction.showToast({
|
||||
message: '测试登录失败',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
|
||||
Blank(100)
|
||||
|
||||
Button({ type: ButtonType.Capsule }) {
|
||||
Text("注册")
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
}
|
||||
.backgroundColor(Color.Transparent)
|
||||
.onClick(() => {
|
||||
AlertDialog.show({
|
||||
message: "注册功能尚未开发,请联系管理员创建账号。",
|
||||
confirm: {
|
||||
value: "确定",
|
||||
action: () => {}
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
.width('90%')
|
||||
.margin({ top: 20 })
|
||||
}).finally(() => {
|
||||
this.isLoading = false;
|
||||
});
|
||||
})
|
||||
.shadow({
|
||||
radius: 8,
|
||||
color: 'rgba(0, 0, 0, 0.2)',
|
||||
offsetX: 2,
|
||||
offsetY: 4
|
||||
})
|
||||
.animation({
|
||||
duration: 250,
|
||||
curve: Curve.EaseInOut
|
||||
})
|
||||
.opacity(this.isLoading ? 0.6 : 1)
|
||||
}
|
||||
.height('100%')
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
.backgroundColor('#F5F7FA') // 页面背景色
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
// 页面生命周期方法
|
||||
@ -248,6 +555,23 @@ struct Login {
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.Log_LoginEvent('aboutToAppear');
|
||||
|
||||
// 获取应用目录中的Userpass.txt文件路径 - 使用应用程序内部文件目录而非resources
|
||||
const context = getContext(this) as common.UIAbilityContext;
|
||||
this.userpassFilePath = context.filesDir + "/Userpass.txt";
|
||||
|
||||
// 加载保存的用户凭证
|
||||
this.loadUserCredentials();
|
||||
|
||||
// 检查是否有保存的凭据
|
||||
setTimeout(() => {
|
||||
if (this.isRememberPassword && (!this.username || !this.password)) {
|
||||
promptAction.showToast({
|
||||
message: '当前没有保存的密码',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
}, 500); // 短暂延迟确保加载完成
|
||||
}
|
||||
|
||||
aboutToDisappear(): void {
|
||||
@ -278,17 +602,6 @@ struct Login {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
interface User{
|
||||
uname:string
|
||||
upwd:string
|
||||
}
|
||||
class Userinfo{
|
||||
uname:string
|
||||
upwd:string
|
||||
|
||||
constructor(uname: string, upwd: string) {
|
||||
this.uname = uname;
|
||||
this.upwd = upwd;
|
||||
}
|
||||
}*/
|
||||
export { Login }
|
||||
|
||||
|
489
entry/src/main/ets/pages/register.ets
Normal file
@ -0,0 +1,489 @@
|
||||
/**
|
||||
* Copyright (c) 2025 TDCAT.CN
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import prompt from '@ohos.promptAction';
|
||||
import { DatabaseService, RegisterUserData } from '../common/DatabaseService';
|
||||
import logManager, { LogCategory, LogEventType } from '../common/logtext';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Register {
|
||||
@State message: string = '注册新账号';
|
||||
@State username: string = ''; // 账号
|
||||
@State password: string = ''; // 密码
|
||||
@State confirmPassword: string = ''; // 确认密码
|
||||
@State nickname: string = ''; // 昵称
|
||||
@State email: string = ''; // 邮箱
|
||||
@State phone: string = ''; // 手机号
|
||||
@State photo: string = ''; // 用户照片
|
||||
@State isLoading: boolean = false; // 加载状态
|
||||
@State errorMessage: string = ''; // 错误信息
|
||||
@State isAgreementChecked: boolean = false; // 是否同意条款
|
||||
|
||||
// 获取数据库服务实例
|
||||
private dbService: DatabaseService = DatabaseService.getInstance();
|
||||
|
||||
// 验证输入
|
||||
private validateInput(): boolean {
|
||||
// 验证账号
|
||||
if (!this.username || this.username.trim() === '') {
|
||||
this.errorMessage = '请输入账号';
|
||||
return false;
|
||||
}
|
||||
if (this.username.length < 4) {
|
||||
this.errorMessage = '账号长度不能少于4位';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if (!this.password || this.password.trim() === '') {
|
||||
this.errorMessage = '请输入密码';
|
||||
return false;
|
||||
}
|
||||
if (this.password.length < 6) {
|
||||
this.errorMessage = '密码长度不能少于6位';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证确认密码
|
||||
if (this.password !== this.confirmPassword) {
|
||||
this.errorMessage = '两次输入的密码不一致';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证邮箱
|
||||
if (!this.email || this.email.trim() === '') {
|
||||
this.errorMessage = '请输入邮箱';
|
||||
return false;
|
||||
}
|
||||
if (!this.dbService.validateEmailFormat(this.email)) {
|
||||
this.errorMessage = '请输入有效的邮箱地址';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证手机号(如果填写)
|
||||
if (this.phone && !/^1[3-9]\d{9}$/.test(this.phone)) {
|
||||
this.errorMessage = '请输入有效的手机号';
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证条款
|
||||
if (!this.isAgreementChecked) {
|
||||
this.errorMessage = '请阅读并同意相关条款';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 处理注册
|
||||
private async handleRegister(): Promise<void> {
|
||||
if (!this.validateInput()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
this.errorMessage = '';
|
||||
|
||||
try {
|
||||
// 准备注册数据
|
||||
const userData: RegisterUserData = {
|
||||
account: this.username,
|
||||
password: this.password,
|
||||
nickname: this.nickname || this.username,
|
||||
email: this.email,
|
||||
phone: this.phone,
|
||||
photo: this.photo || 'http://139.155.155.67:2342/images/default_avatar.png'
|
||||
};
|
||||
|
||||
// 发送注册请求
|
||||
const success = await this.dbService.registerUser(userData);
|
||||
if (success) {
|
||||
logManager.info(LogCategory.USER, LogEventType.USER_REGISTER, `User registered: ${this.username}`);
|
||||
prompt.showToast({
|
||||
message: '注册成功',
|
||||
duration: 2000
|
||||
});
|
||||
router.back();
|
||||
} else {
|
||||
this.errorMessage = '注册失败,请稍后重试';
|
||||
}
|
||||
} catch {
|
||||
this.errorMessage = '注册失败,请稍后重试';
|
||||
logManager.error(LogCategory.USER, 'Register error occurred');
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 顶部导航栏
|
||||
Row() {
|
||||
Image($r('app.media.back'))
|
||||
.width(24)
|
||||
.height(24)
|
||||
.margin({ right: 16 })
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
|
||||
Text(this.message)
|
||||
.fontSize(24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor('#333333')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
.padding({ top: 16, bottom: 16, left: 16, right: 16 })
|
||||
|
||||
// 主滚动内容
|
||||
Scroll() {
|
||||
Column({ space: 20 }) {
|
||||
// 用户照片上传区域
|
||||
Column() {
|
||||
Image(this.photo || $r('app.media.default_avatar'))
|
||||
.width(100)
|
||||
.height(100)
|
||||
.borderRadius(50)
|
||||
.margin({ top: 10, bottom: 10 })
|
||||
.onClick(() => {
|
||||
prompt.showToast({
|
||||
message: '照片上传功能开发中',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
|
||||
Text("点击更换头像")
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
|
||||
// 表单区域
|
||||
Column({ space: 16 }) {
|
||||
// 账号输入框
|
||||
Column({ space: 4 }) {
|
||||
Row() {
|
||||
Text("账号")
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
Text("*")
|
||||
.fontSize(16)
|
||||
.fontColor('#FF0000')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入账号(至少4位)' })
|
||||
.type(InputType.Normal)
|
||||
.placeholderColor('#BBBBBB')
|
||||
.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.username = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 密码输入框
|
||||
Column({ space: 4 }) {
|
||||
Row() {
|
||||
Text("密码")
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
Text("*")
|
||||
.fontSize(16)
|
||||
.fontColor('#FF0000')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入密码(至少6位)' })
|
||||
.type(InputType.Password)
|
||||
.placeholderColor('#BBBBBB')
|
||||
.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%')
|
||||
|
||||
// 确认密码输入框
|
||||
Column({ space: 4 }) {
|
||||
Row() {
|
||||
Text("确认密码")
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
Text("*")
|
||||
.fontSize(16)
|
||||
.fontColor('#FF0000')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请再次输入密码' })
|
||||
.type(InputType.Password)
|
||||
.placeholderColor('#BBBBBB')
|
||||
.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.confirmPassword = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 昵称输入框
|
||||
Column({ space: 4 }) {
|
||||
Row() {
|
||||
Text("昵称")
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
Text("(选填)")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入昵称' })
|
||||
.type(InputType.Normal)
|
||||
.placeholderColor('#BBBBBB')
|
||||
.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.nickname = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 邮箱输入框
|
||||
Column({ space: 4 }) {
|
||||
Row() {
|
||||
Text("邮箱")
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
Text("*")
|
||||
.fontSize(16)
|
||||
.fontColor('#FF0000')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入邮箱' })
|
||||
.type(InputType.Email)
|
||||
.placeholderColor('#BBBBBB')
|
||||
.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.email = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 手机号输入框
|
||||
Column({ space: 4 }) {
|
||||
Row() {
|
||||
Text("手机号")
|
||||
.fontSize(16)
|
||||
.fontColor('#333333')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
Text("(选填)")
|
||||
.fontSize(16)
|
||||
.fontColor('#666666')
|
||||
}
|
||||
.width('100%')
|
||||
.justifyContent(FlexAlign.Start)
|
||||
|
||||
TextInput({ placeholder: '请输入手机号' })
|
||||
.type(InputType.Number)
|
||||
.placeholderColor('#BBBBBB')
|
||||
.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.phone = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 错误信息提示
|
||||
if (this.errorMessage !== '') {
|
||||
Text(this.errorMessage)
|
||||
.fontSize(14)
|
||||
.fontColor('#FF0000')
|
||||
.width('100%')
|
||||
.backgroundColor('#FFF0F0')
|
||||
.padding(8)
|
||||
.borderRadius(4)
|
||||
}
|
||||
|
||||
// 条款同意选项
|
||||
Row() {
|
||||
Checkbox()
|
||||
.select(this.isAgreementChecked)
|
||||
.selectedColor('#2196F3')
|
||||
.width(20)
|
||||
.height(20)
|
||||
.margin({ right: 8 })
|
||||
.onChange((value: boolean) => {
|
||||
this.isAgreementChecked = value;
|
||||
this.errorMessage = '';
|
||||
})
|
||||
|
||||
Text() {
|
||||
Span('我已阅读并同意')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
|
||||
Span('《用户服务协议》')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/agreements/UserAgreement'
|
||||
});
|
||||
})
|
||||
|
||||
Span('、')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
|
||||
Span('《隐私政策》')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/agreements/PrivacyPolicy'
|
||||
});
|
||||
})
|
||||
|
||||
Span('和')
|
||||
.fontSize(14)
|
||||
.fontColor('#666666')
|
||||
|
||||
Span('《数据处理声明》')
|
||||
.fontSize(14)
|
||||
.fontColor('#2196F3')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.onClick(() => {
|
||||
router.pushUrl({
|
||||
url: 'pages/agreements/DataProcessingStatement'
|
||||
});
|
||||
})
|
||||
}
|
||||
.width('90%')
|
||||
.textAlign(TextAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(VerticalAlign.Center)
|
||||
.margin({ top: 10, bottom: 10 })
|
||||
|
||||
// 提交按钮
|
||||
Button() {
|
||||
if (this.isLoading) {
|
||||
Row() {
|
||||
LoadingProgress()
|
||||
.width(24)
|
||||
.height(24)
|
||||
.color(Color.White)
|
||||
Text('注册中...')
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor(Color.White)
|
||||
.margin({ left: 12 })
|
||||
}
|
||||
} else {
|
||||
Text('注册账号')
|
||||
.fontSize(18)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor(Color.White)
|
||||
}
|
||||
}
|
||||
.type(ButtonType.Capsule)
|
||||
.width('100%')
|
||||
.height(50)
|
||||
.backgroundColor('#2196F3')
|
||||
.enabled(!this.isLoading)
|
||||
.stateEffect(true)
|
||||
.onClick(() => {
|
||||
this.handleRegister();
|
||||
})
|
||||
.margin({ top: 10, bottom: 20 })
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.backgroundColor(Color.White)
|
||||
.borderRadius(16)
|
||||
}
|
||||
.width('100%')
|
||||
.padding({ left: 16, right: 16, bottom: 30 })
|
||||
}
|
||||
.width('100%')
|
||||
.layoutWeight(1)
|
||||
.scrollBar(BarState.Off)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('#F0F5FF')
|
||||
}
|
||||
}
|
81
entry/src/main/ets/util/WebsocketMessage.ets
Normal file
@ -0,0 +1,81 @@
|
||||
import { webSocket } from "@kit.NetworkKit";
|
||||
import { BusinessError } from "@kit.BasicServicesKit";
|
||||
import { hilog } from "@kit.PerformanceAnalysisKit";
|
||||
|
||||
const DOMAIN: number = 0
|
||||
const TAG: string = "websocket message"
|
||||
|
||||
export default class WebSocketMessage {
|
||||
private ws = webSocket.createWebSocket();
|
||||
private url: string;
|
||||
private room: string;
|
||||
private onMessageCallback: (data: string | ArrayBuffer) => void = () => {
|
||||
};
|
||||
|
||||
constructor(url: string, room: string) {
|
||||
this.url = url;
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
public connect(): void {
|
||||
this.ws.on('open', (err: BusinessError, value: Object) => {
|
||||
hilog.debug(DOMAIN, TAG, "on open, status: " + JSON.stringify(value));
|
||||
this.ws.send("Hello, server!", (err: BusinessError, success: boolean) => {
|
||||
if (!err) {
|
||||
hilog.debug(DOMAIN, TAG, "Message sent successfully");
|
||||
} else {
|
||||
hilog.debug(DOMAIN, TAG, "Failed to send the message. Err: " + JSON.stringify(err));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.ws.on('message', (err: BusinessError, value: string | ArrayBuffer) => {
|
||||
hilog.debug(DOMAIN, TAG, "on message, message: " + value);
|
||||
if (value === 'bye') {
|
||||
this.close();
|
||||
}
|
||||
this.onMessageCallback(value);
|
||||
});
|
||||
|
||||
this.ws.on('close', (err: BusinessError, value: webSocket.CloseResult) => {
|
||||
hilog.debug(DOMAIN, TAG, "on close, code: " + value.code + ", reason: " + value.reason);
|
||||
});
|
||||
|
||||
this.ws.on('error', (err: BusinessError) => {
|
||||
hilog.debug(DOMAIN, TAG, "on error, error: " + JSON.stringify(err));
|
||||
});
|
||||
|
||||
const wsUrl = `ws://${this.url}/ws/room?room=${this.room}`;
|
||||
this.ws.connect(wsUrl, (err: BusinessError, connected: boolean) => {
|
||||
if (!err) {
|
||||
hilog.debug(DOMAIN, TAG, "Connected successfully");
|
||||
} else {
|
||||
hilog.debug(DOMAIN, TAG, "Connection failed. Err: " + JSON.stringify(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public setOnMessage(callback: (data: string | ArrayBuffer) => void): void {
|
||||
this.onMessageCallback = callback;
|
||||
}
|
||||
|
||||
public sendMessage(message: string): void {
|
||||
this.ws.send(message, (err: BusinessError, success: boolean) => {
|
||||
if (!err) {
|
||||
hilog.debug(DOMAIN, TAG, "Message sent: " + message);
|
||||
} else {
|
||||
hilog.debug(DOMAIN, TAG, "Send failed: " + JSON.stringify(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
this.ws.close((err: BusinessError, success: boolean) => {
|
||||
if (!err) {
|
||||
hilog.debug(DOMAIN, TAG, "Connection closed successfully");
|
||||
} else {
|
||||
hilog.debug(DOMAIN, TAG, "Failed to close the connection. Err: " + JSON.stringify(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
BIN
entry/src/main/resources/base/media/add.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
entry/src/main/resources/base/media/back.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
entry/src/main/resources/base/media/close.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
entry/src/main/resources/base/media/default_avatar.webp
Normal file
After Width: | Height: | Size: 450 KiB |
BIN
entry/src/main/resources/base/media/delete.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
entry/src/main/resources/base/media/ic_test.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
entry/src/main/resources/base/media/logo.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
entry/src/main/resources/base/media/question.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
entry/src/main/resources/base/media/see.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
@ -1,10 +1,18 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/login",
|
||||
"pages/register",
|
||||
"pages/WelcomePage",
|
||||
"pages/HomePage",
|
||||
"pages/SettingsPage",
|
||||
"pages/ClassPage",
|
||||
"pages/TransitionPage"
|
||||
"pages/TransitionPage",
|
||||
"pages/ClassLivePage",
|
||||
"pages/AccountPage",
|
||||
"pages/StartPage",
|
||||
"pages/Index",
|
||||
"pages/agreements/PrivacyPolicy",
|
||||
"pages/agreements/UserAgreement",
|
||||
"pages/agreements/DataProcessingStatement"
|
||||
]
|
||||
}
|
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "classmg-server",
|
||||
"version": "1.0.0",
|
||||
"description": "Communication server for ClassMG application",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5"
|
||||
}
|
||||
}
|