Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2a5ab9e3f | ||
|
|
4cbd11eb29 | ||
|
|
9a2123bf47 | ||
|
|
454c6825fa | ||
|
|
97f490e304 | ||
|
|
3aae9200eb | ||
|
|
8f4dd7f5ca | ||
|
|
df478d3516 | ||
|
|
b08d7c1ede | ||
|
|
991f032502 | ||
|
|
61aa025055 | ||
|
|
75d8402ff8 | ||
|
|
c2ef40c4c0 | ||
|
|
29ebabdc4e | ||
|
|
a6bbfb4827 | ||
|
|
632663ce02 | ||
|
|
831e4666f7 | ||
|
|
e69ee64088 | ||
|
|
9861e1af20 | ||
|
|
3e8e94147a | ||
|
|
e5beb6e5a2 | ||
|
|
f9b31383da | ||
|
|
3be384a668 | ||
|
|
1cdabd1ee7 | ||
|
|
e36e5548c1 | ||
|
|
75f6207ccc | ||
|
|
dc7e7fe41b | ||
|
|
1937f09864 | ||
|
|
7093fe22d1 | ||
|
|
ca716ed0dd | ||
|
|
624214a061 | ||
|
|
c56533c2da | ||
|
|
8de7d2ca6f | ||
|
|
937bdd0356 | ||
|
|
485d0b07ca | ||
|
|
0d26b9f89f | ||
|
|
cbb05d5aec | ||
|
|
f11a2dc840 | ||
|
|
31afac93d3 | ||
|
|
8344e3e349 | ||
|
|
91b06ec8fe | ||
|
|
00776ca3a2 | ||
|
|
4f1efc489a | ||
|
|
73f7c687c2 | ||
|
|
a18f26f308 | ||
|
|
20a71ce910 | ||
|
|
00a551f784 | ||
|
|
c66589574c | ||
|
|
2aa1c0bcb2 | ||
|
|
722e413663 | ||
|
|
a7febd84ef | ||
|
|
6deb400144 | ||
|
|
6a5ef1226c | ||
|
|
e97763bfab | ||
|
|
4d5d6fd006 | ||
|
|
1f22424b78 | ||
|
|
67fced6dc7 | ||
|
|
543e7d8ee7 | ||
|
|
dc1fea5f95 | ||
|
|
76fe507e18 | ||
|
|
653dffc14f | ||
|
|
01dbb4461d | ||
|
|
564ae42a57 | ||
|
|
980518df46 | ||
|
|
d6ea0b35d8 | ||
|
|
cb6bf496eb | ||
|
|
cd86161c18 | ||
|
|
d1af83f95d | ||
|
|
2e7f71e860 | ||
|
|
7609e2e525 | ||
|
|
29efc22705 | ||
|
|
bcd4bca768 | ||
|
|
23a0c4b32e | ||
|
|
6e7f4c7cc3 | ||
|
|
9141e861c4 | ||
|
|
81e36f140d | ||
|
|
8d9c13b50b | ||
|
|
97bb7146aa | ||
|
|
e87e0d14e1 | ||
|
|
9ecb124f6e | ||
|
|
14ebc3acc7 | ||
|
|
80f7dc994c | ||
|
|
fc1fec7fc5 | ||
|
|
fcb4b8b027 | ||
|
|
9623fb033b | ||
|
|
269fd4a6fe | ||
|
|
ce7b525f1a | ||
|
|
3b7b523bec | ||
|
|
c1e551b7fb | ||
|
|
a5d1eb7cbe | ||
|
|
c3a8b7d57a | ||
|
|
dc4db4da28 | ||
|
|
c22c5dd51c | ||
|
|
13c6ee54ab | ||
|
|
905f1b37d1 | ||
|
|
321e055726 | ||
|
|
3d015baa56 | ||
|
|
0c1fb6b097 | ||
|
|
728b4a3bd0 | ||
|
|
14a43efb67 | ||
|
|
1f8e2b1e6e | ||
|
|
3af9250443 | ||
|
|
3f993c838f | ||
|
|
edefa34898 | ||
|
|
4fda24f62c | ||
|
|
92fb899d89 | ||
|
|
7a89991358 | ||
|
|
4f48e1dbaa | ||
|
|
a69621e016 | ||
|
|
2a49736cb8 | ||
|
|
f1080e3618 | ||
|
|
03fc965929 | ||
|
|
f991099b54 | ||
|
|
7962ab17a4 | ||
|
|
6cd8a0abea | ||
|
|
26672514f6 | ||
|
|
a201617a92 | ||
|
|
0c8f6dc6ed | ||
|
|
c1a935b88e | ||
|
|
7d8d2c5461 | ||
|
|
00fd583495 | ||
|
|
e693ebe3d1 | ||
|
|
14e391e5bb | ||
|
|
2292184e9e | ||
|
|
206993241a | ||
|
|
d40f0b8eaf | ||
|
|
f6779f2339 | ||
|
|
25f8e9d643 |
@@ -0,0 +1,15 @@
|
|||||||
|
# 数据库配置
|
||||||
|
MYSQL_ROOT_PASSWORD=root
|
||||||
|
MYSQL_DATABASE=comcms
|
||||||
|
MYSQL_USER=comcms
|
||||||
|
MYSQL_PASSWORD=comcms123
|
||||||
|
|
||||||
|
# Redis 配置
|
||||||
|
REDIS_PASSWORD=
|
||||||
|
|
||||||
|
# ASP.NET Core 环境
|
||||||
|
ASPNETCORE_ENVIRONMENT=Production
|
||||||
|
|
||||||
|
# 数据库连接字符串(会被覆盖,但保留作为参考)
|
||||||
|
# ConnectionStrings__dbconn__ConnectionString=Server=mysql;Port=3306;Database=comcms;Uid=comcms;Pwd=comcms123;charset=utf8mb4;
|
||||||
|
# ConnectionStrings__dbconn__providerName=MySql.Data.MySqlClient
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# MySQL 配置
|
||||||
|
MYSQL_HOST=localhost
|
||||||
|
MYSQL_PORT=3306
|
||||||
|
MYSQL_DATABASE=comcms
|
||||||
|
MYSQL_USER=root
|
||||||
|
MYSQL_PASSWORD=your_password_here
|
||||||
|
|
||||||
|
# Redis 配置
|
||||||
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_PASSWORD=your_redis_password_here
|
||||||
|
REDIS_DB=2
|
||||||
|
|
||||||
|
# JWT 配置
|
||||||
|
JWT_SECRET=your_jwt_secret_here
|
||||||
|
|
||||||
|
# 系统配置
|
||||||
|
SIGN_SALT=your_salt_here
|
||||||
|
|
||||||
|
# ASP.NET Core 环境
|
||||||
|
ASPNETCORE_ENVIRONMENT=Development
|
||||||
@@ -1,406 +0,0 @@
|
|||||||
# NewLife Copilot 协作指令
|
|
||||||
|
|
||||||
本说明适用于新生命团队(NewLife)及其全部开源/衍生项目,规范 Copilot 及类似智能助手在 C#/.NET 项目中的协作行为。
|
|
||||||
|
|
||||||
> 目标:把"每次请求必须携带的通用规则"控制在可接受体积;组件/业务专项流程放在 `.github/instructions/`,按需读取。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. 核心原则
|
|
||||||
|
|
||||||
| 原则 | 说明 |
|
|
||||||
|------|------|
|
|
||||||
| **提效** | 减少机械样板,聚焦业务/核心算法 |
|
|
||||||
| **一致** | 风格、结构、命名、API 行为稳定 |
|
|
||||||
| **可控** | 限制改动影响面,可审计,兼容友好 |
|
|
||||||
| **可靠** | 先检索再生成,不虚构,不破坏现有合约 |
|
|
||||||
| **主动** | 发现问题主动修复,不回避合理优化 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. 适用范围
|
|
||||||
|
|
||||||
- 含 NewLife 组件或衍生的全部 C#/.NET 仓库
|
|
||||||
- 不含纯前端/非 .NET/市场文案
|
|
||||||
- 存在本文件 → 必须遵循
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. 组件专用指令索引(按需加载)
|
|
||||||
|
|
||||||
以下专用指令**仅在相关任务时**才需要读取,避免每次请求都携带大段流程/示例。
|
|
||||||
|
|
||||||
### 3.1 XCode / Cube(数据库 & Web 快速开发)
|
|
||||||
|
|
||||||
当任务涉及以下任一信号时,请**先搜索并检查当前仓库** `.github/instructions/xcode.instructions.md` **是否存在**,若存在则读取并遵循:
|
|
||||||
|
|
||||||
- 需求包含:XCode/Cube/魔方/实体生成/模型 XML/数据类库/数据库 CRUD/Controller 生成/`xcodetool`/`xcode` 命令
|
|
||||||
- 解决方案/项目中出现:`NewLife.XCode` 包引用
|
|
||||||
- 存在:`Model.xml`、`*.xcode.xml`、`*.Data.csproj`(或项目名以 `.Data` 结尾)
|
|
||||||
- 代码出现命名空间/类型:`XCode.*`、`Entity`(XCode 实体基类)、XCode 相关特性/接口
|
|
||||||
- **用户提到修改任意 `.xml` 文件**(如 `member.xml`、`area.xml` 等配置文件),应**主动搜索** `xcode.instructions.md` 判断是否需要引入
|
|
||||||
|
|
||||||
**主动检测策略**:当用户提及 XML 文件修改时,即使未明确提到 XCode 关键字,也应先用 `file_search` 搜索 `xcode.instructions.md`,若存在则读取,以确定该 XML 文件是否属于 XCode/Cube 体系。
|
|
||||||
|
|
||||||
未满足以上条件时,**不要**引入 XCode/Cube 初始化流程,避免干扰其它仓库的常规开发。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. 工作流
|
|
||||||
|
|
||||||
```
|
|
||||||
需求分类 → 检索 → 评估 → 设计 → 实施 → 验证 → 说明
|
|
||||||
```
|
|
||||||
|
|
||||||
1. **需求分类**:功能/修复/性能/重构/文档
|
|
||||||
2. **检索**:相关类型、目录、方法、已有扩展/工具(**优先复用**)
|
|
||||||
3. **评估**:是否公共 API?是否性能热点?**是否存在潜在问题?**
|
|
||||||
4. **设计**:列出改动点 + 兼容/降级策略
|
|
||||||
5. **实施**:
|
|
||||||
- 完成用户请求的核心任务
|
|
||||||
- **顺带修复**发现的明显缺陷(资源泄漏、空引用、逻辑错误)
|
|
||||||
- **顺带优化**可简化的重复代码
|
|
||||||
- 保留原注释与结构,除非注释本身有误
|
|
||||||
6. **验证**:
|
|
||||||
- 代码变更:必须编译通过;运行相关单元测试(未找到需说明)
|
|
||||||
- 仅文档变更(未修改任何代码文件):可跳过编译与单元测试
|
|
||||||
7. **说明**:变更摘要/影响范围/风险点
|
|
||||||
|
|
||||||
### 4.1 主动优化原则
|
|
||||||
|
|
||||||
当用户请求分析或优化代码时,**应主动**:
|
|
||||||
|
|
||||||
| 类型 | 行动 |
|
|
||||||
|------|------|
|
|
||||||
| **架构梳理** | 梳理代码架构并进行重构,让代码结构更清晰易懂 |
|
|
||||||
| **语法现代化** | 使用最新的 C# 语法来简化代码,提升可读性 |
|
|
||||||
| **缺陷修复** | 资源泄漏、空引用风险、并发问题、逻辑错误 → 直接修复,让代码更健壮 |
|
|
||||||
| **性能优化** | 无用分配、重复计算、可池化资源 → 通过缓存减少耗时的重复计算 |
|
|
||||||
| **代码简化** | 重复代码提取、冗余判断合并、现代语法替换 → 在不影响可读性前提下简化 |
|
|
||||||
| **注释完善** | 补充类、接口、属性、方法头部的注释,以及方法内部重要代码的注释 |
|
|
||||||
| **架构参考** | 参考网络上同类功能的优秀架构,给出架构调整建议 |
|
|
||||||
|
|
||||||
**架构调整策略**:
|
|
||||||
- **改动较小**:直接调整,完成后说明变更内容
|
|
||||||
- **改动较大**:先列出调整方案,询问用户意见,待确认后再修改
|
|
||||||
|
|
||||||
**不应过度保守**:
|
|
||||||
- ❌ 仅添加注释而忽略明显的代码问题
|
|
||||||
- ❌ 发现资源泄漏却不修复
|
|
||||||
- ❌ 看到重复代码却不提取
|
|
||||||
- ❌ 用户要求优化时只做表面工作
|
|
||||||
|
|
||||||
**保持谨慎的场景**:
|
|
||||||
- 公共 API 签名变更 → 需说明兼容性影响
|
|
||||||
- 性能关键路径 → 需有依据或说明推理
|
|
||||||
- 大范围重构 → 需先与用户确认范围
|
|
||||||
|
|
||||||
### 4.2 防御性注释规则
|
|
||||||
|
|
||||||
在旧有代码中,经常可以看到**被注释掉的代码**,这些注释代码前面通常带有说明文字。
|
|
||||||
|
|
||||||
**这些是防御性注释**:
|
|
||||||
- 记录了过去曾经踩过的坑
|
|
||||||
- 目的是告诉后来人不要按照注释代码去写,否则会有问题
|
|
||||||
- **禁止删除此类防御性注释**,用于警示后人
|
|
||||||
|
|
||||||
**识别特征**:
|
|
||||||
```csharp
|
|
||||||
// 曾经尝试过 xxx 方案,但会导致 yyy 问题
|
|
||||||
// var result = DoSomethingWrong();
|
|
||||||
|
|
||||||
// 不要使用 xxx,否则会造成 yyy
|
|
||||||
// await client.SendAsync(data);
|
|
||||||
|
|
||||||
// 这里不能用 xxx,因为 yyy
|
|
||||||
// stream.Flush();
|
|
||||||
```
|
|
||||||
|
|
||||||
**处理原则**:
|
|
||||||
- ✅ 保留这类带说明的注释代码
|
|
||||||
- ✅ 可以补充更详细的说明,解释为什么不能这样做
|
|
||||||
- ❌ 不要删除这类防御性注释
|
|
||||||
- ❌ 不要尝试"恢复"这些被注释的代码
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. 编码规范
|
|
||||||
|
|
||||||
### 5.1 基础规范
|
|
||||||
|
|
||||||
| 项目 | 规范 |
|
|
||||||
|------|------|
|
|
||||||
| 语言版本 | `<LangVersion>latest</LangVersion>`,所有目标框架均使用最新 C# 语法 |
|
|
||||||
| 命名空间 | file-scoped namespace |
|
|
||||||
| 类型名 | **必须**使用 .NET 正式名 `String`/`Int32`/`Boolean` 等,避免 `string`/`int`/`bool` |
|
|
||||||
| 兼容性 | 代码需兼容 .NET 4.5+;**禁止**使用 `ArgumentNullException.ThrowIfNull`,改用 `if (value == null) throw new ArgumentNullException(nameof(value));` |
|
|
||||||
| 单文件 | 每文件一个主要公共类型;较大平台差异使用 `partial` |
|
|
||||||
|
|
||||||
### 5.2 命名规范
|
|
||||||
|
|
||||||
| 成员类型 | 命名规则 | 示例 |
|
|
||||||
|---------|---------|------|
|
|
||||||
| 类型/公共成员 | PascalCase | `UserService`、`GetName()` |
|
|
||||||
| 参数/局部变量 | camelCase | `userName`、`count` |
|
|
||||||
| 私有字段(实例/静态) | `_camelCase` | `_cache`、`_instance` |
|
|
||||||
| 属性/方法(实例/静态) | PascalCase | `Name`、`Default`、`Create()` |
|
|
||||||
| 扩展方法类 | `xxxHelper` 或 `xxxExtensions` | `StringHelper`、`CollectionExtensions` |
|
|
||||||
|
|
||||||
### 5.3 代码风格
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// ✅ 单行 if:单语句且整行不过长时同行
|
|
||||||
if (value == null) return;
|
|
||||||
if (key == null) throw new ArgumentNullException(nameof(key));
|
|
||||||
|
|
||||||
// ✅ 单行 if:语句较长时另起一行
|
|
||||||
if (value == null)
|
|
||||||
throw new ArgumentNullException(nameof(value), "Value cannot be null");
|
|
||||||
|
|
||||||
// ✅ 多分支单语句:不加花括号
|
|
||||||
if (count > 0)
|
|
||||||
DoSomething();
|
|
||||||
else
|
|
||||||
DoOther();
|
|
||||||
|
|
||||||
// ✅ 循环必须保留花括号(即使单语句)
|
|
||||||
foreach (var item in list)
|
|
||||||
{
|
|
||||||
Process(item);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5.4 Region 组织结构
|
|
||||||
|
|
||||||
较长的类使用 `#region` 分段组织,顺序为:`属性` → `静态`(如有)→ `构造` → `方法` → `辅助`(如有)→ `日志`。
|
|
||||||
|
|
||||||
**日志 Region 规则**:
|
|
||||||
- 类代码中如果带有 `ILog Log { get; set; }` 和 `WriteLog` 方法
|
|
||||||
- **必须放在类代码的最后**
|
|
||||||
- **必须用名为"日志"的 region 包裹**
|
|
||||||
- 不要放在"辅助" region 中,应单独作为"日志" region
|
|
||||||
|
|
||||||
### 5.5 现代 C# 语法
|
|
||||||
|
|
||||||
优先使用最新语法(switch 表达式、模式匹配、目标类型 `new`、record 等),即使目标框架是 net45。
|
|
||||||
|
|
||||||
### 5.6 集合表达式
|
|
||||||
|
|
||||||
优先使用集合表达式 `[]` 初始化集合:`List<String> Tags { get; set; } = [];`
|
|
||||||
|
|
||||||
### 5.7 Null 条件运算符
|
|
||||||
|
|
||||||
优先使用 `?.` / `??` 简化空值检查:`span?.AppendTag("test");` `var name = user?.Profile?.Name ?? "";`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 6. 多目标框架
|
|
||||||
|
|
||||||
NewLife 支持 `net45` 到 `net10`,常用条件符号:`NETFRAMEWORK`、`NETSTANDARD2_0`、`NETCOREAPP`、`NET5_0_OR_GREATER`、`NET6_0_OR_GREATER`、`NET8_0_OR_GREATER`。
|
|
||||||
|
|
||||||
新增 API 时需评估各框架兼容性,必要时提供降级实现。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 7. 文档注释
|
|
||||||
|
|
||||||
| 规则 | 说明 |
|
|
||||||
|------|------|
|
|
||||||
| `<summary>` | **必须同一行闭合**,简短描述方法用途 |
|
|
||||||
| `<param>` | **必须为每个参数添加**,无论方法可见性如何 |
|
|
||||||
| `<returns>` | 有返回值时必须添加 |
|
|
||||||
| `<remarks>` | 复杂方法可增加详细说明(可多行) |
|
|
||||||
| 覆盖范围 | `public`/`protected` 成员必须注释;`private`/`internal` 建议添加 |
|
|
||||||
| `[Obsolete]` | 必须包含迁移建议 |
|
|
||||||
|
|
||||||
**正确示例**:`/// <summary>获取名称</summary>` `/// <param name="id">编号</param>`
|
|
||||||
|
|
||||||
**禁止**:`<summary>` 拆成多行;缺少 `<param>`;有参数但无 param 标签。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 8. 异步与性能
|
|
||||||
|
|
||||||
| 规范 | 说明 |
|
|
||||||
|------|------|
|
|
||||||
| 方法命名 | 异步方法后缀 `Async` |
|
|
||||||
| ConfigureAwait | 库内部默认 `ConfigureAwait(false)` |
|
|
||||||
| 高频路径 | 优先对象池/`ArrayPool<T>`/`Span`,避免多余分配 |
|
|
||||||
| 反射/Linq | 仅用于非热点路径;热点使用手写循环/缓存 |
|
|
||||||
| 池化资源 | 明确获取/归还;异常分支不遗失归还 |
|
|
||||||
|
|
||||||
**内置工具优先**:`Pool.StringBuilder`、`Runtime.TickCount64`、`ToInt()`/`ToBoolean()` 等扩展方法。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 9. 日志与追踪
|
|
||||||
|
|
||||||
规则:若类包含 `ILog Log` 与 `WriteLog`,必须放在类末尾,并用名为"日志"的 `#region` 包裹;关键过程可使用 `Tracer?.NewSpan()` 埋点。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 10. 错误处理
|
|
||||||
|
|
||||||
- **精准异常类型**:`ArgumentNullException`/`InvalidOperationException` 等
|
|
||||||
- **参数校验**:空/越界/格式
|
|
||||||
- **TryXxx 模式**:不用异常作常规分支
|
|
||||||
- **类型转换**:优先使用 `ToInt()`/`ToBoolean()` 等扩展方法
|
|
||||||
- **对外异常**:不暴露内部实现/路径
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 11. 测试规范
|
|
||||||
|
|
||||||
| 项目 | 规范 |
|
|
||||||
|------|------|
|
|
||||||
| 框架 | xUnit |
|
|
||||||
| 命名 | `{ClassName}Tests` |
|
|
||||||
| 描述 | `[DisplayName("中文描述意图")]` |
|
|
||||||
| IO | 使用临时目录;端口用 0/随机 |
|
|
||||||
| 覆盖 | 正常/边界/异常/并发(必要时) |
|
|
||||||
|
|
||||||
### 测试执行策略
|
|
||||||
|
|
||||||
1. 优先检索 `{ClassName}` 引用,若落入测试项目则运行
|
|
||||||
2. 未命中则查找 `{ClassName}Tests.cs`
|
|
||||||
3. **未发现相关测试需明确说明**,不自动创建测试项目
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 12. NuGet 发布规范
|
|
||||||
|
|
||||||
| 类型 | 命名规则 | 示例 |
|
|
||||||
|------|---------|------|
|
|
||||||
| 正式版 | `{主版本}.{子版本}.{年}.{月日}` | `11.9.2025.0701` |
|
|
||||||
| 测试版 | `{主版本}.{子版本}.{年}.{月日}-beta{时分}` | `11.9.2025.0701-beta0906` |
|
|
||||||
|
|
||||||
- **正式版**:每月月初发布
|
|
||||||
- **测试版**:提交代码到 GitHub 时自动发布
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 13. Markdown 文档规范
|
|
||||||
|
|
||||||
| 项目 | 规范 |
|
|
||||||
|------|------|
|
|
||||||
| 文件编码 | **必须** UTF-8,**禁止** GB2312/GBK/UTF-8 BOM |
|
|
||||||
| 默认存放 | 代码库根目录下的 `Doc` 目录 |
|
|
||||||
| 文件命名 | 优先**中文文件名**,简洁描述内容 |
|
|
||||||
|
|
||||||
**注意**:已有文件**必须先读取**再增量修改,**禁止直接覆盖**。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 14. Copilot 行为守则
|
|
||||||
|
|
||||||
### 必须
|
|
||||||
|
|
||||||
- 简体中文回复
|
|
||||||
- 输出前检索现有实现,**禁止重复造轮子**
|
|
||||||
- 先列方案再实现
|
|
||||||
- 标记不确定上下文为"需查看文件"
|
|
||||||
- **发现明显缺陷时主动修复**(资源泄漏、空引用、逻辑错误)
|
|
||||||
- **用户要求优化时深入分析**,不做表面工作
|
|
||||||
|
|
||||||
### 鼓励
|
|
||||||
|
|
||||||
- 提取重复代码为公共方法
|
|
||||||
- 简化冗余的条件判断
|
|
||||||
- 使用现代 C# 语法改进可读性
|
|
||||||
- 补充缺失的资源释放逻辑
|
|
||||||
- 修正错误或过时的注释
|
|
||||||
|
|
||||||
### 禁止
|
|
||||||
|
|
||||||
- 虚构 API/文件/类型
|
|
||||||
- 伪造测试结果/性能数据
|
|
||||||
- 擅自删除公共/受保护成员
|
|
||||||
- 擅自删除已有代码注释(除非注释本身错误)
|
|
||||||
- **删除防御性注释**(带说明的注释代码,记录历史踩坑经验)
|
|
||||||
- 仅删除空白行制造"格式优化"提交
|
|
||||||
- 删除循环体的花括号
|
|
||||||
- 将 `<summary>` 拆成多行
|
|
||||||
- 将 `String`/`Int32` 改为 `string`/`int`
|
|
||||||
- 新增外部依赖(除非说明理由并给出权衡)
|
|
||||||
- 在热点路径添加未缓存反射/复杂 Linq
|
|
||||||
- 输出敏感凭据/内部地址
|
|
||||||
- **发现问题却视而不见**
|
|
||||||
- **用户要求优化时仅做注释/测试等表面工作**
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 15. 变更说明模板
|
|
||||||
|
|
||||||
提交或答复需包含:
|
|
||||||
|
|
||||||
```markdown
|
|
||||||
## 概述
|
|
||||||
做了什么 / 为什么
|
|
||||||
|
|
||||||
## 影响
|
|
||||||
- 公共 API:是/否
|
|
||||||
- 性能影响:无/有(说明)
|
|
||||||
|
|
||||||
## 兼容性
|
|
||||||
降级策略 / 条件编译点
|
|
||||||
|
|
||||||
## 风险
|
|
||||||
潜在回归 / 性能开销
|
|
||||||
|
|
||||||
## 后续
|
|
||||||
是否补测试 / 文档
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 16. 术语说明
|
|
||||||
|
|
||||||
| 术语 | 定义 |
|
|
||||||
|------|------|
|
|
||||||
| **热点路径** | 经性能分析或高频调用栈确认的关键执行段 |
|
|
||||||
| **基线** | 变更前的功能/性能参考数据 |
|
|
||||||
| **顺带修复** | 在完成主任务过程中,修复发现的相关问题 |
|
|
||||||
| **防御性注释** | 被注释掉的代码,前面带有说明,记录历史踩坑经验,用于警示后人 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 17. 代码优化检查清单
|
|
||||||
|
|
||||||
当进行代码优化时,按以下清单逐项检查:
|
|
||||||
|
|
||||||
### 架构与结构
|
|
||||||
- [ ] 代码架构是否清晰?是否需要重构?
|
|
||||||
- [ ] 类的职责是否单一?是否需要拆分?
|
|
||||||
- [ ] 是否有重复代码可以提取为公共方法?
|
|
||||||
- [ ] Region 组织是否符合规范(属性→静态→构造→方法→辅助→日志)?
|
|
||||||
|
|
||||||
### 语法现代化
|
|
||||||
- [ ] 是否可以使用更简洁的 C# 语法?(switch 表达式、模式匹配等)
|
|
||||||
- [ ] 集合初始化是否使用了集合表达式 `[]`?
|
|
||||||
- [ ] 是否可以使用 null 条件运算符 `?.` 简化代码?
|
|
||||||
|
|
||||||
### 健壮性
|
|
||||||
- [ ] 是否存在空引用风险?
|
|
||||||
- [ ] 资源是否正确释放?(IDisposable、流、连接等)
|
|
||||||
- [ ] 异常处理是否完善?
|
|
||||||
- [ ] 并发场景是否线程安全?
|
|
||||||
|
|
||||||
### 性能
|
|
||||||
- [ ] 是否存在可以缓存的重复计算?
|
|
||||||
- [ ] 是否有不必要的对象分配?
|
|
||||||
- [ ] 热点路径是否避免了反射和复杂 Linq?
|
|
||||||
- [ ] 是否使用了对象池/ArrayPool 等池化技术?
|
|
||||||
|
|
||||||
### 注释与文档
|
|
||||||
- [ ] 类、接口是否有 `<summary>` 注释?
|
|
||||||
- [ ] 公共方法是否有完整的参数和返回值注释?
|
|
||||||
- [ ] 方法内重要逻辑是否有注释说明?
|
|
||||||
- [ ] 防御性注释是否保留?
|
|
||||||
|
|
||||||
### 日志
|
|
||||||
- [ ] `ILog Log` 和 `WriteLog` 是否放在类的最后?
|
|
||||||
- [ ] 是否用名为"日志"的 region 包裹?
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(完)
|
|
||||||
@@ -1,506 +0,0 @@
|
|||||||
# XCode 协作指令
|
|
||||||
|
|
||||||
本指令面向新生命团队(NewLife)开源数据中间件 XCode,帮助 Copilot 在 .NET 项目中正确使用 XCode 进行数据建模和实体操作。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. XCode 定位与边界
|
|
||||||
|
|
||||||
### 1.1 技术栈定位
|
|
||||||
|
|
||||||
```
|
|
||||||
NewLife.Core(基础库)
|
|
||||||
↓
|
|
||||||
NewLife.XCode(数据中间件)← 本指令
|
|
||||||
↓
|
|
||||||
NewLife.Cube(Web 快速开发框架)→ cube.instructions.md
|
|
||||||
```
|
|
||||||
|
|
||||||
### 1.2 职责边界
|
|
||||||
|
|
||||||
| 层级 | 职责 | 指令文件 |
|
|
||||||
|------|------|---------|
|
|
||||||
| **NewLife.Core** | 基础扩展、日志、缓存、网络等 | `copilot-instructions.md` |
|
|
||||||
| **NewLife.XCode** | 数据建模、ORM、实体增删改查、数据库操作 | 本指令 |
|
|
||||||
| **NewLife.Cube** | Web 管理后台、控制器、视图、权限 | `cube.instructions.md` |
|
|
||||||
|
|
||||||
### 1.3 本指令覆盖范围
|
|
||||||
|
|
||||||
**包含**:
|
|
||||||
- 数据模型设计(Model.xml)
|
|
||||||
- 实体类生成与使用
|
|
||||||
- 数据库 CRUD 操作
|
|
||||||
- 项目初始化与 XCode 接入
|
|
||||||
|
|
||||||
**不包含**(由 cube.instructions.md 负责):
|
|
||||||
- Web 控制器逻辑
|
|
||||||
- 视图与前端交互
|
|
||||||
- 权限管理配置
|
|
||||||
- 魔方区域深度定制
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. 使用场景与快速入口
|
|
||||||
|
|
||||||
### 2.1 场景一:已有项目接入 XCode
|
|
||||||
|
|
||||||
1. 引入 NuGet 包:`dotnet add package NewLife.XCode`
|
|
||||||
2. 创建或编辑 `Model.xml` 进行数据建模
|
|
||||||
3. 执行 `xcode` 命令生成实体类
|
|
||||||
4. 在业务代码中使用实体类进行数据操作
|
|
||||||
|
|
||||||
### 2.2 场景二:从零创建新项目
|
|
||||||
|
|
||||||
1. 安装模板:`dotnet new install NewLife.Templates`
|
|
||||||
2. 创建数据类库:`dotnet new xcode -n {系统名}.Data`
|
|
||||||
3. 创建应用项目:
|
|
||||||
- Web 应用:`dotnet new cube -n {系统名}Web`
|
|
||||||
- 控制台应用:`dotnet new nconsole -n {系统名}App`
|
|
||||||
4. 编辑 `Model.xml` 进行数据建模
|
|
||||||
5. 执行 `xcode` 生成实体类
|
|
||||||
|
|
||||||
### 2.3 核心工作流
|
|
||||||
|
|
||||||
```
|
|
||||||
理解业务需求 → 数据建模(Model.xml) → 生成实体类(xcode) → 编写业务代码
|
|
||||||
```
|
|
||||||
|
|
||||||
**关键点**:无论哪种场景,核心都是 **充分理解业务需求,在 Model.xml 中设计合理的数据表结构**。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. 环境准备
|
|
||||||
|
|
||||||
### 3.1 前置要求
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 检查 .NET SDK(要求 8.0+)
|
|
||||||
dotnet --version
|
|
||||||
|
|
||||||
# 安装全局工具 xcodetool
|
|
||||||
dotnet tool install xcodetool -g
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3.2 模板版本检查
|
|
||||||
|
|
||||||
NewLife.Templates 模板会持续更新,使用前需检查版本:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 查看模板详情
|
|
||||||
dotnet new details NewLife.Templates
|
|
||||||
```
|
|
||||||
|
|
||||||
**判定规则**:输出包含类似 `包版本: 1.1.2025.820-beta1836`
|
|
||||||
- 其中 `1.1.2025.820` 表示 v1.1,发布日期为 2025-08-20
|
|
||||||
- **要求**:发布日期需 > 2025-08-01(即严格晚于 2025-08-01)
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 若未安装或版本过旧,执行安装/更新
|
|
||||||
dotnet new install NewLife.Templates
|
|
||||||
```
|
|
||||||
|
|
||||||
> **强约束**:仅当未安装或发布日期 ≤ 2025-08-01 时才执行安装;否则保持现状,避免无谓变更。
|
|
||||||
|
|
||||||
### 3.3 模板说明
|
|
||||||
|
|
||||||
| 模板 | 命令 | 用途 |
|
|
||||||
|------|------|------|
|
|
||||||
| `xcode` | `dotnet new xcode -n Name.Data` | 数据类库项目 |
|
|
||||||
| `cube` | `dotnet new cube -n NameWeb` | Web 管理后台 |
|
|
||||||
| `nconsole` | `dotnet new nconsole -n NameApp` | 控制台应用 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. Model.xml 完整参考
|
|
||||||
|
|
||||||
### 4.1 文件结构
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<EntityModel xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xs:schemaLocation="https://newlifex.com https://newlifex.com/Model202509.xsd"
|
|
||||||
xmlns="https://newlifex.com/Model202509.xsd">
|
|
||||||
<Option>
|
|
||||||
<!-- 全局配置 -->
|
|
||||||
</Option>
|
|
||||||
<Tables>
|
|
||||||
<Table>
|
|
||||||
<Columns>
|
|
||||||
<Column />
|
|
||||||
</Columns>
|
|
||||||
<Indexes>
|
|
||||||
<Index />
|
|
||||||
</Indexes>
|
|
||||||
</Table>
|
|
||||||
</Tables>
|
|
||||||
</EntityModel>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4.2 Option 配置项
|
|
||||||
|
|
||||||
| 配置项 | 说明 | 示例 |
|
|
||||||
|--------|------|------|
|
|
||||||
| `Namespace` | 命名空间 | `Zero.Data` |
|
|
||||||
| `ConnName` | 数据库连接名 | `Zero` |
|
|
||||||
| `Output` | 实体类输出目录 | `.\` |
|
|
||||||
| `BaseClass` | 实体基类 | `Entity` |
|
|
||||||
| `ChineseFileName` | 使用中文文件名 | `True` |
|
|
||||||
| `Nullable` | 生成可空引用类型 | `True` |
|
|
||||||
| `HasIModel` | 实现 IModel 接口 | `True` |
|
|
||||||
| `ModelClass` | 模型类模板 | `{name}Model` |
|
|
||||||
| `ModelsOutput` | 模型类输出目录 | `.\Models\` |
|
|
||||||
| `ModelInterface` | 模型接口模板 | `I{name}` |
|
|
||||||
| `InterfacesOutput` | 接口输出目录 | `.\Interfaces\` |
|
|
||||||
| `NameFormat` | 命名格式 | `Default`/`Upper`/`Lower`/`Underline` |
|
|
||||||
| `DisplayName` | 魔方区域显示名 | `订单管理` |
|
|
||||||
| `CubeOutput` | 魔方控制器输出目录 | `../../Web/Areas/Order` |
|
|
||||||
|
|
||||||
### 4.3 Table 属性
|
|
||||||
|
|
||||||
| 属性 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `Name` | 实体类名 | `User` |
|
|
||||||
| `TableName` | 数据库表名(可选,默认同 Name) | `sys_user` |
|
|
||||||
| `Description` | 表说明 | `用户。用户账号信息` |
|
|
||||||
| `ConnName` | 独立连接名(覆盖全局) | `Log` |
|
|
||||||
| `BaseType` | 基类(支持实体继承) | `EntityBase` |
|
|
||||||
| `InsertOnly` | 仅插入模式(日志表优化) | `True` |
|
|
||||||
| `IsView` | 视图标识 | `True` |
|
|
||||||
|
|
||||||
### 4.4 Column 属性完整参考
|
|
||||||
|
|
||||||
#### 基础属性
|
|
||||||
|
|
||||||
| 属性 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `Name` | 属性名 | `UserName` |
|
|
||||||
| `ColumnName` | 数据库列名(可选) | `user_name` |
|
|
||||||
| `DataType` | 数据类型 | `Int32`/`Int64`/`String`/`DateTime`/`Boolean`/`Double`/`Decimal` |
|
|
||||||
| `Description` | 字段说明 | `用户名。登录账号` |
|
|
||||||
| `Length` | 字符串长度 | `50`/`200`/`-1`(大文本) |
|
|
||||||
| `Precision` | 数值精度 | `18` |
|
|
||||||
| `Scale` | 小数位数 | `2` |
|
|
||||||
|
|
||||||
#### 主键与标识
|
|
||||||
|
|
||||||
| 属性 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `PrimaryKey` | 主键 | `True` |
|
|
||||||
| `Identity` | 自增标识 | `True` |
|
|
||||||
| `Master` | 主字段(业务主要字段) | `True` |
|
|
||||||
|
|
||||||
#### 约束与默认值
|
|
||||||
|
|
||||||
| 属性 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `Nullable` | 允许空 | `False` |
|
|
||||||
| `DefaultValue` | 默认值 | `0`/`''`/`getdate()` |
|
|
||||||
|
|
||||||
#### 映射关系(Map)
|
|
||||||
|
|
||||||
格式:`表名@主键@显示字段@属性名`
|
|
||||||
|
|
||||||
| 格式 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `Table@Id@Name` | 基本映射(三段) | `Role@Id@Name` |
|
|
||||||
| `Table@Id@Name@RoleName` | 指定属性名(四段) | `Role@Id@Name@RoleName` |
|
|
||||||
| `NS.Table@Id@Path@AreaPath` | 完整命名空间 | `XCode.Membership.Area@Id@Path@AreaPath` |
|
|
||||||
|
|
||||||
#### 元素类型(ItemType)
|
|
||||||
|
|
||||||
用于魔方前端渲染和数据验证:
|
|
||||||
|
|
||||||
| ItemType | 说明 |
|
|
||||||
|----------|------|
|
|
||||||
| `image` | 图片上传 |
|
|
||||||
| `file` | 文件上传 |
|
|
||||||
| `mail` | 邮箱格式 |
|
|
||||||
| `mobile` | 手机号格式 |
|
|
||||||
| `url` | URL 链接 |
|
|
||||||
| `TimeSpan` | 时间间隔(秒转可读格式) |
|
|
||||||
| `GMK` | 字节数转 GB/MB/KB |
|
|
||||||
| `html` | HTML 富文本 |
|
|
||||||
| `code` | 代码编辑器 |
|
|
||||||
| `json` | JSON 编辑器 |
|
|
||||||
|
|
||||||
#### 显示选项(ShowIn)
|
|
||||||
|
|
||||||
控制字段在魔方各区域的显示,支持三种语法:
|
|
||||||
|
|
||||||
**语法一:具名列表(推荐)**
|
|
||||||
```
|
|
||||||
ShowIn="List,Search" # List和Search显示
|
|
||||||
ShowIn="-EditForm,-Detail" # 编辑表单和详情隐藏
|
|
||||||
ShowIn="All,-Detail" # 全部显示,详情隐藏
|
|
||||||
ShowIn="None,Search,Add" # 全部隐藏,搜索和添加显示
|
|
||||||
```
|
|
||||||
|
|
||||||
区域别名:`List(L)`、`Detail(D)`、`AddForm(Add/A)`、`EditForm(Edit/E)`、`Search(S)`、`Form(F)`(同时控制 Add 和 Edit)
|
|
||||||
|
|
||||||
**语法二:管道分隔**
|
|
||||||
```
|
|
||||||
ShowIn="Y|Y|N||A" # List=显示|Detail=显示|Add=隐藏|Edit=自动|Search=自动
|
|
||||||
```
|
|
||||||
|
|
||||||
**语法三:5字符掩码**
|
|
||||||
```
|
|
||||||
ShowIn="11110" # 1=显示, 0=隐藏, A/?/-=自动
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 分表字段(DataScale)
|
|
||||||
|
|
||||||
| 值 | 说明 |
|
|
||||||
|----|------|
|
|
||||||
| `time` | 大数据单表的时间字段(用于雪花 ID) |
|
|
||||||
| `timeShard:yyMMdd` | 分表字段,按日期格式分表 |
|
|
||||||
|
|
||||||
#### 其他属性
|
|
||||||
|
|
||||||
| 属性 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `Type` | 枚举类型 | `XCode.Membership.SexKinds` |
|
|
||||||
| `Category` | 表单分组 | `登录信息`/`扩展` |
|
|
||||||
| `Attribute` | 额外特性 | `XmlIgnore, IgnoreDataMember` |
|
|
||||||
| `Model` | 是否包含在模型类中 | `False` |
|
|
||||||
| `RawType` | 原始数据库类型 | `varchar(50)` |
|
|
||||||
|
|
||||||
### 4.5 Index 属性
|
|
||||||
|
|
||||||
| 属性 | 说明 | 示例 |
|
|
||||||
|------|------|------|
|
|
||||||
| `Columns` | 索引列(逗号分隔) | `Name`/`Category,CreateTime` |
|
|
||||||
| `Unique` | 唯一索引 | `True` |
|
|
||||||
|
|
||||||
### 4.6 完整示例
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<EntityModel xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xs:schemaLocation="https://newlifex.com https://newlifex.com/Model202509.xsd"
|
|
||||||
xmlns="https://newlifex.com/Model202509.xsd">
|
|
||||||
<Option>
|
|
||||||
<Namespace>Order.Data</Namespace>
|
|
||||||
<ConnName>Order</ConnName>
|
|
||||||
<Output>.\</Output>
|
|
||||||
<ChineseFileName>True</ChineseFileName>
|
|
||||||
<Nullable>True</Nullable>
|
|
||||||
<HasIModel>True</HasIModel>
|
|
||||||
<DisplayName>订单管理</DisplayName>
|
|
||||||
<CubeOutput>../../OrderWeb/Areas/Order</CubeOutput>
|
|
||||||
</Option>
|
|
||||||
<Tables>
|
|
||||||
<Table Name="Order" Description="订单。电商订单主表">
|
|
||||||
<Columns>
|
|
||||||
<Column Name="Id" DataType="Int64" PrimaryKey="True" DataScale="time" Description="编号" />
|
|
||||||
<Column Name="OrderNo" DataType="String" Master="True" Length="50" Nullable="False" Description="订单号" />
|
|
||||||
<Column Name="UserId" DataType="Int32" Map="User@Id@Name" Description="用户" />
|
|
||||||
<Column Name="Status" DataType="Int32" Type="Order.Data.OrderStatus" Description="状态" />
|
|
||||||
<Column Name="TotalAmount" DataType="Decimal" Precision="18" Scale="2" Description="总金额" />
|
|
||||||
<Column Name="Remark" DataType="String" Length="500" Description="备注" Category="扩展" />
|
|
||||||
<Column Name="CreateUser" DataType="String" Description="创建者" Model="False" Category="扩展" />
|
|
||||||
<Column Name="CreateTime" DataType="DateTime" Nullable="False" Description="创建时间" Category="扩展" />
|
|
||||||
<Column Name="UpdateTime" DataType="DateTime" Description="更新时间" Model="False" Category="扩展" />
|
|
||||||
</Columns>
|
|
||||||
<Indexes>
|
|
||||||
<Index Columns="OrderNo" Unique="True" />
|
|
||||||
<Index Columns="UserId" />
|
|
||||||
<Index Columns="Status,CreateTime" />
|
|
||||||
</Indexes>
|
|
||||||
</Table>
|
|
||||||
</Tables>
|
|
||||||
</EntityModel>
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. 实体类操作指南
|
|
||||||
|
|
||||||
### 5.1 基础 CRUD
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// 新增
|
|
||||||
var entity = new User { Name = "test", Password = "123456" };
|
|
||||||
entity.Insert();
|
|
||||||
|
|
||||||
// 查询单个
|
|
||||||
var user = User.FindByKey(1);
|
|
||||||
var user = User.Find(User._.Name == "test");
|
|
||||||
|
|
||||||
// 查询列表
|
|
||||||
var list = User.FindAll();
|
|
||||||
var list = User.FindAll(User._.Status == 1, User._.Id.Desc(), null, 0, 10);
|
|
||||||
|
|
||||||
// 更新
|
|
||||||
user.Name = "newName";
|
|
||||||
user.Update();
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
user.Delete();
|
|
||||||
|
|
||||||
// 保存(自动判断 Insert/Update)
|
|
||||||
entity.Save();
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5.2 高级查询
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// 分页查询
|
|
||||||
var page = new PageParameter { PageIndex = 1, PageSize = 20 };
|
|
||||||
var list = User.FindAll(User._.Status == 1, page);
|
|
||||||
|
|
||||||
// 条件组合
|
|
||||||
var where = new WhereExpression();
|
|
||||||
where &= User._.Status == 1;
|
|
||||||
where &= User._.CreateTime >= DateTime.Today;
|
|
||||||
if (!key.IsNullOrEmpty()) where &= User._.Name.Contains(key);
|
|
||||||
var list = User.FindAll(where, page);
|
|
||||||
|
|
||||||
// 统计
|
|
||||||
var count = User.FindCount(User._.Status == 1);
|
|
||||||
|
|
||||||
// 查询最大/最小值
|
|
||||||
var maxId = User.FindMax(User._.Id, null);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5.3 批量操作
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// 批量插入
|
|
||||||
var list = new List<User>();
|
|
||||||
list.Insert();
|
|
||||||
|
|
||||||
// 批量更新
|
|
||||||
User.Update(User._.Status == 2, User._.Status == 1);
|
|
||||||
|
|
||||||
// 批量删除
|
|
||||||
User.Delete(User._.Status == 0);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5.4 异步操作
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
var user = await User.FindAsync(User._.Id == 1);
|
|
||||||
var list = await User.FindAllAsync(User._.Status == 1, page);
|
|
||||||
await entity.InsertAsync();
|
|
||||||
await entity.SaveAsync(); // 异步保存,用于日志等高频写入
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5.5 缓存查询
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// 实体缓存(适用于小表)
|
|
||||||
var list = User.FindAllWithCache();
|
|
||||||
|
|
||||||
// 单对象缓存(按主键)
|
|
||||||
var user = User.FindByKeyWithCache(1);
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 6. 多模块项目结构
|
|
||||||
|
|
||||||
对于复杂业务系统,建议按模块组织:
|
|
||||||
|
|
||||||
```
|
|
||||||
Zero.Data/
|
|
||||||
├── Order/ # 订单模块
|
|
||||||
│ ├── Order.xml # 订单模型
|
|
||||||
│ ├── 订单.cs
|
|
||||||
│ └── 订单明细.cs
|
|
||||||
├── Product/ # 商品模块
|
|
||||||
│ ├── Product.xml # 商品模型
|
|
||||||
│ ├── 商品.cs
|
|
||||||
│ └── 分类.cs
|
|
||||||
└── Member/ # 会员模块
|
|
||||||
├── Member.xml # 会员模型
|
|
||||||
└── 会员.cs
|
|
||||||
```
|
|
||||||
|
|
||||||
每个模块目录内有独立的 `*.xml` 模型文件,在各自目录执行 `xcode` 命令生成实体类。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 7. xcode 命令参考
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 在模型文件所在目录执行(自动查找所有 *.xml)
|
|
||||||
xcode
|
|
||||||
|
|
||||||
# 指定模型文件
|
|
||||||
xcode Model.xml
|
|
||||||
xcode Order.xml
|
|
||||||
```
|
|
||||||
|
|
||||||
**执行效果**:
|
|
||||||
1. 读取 XML 模型文件
|
|
||||||
2. 生成实体类(`*.cs`)
|
|
||||||
3. 生成模型类(如配置了 `ModelClass`)
|
|
||||||
4. 生成接口(如配置了 `ModelInterface`)
|
|
||||||
5. 生成数据字典(`*.htm`)
|
|
||||||
6. 生成魔方控制器(如配置了 `CubeOutput`)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 8. 常见问题
|
|
||||||
|
|
||||||
### 8.1 模型文件命名
|
|
||||||
|
|
||||||
- 默认:`Model.xml`
|
|
||||||
- 推荐:`{系统英文名}.xml` 或 `{模块名}.xml`
|
|
||||||
- 复杂项目:每个模块目录一个模型文件
|
|
||||||
|
|
||||||
### 8.2 实体类生成位置
|
|
||||||
|
|
||||||
- 实体类生成在 `xcode` 命令执行目录
|
|
||||||
- 可通过 `Output` 配置项指定输出目录
|
|
||||||
- 魔方控制器通过 `CubeOutput` 指定
|
|
||||||
|
|
||||||
### 8.3 数据库连接
|
|
||||||
|
|
||||||
在应用配置文件中配置连接字符串:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"ConnectionStrings": {
|
|
||||||
"Order": "Server=.;Database=Order;Uid=sa;Pwd=xxx"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
连接名对应 Model.xml 中的 `ConnName`。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 9. 与 Cube 的协作
|
|
||||||
|
|
||||||
当需要生成 Web 管理界面时:
|
|
||||||
|
|
||||||
1. 在 Model.xml 中配置 `CubeOutput` 指向 Web 项目的 Areas 目录
|
|
||||||
2. 配置 `DisplayName` 作为魔方区域名称
|
|
||||||
3. 执行 `xcode` 自动生成控制器
|
|
||||||
4. 深度定制请参考 `cube.instructions.md`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 10. Copilot 行为指引
|
|
||||||
|
|
||||||
### 10.1 数据建模时
|
|
||||||
|
|
||||||
1. **充分理解业务**:在设计表结构前,确保理解业务场景和数据关系
|
|
||||||
2. **合理设计主键**:
|
|
||||||
- 普通表:`Int32` 自增主键
|
|
||||||
- 大数据表:`Int64` + `DataScale="time"`(雪花 ID)
|
|
||||||
3. **必要的索引**:为查询条件字段添加索引
|
|
||||||
4. **字段长度**:String 类型必须指定合理的 `Length`
|
|
||||||
|
|
||||||
### 10.2 生成代码时
|
|
||||||
|
|
||||||
1. 确保在正确目录执行 `xcode`
|
|
||||||
2. 生成后检查编译是否通过
|
|
||||||
3. 如需修改生成的代码,应修改 Model.xml 后重新生成
|
|
||||||
|
|
||||||
### 10.3 边界意识
|
|
||||||
|
|
||||||
- 数据模型和实体操作 → 本指令
|
|
||||||
- Web 控制器和界面 → `cube.instructions.md`
|
|
||||||
- 基础编码规范 → `copilot-instructions.md`
|
|
||||||
@@ -313,3 +313,12 @@ COMCMS.Web/wwwroot/install.lock
|
|||||||
|
|
||||||
# others
|
# others
|
||||||
.cursorrules
|
.cursorrules
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
# 环境变量文件(包含敏感信息)
|
||||||
|
.env
|
||||||
|
|
||||||
|
# 环境变量文件(包含敏感信息)
|
||||||
|
.env
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## 项目概述
|
||||||
|
|
||||||
|
COMCMS NetCore 是一个基于 .NET 10 的内容管理系统(CMS),包含后台管理和前台展示功能。支持二次开发扩展为商城系统、小程序、APP服务端等。
|
||||||
|
|
||||||
|
## 常用命令
|
||||||
|
|
||||||
|
### 构建和运行
|
||||||
|
```bash
|
||||||
|
# 构建整个解决方案
|
||||||
|
dotnet build COMCMS_NETCORE.sln
|
||||||
|
|
||||||
|
# 运行 Web 项目(开发模式)
|
||||||
|
cd COMCMS.Web
|
||||||
|
dotnet run
|
||||||
|
|
||||||
|
# 发布 Web 项目
|
||||||
|
dotnet publish -c Release -o ./publish
|
||||||
|
|
||||||
|
# 使用 Docker 运行
|
||||||
|
cd COMCMS.Web
|
||||||
|
docker build -t comcms .
|
||||||
|
docker run -p 80:80 comcms
|
||||||
|
```
|
||||||
|
|
||||||
|
### 数据库初始化
|
||||||
|
项目支持 MySQL 5.7/8.0 和 SQL Server 2008+ 数据库。初始化脚本位于 `data` 目录:
|
||||||
|
- `comcms_for_windows.sql` - Windows 环境的 MySQL 初始化脚本
|
||||||
|
- `comcms_for_linux.sql` - Linux 环境的 MySQL 初始化脚本
|
||||||
|
- `comcms_sqlserver.sql` - SQL Server 初始化脚本
|
||||||
|
|
||||||
|
### 测试
|
||||||
|
```bash
|
||||||
|
# 运行所有测试(如果存在)
|
||||||
|
dotnet test
|
||||||
|
|
||||||
|
# 运行特定项目测试
|
||||||
|
dotnet test [项目名称]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 项目架构
|
||||||
|
|
||||||
|
### 核心组件
|
||||||
|
1. **COMCMS.Web** - ASP.NET Core MVC 网站,包含前台和后台管理界面
|
||||||
|
2. **COMCMS.Core** - 核心业务逻辑和数据访问层,使用 XCode ORM
|
||||||
|
3. **COMCMS.Common** - 通用工具类库
|
||||||
|
4. **COMCMS.API** - API 接口层(预留)
|
||||||
|
5. **Lib.Core** - 中间件库
|
||||||
|
6. **NewLife.UserGroup.WebUploader** - 大文件上传组件
|
||||||
|
7. **XCoder** - 代码生成器
|
||||||
|
|
||||||
|
### 数据层架构
|
||||||
|
- 使用 **XCode ORM** 进行数据访问,支持 MySQL 和 SQL Server
|
||||||
|
- 实体类采用部分类设计,包含实体定义(.cs)和业务逻辑(.Biz.cs)
|
||||||
|
- 每个实体类使用 `[BindTable]` 特性映射到数据库表
|
||||||
|
- 支持缓存机制,使用 Redis 作为分布式缓存
|
||||||
|
|
||||||
|
### Web 层结构
|
||||||
|
- **前台控制器**:位于 `Controllers/` 目录
|
||||||
|
- **后台管理**:位于 `Areas/AdminCP/`,使用 MVC Areas 组织
|
||||||
|
- **API 接口**:位于 `Controllers/api/`,提供 RESTful API
|
||||||
|
- **视图**:Razor 视图,后台使用 H+ 模板
|
||||||
|
- **静态资源**:位于 `wwwroot/`,包含编辑器(CKEditor)、上传组件(WebUploader)等
|
||||||
|
|
||||||
|
### 功能模块
|
||||||
|
- **文章系统**:文章管理、栏目管理、标签系统
|
||||||
|
- **商城模块**:商品管理、订单管理、购物车、优惠券
|
||||||
|
- **用户系统**:用户管理、角色权限、地址管理、余额管理
|
||||||
|
- **系统管理**:系统配置、数据字典、菜单权限、日志管理
|
||||||
|
- **微信集成**:微信公众号、微信支付
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
- **.NET 10** - 主框架
|
||||||
|
- **MySQL/SQL Server** - 数据库
|
||||||
|
- **XCode ORM** - 数据访问层
|
||||||
|
- **Redis** - 分布式缓存
|
||||||
|
- **JWT** - 身份认证
|
||||||
|
- **CKEditor** - 富文本编辑器
|
||||||
|
- **WebUploader** - 文件上传
|
||||||
|
- **Senparc Weixin SDK** - 微信开发
|
||||||
|
|
||||||
|
## 配置说明
|
||||||
|
|
||||||
|
### 数据库连接
|
||||||
|
在 `appsettings.json` 中配置数据库连接字符串:
|
||||||
|
```json
|
||||||
|
"connectionStrings": {
|
||||||
|
"dbconn": {
|
||||||
|
"connectionString": "Server=.;Port=3306;Database=comcms;Uid=root;Pwd=root;charset=utf8mb4",
|
||||||
|
"providerName": "MySql.Data.MySqlClient"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Redis 缓存配置
|
||||||
|
```json
|
||||||
|
"RedisCache": {
|
||||||
|
"ConnectionString": "server=127.0.0.1;password=;db=2",
|
||||||
|
"InstanceName": "COMCMS:",
|
||||||
|
"DefaultDatabase": 2
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 系统配置
|
||||||
|
```json
|
||||||
|
"SystemSetting": {
|
||||||
|
"FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv",
|
||||||
|
"ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp",
|
||||||
|
"JwtSecret": "your-jwt-secret",
|
||||||
|
"COMCMSPrefixKey": "abc_"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 开发指南
|
||||||
|
|
||||||
|
### 添加新功能模块
|
||||||
|
1. 在 `COMCMS.Core` 中创建实体类和业务逻辑
|
||||||
|
2. 使用 XCoder 代码生成器生成基础代码
|
||||||
|
3. 在 `COMCMS.Web` 中添加控制器和视图
|
||||||
|
4. 更新菜单权限配置
|
||||||
|
|
||||||
|
### 权限控制
|
||||||
|
- 后台使用 `AdminBaseController` 进行登录验证
|
||||||
|
- 使用 `[MyAuthorize]` 特性进行权限控制
|
||||||
|
- 菜单和事件权限在 `后台菜单` 和 `目标事件` 表中配置
|
||||||
|
|
||||||
|
### 缓存使用
|
||||||
|
- 通过 `ICacheService` 接口使用缓存
|
||||||
|
- 支持分布式缓存(Redis)和内存缓存
|
||||||
|
- 在 `CacheSettings` 中配置不同类型数据的过期时间
|
||||||
|
|
||||||
|
### 文件上传
|
||||||
|
- 使用 WebUploader 组件处理文件上传
|
||||||
|
- 在 `UploadController` 中处理上传逻辑
|
||||||
|
- 支持图片、文件、媒体等多种类型
|
||||||
|
|
||||||
|
## 部署说明
|
||||||
|
|
||||||
|
### Docker 部署
|
||||||
|
项目包含 Dockerfile,支持容器化部署:
|
||||||
|
```dockerfile
|
||||||
|
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 80
|
||||||
|
COPY . .
|
||||||
|
ENTRYPOINT ["dotnet", "COMCMS.Web.dll"]
|
||||||
|
```
|
||||||
|
|
||||||
|
注意:Dockerfile 中的 .NET 版本需要更新到与项目一致的版本。
|
||||||
|
|
||||||
|
### 环境要求
|
||||||
|
- .NET 10 Runtime 或 SDK
|
||||||
|
- MySQL 5.7+ 或 SQL Server 2008+
|
||||||
|
- Redis(可选,用于分布式缓存)
|
||||||
|
|
||||||
|
### 默认账号
|
||||||
|
- 后台管理员账号:admin / admin
|
||||||
|
- 登录地址:/AdminCP
|
||||||
|
|
||||||
|
## 重要提示
|
||||||
|
|
||||||
|
- 项目使用中文命名实体类和字段,这是为了便于中文开发者理解
|
||||||
|
- 修改数据库结构后需要更新相应的实体类
|
||||||
|
- 部署前确保正确配置数据库连接字符串和系统配置
|
||||||
|
- 建议使用源码管理保存自定义修改,避免升级时覆盖
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<<<<<<< HEAD
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
=======
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NewLife.Core" Version="11.16.2026.601" />
|
<PackageReference Include="NewLife.Core" Version="11.9.2025.1112" />
|
||||||
<PackageReference Include="Senparc.Weixin" Version="6.23.1" />
|
<PackageReference Include="Senparc.Weixin" Version="6.23.0" />
|
||||||
<PackageReference Include="Senparc.Weixin.MP" Version="16.24.2" />
|
<PackageReference Include="Senparc.Weixin.MP" Version="16.24.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<<<<<<< HEAD
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
=======
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="NewLife.Core" Version="11.16.2026.601" />
|
<PackageReference Include="NewLife.Core" Version="11.9.2025.1112" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
<PackageReference Include="PinYinConverterCore" Version="1.0.2" />
|
<PackageReference Include="PinYinConverterCore" Version="1.0.2" />
|
||||||
<PackageReference Include="SkiaSharp" Version="3.119.4" />
|
<PackageReference Include="SkiaSharp" Version="3.119.1" />
|
||||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.119.4" />
|
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.119.1" />
|
||||||
<PackageReference Include="SkiaSharp.QrCode" Version="0.12.0" />
|
<PackageReference Include="SkiaSharp.QrCode" Version="0.9.0" />
|
||||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.9" />
|
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace COMCMS.Common
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var newImg = originalImage.Resize(new SKSizeI(towidth, toheight), new SKSamplingOptions(SKFilterMode.Linear, SKMipmapMode.Linear));
|
var newImg = originalImage.Resize(new SKSizeI(towidth, toheight), SKFilterQuality.Medium);
|
||||||
using var fs = new FileStream(newFileName, FileMode.Create);
|
using var fs = new FileStream(newFileName, FileMode.Create);
|
||||||
//判断类型
|
//判断类型
|
||||||
SKEncodedImageFormat imgType = new SKEncodedImageFormat();
|
SKEncodedImageFormat imgType = new SKEncodedImageFormat();
|
||||||
|
|||||||
@@ -293,13 +293,14 @@ namespace COMCMS.Common
|
|||||||
canvas.DrawLine(random.Next(0, width), random.Next(0, height), random.Next(0, width), random.Next(0, height), drawStyle);
|
canvas.DrawLine(random.Next(0, width), random.Next(0, height), random.Next(0, width), random.Next(0, height), drawStyle);
|
||||||
}
|
}
|
||||||
// 在图片上写验证码
|
// 在图片上写验证码
|
||||||
using SKFont textFont = new() { Size = 22 };
|
|
||||||
SKPaint textPaint = new SKPaint
|
SKPaint textPaint = new SKPaint
|
||||||
{
|
{
|
||||||
IsAntialias = true,
|
IsAntialias = true,
|
||||||
|
TextAlign = SKTextAlign.Left,
|
||||||
Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(width, height), new SKColor[] { SKColors.Blue, SKColors.DarkRed }, SKShaderTileMode.Clamp),
|
Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(width, height), new SKColor[] { SKColors.Blue, SKColors.DarkRed }, SKShaderTileMode.Clamp),
|
||||||
|
TextSize = 22
|
||||||
};
|
};
|
||||||
canvas.DrawText(text, 4, 24, SKTextAlign.Left, textFont, textPaint);
|
canvas.DrawText(text, 4, 24, textPaint);
|
||||||
|
|
||||||
//将文字写到画布上
|
//将文字写到画布上
|
||||||
//using (SKPaint drawStyle = new())
|
//using (SKPaint drawStyle = new())
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<<<<<<< HEAD
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
=======
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NewLife.XCode" Version="11.27.2026.601" />
|
<PackageReference Include="NewLife.XCode" Version="11.22.2025.1112" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace COMCMS.Core
|
|||||||
//Meta.Factory.AdditionalFields.Add(__.Logins);
|
//Meta.Factory.AdditionalFields.Add(__.Logins);
|
||||||
|
|
||||||
// 过滤器 UserModule、TimeModule、IPModule
|
// 过滤器 UserModule、TimeModule、IPModule
|
||||||
Meta.Interceptors.Add<TimeInterceptor>();
|
Meta.Modules.Add<TimeModule>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace COMCMS.Core
|
|||||||
//Meta.Factory.AdditionalFields.Add(__.Logins);
|
//Meta.Factory.AdditionalFields.Add(__.Logins);
|
||||||
|
|
||||||
// 过滤器 UserModule、TimeModule、IPModule
|
// 过滤器 UserModule、TimeModule、IPModule
|
||||||
Meta.Interceptors.Add<TimeInterceptor>();
|
Meta.Modules.Add<TimeModule>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace COMCMS.Core
|
|||||||
{
|
{
|
||||||
|
|
||||||
// 过滤器 UserModule、TimeModule、IPModule
|
// 过滤器 UserModule、TimeModule、IPModule
|
||||||
Meta.Interceptors.Add<TimeInterceptor>();
|
Meta.Modules.Add<TimeModule>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace COMCMS.Core
|
|||||||
//df.Add(__.RequestType);
|
//df.Add(__.RequestType);
|
||||||
|
|
||||||
// 过滤器 UserModule、TimeModule、IPModule
|
// 过滤器 UserModule、TimeModule、IPModule
|
||||||
Meta.Interceptors.Add<TimeInterceptor>();
|
Meta.Modules.Add<TimeModule>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace COMCMS.Core
|
|||||||
//df.Add(__.RuleId);
|
//df.Add(__.RuleId);
|
||||||
|
|
||||||
// 过滤器 UserModule、TimeModule、IPModule
|
// 过滤器 UserModule、TimeModule、IPModule
|
||||||
Meta.Interceptors.Add<TimeInterceptor>();
|
Meta.Modules.Add<TimeModule>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
|
||||||
|
|||||||
@@ -53,297 +53,11 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
public IActionResult GetDirList(string subdir)
|
public IActionResult GetDirList(string subdir)
|
||||||
{
|
{
|
||||||
//string attachPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
//string attachPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
||||||
List<DirInfo> list = getAllAttach(subdir);
|
|
||||||
return Json(new { code = 0, message = "success", data = list });
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 获取指定目录下的文件
|
|
||||||
[HttpPost]
|
|
||||||
[MyAuthorize("viewlist", "attach", "JSON")]
|
|
||||||
public IActionResult GetFileList(string path)
|
|
||||||
{
|
|
||||||
string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
|
||||||
string currentPath = basePath;
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
|
||||||
{
|
|
||||||
currentPath = Path.Combine(basePath, path.TrimStart('/').Replace("/", Path.DirectorySeparatorChar.ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Directory.Exists(currentPath))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "目录不存在" });
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AttachFileInfo> list = new List<AttachFileInfo>();
|
//Directory.GetDirectories()
|
||||||
DirectoryInfo dir = new DirectoryInfo(currentPath);
|
return Json(tip);
|
||||||
|
|
||||||
// 获取子目录
|
|
||||||
foreach (var d in dir.GetDirectories())
|
|
||||||
{
|
|
||||||
if (d.Name.Equals("_thumbs", StringComparison.OrdinalIgnoreCase)) continue; // 过滤缩略图目录
|
|
||||||
list.Add(new AttachFileInfo
|
|
||||||
{
|
|
||||||
name = d.Name,
|
|
||||||
path = (string.IsNullOrEmpty(path) ? "" : path + "/") + d.Name,
|
|
||||||
updateTime = d.LastWriteTime,
|
|
||||||
isDir = true,
|
|
||||||
type = "folder"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取文件
|
|
||||||
foreach (var f in dir.GetFiles())
|
|
||||||
{
|
|
||||||
string ext = f.Extension.ToLower();
|
|
||||||
string type = "file";
|
|
||||||
if (IsImage(ext)) type = "image";
|
|
||||||
else if (IsVideo(ext)) type = "video";
|
|
||||||
|
|
||||||
list.Add(new AttachFileInfo
|
|
||||||
{
|
|
||||||
name = f.Name,
|
|
||||||
path = (string.IsNullOrEmpty(path) ? "" : path + "/") + f.Name,
|
|
||||||
ext = ext,
|
|
||||||
size = f.Length,
|
|
||||||
updateTime = f.LastWriteTime,
|
|
||||||
isDir = false,
|
|
||||||
type = type
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Json(new { code = 0, message = "success", data = list });
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 创建文件夹
|
|
||||||
[HttpPost]
|
|
||||||
[MyAuthorize("add", "attach", "JSON")]
|
|
||||||
public IActionResult CreateDir(string path, string name)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(name)) return Json(new { code = 1, message = "文件夹名称不能为空" });
|
|
||||||
if (!IsSafeName(name)) return Json(new { code = 1, message = "文件夹名称包含非法字符" });
|
|
||||||
|
|
||||||
string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
|
||||||
string currentPath = basePath;
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
|
||||||
{
|
|
||||||
currentPath = Path.Combine(basePath, path.TrimStart('/').Replace("/", Path.DirectorySeparatorChar.ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
string newDirPath = Path.Combine(currentPath, name);
|
|
||||||
if (Directory.Exists(newDirPath))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "文件夹已存在" });
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(newDirPath);
|
|
||||||
return Json(new { code = 0, message = "创建成功" });
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "创建失败:" + ex.Message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 删除文件或文件夹
|
|
||||||
[HttpPost]
|
|
||||||
[MyAuthorize("del", "attach", "JSON")]
|
|
||||||
public IActionResult DeleteFile(string path, bool isDir)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(path)) return Json(new { code = 1, message = "路径不能为空" });
|
|
||||||
|
|
||||||
string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
|
||||||
string fullPath = Path.Combine(basePath, path.TrimStart('/').Replace("/", Path.DirectorySeparatorChar.ToString()));
|
|
||||||
|
|
||||||
// 安全检查,防止删除基础目录以外的文件
|
|
||||||
if (!Path.GetFullPath(fullPath).StartsWith(Path.GetFullPath(basePath)))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "非法路径" });
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (isDir)
|
|
||||||
{
|
|
||||||
if (Directory.Exists(fullPath))
|
|
||||||
{
|
|
||||||
Directory.Delete(fullPath, true); // 递归删除
|
|
||||||
return Json(new { code = 0, message = "删除成功" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (System.IO.File.Exists(fullPath))
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(fullPath);
|
|
||||||
return Json(new { code = 0, message = "删除成功" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Json(new { code = 1, message = "文件或目录不存在" });
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "删除失败:" + ex.Message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 重命名文件或文件夹
|
|
||||||
[HttpPost]
|
|
||||||
[MyAuthorize("edit", "attach", "JSON")]
|
|
||||||
public IActionResult RenameFile(string path, string newName, bool isDir)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(newName)) return Json(new { code = 1, message = "参数不能为空" });
|
|
||||||
if (!IsSafeName(newName)) return Json(new { code = 1, message = "新名称包含非法字符" });
|
|
||||||
|
|
||||||
string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
|
||||||
string fullPath = Path.Combine(basePath, path.TrimStart('/').Replace("/", Path.DirectorySeparatorChar.ToString()));
|
|
||||||
|
|
||||||
// 安全检查
|
|
||||||
if (!Path.GetFullPath(fullPath).StartsWith(Path.GetFullPath(basePath)))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "非法路径" });
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string parentDir = Path.GetDirectoryName(fullPath);
|
|
||||||
string newFullPath = Path.Combine(parentDir, newName);
|
|
||||||
|
|
||||||
if (isDir)
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(fullPath)) return Json(new { code = 1, message = "原文件夹不存在" });
|
|
||||||
if (Directory.Exists(newFullPath)) return Json(new { code = 1, message = "目标文件夹已存在" });
|
|
||||||
Directory.Move(fullPath, newFullPath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!System.IO.File.Exists(fullPath)) return Json(new { code = 1, message = "原文件不存在" });
|
|
||||||
// 保持扩展名一致性检查(可选,这里简单处理,如果newName没有扩展名则加上原扩展名,或者要求用户输入完整文件名)
|
|
||||||
// 假设前端传来的 newName 是完整文件名
|
|
||||||
if (System.IO.File.Exists(newFullPath)) return Json(new { code = 1, message = "目标文件已存在" });
|
|
||||||
System.IO.File.Move(fullPath, newFullPath);
|
|
||||||
}
|
|
||||||
return Json(new { code = 0, message = "重命名成功" });
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "重命名失败:" + ex.Message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 上传文件
|
|
||||||
[HttpPost]
|
|
||||||
[MyAuthorize("add", "attach", "JSON")]
|
|
||||||
public async Task<IActionResult> UploadFile(string path)
|
|
||||||
{
|
|
||||||
// 安全检查:禁止在根目录上传
|
|
||||||
if (string.IsNullOrEmpty(path))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "根目录不允许上传文件,请选择子目录" });
|
|
||||||
}
|
|
||||||
|
|
||||||
var files = Request.Form.Files;
|
|
||||||
if (files == null || files.Count == 0)
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "请选择文件" });
|
|
||||||
}
|
|
||||||
|
|
||||||
string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
|
||||||
string currentPath = basePath;
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
|
||||||
{
|
|
||||||
currentPath = Path.Combine(basePath, path.TrimStart('/').Replace("/", Path.DirectorySeparatorChar.ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 安全检查:防止目录遍历
|
|
||||||
if (!Path.GetFullPath(currentPath).StartsWith(Path.GetFullPath(basePath)))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "非法路径" });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Directory.Exists(currentPath))
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = "目录不存在" });
|
|
||||||
}
|
|
||||||
|
|
||||||
int successCount = 0;
|
|
||||||
string msg = "";
|
|
||||||
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
|
||||||
string fileName = file.FileName;
|
|
||||||
// 安全检查:文件名
|
|
||||||
if (!IsSafeName(fileName))
|
|
||||||
{
|
|
||||||
msg += $"文件 {fileName} 名称非法; ";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查扩展名
|
|
||||||
string ext = Path.GetExtension(fileName).ToLower();
|
|
||||||
string allowedExts = _attachsetting.FileAllowedExtensions + "," + _attachsetting.ImageAllowedExtensions + "," + _attachsetting.MediaAllowedExtensions;
|
|
||||||
if (!allowedExts.ToLower().Split(',').Contains(ext.TrimStart('.')))
|
|
||||||
{
|
|
||||||
msg += $"文件 {fileName} 类型不允许; ";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string fullPath = Path.Combine(currentPath, fileName);
|
|
||||||
// 如果文件存在,重命名
|
|
||||||
if (System.IO.File.Exists(fullPath))
|
|
||||||
{
|
|
||||||
string nameNoExt = Path.GetFileNameWithoutExtension(fileName);
|
|
||||||
fileName = $"{nameNoExt}_{Utils.GetOrderNum()}{ext}";
|
|
||||||
fullPath = Path.Combine(currentPath, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = new FileStream(fullPath, FileMode.Create))
|
|
||||||
{
|
|
||||||
await file.CopyToAsync(stream);
|
|
||||||
}
|
|
||||||
successCount++;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
msg += $"文件 {fileName} 上传失败: {ex.Message}; ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (successCount > 0)
|
|
||||||
{
|
|
||||||
return Json(new { code = 0, message = $"成功上传 {successCount} 个文件. {msg}" });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Json(new { code = 1, message = msg });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 辅助方法
|
|
||||||
private bool IsImage(string ext)
|
|
||||||
{
|
|
||||||
return new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" }.Contains(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsVideo(string ext)
|
|
||||||
{
|
|
||||||
return new[] { ".mp4", ".avi", ".mov", ".wmv", ".flv", ".mkv" }.Contains(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsSafeName(string str)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(str)) return false;
|
|
||||||
// 允许字母、数字、下划线、中划线、点、中文
|
|
||||||
return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[\u4e00-\u9fa5a-zA-Z0-9_\-\.]+$");
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -362,22 +76,17 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
basePath += subdir.Replace("/", Path.DirectorySeparatorChar.ToString());
|
basePath += subdir.Replace("/", Path.DirectorySeparatorChar.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Directory.Exists(basePath)) return list;
|
|
||||||
|
|
||||||
string[] arrDirs = Directory.GetDirectories(basePath);
|
string[] arrDirs = Directory.GetDirectories(basePath);
|
||||||
|
|
||||||
if (arrDirs !=null && arrDirs.Length > 0)
|
if (arrDirs !=null && arrDirs.Length > 0)
|
||||||
{
|
{
|
||||||
foreach (var item in arrDirs)
|
foreach (var item in arrDirs)
|
||||||
{
|
{
|
||||||
string dirName = item.Substring(item.LastIndexOf(Path.DirectorySeparatorChar) + 1);
|
string nextSubDir = subdir + "/" + item.Substring(item.LastIndexOf(Path.DirectorySeparatorChar)+1);
|
||||||
if (dirName.Equals("_thumbs", StringComparison.OrdinalIgnoreCase)) continue; // 过滤缩略图目录
|
|
||||||
|
|
||||||
string nextSubDir = string.IsNullOrEmpty(subdir) ? dirName : subdir + "/" + dirName;
|
|
||||||
var tpmList = getAllAttach(nextSubDir);
|
var tpmList = getAllAttach(nextSubDir);
|
||||||
list.Add(new DirInfo()
|
list.Add(new DirInfo()
|
||||||
{
|
{
|
||||||
name = dirName,
|
name = item.Substring(item.LastIndexOf(Path.DirectorySeparatorChar)+1),
|
||||||
path = nextSubDir,
|
path = nextSubDir,
|
||||||
//fullPath = item,
|
//fullPath = item,
|
||||||
subList = tpmList
|
subList = tpmList
|
||||||
@@ -389,22 +98,4 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DirInfo
|
|
||||||
{
|
|
||||||
public string name { get; set; }
|
|
||||||
public string path { get; set; }
|
|
||||||
public List<DirInfo> subList { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AttachFileInfo
|
|
||||||
{
|
|
||||||
public string name { get; set; }
|
|
||||||
public string path { get; set; }
|
|
||||||
public string ext { get; set; }
|
|
||||||
public long size { get; set; }
|
|
||||||
public DateTime updateTime { get; set; }
|
|
||||||
public bool isDir { get; set; }
|
|
||||||
public string type { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
using (Stream stream = fileProvider.GetFileInfo(logname).CreateReadStream())
|
using (Stream stream = fileProvider.GetFileInfo(logname).CreateReadStream())
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[stream.Length];
|
byte[] buffer = new byte[stream.Length];
|
||||||
await stream.ReadExactlyAsync(buffer);
|
await stream.ReadAsync(buffer, 0, buffer.Length);
|
||||||
detail.Append(Encoding.Default.GetString(buffer));
|
detail.Append(Encoding.Default.GetString(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using System.Drawing;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
using NewLife.UserGroup.WebUploader;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace COMCMS.Web.Areas.AdminCP.Controllers
|
namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||||
@@ -808,6 +809,99 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
return Content(JsonConvert.SerializeObject(new { status = status, msg = msg, name = name, path = path, thumb = thumb, size = size, ext = ext }), "text/plain");
|
return Content(JsonConvert.SerializeObject(new { status = status, msg = msg, name = name, path = path, thumb = thumb, size = size, ext = ext }), "text/plain");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 分片上传文件,可断点续传
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存文件或者分块
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="md5">文件md5</param>
|
||||||
|
/// <param name="chunk">分块号</param>
|
||||||
|
/// <param name="chunks">分块总数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult SaveFile(string md5, int? chunk, int? chunks)
|
||||||
|
{
|
||||||
|
var tempDir = "UploadTemp"; // 缓存文件夹
|
||||||
|
var targetDir = "UploadFile"; // 目标文件夹
|
||||||
|
|
||||||
|
var file = Request.Form.Files[0];
|
||||||
|
|
||||||
|
file.SaveFileOrChunkFile(targetDir, tempDir, md5, chunks, chunk);
|
||||||
|
|
||||||
|
return Json(new
|
||||||
|
{
|
||||||
|
Data = new { md5 = md5, url = Path.Combine("/", targetDir, file.FileName) },
|
||||||
|
Message = "ok",
|
||||||
|
Result = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 合并文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="md5">文件md5</param>
|
||||||
|
/// <param name="fileName">文件名</param>
|
||||||
|
/// <param name="chunks">分块数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult MergeFile(string md5, string fileName, int chunks)
|
||||||
|
{
|
||||||
|
var tempDir = "UploadTemp";
|
||||||
|
var targetDir = "UploadFile";
|
||||||
|
|
||||||
|
var (res, msg) = tempDir.Merge(targetDir, fileName, md5, chunks);
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
{
|
||||||
|
return Json(new
|
||||||
|
{
|
||||||
|
Message = msg,
|
||||||
|
Result = false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Json(new
|
||||||
|
{
|
||||||
|
Data = new { md5 = md5, url = Path.Combine("/", targetDir, fileName) },
|
||||||
|
Message = "ok",
|
||||||
|
Result = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查文件或分块是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="md5">文件md5</param>
|
||||||
|
/// <param name="fileName">文件名</param>
|
||||||
|
/// <param name="chunk">分块号</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IActionResult CheckFile(string md5, string fileName, int? chunk)
|
||||||
|
{
|
||||||
|
var tempDir = "UploadTemp";
|
||||||
|
var targetDir = "UploadFile";
|
||||||
|
|
||||||
|
string filePath;
|
||||||
|
|
||||||
|
//分片文件
|
||||||
|
if (chunk != null)
|
||||||
|
{
|
||||||
|
filePath = Path.Combine(tempDir, md5, $"{chunk}.part");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filePath = Path.Combine(targetDir, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = System.IO.File.Exists(filePath);
|
||||||
|
|
||||||
|
return Json(new
|
||||||
|
{
|
||||||
|
Data = fileName != null && exists ? (object)new { md5 = md5, url = Path.Combine("/", targetDir, fileName) } : null,
|
||||||
|
Result = exists
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 帮助方法
|
#region 帮助方法
|
||||||
@@ -815,7 +909,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
{
|
{
|
||||||
// 保存为byte[]
|
// 保存为byte[]
|
||||||
byte[] byData = new byte[stream.Length];
|
byte[] byData = new byte[stream.Length];
|
||||||
stream.ReadExactly(byData);
|
stream.Read(byData, 0, byData.Length);
|
||||||
stream.Dispose();
|
stream.Dispose();
|
||||||
return byData;
|
return byData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,673 +1,75 @@
|
|||||||
@using Newtonsoft.Json
|
@{
|
||||||
@{
|
|
||||||
ViewBag.title = "附件管理";
|
ViewBag.title = "附件管理";
|
||||||
var folderJson = ViewBag.folderJson as string;
|
|
||||||
}
|
}
|
||||||
<style>
|
|
||||||
/* Grid View Styles */
|
|
||||||
.file-box {
|
|
||||||
float: left;
|
|
||||||
width: 120px;
|
|
||||||
height: 140px;
|
|
||||||
padding: 10px;
|
|
||||||
text-align: center;
|
|
||||||
cursor: pointer;
|
|
||||||
position: relative;
|
|
||||||
margin: 5px;
|
|
||||||
border: 1px solid #eee;
|
|
||||||
border-radius: 4px;
|
|
||||||
transition: all 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-box:hover {
|
|
||||||
background-color: #f8f8f8;
|
|
||||||
border-color: #ddd;
|
|
||||||
box-shadow: 0 0 5px rgba(0,0,0,0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-box.active {
|
|
||||||
background-color: #e8f0fe;
|
|
||||||
border-color: #1c84c6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-icon {
|
|
||||||
height: 80px;
|
|
||||||
line-height: 80px;
|
|
||||||
font-size: 48px;
|
|
||||||
color: #666;
|
|
||||||
margin-bottom: 5px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-icon img {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-name {
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.5;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-info {
|
|
||||||
font-size: 10px;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* List View Styles */
|
|
||||||
.file-list-item {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 8px 15px;
|
|
||||||
border-bottom: 1px solid #eee;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background-color 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-item:hover {
|
|
||||||
background-color: #f8f8f8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-item.active {
|
|
||||||
background-color: #e8f0fe;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-icon {
|
|
||||||
width: 30px;
|
|
||||||
font-size: 20px;
|
|
||||||
color: #666;
|
|
||||||
text-align: center;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-icon img {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-name {
|
|
||||||
flex: 1;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
font-size: 14px;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-info {
|
|
||||||
width: 150px;
|
|
||||||
text-align: right;
|
|
||||||
font-size: 12px;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-list-date {
|
|
||||||
width: 150px;
|
|
||||||
text-align: right;
|
|
||||||
font-size: 12px;
|
|
||||||
color: #999;
|
|
||||||
margin-left: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree {
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree ul {
|
|
||||||
list-style: none;
|
|
||||||
padding-left: 20px;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree li {
|
|
||||||
padding: 2px 0;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree a {
|
|
||||||
color: #333;
|
|
||||||
text-decoration: none;
|
|
||||||
display: inline-block;
|
|
||||||
padding: 4px 8px;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree a:hover {
|
|
||||||
background-color: #f0f0f0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree a.active {
|
|
||||||
background-color: #e8f0fe;
|
|
||||||
color: #1c84c6;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-tree i {
|
|
||||||
margin-right: 5px;
|
|
||||||
color: #f8ac59;
|
|
||||||
}
|
|
||||||
|
|
||||||
.breadcrumb {
|
|
||||||
background: none;
|
|
||||||
padding: 8px 0;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Drag and Drop Overlay */
|
|
||||||
#dropOverlay {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background: rgba(255, 255, 255, 0.8);
|
|
||||||
z-index: 1000;
|
|
||||||
border: 3px dashed #1c84c6;
|
|
||||||
text-align: center;
|
|
||||||
padding-top: 20%;
|
|
||||||
font-size: 24px;
|
|
||||||
color: #1c84c6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ibox-content {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<div class="wrapper wrapper-content">
|
<div class="wrapper wrapper-content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<div class="ibox float-e-margins">
|
<div class="ibox float-e-margins">
|
||||||
<div class="ibox-title">
|
<div class="ibox-content">
|
||||||
|
<div class="file-manager">
|
||||||
|
<h5>显示:</h5>
|
||||||
|
<a href="file_manager.html#" class="file-control active">所有</a>
|
||||||
|
<a href="file_manager.html#" class="file-control">文档</a>
|
||||||
|
<a href="file_manager.html#" class="file-control">视频</a>
|
||||||
|
<a href="file_manager.html#" class="file-control">图片</a>
|
||||||
|
<div class="hr-line-dashed"></div>
|
||||||
|
<button class="btn btn-primary btn-block">上传文件</button>
|
||||||
|
<div class="hr-line-dashed"></div>
|
||||||
<h5>文件夹</h5>
|
<h5>文件夹</h5>
|
||||||
<div class="ibox-tools">
|
<ul class="folder-list" style="padding: 0">
|
||||||
<a onclick="window.location.reload()"><i class="fa fa-refresh"></i></a>
|
<li>
|
||||||
</div>
|
<a href="file_manager.html"><i class="fa fa-folder"></i> 文件</a>
|
||||||
</div>
|
</li>
|
||||||
<div class="ibox-content" style="min-height: 600px; overflow-y: auto;">
|
<li>
|
||||||
<div id="folderTree"></div>
|
<a href="file_manager.html"><i class="fa fa-folder"></i> 图片</a>
|
||||||
</div>
|
</li>
|
||||||
</div>
|
<li>
|
||||||
</div>
|
<a href="file_manager.html"><i class="fa fa-folder"></i> Web页面</a>
|
||||||
<div class="col-sm-9">
|
</li>
|
||||||
<div class="ibox float-e-margins">
|
<li>
|
||||||
<div class="ibox-title">
|
<a href="file_manager.html"><i class="fa fa-folder"></i> 插图</a>
|
||||||
<div class="btn-group">
|
</li>
|
||||||
<button class="btn btn-primary btn-sm" onclick="uploadFile()"><i class="fa fa-upload"></i> 上传</button>
|
<li>
|
||||||
<button class="btn btn-success btn-sm" onclick="createFolder()"><i class="fa fa-plus"></i> 新建文件夹</button>
|
<a href="file_manager.html"><i class="fa fa-folder"></i> 电影</a>
|
||||||
<button class="btn btn-danger btn-sm" onclick="deleteSelected()"><i class="fa fa-trash"></i> 删除</button>
|
</li>
|
||||||
<button class="btn btn-warning btn-sm" onclick="renameFile()"><i class="fa fa-pencil"></i> 重命名</button>
|
<li>
|
||||||
<button class="btn btn-info btn-sm" onclick="copyLink()"><i class="fa fa-copy"></i> 复制链接</button>
|
<a href="file_manager.html"><i class="fa fa-folder"></i> 书籍</a>
|
||||||
<button class="btn btn-default btn-sm" onclick="refreshFiles()"><i class="fa fa-refresh"></i> 刷新</button>
|
</li>
|
||||||
</div>
|
</ul>
|
||||||
<div class="pull-right">
|
<h5 class="tag-title">标签</h5>
|
||||||
<div class="btn-group">
|
<ul class="tag-list" style="padding: 0">
|
||||||
<button type="button" class="btn btn-default btn-sm active" id="btnViewGrid" onclick="switchView('grid')" title="缩略图模式"><i class="fa fa-th-large"></i></button>
|
<li>
|
||||||
<button type="button" class="btn btn-default btn-sm" id="btnViewList" onclick="switchView('list')" title="列表模式"><i class="fa fa-list"></i></button>
|
<a href="file_manager.html">爱人</a>
|
||||||
</div>
|
</li>
|
||||||
<span id="currentPathDisplay" class="text-muted" style="margin-left: 10px;">/</span>
|
<li>
|
||||||
</div>
|
<a href="file_manager.html">工作</a>
|
||||||
</div>
|
</li>
|
||||||
<div class="ibox-content" style="min-height: 600px;" id="fileContainer">
|
<li>
|
||||||
<div id="dropOverlay">
|
<a href="file_manager.html">家庭</a>
|
||||||
<i class="fa fa-cloud-upload fa-3x"></i><br>
|
</li>
|
||||||
松开鼠标上传文件
|
<li>
|
||||||
</div>
|
<a href="file_manager.html">孩子</a>
|
||||||
<div id="fileList" class="clearfix">
|
</li>
|
||||||
<div class="text-center text-muted" style="padding: 50px;">正在加载...</div>
|
<li>
|
||||||
|
<a href="file_manager.html">假期</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="file_manager.html">音乐</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="file_manager.html">照片</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="file_manager.html">电影</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="file" id="fileInput" multiple style="display:none" onchange="doUpload()" />
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var currentPath = "";
|
|
||||||
var folders = @Html.Raw(string.IsNullOrEmpty(folderJson) ? "[]" : folderJson);
|
|
||||||
var selectedFile = null;
|
|
||||||
var currentView = 'grid'; // 'grid' or 'list'
|
|
||||||
var currentFilesData = []; // Store current files data for view switching
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
initTree();
|
|
||||||
loadFiles("");
|
|
||||||
|
|
||||||
// 点击空白处取消选择
|
|
||||||
$(document).on('click', function(e) {
|
|
||||||
if (!$(e.target).closest('.file-box').length &&
|
|
||||||
!$(e.target).closest('.file-list-item').length &&
|
|
||||||
!$(e.target).closest('.btn-group').length) {
|
|
||||||
$('.file-box, .file-list-item').removeClass('active');
|
|
||||||
selectedFile = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Drag and Drop Support
|
|
||||||
var $container = $('#fileContainer');
|
|
||||||
var $overlay = $('#dropOverlay');
|
|
||||||
var dragCounter = 0;
|
|
||||||
|
|
||||||
$container.on('dragenter', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
dragCounter++;
|
|
||||||
$overlay.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
$container.on('dragover', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
|
|
||||||
$container.on('dragleave', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
dragCounter--;
|
|
||||||
if (dragCounter === 0) {
|
|
||||||
$overlay.hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$container.on('drop', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
dragCounter = 0;
|
|
||||||
$overlay.hide();
|
|
||||||
|
|
||||||
var files = e.originalEvent.dataTransfer.files;
|
|
||||||
if (files.length > 0) {
|
|
||||||
handleDroppedFiles(files);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function switchView(view) {
|
|
||||||
currentView = view;
|
|
||||||
if (view === 'grid') {
|
|
||||||
$('#btnViewGrid').addClass('active');
|
|
||||||
$('#btnViewList').removeClass('active');
|
|
||||||
} else {
|
|
||||||
$('#btnViewGrid').removeClass('active');
|
|
||||||
$('#btnViewList').addClass('active');
|
|
||||||
}
|
|
||||||
renderFiles(currentFilesData);
|
|
||||||
}
|
|
||||||
|
|
||||||
function initTree() {
|
|
||||||
var treeData = convertToJsTreeData(folders);
|
|
||||||
// Add root node
|
|
||||||
var rootNode = {
|
|
||||||
"id": "root",
|
|
||||||
"text": "根目录",
|
|
||||||
"state": { "opened": true, "selected": true },
|
|
||||||
"icon": "fa fa-folder-open",
|
|
||||||
"data": { "path": "" },
|
|
||||||
"children": treeData
|
|
||||||
};
|
|
||||||
|
|
||||||
$('#folderTree').jstree({
|
|
||||||
'core': {
|
|
||||||
'data': [rootNode],
|
|
||||||
'check_callback': true
|
|
||||||
},
|
|
||||||
'plugins': ['types', 'wholerow'],
|
|
||||||
'types': {
|
|
||||||
'default': {
|
|
||||||
'icon': 'fa fa-folder'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).on('select_node.jstree', function(e, data) {
|
|
||||||
var path = data.node.data.path;
|
|
||||||
currentPath = path;
|
|
||||||
$('#currentPathDisplay').text(path || '/');
|
|
||||||
loadFiles(path);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function convertToJsTreeData(nodes) {
|
|
||||||
var data = [];
|
|
||||||
$.each(nodes, function(i, node) {
|
|
||||||
var item = {
|
|
||||||
"text": node.name,
|
|
||||||
"icon": "fa fa-folder",
|
|
||||||
"data": { "path": node.path },
|
|
||||||
"children": []
|
|
||||||
};
|
|
||||||
if (node.subList && node.subList.length > 0) {
|
|
||||||
item.children = convertToJsTreeData(node.subList);
|
|
||||||
}
|
|
||||||
data.push(item);
|
|
||||||
});
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadFiles(path) {
|
|
||||||
$('#fileList').html('<div class="text-center text-muted" style="padding: 50px;"><i class="fa fa-spinner fa-spin"></i> 正在加载...</div>');
|
|
||||||
selectedFile = null;
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '/AdminCP/Attach/GetFileList',
|
|
||||||
type: 'POST',
|
|
||||||
data: { path: path },
|
|
||||||
success: function(res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
currentFilesData = res.data;
|
|
||||||
renderFiles(res.data);
|
|
||||||
} else {
|
|
||||||
layer.msg(res.message, {icon: 2});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
layer.msg('加载失败', {icon: 2});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderFiles(files) {
|
|
||||||
var html = '';
|
|
||||||
if (!files || files.length === 0) {
|
|
||||||
html = '<div class="text-center text-muted" style="padding: 50px;">暂无文件</div>';
|
|
||||||
} else {
|
|
||||||
if (currentView === 'grid') {
|
|
||||||
// Grid View
|
|
||||||
$.each(files, function(i, file) {
|
|
||||||
var icon = '';
|
|
||||||
if (file.isDir) {
|
|
||||||
icon = '<i class="fa fa-folder" style="color: #f8ac59;"></i>';
|
|
||||||
} else if (file.type === 'image') {
|
|
||||||
icon = '<img src="/' + '@(Config.GetSystemConfig().AttachConfigEntity.AttachPatch)/' + file.path + '" />';
|
|
||||||
} else if (file.type === 'video') {
|
|
||||||
icon = '<i class="fa fa-file-video-o" style="color: #23c6c8;"></i>';
|
|
||||||
} else {
|
|
||||||
icon = '<i class="fa fa-file-o"></i>';
|
|
||||||
}
|
|
||||||
|
|
||||||
var safeName = file.name.replace(/'/g, "\\'");
|
|
||||||
var safePath = file.path.replace(/'/g, "\\'");
|
|
||||||
|
|
||||||
html += '<div class="file-box" onclick="selectFile(this, \'' + safePath + '\', ' + file.isDir + ', \'' + safeName + '\')" ondblclick="openFile(\'' + safePath + '\', ' + file.isDir + ')">';
|
|
||||||
html += '<div class="file-icon">' + icon + '</div>';
|
|
||||||
html += '<div class="file-name" title="' + file.name + '">' + file.name + '</div>';
|
|
||||||
if (!file.isDir) {
|
|
||||||
html += '<div class="file-info">' + formatSize(file.size) + '</div>';
|
|
||||||
}
|
|
||||||
html += '</div>';
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// List View
|
|
||||||
html += '<div class="file-list-header" style="padding: 8px 15px; border-bottom: 1px solid #ddd; font-weight: bold; color: #666; display: flex;">';
|
|
||||||
html += '<div style="width: 40px;"></div>';
|
|
||||||
html += '<div style="flex: 1;">名称</div>';
|
|
||||||
html += '<div style="width: 150px; text-align: right;">大小</div>';
|
|
||||||
html += '<div style="width: 150px; text-align: right; margin-left: 15px;">修改时间</div>';
|
|
||||||
html += '</div>';
|
|
||||||
|
|
||||||
$.each(files, function(i, file) {
|
|
||||||
var icon = '';
|
|
||||||
if (file.isDir) {
|
|
||||||
icon = '<i class="fa fa-folder" style="color: #f8ac59;"></i>';
|
|
||||||
} else if (file.type === 'image') {
|
|
||||||
icon = '<i class="fa fa-file-image-o" style="color: #1c84c6;"></i>';
|
|
||||||
} else if (file.type === 'video') {
|
|
||||||
icon = '<i class="fa fa-file-video-o" style="color: #23c6c8;"></i>';
|
|
||||||
} else {
|
|
||||||
icon = '<i class="fa fa-file-o"></i>';
|
|
||||||
}
|
|
||||||
|
|
||||||
var safeName = file.name.replace(/'/g, "\\'");
|
|
||||||
var safePath = file.path.replace(/'/g, "\\'");
|
|
||||||
var sizeStr = file.isDir ? '-' : formatSize(file.size);
|
|
||||||
var dateStr = file.updateTime ? file.updateTime.replace('T', ' ').substring(0, 19) : '-';
|
|
||||||
|
|
||||||
html += '<div class="file-list-item" onclick="selectFile(this, \'' + safePath + '\', ' + file.isDir + ', \'' + safeName + '\')" ondblclick="openFile(\'' + safePath + '\', ' + file.isDir + ')">';
|
|
||||||
html += '<div class="file-list-icon">' + icon + '</div>';
|
|
||||||
html += '<div class="file-list-name" title="' + file.name + '">' + file.name + '</div>';
|
|
||||||
html += '<div class="file-list-info">' + sizeStr + '</div>';
|
|
||||||
html += '<div class="file-list-date">' + dateStr + '</div>';
|
|
||||||
html += '</div>';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$('#fileList').html(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectFile(el, path, isDir, name) {
|
|
||||||
$('.file-box, .file-list-item').removeClass('active');
|
|
||||||
$(el).addClass('active');
|
|
||||||
selectedFile = { path: path, isDir: isDir, name: name };
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
function openFile(path, isDir) {
|
|
||||||
if (isDir) {
|
|
||||||
currentPath = path;
|
|
||||||
$('#currentPathDisplay').text(path || '/');
|
|
||||||
loadFiles(path);
|
|
||||||
} else {
|
|
||||||
// Preview file?
|
|
||||||
var file = currentFilesData.find(function(f) { return f.path == path; });
|
|
||||||
if (file && file.type === 'image') {
|
|
||||||
var photosData = {
|
|
||||||
"title": "图片预览",
|
|
||||||
"id": 1,
|
|
||||||
"start": 0,
|
|
||||||
"data": []
|
|
||||||
};
|
|
||||||
|
|
||||||
var images = [];
|
|
||||||
$.each(currentFilesData, function(i, f) {
|
|
||||||
if (f.type === 'image') images.push(f);
|
|
||||||
});
|
|
||||||
|
|
||||||
$.each(images, function(i, img) {
|
|
||||||
var src = '/' + '@(Config.GetSystemConfig().AttachConfigEntity.AttachPatch)/' + img.path;
|
|
||||||
photosData.data.push({
|
|
||||||
"alt": img.name,
|
|
||||||
"pid": i,
|
|
||||||
"src": src,
|
|
||||||
"thumb": ""
|
|
||||||
});
|
|
||||||
|
|
||||||
if (img.path === path) {
|
|
||||||
photosData.start = i;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
layer.photos({
|
|
||||||
photos: photosData,
|
|
||||||
anim: 5
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var url = '/' + '@(Config.GetSystemConfig().AttachConfigEntity.AttachPatch)/' + path;
|
|
||||||
window.open(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createFolder() {
|
|
||||||
layer.prompt({title: '请输入文件夹名称', formType: 0}, function(text, index){
|
|
||||||
layer.close(index);
|
|
||||||
$.ajax({
|
|
||||||
url: '/AdminCP/Attach/CreateDir',
|
|
||||||
type: 'POST',
|
|
||||||
data: { path: currentPath, name: text },
|
|
||||||
success: function(res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
layer.msg('创建成功', {icon: 1});
|
|
||||||
refreshFiles();
|
|
||||||
setTimeout(function(){ window.location.reload(); }, 1000);
|
|
||||||
} else {
|
|
||||||
layer.msg(res.message, {icon: 2});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteSelected() {
|
|
||||||
if (!selectedFile) {
|
|
||||||
layer.msg('请先选择文件或文件夹', {icon: 0});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
layer.confirm('确定要删除吗?此操作不可恢复!', {icon: 3, title:'提示'}, function(index){
|
|
||||||
$.ajax({
|
|
||||||
url: '/AdminCP/Attach/DeleteFile',
|
|
||||||
type: 'POST',
|
|
||||||
data: { path: selectedFile.path, isDir: selectedFile.isDir },
|
|
||||||
success: function(res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
layer.msg('删除成功', {icon: 1});
|
|
||||||
refreshFiles();
|
|
||||||
if (selectedFile.isDir) {
|
|
||||||
setTimeout(function(){ window.location.reload(); }, 1000);
|
|
||||||
}
|
|
||||||
selectedFile = null;
|
|
||||||
} else {
|
|
||||||
layer.msg(res.message, {icon: 2});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
layer.close(index);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renameFile() {
|
|
||||||
if (!selectedFile) {
|
|
||||||
layer.msg('请先选择文件或文件夹', {icon: 0});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentFile = selectedFile;
|
|
||||||
|
|
||||||
layer.prompt({
|
|
||||||
title: '请输入新名称',
|
|
||||||
formType: 0,
|
|
||||||
value: currentFile.name
|
|
||||||
}, function(text, index){
|
|
||||||
layer.close(index);
|
|
||||||
|
|
||||||
if (text === currentFile.name) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var loading = layer.load(1, {shade: [0.1,'#fff']});
|
|
||||||
$.ajax({
|
|
||||||
url: '/AdminCP/Attach/RenameFile',
|
|
||||||
type: 'POST',
|
|
||||||
data: { path: currentFile.path, newName: text, isDir: currentFile.isDir },
|
|
||||||
success: function(res) {
|
|
||||||
layer.close(loading);
|
|
||||||
if (res.code === 0) {
|
|
||||||
layer.msg('重命名成功', {icon: 1});
|
|
||||||
refreshFiles();
|
|
||||||
if (currentFile.isDir) {
|
|
||||||
setTimeout(function(){ window.location.reload(); }, 1000);
|
|
||||||
}
|
|
||||||
selectedFile = null;
|
|
||||||
} else {
|
|
||||||
layer.msg(res.message, {icon: 2});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
layer.close(loading);
|
|
||||||
layer.msg('请求失败', {icon: 2});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function uploadFile() {
|
|
||||||
if (!checkUploadPermission()) return;
|
|
||||||
$('#fileInput').click();
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkUploadPermission() {
|
|
||||||
if (!currentPath || currentPath === "") {
|
|
||||||
layer.msg('根目录不允许上传文件,请选择子目录', {icon: 0});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function doUpload() {
|
|
||||||
var files = $('#fileInput')[0].files;
|
|
||||||
if (files.length === 0) return;
|
|
||||||
processUpload(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDroppedFiles(files) {
|
|
||||||
if (!checkUploadPermission()) return;
|
|
||||||
processUpload(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
function processUpload(files) {
|
|
||||||
var formData = new FormData();
|
|
||||||
for (var i = 0; i < files.length; i++) {
|
|
||||||
formData.append("files", files[i]);
|
|
||||||
}
|
|
||||||
formData.append("path", currentPath);
|
|
||||||
|
|
||||||
var loading = layer.load(1, {shade: [0.1,'#fff']});
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '/AdminCP/Attach/UploadFile',
|
|
||||||
type: 'POST',
|
|
||||||
data: formData,
|
|
||||||
processData: false,
|
|
||||||
contentType: false,
|
|
||||||
success: function(res) {
|
|
||||||
layer.close(loading);
|
|
||||||
if (res.code === 0) {
|
|
||||||
layer.msg(res.message, {icon: 1});
|
|
||||||
refreshFiles();
|
|
||||||
} else {
|
|
||||||
layer.alert(res.message, {icon: 2});
|
|
||||||
}
|
|
||||||
$('#fileInput').val('');
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
layer.close(loading);
|
|
||||||
layer.msg('上传出错', {icon: 2});
|
|
||||||
$('#fileInput').val('');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshFiles() {
|
|
||||||
loadFiles(currentPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyLink() {
|
|
||||||
if (!selectedFile || selectedFile.isDir) {
|
|
||||||
layer.msg('请选择一个文件', {icon: 0});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var url = '/' + '@(Config.GetSystemConfig().AttachConfigEntity.AttachPatch)/' + selectedFile.path;
|
|
||||||
var $temp = $("<input>");
|
|
||||||
$("body").append($temp);
|
|
||||||
$temp.val(url).select();
|
|
||||||
document.execCommand("copy");
|
|
||||||
$temp.remove();
|
|
||||||
layer.msg('链接已复制', {icon: 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatSize(bytes) {
|
|
||||||
if (bytes === 0) return '0 B';
|
|
||||||
var k = 1024;
|
|
||||||
var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
||||||
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
<link href="~/hplus/css/style.css" rel="stylesheet" />
|
<link href="~/hplus/css/style.css" rel="stylesheet" />
|
||||||
<link href="~/hplus/css/font-awesome.min.css" rel="stylesheet" />
|
<link href="~/hplus/css/font-awesome.min.css" rel="stylesheet" />
|
||||||
<link href="~/hplus/css/animate.min.css" rel="stylesheet" />
|
<link href="~/hplus/css/animate.min.css" rel="stylesheet" />
|
||||||
|
<link href="~/hplus/css/login.css" rel="stylesheet" />
|
||||||
<link href="~/js/treegrid/jquery.treegrid.css" rel="stylesheet" />
|
<link href="~/js/treegrid/jquery.treegrid.css" rel="stylesheet" />
|
||||||
<script src="~/js/jquery2.min.js"></script>
|
<script src="~/js/jquery2.min.js"></script>
|
||||||
<script src="~/js/layer/layer.js"></script>
|
<script src="~/js/layer/layer.js"></script>
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
<script>var encrypt_key = '@ViewBag.key';</script>
|
<script>var encrypt_key = '@ViewBag.key';</script>
|
||||||
</head>
|
</head>
|
||||||
<body class="gray-bg">
|
<body class="gray-bg">
|
||||||
<canvas id="canvas-bg"></canvas>
|
<div class="middle-box text-center loginscreen animated fadeInDown">
|
||||||
<div class="middle-box animated fadeInDown">
|
|
||||||
<div>
|
<div>
|
||||||
<div class="text-center m-b-md" style="font-size:64px">
|
<div class="text-center m-b-md" style="font-size:64px">
|
||||||
COMCMS
|
COMCMS
|
||||||
@@ -81,89 +80,6 @@
|
|||||||
};
|
};
|
||||||
DoAdminLogin("loginForm", rules);
|
DoAdminLogin("loginForm", rules);
|
||||||
});
|
});
|
||||||
// --- 科技感粒子连线动画特效 (原生JS实现,无需引入额外库) ---
|
|
||||||
(function() {
|
|
||||||
var canvas = document.getElementById('canvas-bg');
|
|
||||||
var ctx = canvas.getContext('2d');
|
|
||||||
var width, height;
|
|
||||||
var particles = [];
|
|
||||||
|
|
||||||
// 特效配置
|
|
||||||
var config = {
|
|
||||||
count: 80, // 粒子数量
|
|
||||||
dist: 160, // 连线距离
|
|
||||||
radius: 2, // 粒子大小
|
|
||||||
color: '26, 179, 148',// 主色调 RGB (#1ab394)
|
|
||||||
speed: 0.8 // 移动速度
|
|
||||||
};
|
|
||||||
|
|
||||||
function resize() {
|
|
||||||
width = window.innerWidth;
|
|
||||||
height = window.innerHeight;
|
|
||||||
canvas.width = width;
|
|
||||||
canvas.height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Particle() {
|
|
||||||
this.x = Math.random() * width;
|
|
||||||
this.y = Math.random() * height;
|
|
||||||
this.vx = (Math.random() - 0.5) * config.speed;
|
|
||||||
this.vy = (Math.random() - 0.5) * config.speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
Particle.prototype.update = function() {
|
|
||||||
this.x += this.vx;
|
|
||||||
this.y += this.vy;
|
|
||||||
if (this.x < 0 || this.x > width) this.vx = -this.vx;
|
|
||||||
if (this.y < 0 || this.y > height) this.vy = -this.vy;
|
|
||||||
};
|
|
||||||
|
|
||||||
Particle.prototype.draw = function() {
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(this.x, this.y, config.radius, 0, Math.PI * 2);
|
|
||||||
ctx.fillStyle = 'rgba(' + config.color + ', 0.6)';
|
|
||||||
ctx.fill();
|
|
||||||
};
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
resize();
|
|
||||||
particles = [];
|
|
||||||
for (var i = 0; i < config.count; i++) {
|
|
||||||
particles.push(new Particle());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function animate() {
|
|
||||||
ctx.clearRect(0, 0, width, height);
|
|
||||||
|
|
||||||
for (var i = 0; i < particles.length; i++) {
|
|
||||||
var p1 = particles[i];
|
|
||||||
p1.update();
|
|
||||||
p1.draw();
|
|
||||||
|
|
||||||
for (var j = i + 1; j < particles.length; j++) {
|
|
||||||
var p2 = particles[j];
|
|
||||||
var dx = p1.x - p2.x;
|
|
||||||
var dy = p1.y - p2.y;
|
|
||||||
var dist = Math.sqrt(dx * dx + dy * dy);
|
|
||||||
|
|
||||||
if (dist < config.dist) {
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.strokeStyle = 'rgba(' + config.color + ',' + (1 - dist / config.dist) * 0.4 + ')';
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
ctx.moveTo(p1.x, p1.y);
|
|
||||||
ctx.lineTo(p2.x, p2.y);
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requestAnimationFrame(animate);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('resize', resize);
|
|
||||||
init();
|
|
||||||
animate();
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -8,15 +8,15 @@
|
|||||||
<link href="~/hplus/css/style.css" rel="stylesheet" />
|
<link href="~/hplus/css/style.css" rel="stylesheet" />
|
||||||
<link href="~/hplus/css/font-awesome.min.css" rel="stylesheet" />
|
<link href="~/hplus/css/font-awesome.min.css" rel="stylesheet" />
|
||||||
<link href="~/hplus/css/animate.min.css" rel="stylesheet" />
|
<link href="~/hplus/css/animate.min.css" rel="stylesheet" />
|
||||||
|
<link href="~/hplus/css/login.css" rel="stylesheet" />
|
||||||
<link href="~/hplus/js/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
|
<link href="~/hplus/js/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
|
||||||
<link href="~/hplus/css/plugins/iCheck/custom.css" rel="stylesheet" />
|
<link href="~/hplus/css/plugins/iCheck/custom.css" rel="stylesheet" />
|
||||||
<link href="~/js/treegrid/jquery.treegrid.css" rel="stylesheet" />
|
<link href="~/js/treegrid/jquery.treegrid.css" rel="stylesheet" />
|
||||||
<link href="~/js/webuploader/webuploader.css" rel="stylesheet" />
|
<link href="~/js/webuploader/webuploader.css" rel="stylesheet" />
|
||||||
<link href="~/js/bootstrap-colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet" />
|
<link href="~/js/bootstrap-colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet" />
|
||||||
<link href="~/js/jstree/themes/default/style.min.css" rel="stylesheet" />
|
|
||||||
<script src="~/js/my97/WdatePicker.js"></script>
|
<script src="~/js/my97/WdatePicker.js"></script>
|
||||||
<script src="~/js/jquery-3.min.js"></script>
|
|
||||||
<environment names="Development">
|
<environment names="Development">
|
||||||
|
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
||||||
<script src="~/js/validation/jquery.validate.js"></script>
|
<script src="~/js/validation/jquery.validate.js"></script>
|
||||||
<script src="~/js/validation/messages_zh.js"></script>
|
<script src="~/js/validation/messages_zh.js"></script>
|
||||||
@@ -35,9 +35,9 @@
|
|||||||
<script src="~/js/uploader.js"></script>
|
<script src="~/js/uploader.js"></script>
|
||||||
<script src="~/editor/ckeditor/ckeditor.js" asp-append-version="true"></script>
|
<script src="~/editor/ckeditor/ckeditor.js" asp-append-version="true"></script>
|
||||||
<script src="~/js/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
|
<script src="~/js/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
|
||||||
<script src="~/js/jstree/jstree.min.js"></script>
|
|
||||||
</environment>
|
</environment>
|
||||||
<environment names="Staging,Production">
|
<environment names="Staging,Production">
|
||||||
|
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
||||||
<script src="~/js/validation/jquery.validate.min.js"></script>
|
<script src="~/js/validation/jquery.validate.min.js"></script>
|
||||||
<script src="~/js/validation/messages_zh.min.js"></script>
|
<script src="~/js/validation/messages_zh.min.js"></script>
|
||||||
@@ -55,7 +55,6 @@
|
|||||||
<script src="~/js/uploader.js"></script>
|
<script src="~/js/uploader.js"></script>
|
||||||
<script src="~/editor/ckeditor/ckeditor.js"></script>
|
<script src="~/editor/ckeditor/ckeditor.js"></script>
|
||||||
<script src="~/js/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
|
<script src="~/js/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
|
||||||
<script src="~/js/jstree/jstree.min.js"></script>
|
|
||||||
</environment>
|
</environment>
|
||||||
</head>
|
</head>
|
||||||
<body class="gray-bg">
|
<body class="gray-bg">
|
||||||
|
|||||||
@@ -1,30 +1,39 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<<<<<<< HEAD
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
=======
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MailKit" Version="4.17.0" />
|
<PackageReference Include="MailKit" Version="4.14.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.9" />
|
<<<<<<< HEAD
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.9" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="10.0.9" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="10.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="10.0.2" />
|
=======
|
||||||
<PackageReference Include="MimeKit" Version="4.17.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
|
||||||
<PackageReference Include="MySql.Data" Version="9.7.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
|
||||||
<PackageReference Include="NewLife.Redis" Version="6.5.2026.601" />
|
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0" />
|
||||||
<PackageReference Include="NewLife.XCode" Version="11.27.2026.601" />
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
||||||
|
<PackageReference Include="MimeKit" Version="4.14.0" />
|
||||||
|
<PackageReference Include="MySql.Data" Version="9.5.0" />
|
||||||
|
<PackageReference Include="NewLife.Redis" Version="6.3.2025.1001" />
|
||||||
|
<PackageReference Include="NewLife.XCode" Version="11.22.2025.1112" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
<PackageReference Include="NuGet.Protocol" Version="6.12.5" />
|
|
||||||
<PackageReference Include="Senparc.NeuChar" Version="2.6.2" />
|
<PackageReference Include="Senparc.NeuChar" Version="2.6.2" />
|
||||||
<PackageReference Include="Senparc.Weixin" Version="6.23.1" />
|
<PackageReference Include="Senparc.Weixin" Version="6.23.0" />
|
||||||
<PackageReference Include="Senparc.Weixin.MP" Version="16.24.2" />
|
<PackageReference Include="Senparc.Weixin.MP" Version="16.24.0" />
|
||||||
<PackageReference Include="Senparc.Weixin.MP.MvcExtension" Version="4.1.1" />
|
<PackageReference Include="Senparc.Weixin.MP.MvcExtension" Version="4.1.1" />
|
||||||
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.18.1" />
|
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.18.0" />
|
||||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.26.1" />
|
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.24.1" />
|
||||||
<PackageReference Include="System.Data.SqlClient" Version="4.9.1" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -32,6 +41,7 @@
|
|||||||
<ProjectReference Include="..\COMCMS.Common\COMCMS.Common.csproj" />
|
<ProjectReference Include="..\COMCMS.Common\COMCMS.Common.csproj" />
|
||||||
<ProjectReference Include="..\COMCMS.Core\COMCMS.Core.csproj" />
|
<ProjectReference Include="..\COMCMS.Core\COMCMS.Core.csproj" />
|
||||||
<ProjectReference Include="..\Lib.Core\Lib.Core.csproj" />
|
<ProjectReference Include="..\Lib.Core\Lib.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\NewLife.UserGroup.WebUploader\NewLife.UserGroup.WebUploader.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -390,6 +400,8 @@
|
|||||||
<None Include="wwwroot\editor\ckeditor\plugins\xml\plugin.js" />
|
<None Include="wwwroot\editor\ckeditor\plugins\xml\plugin.js" />
|
||||||
<None Include="wwwroot\editor\ckeditor\skins\moono-lisa\readme.md" />
|
<None Include="wwwroot\editor\ckeditor\skins\moono-lisa\readme.md" />
|
||||||
<None Include="wwwroot\editor\ckeditor\vendor\promise.js" />
|
<None Include="wwwroot\editor\ckeditor\vendor\promise.js" />
|
||||||
|
<None Include="wwwroot\install\comcms_for_linux.sql" />
|
||||||
|
<None Include="wwwroot\install\comcms_for_windows.sql" />
|
||||||
<None Include="wwwroot\install\comcms_sqlserver.sql" />
|
<None Include="wwwroot\install\comcms_sqlserver.sql" />
|
||||||
<None Include="wwwroot\js\my97\lang\en.js" />
|
<None Include="wwwroot\js\my97\lang\en.js" />
|
||||||
<None Include="wwwroot\js\my97\lang\zh-cn.js" />
|
<None Include="wwwroot\js\my97\lang\zh-cn.js" />
|
||||||
|
|||||||
@@ -154,7 +154,10 @@ namespace COMCMS.Web.Controllers
|
|||||||
string sqlname = "comcms_sqlserver.sql";
|
string sqlname = "comcms_sqlserver.sql";
|
||||||
if (sqltype == "mysql")
|
if (sqltype == "mysql")
|
||||||
{
|
{
|
||||||
sqlname = "comcms_mysql.sql";
|
if (mysqltype == "linux")
|
||||||
|
sqlname = "comcms_for_linux.sql";
|
||||||
|
else
|
||||||
|
sqlname = "comcms_for_windows.sql";
|
||||||
}
|
}
|
||||||
|
|
||||||
string sqlPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}install{Path.DirectorySeparatorChar}";
|
string sqlPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}install{Path.DirectorySeparatorChar}";
|
||||||
@@ -249,6 +252,7 @@ namespace COMCMS.Web.Controllers
|
|||||||
tip.ReturnUrl = "/";
|
tip.ReturnUrl = "/";
|
||||||
return Json(tip);
|
return Json(tip);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 测试
|
#region 测试
|
||||||
|
|||||||
+67
-3
@@ -1,8 +1,72 @@
|
|||||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
|
# 构建阶段
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# 复制项目文件
|
||||||
|
COPY ["COMCMS.Web/COMCMS.Web.csproj", "COMCMS.Web/"]
|
||||||
|
COPY ["COMCMS.Core/COMCMS.Core.csproj", "COMCMS.Core/"]
|
||||||
|
COPY ["COMCMS.Common/COMCMS.Common.csproj", "COMCMS.Common/"]
|
||||||
|
COPY ["COMCMS.API/COMCMS.API.csproj", "COMCMS.API/"]
|
||||||
|
COPY ["Lib.Core/Lib.Core.csproj", "Lib.Core/"]
|
||||||
|
COPY ["NewLife.UserGroup.WebUploader/NewLife.UserGroup.WebUploader.csproj", "NewLife.UserGroup.WebUploader/"]
|
||||||
|
|
||||||
|
# 还原依赖
|
||||||
|
RUN dotnet restore "COMCMS.Web/COMCMS.Web.csproj"
|
||||||
|
|
||||||
|
# 复制所有源代码
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 构建项目
|
||||||
|
WORKDIR "/src/COMCMS.Web"
|
||||||
|
RUN dotnet build "COMCMS.Web.csproj" -c Release -o /app/build
|
||||||
|
|
||||||
|
# 发布阶段
|
||||||
|
FROM build AS publish
|
||||||
|
RUN dotnet publish "COMCMS.Web.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
# 运行时阶段
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
|
||||||
|
|
||||||
|
# 安装 curl 用于健康检查和 SkiaSharp 依赖
|
||||||
|
USER root
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
curl \
|
||||||
|
libfontconfig1 \
|
||||||
|
libfreetype6 \
|
||||||
|
libx11-6 \
|
||||||
|
libxext6 \
|
||||||
|
libxrender1 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
COPY . .
|
# 设置 ASP.NET Core 监听端口
|
||||||
ENTRYPOINT ["dotnet", "COMCMS.Web.dll"]
|
ENV ASPNETCORE_URLS=http://+:80
|
||||||
|
|
||||||
|
# 从发布阶段复制文件
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
|
||||||
|
# 复制启动脚本
|
||||||
|
COPY run.sh /app/run.sh
|
||||||
|
|
||||||
|
# 创建必要的目录并设置权限(在切换用户之前)
|
||||||
|
RUN mkdir -p /app/wwwroot/userfiles \
|
||||||
|
&& mkdir -p /app/logs \
|
||||||
|
&& mkdir -p /app/Log \
|
||||||
|
&& mkdir -p /appLog \
|
||||||
|
&& mkdir -p /home/app/.aspnet/DataProtection-Keys \
|
||||||
|
&& chmod +x /app/run.sh \
|
||||||
|
&& chown -R app:app /app \
|
||||||
|
&& chown -R app:app /appLog \
|
||||||
|
&& chown -R app:app /home/app/.aspnet
|
||||||
|
|
||||||
|
USER app
|
||||||
|
|
||||||
|
# 健康检查
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD curl -f http://localhost/ || exit 1
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/run.sh", "prod"]
|
||||||
@@ -51,6 +51,14 @@ namespace COMCMS.Web
|
|||||||
//添加Configuration到静态变量
|
//添加Configuration到静态变量
|
||||||
Utils.AddUtils(Configuration);
|
Utils.AddUtils(Configuration);
|
||||||
|
|
||||||
|
// 配置XCode数据库连接
|
||||||
|
var connStr = Configuration["connectionStrings:dbconn:connectionString"];
|
||||||
|
var providerName = Configuration["connectionStrings:dbconn:providerName"];
|
||||||
|
if (!string.IsNullOrEmpty(connStr))
|
||||||
|
{
|
||||||
|
XCode.DataAccessLayer.DAL.AddConnStr("dbconn", connStr, null, providerName);
|
||||||
|
}
|
||||||
|
|
||||||
services.Configure<CookiePolicyOptions>(options =>
|
services.Configure<CookiePolicyOptions>(options =>
|
||||||
{
|
{
|
||||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||||
|
|||||||
@@ -37,10 +37,27 @@
|
|||||||
</div>
|
</div>
|
||||||
@if (ViewBag.sqltype == "mysql")
|
@if (ViewBag.sqltype == "mysql")
|
||||||
{
|
{
|
||||||
|
<<<<<<< HEAD
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<select class="form-control" name="mysqltype" id="mysqltype">
|
<select class="form-control" name="mysqltype" id="mysqltype">
|
||||||
<option value="windows">Windows 下 Mysql(数据库表不区分大小写)</option>
|
<option value="windows">Windows 下 Mysql(数据库表不区分大小写)</option>
|
||||||
<option value="linux">Linux 下 Mysql(数据库表区分大小写)</option>
|
<option value="linux">Linux 下 Mysql(数据库表区分大小写)</option>
|
||||||
|
=======
|
||||||
|
var isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux);
|
||||||
|
var defaultMysqlType = isLinux ? "linux" : "windows";
|
||||||
|
<div class="form-group">
|
||||||
|
<select class="form-control" name="mysqltype" id="mysqltype">
|
||||||
|
@if (defaultMysqlType == "windows")
|
||||||
|
{
|
||||||
|
<option value="windows" selected>Windows 下 Mysql(数据库表不区分大小写)</option>
|
||||||
|
<option value="linux">Linux 下 Mysql(数据库表区分大小写)</option>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<option value="windows">Windows 下 Mysql(数据库表不区分大小写)</option>
|
||||||
|
<option value="linux" selected>Linux 下 Mysql(数据库表区分大小写)</option>
|
||||||
|
}
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<link href="~/js/swpier/swiper.min.css" rel="stylesheet" />
|
<link href="~/js/swpier/swiper.min.css" rel="stylesheet" />
|
||||||
<link href="~/images/default/style.css" rel="stylesheet" />
|
<link href="~/images/default/style.css" rel="stylesheet" />
|
||||||
<script src="~/js/html5shiv.min.js"></script>
|
<script src="~/js/html5shiv.min.js"></script>
|
||||||
<script src="~/js/jquery-3.min.js"></script>
|
<script src="~/js/jquery2.min.js"></script>
|
||||||
<script src="~/js/layer/layer.js"></script>
|
<script src="~/js/layer/layer.js"></script>
|
||||||
<script src="~/js/jquery.form.js"></script>
|
<script src="~/js/jquery.form.js"></script>
|
||||||
<script src="~/js/swpier/swiper.min.js"></script>
|
<script src="~/js/swpier/swiper.min.js"></script>
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
"Logging": {
|
"Logging": {
|
||||||
"IncludeScopes": false,
|
"IncludeScopes": false,
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Warning"
|
"Default": "Information",
|
||||||
|
"Microsoft": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"RedisCache": {
|
"RedisCache": {
|
||||||
@@ -38,7 +40,11 @@
|
|||||||
},
|
},
|
||||||
"connectionStrings": {
|
"connectionStrings": {
|
||||||
"dbconn": {
|
"dbconn": {
|
||||||
|
<<<<<<< HEAD
|
||||||
"connectionString": "Server=.;Port=3306;Database=comcms;Uid=root;Pwd=root;charset=utf8mb4",
|
"connectionString": "Server=.;Port=3306;Database=comcms;Uid=root;Pwd=root;charset=utf8mb4",
|
||||||
|
=======
|
||||||
|
"connectionString": "Server=localhost;Port=3306;Database=comcms;Uid=root;Pwd=root;charset=utf8mb4",
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
"providerName": "MySql.Data.MySqlClient"
|
"providerName": "MySql.Data.MySqlClient"
|
||||||
},
|
},
|
||||||
"mssqlconnon": {
|
"mssqlconnon": {
|
||||||
|
|||||||
@@ -38,31 +38,6 @@ CKEDITOR.dialog.add( 'html5video', function( editor ) {
|
|||||||
hidden: true,
|
hidden: true,
|
||||||
filebrowser: 'info:url'
|
filebrowser: 'info:url'
|
||||||
} ]
|
} ]
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'hbox',
|
|
||||||
widths: [ '365px', '110px' ],
|
|
||||||
align: 'right',
|
|
||||||
children: [ {
|
|
||||||
type: 'text',
|
|
||||||
id: 'poster',
|
|
||||||
label: editor.lang.html5video.poster,
|
|
||||||
setup: function( widget ) {
|
|
||||||
this.setValue( widget.data.poster );
|
|
||||||
},
|
|
||||||
commit: function( widget ) {
|
|
||||||
widget.setData( 'poster', this.getValue() );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
id: 'browsePoster',
|
|
||||||
style: 'display:inline-block;margin-top:14px;',
|
|
||||||
align: 'center',
|
|
||||||
label: editor.lang.common.browseServer,
|
|
||||||
hidden: true,
|
|
||||||
filebrowser: 'info:poster'
|
|
||||||
} ]
|
|
||||||
} ]
|
} ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -151,20 +126,6 @@ CKEDITOR.dialog.add( 'html5video', function( editor ) {
|
|||||||
filebrowser: 'info:url',
|
filebrowser: 'info:url',
|
||||||
label: editor.lang.html5video.btnUpload,
|
label: editor.lang.html5video.btnUpload,
|
||||||
'for': [ 'Upload', 'upload' ]
|
'for': [ 'Upload', 'upload' ]
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'file',
|
|
||||||
id: 'uploadPoster',
|
|
||||||
label: editor.lang.html5video.posterUpload,
|
|
||||||
style: 'height:40px',
|
|
||||||
size: 38
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'fileButton',
|
|
||||||
id: 'uploadButtonPoster',
|
|
||||||
filebrowser: 'info:poster',
|
|
||||||
label: editor.lang.html5video.btnUpload,
|
|
||||||
'for': [ 'Upload', 'uploadPoster' ]
|
|
||||||
} ]
|
} ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,5 @@ CKEDITOR.plugins.setLang( 'html5video', 'en', {
|
|||||||
autoplay: 'Autoplay?',
|
autoplay: 'Autoplay?',
|
||||||
yes: 'Yes',
|
yes: 'Yes',
|
||||||
no: 'No',
|
no: 'No',
|
||||||
responsive: 'Responsive width',
|
responsive: 'Responsive width'
|
||||||
poster: 'Poster image',
|
|
||||||
posterUpload: 'Upload poster image'
|
|
||||||
} );
|
} );
|
||||||
|
|||||||
@@ -11,7 +11,5 @@ CKEDITOR.plugins.setLang('html5video', 'zh-cn', {
|
|||||||
autoplay: '自动播放?',
|
autoplay: '自动播放?',
|
||||||
yes: '是',
|
yes: '是',
|
||||||
no: '否',
|
no: '否',
|
||||||
responsive: '响应式宽度',
|
responsive: '响应式宽度'
|
||||||
poster: '封面图',
|
|
||||||
posterUpload: '上传封面图'
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ CKEDITOR.plugins.add( 'html5video', {
|
|||||||
* - div-s with text-align,float,margin-left,margin-right inline style rules and required ckeditor-html5-video class.
|
* - div-s with text-align,float,margin-left,margin-right inline style rules and required ckeditor-html5-video class.
|
||||||
* - video tags with src, controls, width and height attributes.
|
* - video tags with src, controls, width and height attributes.
|
||||||
*/
|
*/
|
||||||
allowedContent: 'div[data-responsive](!ckeditor-html5-video){text-align,float,margin-left,margin-right}; video[src,controls,autoplay,width,height,poster]{max-width,height};',
|
allowedContent: 'div[data-responsive](!ckeditor-html5-video){text-align,float,margin-left,margin-right}; video[src,controls,autoplay,width, height]{max-width,height};',
|
||||||
requiredContent: 'div(ckeditor-html5-video); video[src,controls];',
|
requiredContent: 'div(ckeditor-html5-video); video[src,controls];',
|
||||||
upcast: function( element ) {
|
upcast: function( element ) {
|
||||||
return element.name === 'div' && element.hasClass( 'ckeditor-html5-video' );
|
return element.name === 'div' && element.hasClass( 'ckeditor-html5-video' );
|
||||||
@@ -21,7 +21,6 @@ CKEDITOR.plugins.add( 'html5video', {
|
|||||||
var src = '';
|
var src = '';
|
||||||
var autoplay = '';
|
var autoplay = '';
|
||||||
var align = this.element.getStyle( 'text-align' );
|
var align = this.element.getStyle( 'text-align' );
|
||||||
var poster = '';
|
|
||||||
|
|
||||||
var width = '';
|
var width = '';
|
||||||
var height = '';
|
var height = '';
|
||||||
@@ -33,7 +32,6 @@ CKEDITOR.plugins.add( 'html5video', {
|
|||||||
width = this.element.getChild( 0 ).getAttribute( 'width' );
|
width = this.element.getChild( 0 ).getAttribute( 'width' );
|
||||||
height = this.element.getChild( 0 ).getAttribute( 'height' );
|
height = this.element.getChild( 0 ).getAttribute( 'height' );
|
||||||
autoplay = this.element.getChild( 0 ).getAttribute( 'autoplay' );
|
autoplay = this.element.getChild( 0 ).getAttribute( 'autoplay' );
|
||||||
poster = this.element.getChild( 0 ).getAttribute( 'poster' );
|
|
||||||
responsive = this.element.getAttribute( 'data-responsive' );
|
responsive = this.element.getAttribute( 'data-responsive' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,10 +56,6 @@ CKEDITOR.plugins.add( 'html5video', {
|
|||||||
this.setData( 'autoplay', 'yes' );
|
this.setData( 'autoplay', 'yes' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( poster ) {
|
|
||||||
this.setData('poster', poster);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( responsive ) {
|
if ( responsive ) {
|
||||||
this.setData( 'responsive', responsive );
|
this.setData( 'responsive', responsive );
|
||||||
}
|
}
|
||||||
@@ -82,7 +76,6 @@ CKEDITOR.plugins.add( 'html5video', {
|
|||||||
this.element.getChild( 0 ).setAttribute( 'src', this.data.src );
|
this.element.getChild( 0 ).setAttribute( 'src', this.data.src );
|
||||||
if (this.data.width) this.element.getChild( 0 ).setAttribute( 'width', this.data.width );
|
if (this.data.width) this.element.getChild( 0 ).setAttribute( 'width', this.data.width );
|
||||||
if (this.data.height) this.element.getChild( 0 ).setAttribute( 'height', this.data.height );
|
if (this.data.height) this.element.getChild( 0 ).setAttribute( 'height', this.data.height );
|
||||||
if (this.data.poster) this.element.getChild( 0 ).setAttribute( 'poster', this.data.poster );
|
|
||||||
|
|
||||||
if ( this.data.responsive ) {
|
if ( this.data.responsive ) {
|
||||||
this.element.setAttribute("data-responsive", this.data.responsive);
|
this.element.setAttribute("data-responsive", this.data.responsive);
|
||||||
|
|||||||
@@ -1,129 +1,93 @@
|
|||||||
/* login-tech.css */
|
html{height: 100%;}
|
||||||
|
body.signin {
|
||||||
/* 定义主色调变量 */
|
background: #18c8f6;
|
||||||
:root {
|
height: auto;
|
||||||
--primary-color: #1ab394;
|
background:url("../img/login-background.jpg") no-repeat center fixed;
|
||||||
--primary-glow: rgba(26, 179, 148, 0.5);
|
-webkit-background-size: cover;
|
||||||
--bg-dark: #0f1319;
|
-moz-background-size: cover;
|
||||||
--text-color: #e0e0e0;
|
-o-background-size: cover;
|
||||||
|
background-size: cover;
|
||||||
|
color: rgba(255,255,255,.95);
|
||||||
}
|
}
|
||||||
|
|
||||||
body.gray-bg {
|
.signinpanel {
|
||||||
background: var(--bg-dark);
|
width: 750px;
|
||||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
margin: 10% auto 0 auto;
|
||||||
color: var(--text-color);
|
|
||||||
overflow: hidden; /* 防止滚动条出现 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 动态背景 Canvas */
|
.signinpanel .logopanel {
|
||||||
#canvas-bg {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 登录框主体 - 毛玻璃特效 */
|
|
||||||
.middle-box {
|
|
||||||
background: rgba(255, 255, 255, 0.05);
|
|
||||||
backdrop-filter: blur(10px); /* 毛玻璃模糊 */
|
|
||||||
-webkit-backdrop-filter: blur(10px);
|
|
||||||
padding: 40px;
|
|
||||||
border-radius: 10px;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
||||||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
|
|
||||||
margin: 50px auto auto auto; /* 调整垂直位置 */
|
|
||||||
max-width: 400px;
|
|
||||||
width: 100%;
|
|
||||||
float: none;
|
float: none;
|
||||||
/* display: inline-block;*/
|
width: auto;
|
||||||
position: relative;
|
padding: 0;
|
||||||
z-index: 10;
|
background: none;
|
||||||
top: 50px
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 标题样式 */
|
.signinpanel .signin-info ul {
|
||||||
.logo-name {
|
list-style: none;
|
||||||
color: var(--primary-color);
|
padding: 0;
|
||||||
font-size: 60px;
|
margin: 20px 0;
|
||||||
font-weight: 800;
|
|
||||||
letter-spacing: 2px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
text-shadow: 0 0 10px var(--primary-glow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.middle-box h3 {
|
.signinpanel .form-control {
|
||||||
color: #fff;
|
display: block;
|
||||||
font-weight: 300;
|
margin-top: 15px;
|
||||||
margin-bottom: 30px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 输入框重写 - 科技感下划线风格 */
|
.signinpanel .uname {
|
||||||
.form-control {
|
background: #fff url(../img/user.png) no-repeat 95% center;color:#333;
|
||||||
background-color: transparent !important;
|
|
||||||
border: none;
|
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
|
||||||
border-radius: 0;
|
|
||||||
color: #fff !important;
|
|
||||||
box-shadow: none;
|
|
||||||
padding-left: 0;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
height: 40px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-control:focus {
|
.signinpanel .pword {
|
||||||
border-bottom: 1px solid var(--primary-color);
|
background: #fff url(../img/locked.png) no-repeat 95% center;color:#333;
|
||||||
box-shadow: 0 1px 0 0 var(--primary-glow);
|
|
||||||
color: #fff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 针对浏览器自动填充背景色的 Hack */
|
.signinpanel .btn {
|
||||||
input:-webkit-autofill,
|
margin-top: 15px;
|
||||||
input:-webkit-autofill:hover,
|
|
||||||
input:-webkit-autofill:focus,
|
|
||||||
input:-webkit-autofill:active {
|
|
||||||
-webkit-box-shadow: 0 0 0 30px #151a23 inset !important;
|
|
||||||
-webkit-text-fill-color: white !important;
|
|
||||||
transition: background-color 5000s ease-in-out 0s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-control::-webkit-input-placeholder {
|
.signinpanel form {
|
||||||
color: rgba(255,255,255,0.4);
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border: 1px solid rgba(255,255,255,.3);
|
||||||
|
-moz-box-shadow: 0 3px 0 rgba(12, 12, 12, 0.03);
|
||||||
|
-webkit-box-shadow: 0 3px 0 rgba(12, 12, 12, 0.03);
|
||||||
|
box-shadow: 0 3px 0 rgba(12, 12, 12, 0.03);
|
||||||
|
-moz-border-radius: 3px;
|
||||||
|
-webkit-border-radius: 3px;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-control:-moz-placeholder {
|
.signup-footer{border-top: solid 1px rgba(255,255,255,.3);margin:20px 0;padding-top: 15px;}
|
||||||
color: rgba(255,255,255,0.4);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 验证码输入框调整 */
|
@media screen and (max-width: 768px) {
|
||||||
.input-group-addon {
|
.signinpanel,
|
||||||
background: transparent;
|
.signuppanel {
|
||||||
border: none;
|
margin: 0 auto;
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
width: 420px!important;
|
||||||
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
.signinpanel form {
|
||||||
/* 按钮样式 - 霓虹光效 */
|
|
||||||
.btn-primary {
|
|
||||||
background-color: var(--primary-color);
|
|
||||||
border-color: var(--primary-color);
|
|
||||||
color: #fff;
|
|
||||||
font-weight: bold;
|
|
||||||
border-radius: 25px; /* 圆角按钮 */
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
box-shadow: 0 4px 15px var(--primary-glow);
|
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
.signup-footer {
|
||||||
.btn-primary:hover, .btn-primary:active, .btn-primary:focus {
|
margin-bottom: 10px;
|
||||||
background-color: #15947a !important;
|
}
|
||||||
border-color: #15947a !important;
|
.signuppanel .form-control {
|
||||||
box-shadow: 0 6px 20px rgba(26, 179, 148, 0.8);
|
margin-bottom: 10px;
|
||||||
transform: translateY(-2px);
|
}
|
||||||
|
.signup-footer .pull-left,
|
||||||
|
.signup-footer .pull-right {
|
||||||
|
float: none !important;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.signinpanel .signin-info ul {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 320px) {
|
||||||
|
.signinpanel,
|
||||||
|
.signuppanel {
|
||||||
|
margin:0 20px;
|
||||||
|
width:auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 底部文字 */
|
|
||||||
.text-muted {
|
|
||||||
color: rgba(255, 255, 255, 0.5) !important;
|
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
+824
-172
File diff suppressed because it is too large
Load Diff
+2
-2
File diff suppressed because one or more lines are too long
Vendored
-2
File diff suppressed because one or more lines are too long
Vendored
+4
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
-3
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.4 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
@@ -1,7 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<<<<<<< HEAD
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
=======
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,带前台演示。
|
|||||||
- WebTest 测试站点;暂时屏蔽
|
- WebTest 测试站点;暂时屏蔽
|
||||||
|
|
||||||
- data 目录是初始化sql ,目前是mysql,注意linux版本要还原comcms_for_linux.sql
|
- data 目录是初始化sql ,目前是mysql,注意linux版本要还原comcms_for_linux.sql
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
### 演示地址
|
### 演示地址
|
||||||
|
|
||||||
@@ -52,6 +53,80 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,带前台演示。
|
|||||||
|
|
||||||
账号密码都是admin
|
账号密码都是admin
|
||||||
```
|
```
|
||||||
|
=======
|
||||||
|
|
||||||
|
### Docker 快速部署
|
||||||
|
|
||||||
|
#### 一键启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 克隆项目
|
||||||
|
git clone https://github.com/hogenwang/comcms_core.git
|
||||||
|
cd comcms_core
|
||||||
|
|
||||||
|
# 启动所有服务(MySQL + Redis + Web)
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
docker logs -f comcms_web
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 访问地址
|
||||||
|
|
||||||
|
- **前台首页**: http://localhost:8080
|
||||||
|
- **后台管理**: http://localhost:8080/AdminCP
|
||||||
|
- **默认账号**: admin
|
||||||
|
- **默认密码**: admin
|
||||||
|
|
||||||
|
#### 自动初始化说明
|
||||||
|
|
||||||
|
Docker环境会在首次启动时**自动初始化数据库**:
|
||||||
|
|
||||||
|
1. MySQL容器启动时检测到数据库为空
|
||||||
|
2. 自动执行 `./data/comcms_for_linux.sql` 初始化脚本
|
||||||
|
3. 创建所有表结构和初始数据(包括默认管理员账号)
|
||||||
|
4. Web应用启动后即可直接使用
|
||||||
|
|
||||||
|
如需重新初始化数据库:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 停止并删除所有容器和数据卷
|
||||||
|
docker-compose down -v
|
||||||
|
|
||||||
|
# 重新启动(会自动初始化)
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 环境配置
|
||||||
|
|
||||||
|
所有配置通过环境变量管理,无需修改代码:
|
||||||
|
|
||||||
|
- **MySQL配置**: 在 `compose.yaml` 中修改 `MYSQL_*` 环境变量
|
||||||
|
- **Redis配置**: 在 `compose.yaml` 中修改 `REDIS_*` 环境变量
|
||||||
|
- **数据持久化**: 数据自动保存在Docker卷中,重启不丢失
|
||||||
|
|
||||||
|
### 本地开发
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用 run.sh 脚本启动(需要先配置本地MySQL和Redis)
|
||||||
|
./run.sh
|
||||||
|
|
||||||
|
# 访问地址
|
||||||
|
http://localhost:5000
|
||||||
|
```
|
||||||
|
|
||||||
|
### 演示地址
|
||||||
|
|
||||||
|
- **演示地址1**(Windows Server 2016 + IIS)
|
||||||
|
- 前台:http://demo.comcms.com
|
||||||
|
- 后台:http://demo.comcms.com/AdminCP
|
||||||
|
|
||||||
|
- **演示地址2**(CentOS + Nginx)
|
||||||
|
- 前台:http://demo.comcms.cn
|
||||||
|
- 后台:http://demo.comcms.cn/AdminCP
|
||||||
|
|
||||||
|
**账号密码都是 admin**
|
||||||
|
>>>>>>> df478d351626c40c987712d66d991f327a698ff5
|
||||||
|
|
||||||
|
|
||||||
### 技术交流群
|
### 技术交流群
|
||||||
@@ -60,7 +135,10 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,带前台演示。
|
|||||||
|
|
||||||
### 贡献者
|
### 贡献者
|
||||||
|
|
||||||
漫遊者(hogenwang)、笑笑(xxred)、一只萌新(HTR)
|
- 漫遊者(hogenwang)
|
||||||
|
- 笑笑(xxred)
|
||||||
|
- 一只萌新(HTR)
|
||||||
|
- 兼哲(github: ferocknew)
|
||||||
|
|
||||||
### 捐赠
|
### 捐赠
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
services:
|
||||||
|
# MySQL 数据库服务
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.4.7
|
||||||
|
container_name: comcms_mysql
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
|
||||||
|
MYSQL_DATABASE: ${MYSQL_DATABASE:-comcms}
|
||||||
|
MYSQL_USER: ${MYSQL_USER:-comcms}
|
||||||
|
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-comcms123}
|
||||||
|
volumes:
|
||||||
|
- mysql_data:/var/lib/mysql
|
||||||
|
- ./data:/docker-entrypoint-initdb.d:ro
|
||||||
|
networks:
|
||||||
|
- comcms_network
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 20s
|
||||||
|
retries: 10
|
||||||
|
start_period: 30s
|
||||||
|
|
||||||
|
# Redis 缓存服务
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
container_name: comcms_redis
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
networks:
|
||||||
|
- comcms_network
|
||||||
|
command: >
|
||||||
|
sh -c "
|
||||||
|
if [ -n \"${REDIS_PASSWORD:-}\" ]; then
|
||||||
|
redis-server --requirepass \"${REDIS_PASSWORD}\"
|
||||||
|
else
|
||||||
|
redis-server
|
||||||
|
fi
|
||||||
|
"
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "redis-cli", "ping" ]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
|
||||||
|
# COMCMS Web 服务
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: ./COMCMS.Web
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: comcms_web
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
environment:
|
||||||
|
ASPNETCORE_ENVIRONMENT: ${ASPNETCORE_ENVIRONMENT:-Production}
|
||||||
|
ConnectionStrings__dbconn__ConnectionString: "Server=mysql;Port=3306;Database=${MYSQL_DATABASE:-comcms};Uid=${MYSQL_USER:-comcms};Pwd=${MYSQL_PASSWORD:-comcms123};charset=utf8mb4;"
|
||||||
|
ConnectionStrings__dbconn__providerName: MySql.Data.MySqlClient
|
||||||
|
RedisCache__ConnectionString: "server=redis;password=${REDIS_PASSWORD:-};db=2;"
|
||||||
|
RedisCache__InstanceName: "COMCMS:"
|
||||||
|
RedisCache__DefaultDatabase: "2"
|
||||||
|
depends_on:
|
||||||
|
mysql:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
volumes:
|
||||||
|
- uploads_data:/app/wwwroot/userfiles
|
||||||
|
- logs_data:/app/logs
|
||||||
|
- dataprotection_keys:/home/app/.aspnet/DataProtection-Keys
|
||||||
|
networks:
|
||||||
|
- comcms_network
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "curl", "-f", "http://localhost:80/" ]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mysql_data:
|
||||||
|
driver: local
|
||||||
|
redis_data:
|
||||||
|
driver: local
|
||||||
|
uploads_data:
|
||||||
|
driver: local
|
||||||
|
logs_data:
|
||||||
|
driver: local
|
||||||
|
dataprotection_keys:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
networks:
|
||||||
|
comcms_network:
|
||||||
|
driver: bridge
|
||||||
-1247
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# 检查运行模式
|
||||||
|
MODE="${1:-dev}"
|
||||||
|
|
||||||
|
# 开发模式才加载 .env 文件
|
||||||
|
if [ "$MODE" != "prod" ]; then
|
||||||
|
if [ -f .env ]; then
|
||||||
|
echo "正在加载 .env 配置..."
|
||||||
|
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
|
||||||
|
else
|
||||||
|
echo "提示: .env 文件不存在,使用默认配置"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 设置数据库连接字符串(使用环境变量,注意:冒号用双下划线替代)
|
||||||
|
export connectionStrings__dbconn__connectionString="Server=${MYSQL_HOST:-localhost};Port=${MYSQL_PORT:-3306};Database=${MYSQL_DATABASE:-comcms};Uid=${MYSQL_USER:-root};Pwd=${MYSQL_PASSWORD:-root};charset=utf8mb4;AllowUserVariables=True"
|
||||||
|
export connectionStrings__dbconn__providerName="MySql.Data.MySqlClient"
|
||||||
|
|
||||||
|
# 设置 Redis 连接字符串
|
||||||
|
export RedisCache__ConnectionString="server=${REDIS_HOST:-127.0.0.1};password=${REDIS_PASSWORD};db=${REDIS_DB:-2}"
|
||||||
|
export RedisCache__InstanceName="${REDIS_INSTANCE_NAME:-COMCMS:}"
|
||||||
|
export RedisCache__DefaultDatabase="${REDIS_DB:-2}"
|
||||||
|
|
||||||
|
# 设置其他配置
|
||||||
|
export SystemSetting__JwtSecret="${JWT_SECRET:-comcms0b311362786dabe03af7b484ed032b91698a4eb9377687bd031d837082}"
|
||||||
|
export SystemSetting__SignSalt="${SIGN_SALT:-comcms}"
|
||||||
|
|
||||||
|
# 设置环境
|
||||||
|
export ASPNETCORE_ENVIRONMENT="${ASPNETCORE_ENVIRONMENT:-Development}"
|
||||||
|
|
||||||
|
# 显示配置信息(隐藏密码)
|
||||||
|
echo "================================"
|
||||||
|
echo "COMCMS 启动配置 [模式: $MODE]"
|
||||||
|
echo " MySQL: ${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}"
|
||||||
|
echo " Redis: ${REDIS_HOST}"
|
||||||
|
echo " 环境: ${ASPNETCORE_ENVIRONMENT}"
|
||||||
|
echo "================================"
|
||||||
|
|
||||||
|
# 根据模式启动
|
||||||
|
if [ "$MODE" = "prod" ]; then
|
||||||
|
# 生产模式:使用已编译的dll(Docker容器中已在正确目录)
|
||||||
|
echo "生产模式启动..."
|
||||||
|
if [ -f "COMCMS.Web.dll" ]; then
|
||||||
|
exec dotnet COMCMS.Web.dll
|
||||||
|
else
|
||||||
|
cd COMCMS.Web
|
||||||
|
exec dotnet COMCMS.Web.dll
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# 开发模式:使用dotnet run
|
||||||
|
echo "开发模式启动..."
|
||||||
|
cd COMCMS.Web
|
||||||
|
dotnet run --urls "http://localhost:${PORT:-5000}"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user