ow
This commit is contained in:
1 parent
9b01c4a57a
commit
6417562c4f
37 files changed
+2767
-202
No files matched your search
@@ -1698,6 +1698,10 @@ namespace CloudBuilder.Master.Service
|
||||
entity.OwerId = service.UserId;
|
||||
entity.IsLinkIndc = YesNoPolicy.NO;
|
||||
|
||||
// 网盘额度闸门:按当前用户类型限额,已用(KB)+本次(KB) 超限直接拒。
|
||||
// 放任何 InsertNow 之前,抛异常时主表/上传表/目录关系均未落库,DB 保持一致(仅物理文件可能成为孤儿,属上传前置阶段)。
|
||||
EnsureQuotaAllowed(dmsFile.FileSize);
|
||||
|
||||
repository.InsertNow(entity);
|
||||
|
||||
IRepository<DmsFileUploadEntity> repositoryUpload = repository.GetRepository<IRepository<DmsFileUploadEntity>>();
|
||||
@@ -1715,6 +1719,86 @@ namespace CloudBuilder.Master.Service
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前登录用户的网盘用量汇总:类型/头像取自 security_user,已用取自 dms_file_usage_view(ower_id=本人 且非目录),
|
||||
/// 额度按 user_type 从 appsettings:NetDiskQuota 解析。供 dashboard 两张卡片一次拉取。
|
||||
/// </summary>
|
||||
[PermissionOperate(name: MasterPermissionPolicy.DmsFile, operate: Operate.Find)]
|
||||
public StorageUsageData GetMyStorageUsage()
|
||||
{
|
||||
IRepository<SecurityUserEntity> repositoryUser = repository.GetRepository<IRepository<SecurityUserEntity>>();
|
||||
SecurityUserEntity user = repositoryUser.DetachedEntities.Where(x => x.UserName == service.UserId).FirstOrDefault();
|
||||
string userType = user?.UserType;
|
||||
if (string.IsNullOrWhiteSpace(userType)) userType = SecurityUserTypePolicy.UNAUTHENTICATED_USERS;
|
||||
|
||||
long usedKB = GetUsedKB(service.UserId);
|
||||
long quotaKB = ServiceSettingsPolicy.GetNetDiskQuotaKB(service, userType);
|
||||
int percent = quotaKB > 0 ? (int)(usedKB * 100 / quotaKB) : 0;
|
||||
|
||||
return new StorageUsageData
|
||||
{
|
||||
UserType = userType,
|
||||
AvatarUrl = FileTypePolicy.PackAvatarUrl(service, UploadFolderPolicy.USER_AVATAR, user?.UserIconImgPath) ?? "",
|
||||
UsedKB = usedKB,
|
||||
QuotaKB = quotaKB,
|
||||
Percent = percent
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传并保存当前登录用户头像:复用与成员头像同一套 PackUploadFile 落盘(目录名统一走 UploadFolderPolicy.USER_AVATAR),
|
||||
/// 末片物理名回写 security_user.user_icon_img_path(与 family_person.avatar_filename 同口径存物理名),返回可访问 URL。
|
||||
/// </summary>
|
||||
[PermissionOperate(name: MasterPermissionPolicy.DmsFile, operate: Operate.Insert)]
|
||||
[UnitOfWork]
|
||||
public string UploadUserAvatar()
|
||||
{
|
||||
var files = httpContextAccessor.HttpContext.Request.Form.Files;
|
||||
if (files == null || files.Count == 0) return "";
|
||||
|
||||
IFormFile file = files[0];
|
||||
if (file == null || file.Length <= 0) return "";
|
||||
|
||||
// 落盘:单片三段式名(uni-时间戳-1-1.ext)会在 PackUploadFile 内合并到备份目录
|
||||
PackUploadFile(file, UploadFolderPolicy.USER_AVATAR);
|
||||
|
||||
string filename = file.FileName;
|
||||
|
||||
IRepository<SecurityUserEntity> repositoryUser = repository.GetRepository<IRepository<SecurityUserEntity>>();
|
||||
SecurityUserEntity user = repositoryUser.DetachedEntities.Where(x => x.UserName == service.UserId).FirstOrDefault();
|
||||
if (user != null)
|
||||
{
|
||||
user.UserIconImgPath = filename;
|
||||
repositoryUser.UpdateNow(user);
|
||||
}
|
||||
|
||||
return FileTypePolicy.PackAvatarUrl(service, UploadFolderPolicy.USER_AVATAR, filename) ?? "";
|
||||
}
|
||||
|
||||
/// <summary>查本人已用容量(KB)。按 dms_file_usage_view 视图实体标准 LINQ 链路取数,
|
||||
/// 无行(从未上传)记 0;ower_id 源自 JWT 登录态非外部入参。</summary>
|
||||
private long GetUsedKB(string owerId)
|
||||
{
|
||||
IRepository<DmsFileUsageViewEntity> repositoryView = repository.GetRepository<IRepository<DmsFileUsageViewEntity>>();
|
||||
return repositoryView.DetachedEntities.Where(x => x.OwerId == owerId).Select(x => x.UsedKb).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>上传额度校验:额度未配(≤0)视为不限;已用+本次超额度则抛业务异常拒上传。</summary>
|
||||
private void EnsureQuotaAllowed(int incomingKB)
|
||||
{
|
||||
IRepository<SecurityUserEntity> repositoryUser = repository.GetRepository<IRepository<SecurityUserEntity>>();
|
||||
string userType = repositoryUser.DetachedEntities.Where(x => x.UserName == service.UserId).FirstOrDefault()?.UserType;
|
||||
long quotaKB = ServiceSettingsPolicy.GetNetDiskQuotaKB(service, userType);
|
||||
if (quotaKB <= 0) return;
|
||||
long usedKB = GetUsedKB(service.UserId);
|
||||
if (usedKB + incomingKB > quotaKB)
|
||||
{
|
||||
long limitGB = quotaKB / (1024 * 1024);
|
||||
long usedGB = usedKB / (1024 * 1024);
|
||||
throw new ValidatedException($"网盘容量不足(上限约 {limitGB} GB,已用约 {usedGB} GB),请清理或升级会员后再上传。");
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.DmsFile, operate: Operate.Find)]
|
||||
public dynamic DownloadFile(long fileId)
|
||||
{
|
||||
|
||||
@@ -18,9 +18,6 @@ namespace CloudBuilder.Master.Service
|
||||
{
|
||||
public class FamilyPersonService : IFamilyPersonService
|
||||
{
|
||||
/// <summary>头像上传目录,与前端 FileUpload 的 file-path 保持一致</summary>
|
||||
private const string AVATAR_FOLDER_NAME = "FamilyPersonAvatar";
|
||||
|
||||
private readonly IApplicationService service;
|
||||
|
||||
private IRepository<FamilyPersonEntity> repository;
|
||||
@@ -51,7 +48,7 @@ namespace CloudBuilder.Master.Service
|
||||
|
||||
data.FamilyPerson.IsCanAmend = new FamilyTreePermissionHelper(service).HasPermission(data.FamilyPerson.TreeId, data.FamilyPerson.PersonId);
|
||||
|
||||
data.FamilyPerson.AvatarUrl = FileTypePolicy.PackAvatarUrl(service, AVATAR_FOLDER_NAME, data.FamilyPerson.AvatarFilename);
|
||||
data.FamilyPerson.AvatarUrl = FileTypePolicy.PackAvatarUrl(service, UploadFolderPolicy.FAMILY_PERSON_AVATAR, data.FamilyPerson.AvatarFilename);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
namespace CloudBuilder.Master.Service
|
||||
{
|
||||
public class FamilyTreeService : IFamilyTreeService
|
||||
{
|
||||
/// <summary>头像上传目录,与前端 FileUpload 的 file-path 保持一致</summary>
|
||||
private const string AVATAR_FOLDER_NAME = "FamilyPersonAvatar";
|
||||
|
||||
private readonly IApplicationService service;
|
||||
|
||||
private IRepository<FamilyTreeEntity> repository;
|
||||
@@ -36,7 +35,7 @@ namespace CloudBuilder.Master.Service
|
||||
private void FillAvatarUrl(FamilyPersonDisplayData person)
|
||||
{
|
||||
if (person == null) return;
|
||||
person.AvatarUrl = FileTypePolicy.PackAvatarUrl(service, AVATAR_FOLDER_NAME, person.AvatarFilename);
|
||||
person.AvatarUrl = FileTypePolicy.PackAvatarUrl(service, UploadFolderPolicy.FAMILY_PERSON_AVATAR, person.AvatarFilename);
|
||||
}
|
||||
|
||||
/// <summary>批量填充头像访问地址</summary>
|
||||
@@ -151,17 +150,30 @@ namespace CloudBuilder.Master.Service
|
||||
{
|
||||
currentPerson = d.AncestorPersonId;
|
||||
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == currentPerson).FirstOrDefault()!);
|
||||
FamilyPersonEntity ancestor0 = repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == currentPerson).FirstOrDefault();
|
||||
// 始祖行缺失是数据破损,给可读的业务错误而不是 NullReference 服务异常
|
||||
if (ancestor0 == null) throw new ValidatedException("该族谱未设置始祖或始祖档案已丢失.");
|
||||
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(ancestor0);
|
||||
|
||||
data.FamilyTree.AncestorPersonGenealogyName = data.CurrentPerson.FamilyPerson.GenealogyName;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == d.AncestorPersonId).FirstOrDefault()!);
|
||||
FamilyPersonEntity ancestor = repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == d.AncestorPersonId).FirstOrDefault();
|
||||
if (ancestor != null)
|
||||
{
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(ancestor);
|
||||
|
||||
data.FamilyTree.AncestorPersonGenealogyName = data.CurrentPerson.FamilyPerson.GenealogyName;
|
||||
data.FamilyTree.AncestorPersonGenealogyName = data.CurrentPerson.FamilyPerson.GenealogyName;
|
||||
}
|
||||
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == personId).FirstOrDefault()!);
|
||||
// 旧 personId 失效(如整谱替换/备份还原后全员重编号)回落始祖,不再抛「Source entity is null」服务异常
|
||||
FamilyPersonEntity current = repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == personId).FirstOrDefault() ?? ancestor;
|
||||
if (current == null) throw new ValidatedException("该族谱中没有可用的族员.");
|
||||
currentPerson = current.PersonId;
|
||||
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(current);
|
||||
}
|
||||
|
||||
FillAvatarUrl(data.CurrentPerson.FamilyPerson);
|
||||
@@ -362,6 +374,78 @@ namespace CloudBuilder.Master.Service
|
||||
repositoryPermission.InsertNow(fresh);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 小系替换后的权限行迁移(用户拍板:按新旧编号关联保留绑定权限):
|
||||
/// 被删后代/入配配偶若能经 idMap(文件旧号→重编新号)关联上则换绑到新号(同谱 round-trip 场景);
|
||||
/// 关联不上(跨谱嫁接/文件已删掉的人)的悬挂行顺手删除。
|
||||
/// 管理员行(ManagerIndc=YES)与 PersonId 空行(申请/未绑)一律不动;返回 moved/dropped 统计进审计。
|
||||
/// </summary>
|
||||
private string MigrateSubTreePermissions(string treeId, HashSet<string> deletedIds, Dictionary<string, string> idMap)
|
||||
{
|
||||
IRepository<FamilyTreePermissionEntity> repositoryPermission = repository.GetRepository<IRepository<FamilyTreePermissionEntity>>();
|
||||
FamilyTreePermissionEntity[] rows = repositoryPermission.DetachedEntities.Where(x => x.TreeId == treeId).ToArray();
|
||||
int moved = 0;
|
||||
int dropped = 0;
|
||||
foreach (FamilyTreePermissionEntity row in rows)
|
||||
{
|
||||
if (row.ManagerIndc == YesNoPolicy.YES || string.IsNullOrEmpty(row.PersonId) || !deletedIds.Contains(row.PersonId)) continue;
|
||||
string newId = idMap.ContainsKey(row.PersonId) ? idMap[row.PersonId] : null;
|
||||
// 新号已被同名其它行占用(理论上不会)则只删旧行,防复合主键冲突
|
||||
if (newId != null && rows.Any(x => x.PersonId == newId && x.UserName == row.UserName)) newId = null;
|
||||
if (newId == null)
|
||||
{
|
||||
repositoryPermission.DeleteNow(row);
|
||||
dropped++;
|
||||
continue;
|
||||
}
|
||||
RebindFamilyTreePermission(row, newId);
|
||||
moved++;
|
||||
}
|
||||
return $"moved={moved};dropped={dropped}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 跨谱整谱替换后的权限行清理:全员重编号后本谱引用已删旧号的成员权限行必然悬挂(垃圾行),顺手删除;
|
||||
/// 管理员行(ManagerIndc=YES,建谱时 PersonId 指向始祖,IsManager 判定不看 PersonId)与 PersonId 空行保留。
|
||||
/// 同谱替换编号不变权限行天然无损,不需要走这里。返回删除条数进审计。
|
||||
/// </summary>
|
||||
private int CleanDanglingPermissions(string treeId, HashSet<string> aliveIds)
|
||||
{
|
||||
IRepository<FamilyTreePermissionEntity> repositoryPermission = repository.GetRepository<IRepository<FamilyTreePermissionEntity>>();
|
||||
List<string> alive = aliveIds.ToList();
|
||||
FamilyTreePermissionEntity[] dangling = repositoryPermission.DetachedEntities
|
||||
.Where(x => x.TreeId == treeId && x.ManagerIndc != YesNoPolicy.YES && x.PersonId != "" && !alive.Contains(x.PersonId)).ToArray();
|
||||
if (dangling.Length > 0) repositoryPermission.DeleteNow(dangling);
|
||||
return dangling.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 备份还原的权限回放(绝对闭环):把本谱权限行整体替换为备份快照,PersonId 经 idMap 重映射
|
||||
/// (还原恒同谱→编号不变→权限行原样落回);管理员行随快照一并恢复,还原人自身也在快照内故不会自锁。
|
||||
/// 仅备份(含权限快照)触发;.fm 导入无权限快照不会走到这里。返回恢复条数进审计。
|
||||
/// </summary>
|
||||
private int RestorePermissions(string treeId, FamilyTreePermissionEntity[] snapshot, Dictionary<string, string> idMap)
|
||||
{
|
||||
IRepository<FamilyTreePermissionEntity> repositoryPermission = repository.GetRepository<IRepository<FamilyTreePermissionEntity>>();
|
||||
FamilyTreePermissionEntity[] current = repositoryPermission.DetachedEntities.Where(x => x.TreeId == treeId).ToArray();
|
||||
if (current.Length > 0) repositoryPermission.DeleteNow(current);
|
||||
int restored = 0;
|
||||
foreach (FamilyTreePermissionEntity row in snapshot)
|
||||
{
|
||||
FamilyTreePermissionEntity fresh = new FamilyTreePermissionEntity
|
||||
{
|
||||
TreeId = treeId,
|
||||
UserName = row.UserName,
|
||||
PersonId = string.IsNullOrEmpty(row.PersonId) || !idMap.ContainsKey(row.PersonId) ? row.PersonId : idMap[row.PersonId],
|
||||
ManagerIndc = row.ManagerIndc,
|
||||
ValidIndc = row.ValidIndc,
|
||||
};
|
||||
repositoryPermission.InsertNow(fresh);
|
||||
restored++;
|
||||
}
|
||||
return restored;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户中文姓名(security_user.user_local_name);登录账号只是标识,不参与同名比较
|
||||
/// </summary>
|
||||
@@ -718,5 +802,599 @@ namespace CloudBuilder.Master.Service
|
||||
Delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
//=================== 族谱全系/小系 .fm 导入导出(D1-D8 决策) ===================
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public string GetExchangeFactor()
|
||||
{
|
||||
// D2:前端用「用户密码⊕系统因子」PBKDF2 派生 AES 密钥,因子由后端下发,不进前端包体
|
||||
return FamilyTreeExchangePolicy.EXCHANGE_FACTOR;
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public FamilyTreeExchangeData ExportFamilyTree(string treeId, string scope, string anchorPersonId)
|
||||
{
|
||||
FamilyTreeEntity tree = repository.DetachedEntities.Where(x => x.TreeId == treeId).FirstOrDefault();
|
||||
if (tree == null) throw new ValidatedException("族谱不存在.");
|
||||
|
||||
bool isSub = scope == FamilyTreeExchangeScope.SUB;
|
||||
FamilyTreePermissionHelper helper = new FamilyTreePermissionHelper(service);
|
||||
bool isManager = helper.IsManager(treeId);
|
||||
// D8 闸门:全系导出仅管理员;小系导出管理员任意锚点、成员仅限自己可编辑家支的锚点
|
||||
if (!isManager)
|
||||
{
|
||||
if (!helper.IsMember(treeId)) throw new ValidatedException("您没有导出权限.");
|
||||
if (!isSub) throw new ValidatedException("全系导出需要族谱管理员权限.");
|
||||
if (!helper.GetAmendablePersonIds(treeId).Contains(anchorPersonId)) throw new ValidatedException("只能导出以自己为锚点的家支.");
|
||||
}
|
||||
|
||||
IRepository<FamilyPersonEntity> repositoryPerson = repository.GetRepository<IRepository<FamilyPersonEntity>>();
|
||||
IRepository<FamilyTreeSpouseMapEntity> repositorySpouse = repository.GetRepository<IRepository<FamilyTreeSpouseMapEntity>>();
|
||||
IRepository<FamilyTreeChildrenMapEntity> repositoryChild = repository.GetRepository<IRepository<FamilyTreeChildrenMapEntity>>();
|
||||
|
||||
FamilyTreeSpouseMapEntity[] spouseMaps = repositorySpouse.DetachedEntities.Where(x => x.TreeId == treeId).OrderBy(x => x.Orderby).ToArray();
|
||||
FamilyTreeChildrenMapEntity[] childrenMaps = repositoryChild.DetachedEntities.Where(x => x.TreeId == treeId).OrderBy(x => x.Orderby).ToArray();
|
||||
FamilyPersonEntity[] persons = repositoryPerson.DetachedEntities.Where(x => x.TreeId == treeId).ToArray();
|
||||
|
||||
if (isSub)
|
||||
{
|
||||
// 小系子集口径 = 权限 helper 同源家支展开(后代闭包 + 配偶 + 上溯两代及其配偶):
|
||||
// 管理员拿传入锚点展开;成员闸门已验过锚点,直接用自己可编集合
|
||||
List<string> ids;
|
||||
if (isManager)
|
||||
{
|
||||
ids = new List<string>();
|
||||
helper.PackPersonIdByChildrenMaps(childrenMaps, spouseMaps, anchorPersonId, ids);
|
||||
}
|
||||
else
|
||||
{
|
||||
ids = helper.GetAmendablePersonIds(treeId);
|
||||
}
|
||||
persons = persons.Where(x => ids.Contains(x.PersonId)).ToArray();
|
||||
spouseMaps = spouseMaps.Where(x => ids.Contains(x.PersonId) && ids.Contains(x.SpouseId)).ToArray();
|
||||
childrenMaps = childrenMaps.Where(x => ids.Contains(x.PersonId) && ids.Contains(x.ChildrenId)).ToArray();
|
||||
}
|
||||
|
||||
string exportFileName = FamilyTreeExchangePolicy.BuildFileName(isSub ? FamilyTreeExchangeScope.SUB : FamilyTreeExchangeScope.ALL, treeId, anchorPersonId);
|
||||
WriteExchangeLog("OUT", treeId, isSub ? FamilyTreeExchangeScope.SUB : FamilyTreeExchangeScope.ALL, anchorPersonId, exportFileName, persons.Length, "OK", "");
|
||||
|
||||
return new FamilyTreeExchangeData
|
||||
{
|
||||
Scope = isSub ? FamilyTreeExchangeScope.SUB : FamilyTreeExchangeScope.ALL,
|
||||
FamilyTree = tree,
|
||||
Persons = persons,
|
||||
SpouseMaps = spouseMaps,
|
||||
ChildrenMaps = childrenMaps,
|
||||
// 二期:小系文件把锚点写进 payload,导入侧据此验明同一人(一期只体在文件名里,旧文件读进来为空串)
|
||||
AnchorPersonId = isSub ? anchorPersonId : "",
|
||||
ExportedBy = service.UserId,
|
||||
ExportedAt = DateTime.Now,
|
||||
};
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public string SaveExchangeFile(string fileName, string contentBase64)
|
||||
{
|
||||
if (!FamilyTreeExchangePolicy.IsValidFileName(fileName)) throw new ValidatedException("文件名不合法(须为 A谱号_时间.fm 或 P谱号-人名号_时间.fm).");
|
||||
FamilyTreePermissionHelper helper = new FamilyTreePermissionHelper(service);
|
||||
// 管理员也有生效权限行,IsMember 一并覆盖
|
||||
if (!helper.IsMember(FamilyTreeExchangePolicy.ParseFileName(fileName).Item1)) throw new ValidatedException("您不是该族谱成员.");
|
||||
|
||||
byte[] bytes;
|
||||
try { bytes = Convert.FromBase64String(contentBase64 ?? ""); }
|
||||
catch { throw new ValidatedException("文件内容不是合法的 base64."); }
|
||||
if (bytes.Length == 0 || bytes.Length > 50 * 1024 * 1024) throw new ValidatedException("文件大小异常(限 1B~50MB).");
|
||||
|
||||
string dir = FamilyTreeExchangePolicy.GetExchangeDirectory(service);
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllBytes(Path.Combine(dir, fileName), bytes);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public FamilyTreeExchangeFileInfo[] ListExchangeFiles(string treeId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(treeId)) throw new ValidatedException("请先选择族谱.");
|
||||
if (!new FamilyTreePermissionHelper(service).IsMember(treeId)) throw new ValidatedException("您不是该族谱成员.");
|
||||
|
||||
string dir = FamilyTreeExchangePolicy.GetExchangeDirectory(service);
|
||||
if (!Directory.Exists(dir)) return [];
|
||||
|
||||
List<FamilyTreeExchangeFileInfo> files = new List<FamilyTreeExchangeFileInfo>();
|
||||
foreach (string path in Directory.GetFiles(dir, "*" + FamilyTreeExchangePolicy.FILE_EXTENSION))
|
||||
{
|
||||
string name = Path.GetFileName(path);
|
||||
var parsed = FamilyTreeExchangePolicy.ParseFileName(name);
|
||||
// 只列本谱的文件(非法文件名一律跳过)
|
||||
if (parsed == null || parsed.Item1 != treeId) continue;
|
||||
FileInfo info = new FileInfo(path);
|
||||
files.Add(new FamilyTreeExchangeFileInfo
|
||||
{
|
||||
FileName = name,
|
||||
Size = info.Length,
|
||||
LastModified = info.LastWriteTime,
|
||||
Scope = parsed.Item3,
|
||||
TreeId = parsed.Item1,
|
||||
AnchorPersonId = parsed.Item2,
|
||||
});
|
||||
}
|
||||
// 导入以最新为准:时间降序,前端取第一条即可
|
||||
return files.OrderByDescending(x => x.LastModified).ToArray();
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public string ReadExchangeFile(string fileName)
|
||||
{
|
||||
if (!FamilyTreeExchangePolicy.IsValidFileName(fileName)) throw new ValidatedException("文件名不合法.");
|
||||
if (!new FamilyTreePermissionHelper(service).IsMember(FamilyTreeExchangePolicy.ParseFileName(fileName).Item1)) throw new ValidatedException("您不是该族谱成员.");
|
||||
|
||||
string path = Path.Combine(FamilyTreeExchangePolicy.GetExchangeDirectory(service), fileName);
|
||||
if (!File.Exists(path)) throw new ValidatedException("文件不存在或已被清理.");
|
||||
return Convert.ToBase64String(File.ReadAllBytes(path));
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Update)]
|
||||
[UnitOfWork]
|
||||
public int ImportFamilyTree(string targetTreeId, FamilyTreeExchangeData data)
|
||||
{
|
||||
FamilyTreeEntity target = repository.DetachedEntities.Where(x => x.TreeId == targetTreeId).FirstOrDefault();
|
||||
if (target == null) throw new ValidatedException("目标族谱不存在.");
|
||||
// D4:整谱替换是谱级破坏性操作,仅目标谱管理员;失败由 ValidatedException 抛回,事务整体回滚
|
||||
if (!new FamilyTreePermissionHelper(service).IsManager(targetTreeId)) throw new ValidatedException("只有族谱管理员可以整谱替换导入.");
|
||||
if (data == null || data.Persons == null || data.Persons.Length == 0) throw new ValidatedException("导入数据为空.");
|
||||
// 一期只开放全系文件替换;小系 merge 未开(P 文件导进谱会把别人家支的人叠进来,关系锚点不明)
|
||||
if (data.Scope != FamilyTreeExchangeScope.ALL) throw new ValidatedException("目前仅支持全系(ALL)文件导入,小系合并暂未开放.");
|
||||
// D3:允许跨谱导入(payload 自带谱信息,主键以目标谱为准),无谱信息的是非法包
|
||||
if (data.FamilyTree == null) throw new ValidatedException("导入数据缺少谱信息.");
|
||||
return ReplaceTreeCore(target, data, "IN");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 替换前整谱 JSON 备份(回滚点):明文存交换目录 Backup 子目录,文件名进审计 message;
|
||||
/// ListExchangeFiles 只看 *.fm,备份不会被列成可导入文件。
|
||||
/// </summary>
|
||||
private string BackupTree(FamilyTreeEntity target, FamilyPersonEntity[] oldPersons, FamilyTreeSpouseMapEntity[] oldSpouses, FamilyTreeChildrenMapEntity[] oldChildren)
|
||||
{
|
||||
string backupName = FamilyTreeExchangePolicy.BuildBackupFileName(target.TreeId);
|
||||
string backupDir = FamilyTreeExchangePolicy.GetBackupDirectory(service);
|
||||
Directory.CreateDirectory(backupDir);
|
||||
// 权限行一并入快照(还原时随谱回滚,绝对闭环);整份密文落盘(含账号名隐私)
|
||||
IRepository<FamilyTreePermissionEntity> repositoryPermission = repository.GetRepository<IRepository<FamilyTreePermissionEntity>>();
|
||||
FamilyTreePermissionEntity[] perms = repositoryPermission.DetachedEntities.Where(x => x.TreeId == target.TreeId).ToArray();
|
||||
string plainJson = System.Text.Json.JsonSerializer.Serialize(new FamilyTreeExchangeData
|
||||
{
|
||||
Scope = FamilyTreeExchangeScope.ALL,
|
||||
FamilyTree = target,
|
||||
Persons = oldPersons,
|
||||
SpouseMaps = oldSpouses,
|
||||
ChildrenMaps = oldChildren,
|
||||
Permissions = perms,
|
||||
ExportedBy = service.UserId,
|
||||
});
|
||||
File.WriteAllText(Path.Combine(backupDir, backupName), FamilyTreeExchangePolicy.EncryptBackup(plainJson));
|
||||
return backupName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 整谱替换本体(ImportFamilyTree 与 RestoreBackup 共用,调用方已开事务):
|
||||
/// 先备份现谱→关系先行、人后删→插入→关系双端 remap→谱信息行更新→审计。
|
||||
/// 同谱(文件谱号==目标谱,备份还原/服务器文件导入恒同谱):编号与绑定原样保留,库与文件 100% 一致,权限行不悬挂;
|
||||
/// 跨谱嫁接:全员重编号+清绑定(防主键冲突与绑定劫持)。入库前先过完整性闸,坏文件直接拒绝。
|
||||
/// 审计动码区分来源:IN=外部文件导入 / RESTORE=备份回滚回放。
|
||||
/// </summary>
|
||||
private int ReplaceTreeCore(FamilyTreeEntity target, FamilyTreeExchangeData data, string action)
|
||||
{
|
||||
string targetTreeId = target.TreeId;
|
||||
// 同谱判定:文件谱号与目标谱一致(还原走 R6 闸恒同谱;跨谱全系只能来自本地上传)
|
||||
bool sameTree = string.Equals(data.FamilyTree?.TreeId ?? "", targetTreeId, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// 0) 完整性闸:整谱数据必须内部闭合(人员编号非空不重复、关系行两端都在文件内),
|
||||
// 否则拒绝——宁可不导也不允许静默丢行,保证落库与文件 100% 相同
|
||||
HashSet<string> fileIdSet = new HashSet<string>();
|
||||
foreach (FamilyPersonEntity p in data.Persons)
|
||||
if (string.IsNullOrEmpty(p.PersonId) || !fileIdSet.Add(p.PersonId))
|
||||
throw new ValidatedException("导入/还原失败:文件内人员编号为空或重复,数据不完整.");
|
||||
foreach (FamilyTreeSpouseMapEntity m in data.SpouseMaps ?? [])
|
||||
if (!fileIdSet.Contains(m.PersonId) || !fileIdSet.Contains(m.SpouseId))
|
||||
throw new ValidatedException("导入/还原失败:配偶关系引用了文件外的人员,数据不完整.");
|
||||
foreach (FamilyTreeChildrenMapEntity m in data.ChildrenMaps ?? [])
|
||||
if (!fileIdSet.Contains(m.PersonId) || !fileIdSet.Contains(m.ChildrenId))
|
||||
throw new ValidatedException("导入/还原失败:父子关系引用了文件外的人员,数据不完整.");
|
||||
|
||||
IRepository<FamilyPersonEntity> repositoryPerson = repository.GetRepository<IRepository<FamilyPersonEntity>>();
|
||||
IRepository<FamilyTreeSpouseMapEntity> repositorySpouse = repository.GetRepository<IRepository<FamilyTreeSpouseMapEntity>>();
|
||||
IRepository<FamilyTreeChildrenMapEntity> repositoryChild = repository.GetRepository<IRepository<FamilyTreeChildrenMapEntity>>();
|
||||
|
||||
// 1) 替换前自动备份(回滚点)
|
||||
FamilyPersonEntity[] oldPersons = repositoryPerson.DetachedEntities.Where(x => x.TreeId == targetTreeId).ToArray();
|
||||
FamilyTreeSpouseMapEntity[] oldSpouses = repositorySpouse.DetachedEntities.Where(x => x.TreeId == targetTreeId).ToArray();
|
||||
FamilyTreeChildrenMapEntity[] oldChildren = repositoryChild.DetachedEntities.Where(x => x.TreeId == targetTreeId).ToArray();
|
||||
string backupName = BackupTree(target, oldPersons, oldSpouses, oldChildren);
|
||||
|
||||
// 2) 清空当前谱:关系先行、人后删(事务内任一环节失败全部回滚,备份文件已落盘不受影响)
|
||||
if (oldSpouses.Length > 0) repositorySpouse.DeleteNow(oldSpouses);
|
||||
if (oldChildren.Length > 0) repositoryChild.DeleteNow(oldChildren);
|
||||
foreach (FamilyPersonEntity old in oldPersons) repositoryPerson.DeleteNow(old);
|
||||
|
||||
// 同谱回放需保留文件里的 Created 印章,而框架 SaveChanges 会对 Added 强制盖 CreatedBy/CreatedDatetime,
|
||||
// 故插入段临时关闭审计印章(仿 LocaleService 先例;跨谱不开——照旧由框架盖当次操作人/时间);
|
||||
// 下方手工赋值不受影响(Updated* 均为代码显式设置),末尾 finally 复位防残留
|
||||
MasterDbContext dbCtx = repository.GetDbContext() as MasterDbContext;
|
||||
Dictionary<string, string> idMap = new Dictionary<string, string>();
|
||||
try
|
||||
{
|
||||
if (sameTree && dbCtx != null) dbCtx.SkipAudit = true;
|
||||
|
||||
// 3) 编号策略:同谱保留原编号与绑定(权限行/锚点继续有效,数据 100% 回放);
|
||||
// 跨谱一律走号段生成器重发 PersonId + 清绑定(防冲突防劫持,进谱后重走审批绑定)
|
||||
ISecurityGeneratorNumberService generator = service.ServiceProvider.GetService<ISecurityGeneratorNumberService>()!;
|
||||
DateTime now = DateTime.Now;
|
||||
foreach (FamilyPersonEntity p in data.Persons)
|
||||
{
|
||||
idMap[p.PersonId] = sameTree ? p.PersonId : generator.GetNo(MasterPrefixPolicy.FAMILY_PERSON, MasterPrefixPolicy.FAMILY_PERSON_PERSON_ID, MasterPrefixPolicy.FAMILY_PERSON_PREFIX, YesNoPolicy.NO, MasterPrefixPolicy.FAMILY_PERSON_FORMAT);
|
||||
}
|
||||
foreach (FamilyPersonEntity p in data.Persons)
|
||||
{
|
||||
FamilyPersonEntity fresh = p.Clone();
|
||||
fresh.PersonId = idMap[p.PersonId];
|
||||
fresh.TreeId = targetTreeId;
|
||||
fresh.FatherId = string.IsNullOrEmpty(p.FatherId) ? null : (idMap.ContainsKey(p.FatherId) ? idMap[p.FatherId] : null);
|
||||
fresh.BindUserId = sameTree ? p.BindUserId : null;
|
||||
fresh.IsBindUser = sameTree ? p.IsBindUser : null;
|
||||
if (sameTree)
|
||||
{
|
||||
fresh.CreatedBy = p.CreatedBy;
|
||||
fresh.CreatedDatetime = p.CreatedDatetime;
|
||||
}
|
||||
else
|
||||
{
|
||||
fresh.CreatedBy = service.UserId;
|
||||
fresh.CreatedDatetime = now;
|
||||
}
|
||||
fresh.UpdatedBy = service.UserId;
|
||||
fresh.UpdatedDatetime = now;
|
||||
repositoryPerson.InsertNow(fresh);
|
||||
}
|
||||
|
||||
// 4) 关系行双端 remap(完整性闸已保证两端都在文件内,此处必全量命中);
|
||||
// 同谱时 Created 印章随 Clone 原样回放,Updated 补当次操作痕迹;跨谱由框架盖当次
|
||||
foreach (FamilyTreeSpouseMapEntity m in data.SpouseMaps ?? [])
|
||||
{
|
||||
if (!idMap.ContainsKey(m.PersonId) || !idMap.ContainsKey(m.SpouseId)) continue;
|
||||
FamilyTreeSpouseMapEntity fresh = m.Clone();
|
||||
fresh.TreeId = targetTreeId;
|
||||
fresh.PersonId = idMap[m.PersonId];
|
||||
fresh.SpouseId = idMap[m.SpouseId];
|
||||
if (sameTree)
|
||||
{
|
||||
fresh.UpdatedBy = service.UserId;
|
||||
fresh.UpdatedDatetime = now;
|
||||
}
|
||||
repositorySpouse.InsertNow(fresh);
|
||||
}
|
||||
foreach (FamilyTreeChildrenMapEntity m in data.ChildrenMaps ?? [])
|
||||
{
|
||||
if (!idMap.ContainsKey(m.PersonId) || !idMap.ContainsKey(m.ChildrenId)) continue;
|
||||
FamilyTreeChildrenMapEntity fresh = m.Clone();
|
||||
fresh.TreeId = targetTreeId;
|
||||
fresh.PersonId = idMap[m.PersonId];
|
||||
fresh.ChildrenId = idMap[m.ChildrenId];
|
||||
if (sameTree)
|
||||
{
|
||||
fresh.UpdatedBy = service.UserId;
|
||||
fresh.UpdatedDatetime = now;
|
||||
}
|
||||
repositoryChild.InsertNow(fresh);
|
||||
}
|
||||
|
||||
// 5) 谱信息字段以数据为准(主键 TreeId 保持目标谱;始祖指向重编后的始祖)
|
||||
target.TreeName = data.FamilyTree.TreeName;
|
||||
target.Brief = data.FamilyTree.Brief;
|
||||
target.TreeCoverFilename = data.FamilyTree.TreeCoverFilename;
|
||||
target.PublicIndc = data.FamilyTree.PublicIndc;
|
||||
target.AncestorPersonId = idMap.ContainsKey(data.FamilyTree.AncestorPersonId ?? "") ? idMap[data.FamilyTree.AncestorPersonId] : target.AncestorPersonId;
|
||||
target.UpdatedBy = service.UserId;
|
||||
target.UpdatedDatetime = now;
|
||||
repository.UpdateNow(target);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dbCtx != null) dbCtx.SkipAudit = false;
|
||||
}
|
||||
|
||||
// 权限闭环:备份还原(含权限快照)→ 权限整体回放到备份时刻;跨谱 .fm 导入(无快照)→ 清悬挂行;同谱 .fm 导入→不碰
|
||||
string permStat;
|
||||
if (data.Permissions != null && data.Permissions.Length > 0)
|
||||
permStat = $"; permRestored={RestorePermissions(targetTreeId, data.Permissions, idMap)}";
|
||||
else if (!sameTree)
|
||||
permStat = $"; permDropped={CleanDanglingPermissions(targetTreeId, new HashSet<string>(idMap.Values))}";
|
||||
else
|
||||
permStat = "";
|
||||
|
||||
// 6) 审计(事务回滚则审计同滚——失败场景弹错给用户,不留半截日志)
|
||||
WriteExchangeLog(action, targetTreeId, FamilyTreeExchangeScope.ALL, "", backupName, idMap.Count, "OK", $"backup={backupName}; sameTree={(sameTree ? 1 : 0)}{permStat}");
|
||||
return idMap.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支系闭包:锚点以下后代 + 后代的配偶(迭代到不动点,防回头婚配漏拉);锚点本人不进集合。
|
||||
/// 目标侧算删除集、文件侧算插入集共用此口径,保证删/插范围对称。
|
||||
/// </summary>
|
||||
static HashSet<string> BranchClosure(string anchorId, FamilyTreeChildrenMapEntity[] childrenMaps, FamilyTreeSpouseMapEntity[] spouseMaps)
|
||||
{
|
||||
HashSet<string> set = new HashSet<string>();
|
||||
bool changed = true;
|
||||
while (changed)
|
||||
{
|
||||
changed = false;
|
||||
foreach (FamilyTreeChildrenMapEntity m in childrenMaps ?? [])
|
||||
{
|
||||
if ((m.PersonId == anchorId || set.Contains(m.PersonId)) && m.ChildrenId != anchorId && set.Add(m.ChildrenId)) changed = true;
|
||||
}
|
||||
foreach (FamilyTreeSpouseMapEntity m in spouseMaps ?? [])
|
||||
{
|
||||
if (set.Contains(m.PersonId) && m.SpouseId != anchorId && set.Add(m.SpouseId)) changed = true;
|
||||
if (set.Contains(m.SpouseId) && m.PersonId != anchorId && set.Add(m.PersonId)) changed = true;
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Update)]
|
||||
[UnitOfWork]
|
||||
public int ImportSubTree(string targetTreeId, string anchorPersonId, FamilyTreeExchangeData data)
|
||||
{
|
||||
FamilyTreeEntity target = repository.DetachedEntities.Where(x => x.TreeId == targetTreeId).FirstOrDefault();
|
||||
if (target == null) throw new ValidatedException("目标族谱不存在.");
|
||||
if (data == null || data.Persons == null || data.Persons.Length == 0) throw new ValidatedException("导入数据为空.");
|
||||
if (data.Scope != FamilyTreeExchangeScope.SUB) throw new ValidatedException("支系导入仅收小系(SUB)文件,全系请走整谱替换.");
|
||||
if (string.IsNullOrEmpty(data.AnchorPersonId)) throw new ValidatedException("导入文件未标记小系锚点(旧版导出文件),请重新导出.");
|
||||
if (string.IsNullOrEmpty(anchorPersonId)) throw new ValidatedException("请先选择要替换的族内锚点族人.");
|
||||
|
||||
FamilyTreePermissionHelper helper = new FamilyTreePermissionHelper(service);
|
||||
// P6 权限闸:管理员任意锚点;成员仅限自己可编家支的锚点(与小系导出同一把闸)
|
||||
if (!helper.IsManager(targetTreeId))
|
||||
{
|
||||
if (!helper.IsMember(targetTreeId)) throw new ValidatedException("您没有导入权限.");
|
||||
if (!helper.GetAmendablePersonIds(targetTreeId).Contains(anchorPersonId)) throw new ValidatedException("只能替换自己家支的锚点.");
|
||||
}
|
||||
|
||||
IRepository<FamilyPersonEntity> repositoryPerson = repository.GetRepository<IRepository<FamilyPersonEntity>>();
|
||||
IRepository<FamilyTreeSpouseMapEntity> repositorySpouse = repository.GetRepository<IRepository<FamilyTreeSpouseMapEntity>>();
|
||||
IRepository<FamilyTreeChildrenMapEntity> repositoryChild = repository.GetRepository<IRepository<FamilyTreeChildrenMapEntity>>();
|
||||
|
||||
FamilyPersonEntity targetAnchor = repositoryPerson.DetachedEntities.Where(x => x.TreeId == targetTreeId && x.PersonId == anchorPersonId).FirstOrDefault();
|
||||
if (targetAnchor == null) throw new ValidatedException("锚点族人不存在.");
|
||||
// P2/P3 同一人验证:文件锚点与所选族人 姓+谱名 全量一致才同意,否则拒绝
|
||||
FamilyPersonEntity fileAnchor = data.Persons.FirstOrDefault(x => x.PersonId == data.AnchorPersonId);
|
||||
if (fileAnchor == null) throw new ValidatedException("文件里找不到锚点人.");
|
||||
string Trim(string s) => (s ?? "").Trim();
|
||||
if (Trim(fileAnchor.Surname) != Trim(targetAnchor.Surname) || Trim(fileAnchor.GenealogyName) != Trim(targetAnchor.GenealogyName))
|
||||
throw new ValidatedException("文件锚点与所选族人不是同一人(姓/谱名不符),已拒绝导入.");
|
||||
|
||||
FamilyPersonEntity[] oldPersons = repositoryPerson.DetachedEntities.Where(x => x.TreeId == targetTreeId).ToArray();
|
||||
FamilyTreeSpouseMapEntity[] oldSpouses = repositorySpouse.DetachedEntities.Where(x => x.TreeId == targetTreeId).ToArray();
|
||||
FamilyTreeChildrenMapEntity[] oldChildren = repositoryChild.DetachedEntities.Where(x => x.TreeId == targetTreeId).ToArray();
|
||||
|
||||
// 1) 替换前整谱 JSON 备份(P7,回滚点,同整谱替换口径)
|
||||
string backupName = BackupTree(target, oldPersons, oldSpouses, oldChildren);
|
||||
|
||||
// 1.5) 方案 C:锚点本人也纳入替换——资料整体覆盖为文件锚点(备份已先行,可回滚);
|
||||
// PersonId/TreeId/FatherId/绑定字段/建档信息保留目标侧,防锚点脱谱、防绑定被文件旧值劫持
|
||||
DateTime now = DateTime.Now;
|
||||
FamilyPersonEntity mergedAnchor = targetAnchor.Clone();
|
||||
mergedAnchor.CopyFrom(fileAnchor);
|
||||
mergedAnchor.PersonId = targetAnchor.PersonId;
|
||||
mergedAnchor.TreeId = targetTreeId;
|
||||
mergedAnchor.FatherId = targetAnchor.FatherId;
|
||||
mergedAnchor.BindUserId = targetAnchor.BindUserId;
|
||||
mergedAnchor.IsBindUser = targetAnchor.IsBindUser;
|
||||
mergedAnchor.CreatedBy = targetAnchor.CreatedBy;
|
||||
mergedAnchor.CreatedDatetime = targetAnchor.CreatedDatetime;
|
||||
mergedAnchor.UpdatedBy = service.UserId;
|
||||
mergedAnchor.UpdatedDatetime = now;
|
||||
repositoryPerson.UpdateNow(mergedAnchor);
|
||||
|
||||
// 2) 删除集:目标锚点以下后代闭包 + 锚点配偶(方案 C 扩展:锚点整家替换;锚点本人已在 1.5 步覆盖)
|
||||
// 配偶仅「纯入配」(无其它婚配/血缘关系、无账号绑定、非始祖)才随删重插;否则只断与锚点的关系行、人行保留防悬挂
|
||||
HashSet<string> delSet = BranchClosure(anchorPersonId, oldChildren, oldSpouses);
|
||||
HashSet<string> delSpousePersons = new HashSet<string>();
|
||||
foreach (string sid in oldSpouses.Where(x => x.PersonId == anchorPersonId || x.SpouseId == anchorPersonId)
|
||||
.Select(x => x.PersonId == anchorPersonId ? x.SpouseId : x.PersonId).Distinct())
|
||||
{
|
||||
if (sid == anchorPersonId || sid == target.AncestorPersonId || delSet.Contains(sid)) continue;
|
||||
FamilyPersonEntity sp = oldPersons.FirstOrDefault(x => x.PersonId == sid);
|
||||
if (sp == null) continue;
|
||||
bool pure = string.IsNullOrEmpty(sp.BindUserId)
|
||||
&& !oldSpouses.Any(x => (x.PersonId == sid || x.SpouseId == sid) && x.PersonId != anchorPersonId && x.SpouseId != anchorPersonId)
|
||||
&& !oldChildren.Any(x => x.PersonId == sid || x.ChildrenId == sid);
|
||||
if (pure) delSpousePersons.Add(sid);
|
||||
}
|
||||
FamilyTreeSpouseMapEntity[] delSpouses = oldSpouses.Where(x => delSet.Contains(x.PersonId) || delSet.Contains(x.SpouseId) || x.PersonId == anchorPersonId || x.SpouseId == anchorPersonId).ToArray();
|
||||
FamilyTreeChildrenMapEntity[] delChildren = oldChildren.Where(x => delSet.Contains(x.ChildrenId)).ToArray();
|
||||
FamilyPersonEntity[] delPersons = oldPersons.Where(x => delSet.Contains(x.PersonId) || delSpousePersons.Contains(x.PersonId)).ToArray();
|
||||
if (delSpouses.Length > 0) repositorySpouse.DeleteNow(delSpouses);
|
||||
if (delChildren.Length > 0) repositoryChild.DeleteNow(delChildren);
|
||||
foreach (FamilyPersonEntity old in delPersons) repositoryPerson.DeleteNow(old);
|
||||
|
||||
// 3) 插入集:文件侧同口径闭包(上溯段落不插,P4)+ 文件锚点的配偶(方案 C 扩展,与目标侧删除对称);文件锚点映射到保留的目标锚点,其余重编号
|
||||
HashSet<string> insSet = BranchClosure(data.AnchorPersonId, data.ChildrenMaps, data.SpouseMaps);
|
||||
foreach (string fsid in (data.SpouseMaps ?? []).Where(x => x.PersonId == data.AnchorPersonId || x.SpouseId == data.AnchorPersonId)
|
||||
.Select(x => x.PersonId == data.AnchorPersonId ? x.SpouseId : x.PersonId).Distinct())
|
||||
{
|
||||
if (fsid != data.AnchorPersonId && !insSet.Contains(fsid) && data.Persons.Any(p => p.PersonId == fsid)) insSet.Add(fsid);
|
||||
}
|
||||
ISecurityGeneratorNumberService generator = service.ServiceProvider.GetService<ISecurityGeneratorNumberService>()!;
|
||||
Dictionary<string, string> idMap = new Dictionary<string, string> { [data.AnchorPersonId] = anchorPersonId };
|
||||
foreach (FamilyPersonEntity p in data.Persons)
|
||||
{
|
||||
if (!insSet.Contains(p.PersonId) || idMap.ContainsKey(p.PersonId)) continue;
|
||||
idMap[p.PersonId] = generator.GetNo(MasterPrefixPolicy.FAMILY_PERSON, MasterPrefixPolicy.FAMILY_PERSON_PERSON_ID, MasterPrefixPolicy.FAMILY_PERSON_PREFIX, YesNoPolicy.NO, MasterPrefixPolicy.FAMILY_PERSON_FORMAT);
|
||||
}
|
||||
foreach (FamilyPersonEntity p in data.Persons)
|
||||
{
|
||||
if (!insSet.Contains(p.PersonId)) continue; // 锚点以外的文件人(上溯段)一律不插
|
||||
FamilyPersonEntity fresh = p.Clone();
|
||||
fresh.PersonId = idMap[p.PersonId];
|
||||
fresh.TreeId = targetTreeId;
|
||||
fresh.FatherId = string.IsNullOrEmpty(p.FatherId) ? null : (idMap.ContainsKey(p.FatherId) ? idMap[p.FatherId] : null);
|
||||
fresh.BindUserId = null;
|
||||
fresh.IsBindUser = null;
|
||||
fresh.CreatedBy = service.UserId;
|
||||
fresh.CreatedDatetime = now;
|
||||
fresh.UpdatedBy = service.UserId;
|
||||
fresh.UpdatedDatetime = now;
|
||||
repositoryPerson.InsertNow(fresh);
|
||||
}
|
||||
|
||||
// 4) 关系行双端 remap(文件锚点端直接对接保留的目标锚点);引用集合外人的行丢弃防悬挂
|
||||
foreach (FamilyTreeSpouseMapEntity m in data.SpouseMaps ?? [])
|
||||
{
|
||||
if (!idMap.ContainsKey(m.PersonId) || !idMap.ContainsKey(m.SpouseId)) continue;
|
||||
if (m.PersonId == data.AnchorPersonId && m.SpouseId == data.AnchorPersonId) continue;
|
||||
FamilyTreeSpouseMapEntity fresh = m.Clone();
|
||||
fresh.TreeId = targetTreeId;
|
||||
fresh.PersonId = idMap[m.PersonId];
|
||||
fresh.SpouseId = idMap[m.SpouseId];
|
||||
repositorySpouse.InsertNow(fresh);
|
||||
}
|
||||
foreach (FamilyTreeChildrenMapEntity m in data.ChildrenMaps ?? [])
|
||||
{
|
||||
if (!idMap.ContainsKey(m.PersonId) || !idMap.ContainsKey(m.ChildrenId)) continue;
|
||||
FamilyTreeChildrenMapEntity fresh = m.Clone();
|
||||
fresh.TreeId = targetTreeId;
|
||||
fresh.PersonId = idMap[m.PersonId];
|
||||
fresh.ChildrenId = idMap[m.ChildrenId];
|
||||
repositoryChild.InsertNow(fresh);
|
||||
}
|
||||
|
||||
// 4.5) 权限行迁移(用户拍板:按新旧编号关联保留绑定权限):被删后代/入配配偶的绑定成员随人换绑到新号,
|
||||
// 关联不上的悬挂行删除;锚点行(id 未变)与枝外/管理员行不动
|
||||
string permStat = MigrateSubTreePermissions(targetTreeId, new HashSet<string>(delPersons.Select(x => x.PersonId)), idMap);
|
||||
|
||||
// 5) 审计 MERGE(P7 独立动作码,统计口径与整谱替换的 IN 分开):Message 记合并报告;人数含锚点本人(方案 C 同步覆盖)
|
||||
WriteExchangeLog("MERGE", targetTreeId, FamilyTreeExchangeScope.SUB, anchorPersonId, backupName, insSet.Count + 1, "OK", $"backup={backupName}; deleted={delPersons.Length}; inserted={insSet.Count}; anchor=1; anchorSpouse={delSpousePersons.Count}; perm {permStat}");
|
||||
return insSet.Count + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 备份列表(R1 收紧:备份是谁的操作谁的回滚——成员只见自己创建的,管理员不限):
|
||||
/// 只列本谱 BK 文件,R5 保留窗口(一年)内,按备份时刻降序;时刻以文件名为准,归属看 JSON 里的 ExportedBy。
|
||||
/// </summary>
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public FamilyTreeExchangeFileInfo[] ListBackups(string treeId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(treeId)) throw new ValidatedException("请先选择族谱.");
|
||||
FamilyTreePermissionHelper helper = new FamilyTreePermissionHelper(service);
|
||||
if (!helper.IsMember(treeId)) throw new ValidatedException("您不是该族谱成员.");
|
||||
bool isManager = helper.IsManager(treeId);
|
||||
|
||||
string dir = FamilyTreeExchangePolicy.GetBackupDirectory(service);
|
||||
if (!Directory.Exists(dir)) return [];
|
||||
|
||||
List<FamilyTreeExchangeFileInfo> files = new List<FamilyTreeExchangeFileInfo>();
|
||||
DateTime earliest = DateTime.Now.AddYears(-FamilyTreeExchangePolicy.BACKUP_KEEP_YEARS);
|
||||
foreach (string path in Directory.GetFiles(dir, $"BK{treeId}_*.json"))
|
||||
{
|
||||
string name = Path.GetFileName(path);
|
||||
var parsed = FamilyTreeExchangePolicy.ParseBackupFileName(name);
|
||||
// 谱号不符(大小写变体防御)、时刻超出保留窗口、文件名解析失败的一律不列
|
||||
if (parsed == null || parsed.Item1 != treeId || parsed.Item2 < earliest) continue;
|
||||
// 非管理员只列自己创建的备份(读 JSON 取 ExportedBy,大小写不敏感;解析不出归属的旧文件对成员隐藏、管理员可见)
|
||||
if (!isManager && ReadBackupOwner(path) != service.UserId) continue;
|
||||
files.Add(new FamilyTreeExchangeFileInfo
|
||||
{
|
||||
FileName = name,
|
||||
Size = new FileInfo(path).Length,
|
||||
LastModified = parsed.Item2,
|
||||
Scope = "BK",
|
||||
TreeId = treeId,
|
||||
AnchorPersonId = "",
|
||||
});
|
||||
}
|
||||
return files.OrderByDescending(x => x.LastModified).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>从备份 JSON 轻量提取创建人(ExportedBy);密文先解密再读,读不到/损坏返 null</summary>
|
||||
private static string ReadBackupOwner(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
using System.Text.Json.JsonDocument doc = System.Text.Json.JsonDocument.Parse(FamilyTreeExchangePolicy.DecryptBackup(File.ReadAllText(path)));
|
||||
foreach (System.Text.Json.JsonProperty p in doc.RootElement.EnumerateObject())
|
||||
if (string.Equals(p.Name, "ExportedBy", StringComparison.OrdinalIgnoreCase)) return p.Value.GetString();
|
||||
}
|
||||
catch { }
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 备份还原(R2:导小系/导全系出事,用替换前自动备份整谱回放退回):
|
||||
/// R1 成员也可还原;R3 还原前先把现谱再备份一份(还原错了还能退回去);
|
||||
/// R6 文件名严格 BK 格式且谱号必须等于目标谱(防路径穿越与跨谱灌数据)。
|
||||
/// 还原走整谱替换本体:全员重编号、绑定清除,与整谱导入同副作用。
|
||||
/// </summary>
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Update)]
|
||||
[UnitOfWork]
|
||||
public int RestoreBackup(string targetTreeId, string backupFileName)
|
||||
{
|
||||
FamilyTreeEntity target = repository.DetachedEntities.Where(x => x.TreeId == targetTreeId).FirstOrDefault();
|
||||
if (target == null) throw new ValidatedException("目标族谱不存在.");
|
||||
if (!new FamilyTreePermissionHelper(service).IsMember(targetTreeId)) throw new ValidatedException("您没有还原权限.");
|
||||
|
||||
// R6:格式闸(含目录成分拒绝)+ 归属闸(只能还原本谱的备份)+ R5 保留窗口闸
|
||||
var parsed = FamilyTreeExchangePolicy.ParseBackupFileName(backupFileName ?? "");
|
||||
if (parsed == null) throw new ValidatedException("备份文件名不合法.");
|
||||
if (parsed.Item1 != targetTreeId) throw new ValidatedException("备份文件不属于本族谱,不能跨谱还原.");
|
||||
if (parsed.Item2 < DateTime.Now.AddYears(-FamilyTreeExchangePolicy.BACKUP_KEEP_YEARS)) throw new ValidatedException("备份已超出保留窗口(一年),不允许还原.");
|
||||
|
||||
string path = Path.Combine(FamilyTreeExchangePolicy.GetBackupDirectory(service), backupFileName);
|
||||
if (!File.Exists(path)) throw new ValidatedException("备份文件不存在或已被清理.");
|
||||
FamilyTreeExchangeData data;
|
||||
try
|
||||
{
|
||||
// 备份密文先解密(旧明文备份无 ENC: 前缀直接透传);直读需大小写不敏感,实体属性对不上时会静默空值,故下面验内容完整性
|
||||
data = System.Text.Json.JsonSerializer.Deserialize<FamilyTreeExchangeData>(FamilyTreeExchangePolicy.DecryptBackup(File.ReadAllText(path)),
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ValidatedException($"备份文件已损坏,无法解析: {ex.Message}");
|
||||
}
|
||||
if (data == null || data.Persons == null || data.Persons.Length == 0 || data.FamilyTree == null)
|
||||
throw new ValidatedException("备份内容不完整,禁止还原.");
|
||||
// R1 收紧:成员只能还原自己创建的备份(防绕过列表直调接口);管理员不限
|
||||
if (!new FamilyTreePermissionHelper(service).IsManager(targetTreeId) && data.ExportedBy != service.UserId)
|
||||
throw new ValidatedException("该备份由其他用户创建,成员只能还原自己的备份.");
|
||||
|
||||
return ReplaceTreeCore(target, data, "RESTORE");
|
||||
}
|
||||
|
||||
/// <summary>D7 审计:写 family_tree_file_log;失败不阻断主流程(日志丢了可以补,导不出去的体验才是大事)</summary>
|
||||
private void WriteExchangeLog(string action, string treeId, string scope, string anchorPersonId, string fileName, int personCount, string result, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
IRepository<FamilyTreeFileLogEntity> repositoryLog = repository.GetRepository<IRepository<FamilyTreeFileLogEntity>>();
|
||||
DateTime now = DateTime.Now;
|
||||
repositoryLog.InsertNow(new FamilyTreeFileLogEntity
|
||||
{
|
||||
CreatedDatetime = now,
|
||||
CreatedBy = service.UserId,
|
||||
UpdatedDatetime = now,
|
||||
UpdatedBy = service.UserId,
|
||||
TreeId = treeId,
|
||||
Action = action,
|
||||
Scope = scope,
|
||||
AnchorPersonId = string.IsNullOrEmpty(anchorPersonId) ? null : anchorPersonId,
|
||||
FileName = fileName,
|
||||
PersonCount = personCount,
|
||||
Result = result,
|
||||
Message = message,
|
||||
});
|
||||
}
|
||||
catch (Exception ex) { Console.WriteLine($"[FamilyTreeExchange] 审计写入失败: {ex.Message}"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
using CloudBuilder.Master.Data;
|
||||
using CloudBuilder.Security.Policy;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace CloudBuilder.Master.Service.FamilyTreeUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// 族谱全系/小系 .fm 交换文件的规则:目录、文件名、系统因子。
|
||||
/// 不新增配置节——目录与身份证/头像上传同根(FileServiceSettings:UploadFileDirectory),固定挂在 FamilyTree 子目录下
|
||||
/// </summary>
|
||||
public static class FamilyTreeExchangePolicy
|
||||
{
|
||||
/// <summary>交换目录名(身份证用 FamilyPersonAvatar/IdCard,这里同款机制)</summary>
|
||||
public const string EXCHANGE_FOLDER_NAME = "FamilyTree";
|
||||
|
||||
public const string FILE_EXTENSION = ".fm";
|
||||
|
||||
/// <summary>D2 系统因子:前端 PBKDF2(用户密码⊕因子) 派生 AES 密钥,防「只漏密码」离线破解</summary>
|
||||
public const string EXCHANGE_FACTOR = "YouJiaLa.FamilyTree.Exchange.v1";
|
||||
|
||||
// D1 文件名:全系 A{treeId}_{ts}.fm;小系 P{treeId}-{personId}_{ts}.fm(ts=yyyyMMddHHmmss)
|
||||
private static readonly Regex ALL_FILE = new Regex(@"^AT\w+_\d{14}\.fm$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private static readonly Regex SUB_FILE = new Regex(@"^PT\w+-P\w+_\d{14}\.fm$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
// R6 备份文件名:BK{treeId}_{ts}.json(替换前自动落盘的整谱回滚点,存 Backup 子目录,不进交换文件白名单)
|
||||
private static readonly Regex BACKUP_FILE = new Regex(@"^BKT\w+_\d{14}\.json$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
/// <summary>备份目录名(挂在交换目录下)</summary>
|
||||
public const string BACKUP_FOLDER_NAME = "Backup";
|
||||
|
||||
/// <summary>R5 备份保留窗口:列表与还原都只认一年内</summary>
|
||||
public static readonly int BACKUP_KEEP_YEARS = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 备份密文魔数前缀:备份含成员权限行(账号名等隐私),统一用服务端 AES 密钥加密落盘;
|
||||
/// 前缀区分新老格式(无此前缀视为旧明文库,向后兼容),不新增配置节(复用 EncryptHelper 内置密钥)
|
||||
/// </summary>
|
||||
public const string BACKUP_ENCRYPT_PREFIX = "ENC:";
|
||||
|
||||
/// <summary>备份明文 JSON → 密文文本(写盘前调用)</summary>
|
||||
public static string EncryptBackup(string plainJson)
|
||||
{
|
||||
return BACKUP_ENCRYPT_PREFIX + EncryptHelper.AesEncrypt(plainJson);
|
||||
}
|
||||
|
||||
/// <summary>备份文件文本 → 明文 JSON(带 ENC: 前缀解密;旧明文备份直接透传)</summary>
|
||||
public static string DecryptBackup(string fileContent)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileContent)) return fileContent;
|
||||
return fileContent.StartsWith(BACKUP_ENCRYPT_PREFIX)
|
||||
? EncryptHelper.AesDecrpt(fileContent.Substring(BACKUP_ENCRYPT_PREFIX.Length))
|
||||
: fileContent;
|
||||
}
|
||||
|
||||
public static string GetExchangeDirectory(IApplicationService service)
|
||||
{
|
||||
return Path.Combine(ServiceSettingsPolicy.GetUploadFileDirectory(service), EXCHANGE_FOLDER_NAME);
|
||||
}
|
||||
|
||||
/// <summary>生成 D1 规范文件名</summary>
|
||||
public static string BuildFileName(string scope, string treeId, string anchorPersonId)
|
||||
{
|
||||
string ts = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
return scope == FamilyTreeExchangeScope.SUB
|
||||
? $"P{treeId}-{anchorPersonId}_{ts}{FILE_EXTENSION}"
|
||||
: $"A{treeId}_{ts}{FILE_EXTENSION}";
|
||||
}
|
||||
|
||||
/// <summary>校验文件名:只准 D1 两种格式,且拒绝任何目录成分(防 ../ 路径穿越)</summary>
|
||||
public static bool IsValidFileName(string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName)) return false;
|
||||
if (fileName != Path.GetFileName(fileName)) return false;
|
||||
return ALL_FILE.IsMatch(fileName) || SUB_FILE.IsMatch(fileName);
|
||||
}
|
||||
|
||||
/// <summary>从合法文件名反解析 (treeId, anchorPersonId, scope);非法返回 null</summary>
|
||||
public static Tuple<string, string, string> ParseFileName(string fileName)
|
||||
{
|
||||
if (!IsValidFileName(fileName)) return null;
|
||||
// 去掉前缀字母与时间戳,取中间的 id 段
|
||||
string body = fileName.Substring(1, fileName.Length - 1 - FILE_EXTENSION.Length).Split('_')[0];
|
||||
if (fileName[0].ToString().Equals("A", StringComparison.OrdinalIgnoreCase))
|
||||
return Tuple.Create(body, "", FamilyTreeExchangeScope.ALL);
|
||||
string[] parts = body.Split('-');
|
||||
return Tuple.Create(parts[0], parts[1], FamilyTreeExchangeScope.SUB);
|
||||
}
|
||||
|
||||
public static string GetBackupDirectory(IApplicationService service)
|
||||
{
|
||||
return Path.Combine(GetExchangeDirectory(service), BACKUP_FOLDER_NAME);
|
||||
}
|
||||
|
||||
/// <summary>生成备份文件名(谱号+秒级时间戳,同谱同秒重名由覆盖兼容:秒内连点两次导入的极小概率场景)</summary>
|
||||
public static string BuildBackupFileName(string treeId)
|
||||
{
|
||||
return $"BK{treeId}_{DateTime.Now:yyyyMMddHHmmss}.json";
|
||||
}
|
||||
|
||||
/// <summary>校验备份文件名:只准 BK 格式,拒绝任何目录成分(还原入口防路径穿越/拿 *.fm 灌数据)</summary>
|
||||
public static bool IsValidBackupFileName(string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName)) return false;
|
||||
if (fileName != Path.GetFileName(fileName)) return false;
|
||||
return BACKUP_FILE.IsMatch(fileName);
|
||||
}
|
||||
|
||||
/// <summary>从合法备份文件名反解析 (treeId, 备份时刻);非法返回 null。时刻以文件名为准(不依赖文件系统时间戳)</summary>
|
||||
public static Tuple<string, DateTime> ParseBackupFileName(string fileName)
|
||||
{
|
||||
if (!IsValidBackupFileName(fileName)) return null;
|
||||
string body = fileName.Substring(2, fileName.Length - 2 - ".json".Length);
|
||||
string[] parts = body.Split('_');
|
||||
if (!DateTime.TryParseExact(parts[1], "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime ts))
|
||||
return null;
|
||||
return Tuple.Create(parts[0], ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using CloudBuilder.Master.Entity;
|
||||
using System;
|
||||
|
||||
namespace CloudBuilder.Master.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 族谱全系/小系导出的明文数据(按 D1-D8 决策):
|
||||
/// 后端按权限闸裁剪后下发,前端用「用户密码⊕系统因子」派生密钥加密成 .fm 信封,落盘/上传交换目录
|
||||
/// </summary>
|
||||
public class FamilyTreeExchangeData
|
||||
{
|
||||
/// <summary>ALL=全系 / SUB=小系</summary>
|
||||
public string Scope { get; set; } = FamilyTreeExchangeScope.ALL;
|
||||
|
||||
public FamilyTreeEntity FamilyTree { get; set; }
|
||||
|
||||
public FamilyPersonEntity[] Persons { get; set; } = [];
|
||||
|
||||
public FamilyTreeSpouseMapEntity[] SpouseMaps { get; set; } = [];
|
||||
|
||||
public FamilyTreeChildrenMapEntity[] ChildrenMaps { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 本谱权限行快照(仅备份 BK 写入,用于还原时权限随谱回滚形成绝对闭环;
|
||||
/// .fm 交换文件恒为空——防成员账号名随导出文件外泄,也防外部文件携权限行劫持本谱)
|
||||
/// </summary>
|
||||
public FamilyTreePermissionEntity[] Permissions { get; set; } = [];
|
||||
|
||||
public int PersonCount => Persons?.Length ?? 0;
|
||||
|
||||
/// <summary>SUB 导出时的锚点人号(二期支系替换导入靠它验明同一人;ALL 为空)</summary>
|
||||
public string AnchorPersonId { get; set; } = "";
|
||||
|
||||
/// <summary>导出发起人(service.UserId)</summary>
|
||||
public string ExportedBy { get; set; } = "";
|
||||
|
||||
public DateTime ExportedAt { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>交换目录下 .fm 密文文件的列表信息(文件名按 D1 规则反解析出 scope/treeId/锚点)</summary>
|
||||
public class FamilyTreeExchangeFileInfo
|
||||
{
|
||||
public string FileName { get; set; } = "";
|
||||
|
||||
public long Size { get; set; }
|
||||
|
||||
public DateTime LastModified { get; set; }
|
||||
|
||||
public string Scope { get; set; } = "";
|
||||
|
||||
public string TreeId { get; set; } = "";
|
||||
|
||||
public string AnchorPersonId { get; set; } = "";
|
||||
}
|
||||
|
||||
/// <summary>导出范围常量(后端无 CloudBuilder.Master.Service 引用,DTO 与 Policy 各留一份避免工程反向依赖)</summary>
|
||||
public static class FamilyTreeExchangeScope
|
||||
{
|
||||
public const string ALL = "ALL";
|
||||
public const string SUB = "SUB";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using CloudBuilder.Core.Authorization;
|
||||
using CloudBuilder.Core.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Master.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// dashboard 网盘用量卡片数据:当前登录用户的类型、头像、已用/总额度(KB)、百分比。
|
||||
/// 用量取自 dms_file_usage_view(ower_id=本人 且非目录),额度按 user_type 从 appsettings:NetDiskQuota 解析。
|
||||
/// </summary>
|
||||
[TypeScript]
|
||||
public class StorageUsageData
|
||||
{
|
||||
/// <summary>用户类型码:U=未认证 / N=普通 / V=VIP / S=SVIP(名称由前端 i18n 映射)</summary>
|
||||
public string UserType { get; set; } = "";
|
||||
|
||||
/// <summary>头像地址(security_user.user_icon_img_path,当前无上传链路多为空,前端占位兜底)</summary>
|
||||
public string AvatarUrl { get; set; } = "";
|
||||
|
||||
/// <summary>已用容量(KB)</summary>
|
||||
public long UsedKB { get; set; }
|
||||
|
||||
/// <summary>额度总量(KB),0 表示未配置/不限</summary>
|
||||
public long QuotaKB { get; set; }
|
||||
|
||||
/// <summary>已用百分比(额度为 0 时记 0;可大于 100 表示超额)</summary>
|
||||
public int Percent { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,10 @@ builder.Entity<FamilyTreePermissionUserViewEntity>(eb => { eb.HasNoKey(); });
|
||||
|
||||
|
||||
|
||||
//***END***
|
||||
|
||||
|
||||
builder.Entity<DmsFileUsageViewEntity>(eb => { eb.HasNoKey(); });
|
||||
//***END***
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
|
||||
using CloudBuilder.Core.Authorization;
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace CloudBuilder.Master.Entity
|
||||
{
|
||||
[TypeScript]
|
||||
[Table("dms_file_usage_view")]
|
||||
public class DmsFileUsageViewEntity : ViewEntityBase
|
||||
{
|
||||
|
||||
public DmsFileUsageViewEntity()
|
||||
{
|
||||
}
|
||||
|
||||
[Column("ower_id")]
|
||||
public string OwerId { get; set; }
|
||||
[Column("file_count")]
|
||||
public long FileCount { get; set; }
|
||||
[Column("used_kb")]
|
||||
public long UsedKb { get; set; }
|
||||
|
||||
public const string OWER_ID = "OwerId";
|
||||
public const string FILE_COUNT = "FileCount";
|
||||
public const string USED_KB = "UsedKb";
|
||||
|
||||
public const string DB_NAME_DMS_FILE_USAGE_VIEW = "dms_file_usage_view";
|
||||
public const string DB_NAME_FIELDS="ower_id,file_count,used_kb";
|
||||
|
||||
public const string DB_OWER_ID = "ower_id";
|
||||
public const string DB_FILE_COUNT = "file_count";
|
||||
public const string DB_USED_KB = "used_kb";
|
||||
|
||||
private string ProviderName { get; set; }
|
||||
|
||||
public static DmsFileUsageViewEntity GetInstance(string providerName)
|
||||
{
|
||||
return new DmsFileUsageViewEntity() { ProviderName = providerName };
|
||||
}
|
||||
|
||||
public virtual void CopyFrom(DmsFileUsageViewEntity source)
|
||||
{
|
||||
CopyFrom(source, true);
|
||||
}
|
||||
|
||||
public virtual void CopyFrom(DmsFileUsageViewEntity source, bool includeSystemFields)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new NullReferenceException("Source entity is null.");
|
||||
}
|
||||
|
||||
this.OwerId = source.OwerId;
|
||||
this.FileCount = source.FileCount;
|
||||
this.UsedKb = source.UsedKb;
|
||||
|
||||
if (includeSystemFields)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetSelectFrom()
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectFromByMySql();
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectFromByBySqlServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
public string GetSelectFromByMySql()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_DMS_FILE_USAGE_VIEW} with(nolock) ";
|
||||
}
|
||||
public string GetSelectFromByBySqlServer()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_DMS_FILE_USAGE_VIEW} ";
|
||||
}
|
||||
|
||||
public override string GetSelectCountFrom(string sqlWhere)
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectCountFromByMySql(sqlWhere);
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectCountFromBySqlServer(sqlWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSelectCountFromByMySql(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_DMS_FILE_USAGE_VIEW} where 1=1 {sqlWhere}";
|
||||
}
|
||||
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_DMS_FILE_USAGE_VIEW} with(nolock) where 1=1 {sqlWhere}";
|
||||
}
|
||||
|
||||
public override string GetSelectTopFrom(int limit, int start, string orderby, string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectTopFromByMySql(limit, start, orderby, orderbytag, sqlWhere);
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectTopFromBySqlServer(limit, start, orderby, orderbytag, sqlWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSelectTopFromByMySql(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_OWER_ID ; int offset = limit * (start - 1);
|
||||
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_DMS_FILE_USAGE_VIEW} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {limit} ";
|
||||
}
|
||||
|
||||
public string GetSelectTopFromBySqlServer(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_OWER_ID ; string top = limit > 0 ? $"top {limit}" : "";
|
||||
return $" select {top} {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_DMS_FILE_USAGE_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
||||
}
|
||||
|
||||
public DmsFileUsageViewEntity Clone()
|
||||
{
|
||||
DmsFileUsageViewEntity result = new DmsFileUsageViewEntity();
|
||||
result.CopyFrom(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
|
||||
using CloudBuilder.Core.Authorization;
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace CloudBuilder.Master.Entity
|
||||
{
|
||||
[TypeScript]
|
||||
[Table("family_tree_file_log")]
|
||||
public class FamilyTreeFileLogEntity : ViewEntityBase
|
||||
{
|
||||
|
||||
public FamilyTreeFileLogEntity()
|
||||
{
|
||||
}
|
||||
|
||||
[Column("created_datetime")]
|
||||
public DateTime CreatedDatetime { get; set; }
|
||||
[Column("created_by")]
|
||||
public string CreatedBy { get; set; }
|
||||
[Column("updated_datetime")]
|
||||
public DateTime UpdatedDatetime { get; set; }
|
||||
[Column("updated_by")]
|
||||
public string UpdatedBy { get; set; }
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("log_id")]
|
||||
public int LogId { get; set; }
|
||||
[Column("tree_id")]
|
||||
public string TreeId { get; set; }
|
||||
[Column("action")]
|
||||
public string Action { get; set; }
|
||||
[Column("scope")]
|
||||
public string Scope { get; set; }
|
||||
[Column("anchor_person_id")]
|
||||
public string? AnchorPersonId { get; set; }
|
||||
[Column("file_name")]
|
||||
public string? FileName { get; set; }
|
||||
[Column("person_count")]
|
||||
public int PersonCount { get; set; }
|
||||
[Column("result")]
|
||||
public string Result { get; set; }
|
||||
[Column("message")]
|
||||
public string? Message { get; set; }
|
||||
|
||||
public const string CREATED_DATETIME = "CreatedDatetime";
|
||||
public const string CREATED_BY = "CreatedBy";
|
||||
public const string UPDATED_DATETIME = "UpdatedDatetime";
|
||||
public const string UPDATED_BY = "UpdatedBy";
|
||||
public const string LOG_ID = "LogId";
|
||||
public const string TREE_ID = "TreeId";
|
||||
public const string ACTION = "Action";
|
||||
public const string SCOPE = "Scope";
|
||||
public const string ANCHOR_PERSON_ID = "AnchorPersonId";
|
||||
public const string FILE_NAME = "FileName";
|
||||
public const string PERSON_COUNT = "PersonCount";
|
||||
public const string RESULT = "Result";
|
||||
public const string MESSAGE = "Message";
|
||||
|
||||
public const string DB_NAME_FAMILY_TREE_FILE_LOG = "family_tree_file_log";
|
||||
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,log_id,tree_id,action,scope,anchor_person_id,file_name,person_count,result,message";
|
||||
|
||||
public const string DB_CREATED_DATETIME = "created_datetime";
|
||||
public const string DB_CREATED_BY = "created_by";
|
||||
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
||||
public const string DB_UPDATED_BY = "updated_by";
|
||||
public const string DB_LOG_ID = "log_id";
|
||||
public const string DB_TREE_ID = "tree_id";
|
||||
public const string DB_ACTION = "action";
|
||||
public const string DB_SCOPE = "scope";
|
||||
public const string DB_ANCHOR_PERSON_ID = "anchor_person_id";
|
||||
public const string DB_FILE_NAME = "file_name";
|
||||
public const string DB_PERSON_COUNT = "person_count";
|
||||
public const string DB_RESULT = "result";
|
||||
public const string DB_MESSAGE = "message";
|
||||
|
||||
private string ProviderName { get; set; }
|
||||
|
||||
public static FamilyTreeFileLogEntity GetInstance(string providerName)
|
||||
{
|
||||
return new FamilyTreeFileLogEntity() { ProviderName = providerName };
|
||||
}
|
||||
|
||||
public virtual void CopyFrom(FamilyTreeFileLogEntity source)
|
||||
{
|
||||
CopyFrom(source, true);
|
||||
}
|
||||
|
||||
public virtual void CopyFrom(FamilyTreeFileLogEntity source, bool includeSystemFields)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new NullReferenceException("Source entity is null.");
|
||||
}
|
||||
|
||||
this.CreatedDatetime = source.CreatedDatetime;
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
this.LogId = source.LogId;
|
||||
this.TreeId = source.TreeId;
|
||||
this.Action = source.Action;
|
||||
this.Scope = source.Scope;
|
||||
this.AnchorPersonId = source.AnchorPersonId;
|
||||
this.FileName = source.FileName;
|
||||
this.PersonCount = source.PersonCount;
|
||||
this.Result = source.Result;
|
||||
this.Message = source.Message;
|
||||
|
||||
if (includeSystemFields)
|
||||
{
|
||||
this.CreatedDatetime = source.CreatedDatetime;
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetSelectFrom()
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectFromByMySql();
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectFromByBySqlServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
public string GetSelectFromByMySql()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_TREE_FILE_LOG} with(nolock) ";
|
||||
}
|
||||
public string GetSelectFromByBySqlServer()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_TREE_FILE_LOG} ";
|
||||
}
|
||||
|
||||
public override string GetSelectCountFrom(string sqlWhere)
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectCountFromByMySql(sqlWhere);
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectCountFromBySqlServer(sqlWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSelectCountFromByMySql(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_FAMILY_TREE_FILE_LOG} where 1=1 {sqlWhere}";
|
||||
}
|
||||
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_FAMILY_TREE_FILE_LOG} with(nolock) where 1=1 {sqlWhere}";
|
||||
}
|
||||
|
||||
public override string GetSelectTopFrom(int limit, int start, string orderby, string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectTopFromByMySql(limit, start, orderby, orderbytag, sqlWhere);
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectTopFromBySqlServer(limit, start, orderby, orderbytag, sqlWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSelectTopFromByMySql(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_LOG_ID ;
|
||||
int offset = limit * (start - 1);
|
||||
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_FAMILY_TREE_FILE_LOG} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {limit} ";
|
||||
}
|
||||
|
||||
public string GetSelectTopFromBySqlServer(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_LOG_ID ;
|
||||
string top = limit > 0 ? $"top {limit}" : "";
|
||||
return $" select {top} {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_FAMILY_TREE_FILE_LOG} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
||||
}
|
||||
|
||||
public FamilyTreeFileLogEntity Clone()
|
||||
{
|
||||
FamilyTreeFileLogEntity result = new FamilyTreeFileLogEntity();
|
||||
result.CopyFrom(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace CloudBuilder.Master.Policy
|
||||
{
|
||||
/// <summary>
|
||||
/// 分片上传落盘目录名统一管理。物理文件落在 {UploadFileDirectory}/{folderName}/{扩展名}/,
|
||||
/// 末片合并后拷贝到 {BackupFileDirectory}/{folderName}/{扩展名}/;后端拼头像访问地址
|
||||
/// (FileTypePolicy.PackAvatarUrl)用的目录名必须与前端 multipart 的 FilePath 头完全一致,
|
||||
/// 故把这些散落在各服务的字符串收敛到此处,作为前后端共同对齐的单一真源。
|
||||
/// </summary>
|
||||
public static class UploadFolderPolicy
|
||||
{
|
||||
/// <summary>族谱成员头像目录(family_person.avatar_filename 对应)</summary>
|
||||
public const string FAMILY_PERSON_AVATAR = "FamilyPersonAvatar";
|
||||
|
||||
/// <summary>登录用户(我的)头像目录(security_user.user_icon_img_path 对应)</summary>
|
||||
public const string USER_AVATAR = "UserAvatar";
|
||||
|
||||
/// <summary>身份证照片目录(与前端身份证上传 FilePath 头一致,小写历史沿用)</summary>
|
||||
public const string ID_CARD = "idcard";
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,12 @@ namespace CloudBuilder.Master.Service
|
||||
void UploadFile();
|
||||
void UploadDmsFile();
|
||||
FamilyPersonDisplayData UploadIdCardFile();
|
||||
|
||||
/// <summary>当前登录用户的网盘用量汇总(类型/头像/已用/额度/百分比),供 dashboard 卡片。</summary>
|
||||
StorageUsageData GetMyStorageUsage();
|
||||
|
||||
/// <summary>上传并保存当前登录用户头像(multipart 单图),落盘 UserAvatar 目录并回写 security_user.user_icon_img_path,返回可访问 URL。</summary>
|
||||
string UploadUserAvatar();
|
||||
string FindM3u8Path(long fileId);
|
||||
|
||||
string FindSourceVideoPath(long fileId);
|
||||
|
||||
@@ -21,5 +21,18 @@ namespace CloudBuilder.Master.Service
|
||||
FamilyTreeData BindSelfPerson(string treeId, string personId);
|
||||
FamilyTreeData UnbindSelfPerson(string treeId);
|
||||
|
||||
// 族谱全系/小系 .fm 导入导出(D1-D8):Export 出明文数据由前端加密,Save/List/Read 走交换目录
|
||||
string GetExchangeFactor();
|
||||
FamilyTreeExchangeData ExportFamilyTree(string treeId, string scope, string anchorPersonId);
|
||||
string SaveExchangeFile(string fileName, string contentBase64);
|
||||
FamilyTreeExchangeFileInfo[] ListExchangeFiles(string treeId);
|
||||
string ReadExchangeFile(string fileName);
|
||||
int ImportFamilyTree(string targetTreeId, FamilyTreeExchangeData data);
|
||||
|
||||
int ImportSubTree(string targetTreeId, string anchorPersonId, FamilyTreeExchangeData data);
|
||||
|
||||
FamilyTreeExchangeFileInfo[] ListBackups(string treeId);
|
||||
int RestoreBackup(string targetTreeId, string backupFileName);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,14 @@ return Task.Run(() => serviceRequest.PostAsJsonAsync<string>("/DmsFile/FindSou
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<string>("/DmsFile/FindDeleteLogM3u8Path?fileId=" + fileId.ToString())).GetAwaiter().GetResult(); }
|
||||
|
||||
public StorageUsageData GetMyStorageUsage()
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<StorageUsageData> ("/DmsFile/GetMyStorageUsage")).GetAwaiter().GetResult(); }
|
||||
|
||||
public string UploadUserAvatar()
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<string> ("/DmsFile/UploadUserAvatar")).GetAwaiter().GetResult(); }
|
||||
|
||||
public dynamic DownloadFile(Int64 fileId)
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<dynamic>("/DmsFile/DownloadFile?fileId=" + fileId.ToString())).GetAwaiter().GetResult(); }
|
||||
|
||||
@@ -108,6 +108,74 @@ return Task.Run(() => serviceRequest.PostAsJsonAsync<FamilyTreeData,FamilyTree
|
||||
{
|
||||
Task.Run(() => serviceRequest.PostAsJsonAsync<string[],dynamic>("/FamilyTree/Deletes" , keys)).GetAwaiter().GetResult(); }
|
||||
|
||||
public string GetExchangeFactor()
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<string> ("/FamilyTree/GetExchangeFactor")).GetAwaiter().GetResult(); }
|
||||
|
||||
|
||||
public class ExportFamilyTreeCompositionData3 {
|
||||
public string treeId { get; set; }
|
||||
public string scope { get; set; }
|
||||
public string anchorPersonId { get; set; }
|
||||
|
||||
}
|
||||
public FamilyTreeExchangeData ExportFamilyTree(string treeId, string scope, string anchorPersonId)
|
||||
{
|
||||
var compositionData = new ExportFamilyTreeCompositionData3{ ␍treeId = treeId, ␍scope = scope, ␍anchorPersonId = anchorPersonId }; ␍return Task.Run(() => serviceRequest.PostAsJsonAsync<ExportFamilyTreeCompositionData3, FamilyTreeExchangeData>("/FamilyTree/ExportFamilyTree", compositionData)).GetAwaiter().GetResult(); }
|
||||
|
||||
|
||||
public class SaveExchangeFileCompositionData2 {
|
||||
public string fileName { get; set; }
|
||||
public string contentBase64 { get; set; }
|
||||
|
||||
}
|
||||
public string SaveExchangeFile(string fileName, string contentBase64)
|
||||
{
|
||||
var compositionData = new SaveExchangeFileCompositionData2{ ␍fileName = fileName, ␍contentBase64 = contentBase64 }; ␍return Task.Run(() => serviceRequest.PostAsJsonAsync<SaveExchangeFileCompositionData2, string>("/FamilyTree/SaveExchangeFile", compositionData)).GetAwaiter().GetResult(); }
|
||||
|
||||
public FamilyTreeExchangeFileInfo[] ListExchangeFiles(string treeId)
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<FamilyTreeExchangeFileInfo[]>("/FamilyTree/ListExchangeFiles?treeId=" + treeId.ToString())).GetAwaiter().GetResult(); }
|
||||
|
||||
public string ReadExchangeFile(string fileName)
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<string>("/FamilyTree/ReadExchangeFile?fileName=" + fileName.ToString())).GetAwaiter().GetResult(); }
|
||||
|
||||
|
||||
public class ImportFamilyTreeCompositionData2 {
|
||||
public string targetTreeId { get; set; }
|
||||
public FamilyTreeExchangeData data { get; set; }
|
||||
|
||||
}
|
||||
public Int32 ImportFamilyTree(string targetTreeId, FamilyTreeExchangeData data)
|
||||
{
|
||||
var compositionData = new ImportFamilyTreeCompositionData2{ ␍targetTreeId = targetTreeId, ␍data = data }; ␍return Task.Run(() => serviceRequest.PostAsJsonAsync<ImportFamilyTreeCompositionData2, Int32>("/FamilyTree/ImportFamilyTree", compositionData)).GetAwaiter().GetResult(); }
|
||||
|
||||
|
||||
public class ImportSubTreeCompositionData3 {
|
||||
public string targetTreeId { get; set; }
|
||||
public string anchorPersonId { get; set; }
|
||||
public FamilyTreeExchangeData data { get; set; }
|
||||
|
||||
}
|
||||
public Int32 ImportSubTree(string targetTreeId, string anchorPersonId, FamilyTreeExchangeData data)
|
||||
{
|
||||
var compositionData = new ImportSubTreeCompositionData3{ ␍targetTreeId = targetTreeId, ␍anchorPersonId = anchorPersonId, ␍data = data }; ␍return Task.Run(() => serviceRequest.PostAsJsonAsync<ImportSubTreeCompositionData3, Int32>("/FamilyTree/ImportSubTree", compositionData)).GetAwaiter().GetResult(); }
|
||||
|
||||
public FamilyTreeExchangeFileInfo[] ListBackups(string treeId)
|
||||
{
|
||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<FamilyTreeExchangeFileInfo[]>("/FamilyTree/ListBackups?treeId=" + treeId.ToString())).GetAwaiter().GetResult(); }
|
||||
|
||||
|
||||
public class RestoreBackupCompositionData2 {
|
||||
public string targetTreeId { get; set; }
|
||||
public string backupFileName { get; set; }
|
||||
|
||||
}
|
||||
public Int32 RestoreBackup(string targetTreeId, string backupFileName)
|
||||
{
|
||||
var compositionData = new RestoreBackupCompositionData2{ ␍targetTreeId = targetTreeId, ␍backupFileName = backupFileName }; ␍return Task.Run(() => serviceRequest.PostAsJsonAsync<RestoreBackupCompositionData2, Int32>("/FamilyTree/RestoreBackup", compositionData)).GetAwaiter().GetResult(); }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,12 @@ namespace CloudBuilder.Security.Policy
|
||||
{
|
||||
public class SecurityUserTypePolicy : LocalePolicy, IPolicy
|
||||
{
|
||||
// 用户类型码(security_user.user_type):未认证 / 普通用户 / VIP / SVIP
|
||||
// 普通用户沿用历史 "N",存量普通用户零影响;旧审计码 I/S/K 已作废。
|
||||
public const string UNAUTHENTICATED_USERS = "U";
|
||||
public const string NORMAL_USERS = "N";
|
||||
public const string ICTI_USERS = "I";
|
||||
public const string SEDEX_USERS = "S";
|
||||
public const string KOHLS_USERS = "K";
|
||||
public const string VIP_USERS = "V";
|
||||
public const string SVIP_USERS = "S";
|
||||
|
||||
private readonly IContext context;
|
||||
private readonly ILocaleMessageManager localeMessageManager;
|
||||
@@ -28,30 +30,24 @@ namespace CloudBuilder.Security.Policy
|
||||
}
|
||||
|
||||
|
||||
public static bool IsUnauthenticated(string code)
|
||||
{
|
||||
return code == UNAUTHENTICATED_USERS;
|
||||
}
|
||||
|
||||
public static bool IsNormalUser(string code)
|
||||
{
|
||||
return code == NORMAL_USERS;
|
||||
}
|
||||
|
||||
public static bool IsIctiUser(string code)
|
||||
public static bool IsVipUser(string code)
|
||||
{
|
||||
return code == ICTI_USERS;
|
||||
return code == VIP_USERS;
|
||||
}
|
||||
|
||||
public static bool IsSedexUser(string code)
|
||||
public static bool IsSvipUser(string code)
|
||||
{
|
||||
return code == SEDEX_USERS;
|
||||
}
|
||||
|
||||
public static bool IsKohlsUser(string code)
|
||||
{
|
||||
return code == KOHLS_USERS;
|
||||
}
|
||||
|
||||
|
||||
public static bool IsAuditor(string code)
|
||||
{
|
||||
return IsIctiUser(code) || IsSedexUser(code) || IsKohlsUser(code);
|
||||
return code == SVIP_USERS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,36 @@ namespace CloudBuilder.Security.Policy
|
||||
public const string FfmpegPictrue = "Ffmpeg:Pictrue";
|
||||
public const string FfmpegArguments = "Ffmpeg:Arguments";
|
||||
|
||||
// 网盘额度(appsettings.json:NetDiskQuota),按 user_type 码取档
|
||||
public const string NetDiskQuotaSection = "NetDiskQuota";
|
||||
|
||||
/// <summary>
|
||||
/// 取当前用户类型的网盘额度(KB)。类型码缺失/未知回退按未认证(U)最小权限档;
|
||||
/// 未配置或解析不出数值时返回 0(调用方据 0 判定"不限额"还是"不可用")。
|
||||
/// </summary>
|
||||
public static long GetNetDiskQuotaKB(IApplicationService service, string userType)
|
||||
{
|
||||
var code = string.IsNullOrWhiteSpace(userType) ? SecurityUserTypePolicy.UNAUTHENTICATED_USERS : userType.Trim().ToUpperInvariant();
|
||||
var raw = service.Configuration[$"{NetDiskQuotaSection}:{code}"];
|
||||
// 未知类型码回退未认证档,避免历史脏码绕过限额
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
raw = service.Configuration[$"{NetDiskQuotaSection}:{SecurityUserTypePolicy.UNAUTHENTICATED_USERS}"];
|
||||
return ParseSizeToKB(raw);
|
||||
}
|
||||
|
||||
/// <summary>解析 "2G"/"100G"/"500G"/"1T"/"512M"/"2048K"(大小写兼容,缺省按 KB)为 KB。</summary>
|
||||
private static long ParseSizeToKB(string raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw)) return 0;
|
||||
raw = raw.Trim().ToUpperInvariant();
|
||||
long unit = 1; // KB
|
||||
if (raw.EndsWith("T")) { unit = 1024L * 1024 * 1024; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("G")) { unit = 1024L * 1024; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("M")) { unit = 1024L; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("K")) { unit = 1; raw = raw.Substring(0, raw.Length - 1); }
|
||||
return long.TryParse(raw.Trim(), out var n) && n > 0 ? n * unit : 0;
|
||||
}
|
||||
|
||||
// 身份证 OCR 识别服务(server-to-server 调用,地址来自 appsettings.json,避免写死)
|
||||
public const string IdCardOcrApiUrl = "IdCardOcr:ApiUrl";
|
||||
public const string IdCardOcrApiKey = "IdCardOcr:ApiKey";
|
||||
|
||||
@@ -555,6 +555,47 @@ this.dmsFileService= dmsFileService;
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "DmsFile", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic GetMyStorageUsage()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = dmsFileService.GetMyStorageUsage();
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "DmsFile", operate: "Insert")]
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
public dynamic UploadUserAvatar()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = dmsFileService.UploadUserAvatar();
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "DmsFile", operate: "Find")]
|
||||
|
||||
@@ -331,6 +331,226 @@ this.familyTreeService= familyTreeService;
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic GetExchangeFactor()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.GetExchangeFactor();
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ExportFamilyTreeCompositionData
|
||||
{
|
||||
public string treeId { get; set; }
|
||||
public string scope { get; set; }
|
||||
public string anchorPersonId { get; set; }
|
||||
|
||||
}
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic ExportFamilyTree(ExportFamilyTreeCompositionData compositionData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.ExportFamilyTree(compositionData.treeId,compositionData.scope,compositionData.anchorPersonId);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SaveExchangeFileCompositionData
|
||||
{
|
||||
public string fileName { get; set; }
|
||||
public string contentBase64 { get; set; }
|
||||
|
||||
}
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic SaveExchangeFile(SaveExchangeFileCompositionData compositionData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.SaveExchangeFile(compositionData.fileName,compositionData.contentBase64);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic ListExchangeFiles(string treeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.ListExchangeFiles(treeId);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic ReadExchangeFile(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.ReadExchangeFile(fileName);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ImportFamilyTreeCompositionData
|
||||
{
|
||||
public string targetTreeId { get; set; }
|
||||
public FamilyTreeExchangeData data { get; set; }
|
||||
|
||||
}
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
public dynamic ImportFamilyTree(ImportFamilyTreeCompositionData compositionData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.ImportFamilyTree(compositionData.targetTreeId,compositionData.data);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ImportSubTreeCompositionData
|
||||
{
|
||||
public string targetTreeId { get; set; }
|
||||
public string anchorPersonId { get; set; }
|
||||
public FamilyTreeExchangeData data { get; set; }
|
||||
|
||||
}
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
public dynamic ImportSubTree(ImportSubTreeCompositionData compositionData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.ImportSubTree(compositionData.targetTreeId,compositionData.anchorPersonId,compositionData.data);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
||||
[HttpPost]
|
||||
public dynamic ListBackups(string treeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.ListBackups(treeId);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class RestoreBackupCompositionData
|
||||
{
|
||||
public string targetTreeId { get; set; }
|
||||
public string backupFileName { get; set; }
|
||||
|
||||
}
|
||||
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
public dynamic RestoreBackup(RestoreBackupCompositionData compositionData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var result = familyTreeService.RestoreBackup(compositionData.targetTreeId,compositionData.backupFileName);
|
||||
return result;
|
||||
}
|
||||
catch (ValidatedException vex)
|
||||
{
|
||||
return vex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ServiceErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,13 @@
|
||||
"DescKey": "052636a8b1469efdf5dc0034a3c5bb34",
|
||||
"DefaultActor": "VIEW_SYSTEM"
|
||||
},
|
||||
"NetDiskQuota": {
|
||||
"//": "网盘额度,按 security_user.user_type 取:U=未认证/N=普通用户/V=VIP/S=SVIP;值支持 T/G/M/K 单位(大小写兼容),解析后换算为 KB(dms_file.file_size 单位即 KB)",
|
||||
"U": "2G",
|
||||
"N": "100G",
|
||||
"V": "500G",
|
||||
"S": "1T"
|
||||
},
|
||||
"IpRateLimiting": {
|
||||
"EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each
|
||||
"StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter
|
||||
|
||||
@@ -553,3 +553,16 @@ left join dms_folder_delete_log dd with(nolock) on dms.file_path=dd.folder_name
|
||||
GO
|
||||
|
||||
|
||||
-- ==============================================================================================
|
||||
-- [备案] dms_file_usage_view —— 按用户(ower_id)分组统计网盘已用容量(dashboard 用量卡片 / 上传额度闸门)
|
||||
-- 真源在线上 MySQL(nas.youjiala.com:3307/Furion);上方为 SQL Server 建表脚本,此段仅归档留底,勿在此执行。
|
||||
-- 口径:ower_id=登录用户(=security_user.user_name),仅计非目录行(is_directory_indc='N'),file_size 单位 KB,SUM 转 SIGNED 防 int 溢出。
|
||||
-- MySQL DDL:
|
||||
-- CREATE OR REPLACE VIEW dms_file_usage_view AS
|
||||
-- SELECT ower_id,
|
||||
-- COUNT(*) AS file_count,
|
||||
-- CAST(SUM(CASE WHEN is_directory_indc='N' THEN file_size ELSE 0 END) AS SIGNED) AS used_kb
|
||||
-- FROM dms_file GROUP BY ower_id;
|
||||
-- ==============================================================================================
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ export const ADMIN_FORM_KIND = {
|
||||
TEXTAREA: "textarea",
|
||||
SWITCH: "switch",
|
||||
DATE: "date",
|
||||
SELECT: "select",
|
||||
} as const;
|
||||
|
||||
type FormKinds = typeof ADMIN_FORM_KIND;
|
||||
@@ -134,6 +135,8 @@ export interface AdminFormField {
|
||||
/** 只读模式按日期显示:true 取 yyyy-MM-dd,"datetime" 带时分秒 */
|
||||
date?: boolean | "datetime";
|
||||
maxlength?: number;
|
||||
/** type 为 select 时的候选项(label 展示、value 落库) */
|
||||
options?: AdminFilterChoice[];
|
||||
}
|
||||
|
||||
/** 详情页的一张卡片(旧 ft-card 的等价物) */
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 用户身份徽标字形:登录用户「未认证 / 普通用户 / VIP / SVIP」四类身份的小图标与配色。
|
||||
* uview 图标集无皇冠/盾牌等语义图形,故沿用 brand.ts 的内联 SVG data URI 套路(跨端安全)。
|
||||
* 图标统一白色描边/填充,压在各自配色的圆角胶囊上;普通用户跟随主题(--fg-gradient 兜底)。
|
||||
*/
|
||||
|
||||
/** 未认证:盾牌 + 问号(灰) */
|
||||
const unauthGlyph = `data:image/svg+xml,${encodeURIComponent(
|
||||
[
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='#ffffff' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'>",
|
||||
"<path d='M12 3 5 6v5c0 4.4 3 7.4 7 8.8 4-1.4 7-4.4 7-8.8V6l-7-3z'/>",
|
||||
"<path d='M9.7 9.3a2.3 2.3 0 1 1 3.1 2.2c-.7.3-.9.7-.9 1.5'/>",
|
||||
"<circle cx='11.9' cy='16.3' r='0.9' fill='#ffffff' stroke='none'/>",
|
||||
"</svg>",
|
||||
].join(""),
|
||||
)}`;
|
||||
|
||||
/** 普通用户:人像 + 对勾(跟随主题绿) */
|
||||
const normalGlyph = `data:image/svg+xml,${encodeURIComponent(
|
||||
[
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='#ffffff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'>",
|
||||
"<circle cx='9.5' cy='8' r='3.2'/>",
|
||||
"<path d='M4 19c0-3 2.5-5 5.5-5 1 0 2 .2 2.8.7'/>",
|
||||
"<path d='M13.8 17.2 15.8 19.2 20 15'/>",
|
||||
"</svg>",
|
||||
].join(""),
|
||||
)}`;
|
||||
|
||||
/** VIP:三尖皇冠 + 底座(金) */
|
||||
const vipGlyph = `data:image/svg+xml,${encodeURIComponent(
|
||||
[
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='#ffffff'>",
|
||||
"<path d='M4 8 8 11 12 6 16 11 20 8 18.5 16.5h-13z'/>",
|
||||
"<rect x='5' y='17.4' width='14' height='2.2' rx='1.1'/>",
|
||||
"</svg>",
|
||||
].join(""),
|
||||
)}`;
|
||||
|
||||
/** SVIP:三尖皇冠 + 顶部四角星(紫,比 VIP 多一颗星以示尊贵) */
|
||||
const svipGlyph = `data:image/svg+xml,${encodeURIComponent(
|
||||
[
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='#ffffff'>",
|
||||
"<path d='M12 1.8 12.9 3.9 15 4.8 12.9 5.7 12 7.8 11.1 5.7 9 4.8 11.1 3.9z'/>",
|
||||
"<path d='M4 9.5 8 12.3 12 7.8 16 12.3 20 9.5 18.5 17.5h-13z'/>",
|
||||
"<rect x='5' y='18.4' width='14' height='2.2' rx='1.1'/>",
|
||||
"</svg>",
|
||||
].join(""),
|
||||
)}`;
|
||||
|
||||
/** UserType → 徽标字形 data URI(后端 UserType:U/N/V/S) */
|
||||
export const USER_TYPE_GLYPHS: Record<string, string> = {
|
||||
U: unauthGlyph,
|
||||
N: normalGlyph,
|
||||
V: vipGlyph,
|
||||
S: svipGlyph,
|
||||
};
|
||||
|
||||
/** UserType → 胶囊底色(身份卡为统一主题绿实底,四类胶囊统一用深色半透芯片 + 白字白图标,压住深底高对比) */
|
||||
export const USER_TYPE_PILL_BG: Record<string, string> = {
|
||||
U: "rgba(0, 0, 0, 0.16)",
|
||||
N: "rgba(0, 0, 0, 0.16)",
|
||||
V: "rgba(0, 0, 0, 0.16)",
|
||||
S: "rgba(0, 0, 0, 0.16)",
|
||||
};
|
||||
|
||||
/** 取字形 data URI,未知类型回退普通用户 */
|
||||
export function userTypeGlyph(type?: string): string {
|
||||
return USER_TYPE_GLYPHS[type ?? ""] ?? normalGlyph;
|
||||
}
|
||||
|
||||
/** 取胶囊底色,未知类型回退普通用户 */
|
||||
export function userTypePillBg(type?: string): string {
|
||||
return USER_TYPE_PILL_BG[type ?? ""] ?? USER_TYPE_PILL_BG.N;
|
||||
}
|
||||
@@ -72,6 +72,9 @@ function displayValue(field: AdminFormField): string {
|
||||
if (field.display) {
|
||||
return field.display(props.model) || empty;
|
||||
}
|
||||
if (field.type === "select") {
|
||||
return selectLabel(field) || empty;
|
||||
}
|
||||
const raw = rawValue(field);
|
||||
if (raw === null || raw === undefined || raw === "") {
|
||||
return empty;
|
||||
@@ -82,6 +85,30 @@ function displayValue(field: AdminFormField): string {
|
||||
return String(raw);
|
||||
}
|
||||
|
||||
/** select 候选:无 options 时给空数组,避免模板 range 报错 */
|
||||
function selectOptions(field: AdminFormField) {
|
||||
return field.options ?? [];
|
||||
}
|
||||
|
||||
/** select 当前值对应的展示文案(找不到返回空) */
|
||||
function selectLabel(field: AdminFormField): string {
|
||||
const cur = String(rawValue(field) ?? "");
|
||||
return selectOptions(field).find(o => o.value === cur)?.label ?? "";
|
||||
}
|
||||
|
||||
/** select 当前值在候选中的下标(找不到回退 0,picker 需合法 index) */
|
||||
function selectIndex(field: AdminFormField): number {
|
||||
const cur = String(rawValue(field) ?? "");
|
||||
const i = selectOptions(field).findIndex(o => o.value === cur);
|
||||
return i < 0 ? 0 : i;
|
||||
}
|
||||
|
||||
function onSelectChange(field: AdminFormField, event: any): void {
|
||||
const idx = Number(event?.detail?.value ?? 0);
|
||||
const opt = selectOptions(field)[idx];
|
||||
setInputValue(field, opt ? opt.value : "");
|
||||
}
|
||||
|
||||
/** 编辑态控件的值:统一成字符串,switch 例外(u-switch 只吃布尔) */
|
||||
function inputValue(field: AdminFormField): string {
|
||||
const raw = rawValue(field);
|
||||
@@ -178,6 +205,16 @@ function onTapAction(action: AdminFormAction): void {
|
||||
<u-icon name="arrow-right" size="24" color="#c4c8cf" />
|
||||
</view>
|
||||
</picker>
|
||||
<picker v-else-if="field.type === 'select'" mode="selector" :range="selectOptions(field)"
|
||||
range-key="label" :value="selectIndex(field)" :disabled="field.lock"
|
||||
@change="onSelectChange(field, $event)">
|
||||
<view class="picker-box" :class="{ 'is-empty': !selectLabel(field) }">
|
||||
<text>
|
||||
{{ selectLabel(field) || field.placeholder || t('AdminPage.notSetTip') }}
|
||||
</text>
|
||||
<u-icon name="arrow-right" size="24" color="#c4c8cf" />
|
||||
</view>
|
||||
</picker>
|
||||
<!-- uview-pro 的 u-input border 是布尔,不是旧 uview 的 'surround' 字符串 -->
|
||||
<u-input v-else :model-value="inputValue(field)" :type="field.type || 'text'"
|
||||
:disabled="field.lock" :border="false" input-align="right"
|
||||
|
||||
@@ -13,9 +13,13 @@ import type { FamilyPersonDisplayData } from "@/data/auto/familyPersonDisplayDat
|
||||
import type { AdminRow } from "@/admin/admin-types";
|
||||
import type { ExchangeScope } from "@/composables/useFamilyTreeExchange";
|
||||
import type { FamilyTreeExchangeFileInfo } from "@/data/auto/familyTreeExchangeFileInfo";
|
||||
import { StorageUsageData } from "@/data/auto/storageUsageData";
|
||||
import { useLocale } from "uview-pro";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useThemeGradient, useThemeTokens } from "@/composables";
|
||||
import { brandGlyph } from "@/common/brand";
|
||||
import { buildChunkFileName, uploadFile } from "@/common/http.interceptor";
|
||||
import { userTypeGlyph, userTypePillBg } from "@/common/userTypeIcons";
|
||||
import { useIdCardVerify, useThemeGradient, useThemeTokens } from "@/composables";
|
||||
import { formatFileSize, formatFileTime, useFamilyTreeExchange } from "@/composables/useFamilyTreeExchange";
|
||||
import { usePersonPickConfig } from "@/composables/usePickerConfigs";
|
||||
import { usePolicyOptions } from "@/composables/usePolicyOptions";
|
||||
@@ -31,6 +35,8 @@ import { FamilyTreeSpouseMapViewEntity } from "@/data/auto/familyTreeSpouseMapVi
|
||||
import { FamilyTreeViewEntity } from "@/data/auto/familyTreeViewEntity";
|
||||
import familyPersonService from "@/service/master/familyPersonService";
|
||||
import familyTreeService from "@/service/master/familyTreeService";
|
||||
import dmsFileService from "@/service/master/dmsFileService";
|
||||
import { useLoginProfileStore } from "@/stores";
|
||||
|
||||
/** ready:组件挂载完成通知(时序口径见文件底部 onMounted 注释) */
|
||||
const emit = defineEmits<{ (e: "ready"): void }>();
|
||||
@@ -74,6 +80,117 @@ const inDetail = ref(false);
|
||||
/** 列表整体收起态:卡区缩成一条窄横条(伸缩钮在列表右缘) */
|
||||
const listCollapsed = ref(false);
|
||||
|
||||
// ===== 顶部两张卡片:登录用户身份 + 网盘用量(列表态,静默拉取,失败不阻断族谱列表) =====
|
||||
const loginProfile = useLoginProfileStore();
|
||||
const displayName = computed(() => loginProfile.userLocalName || loginProfile.username || "");
|
||||
const storage = ref<StorageUsageData>(new StorageUsageData());
|
||||
/** 当前用户类型:优先异步用量快照,未就绪时回退登录档案同步值,保证首帧徽标/文字即为真实等级 */
|
||||
const currentType = computed(() => storage.value.UserType || loginProfile.userType);
|
||||
const userTypeText = computed(() => {
|
||||
const map: Record<string, string> = {
|
||||
U: "storage.typeUnauth",
|
||||
N: "storage.typeNormal",
|
||||
V: "storage.typeVip",
|
||||
S: "storage.typeSvip",
|
||||
};
|
||||
return t(map[currentType.value] ?? "storage.typeNormal");
|
||||
});
|
||||
// 后端 file_size/额度均为 KB,formatFileSize 期望字节 → ×1024 对齐
|
||||
const storageUsedText = computed(() => formatFileSize(storage.value.UsedKB * 1024));
|
||||
const storageQuotaText = computed(() => storage.value.QuotaKB > 0 ? formatFileSize(storage.value.QuotaKB * 1024) : "-");
|
||||
const storageOver = computed(() => storage.value.QuotaKB > 0 && storage.value.UsedKB > storage.value.QuotaKB);
|
||||
/** 占比在前端按小数重算(后端 Percent 为整数会截断成 0),极小用量也能如实显示 */
|
||||
const storagePercentNum = computed(() => (storage.value.QuotaKB > 0 ? (storage.value.UsedKB / storage.value.QuotaKB) * 100 : 0));
|
||||
const storagePercentText = computed(() => {
|
||||
const v = storagePercentNum.value;
|
||||
if (v <= 0) {
|
||||
return "0%";
|
||||
}
|
||||
if (v < 0.1) {
|
||||
return "0.1%";
|
||||
}
|
||||
if (v < 10) {
|
||||
return `${v.toFixed(1)}%`;
|
||||
}
|
||||
return `${Math.round(v)}%`;
|
||||
});
|
||||
/** 进度条宽度:按重算占比取区间;有用量但占比极小时给 2% 最小可见宽度,避免完全空条 */
|
||||
const storageBarWidth = computed(() => {
|
||||
const clamped = Math.min(Math.max(storagePercentNum.value, 0), 100);
|
||||
const min = storage.value.UsedKB > 0 ? 2 : 0;
|
||||
return `${Math.max(clamped, min)}%`;
|
||||
});
|
||||
/** 身份徽标字形与胶囊底色:随 UserType(U/N/V/S)切换,未认证灰、普通跟随主题、VIP 金、SVIP 紫 */
|
||||
const userTypeIcon = computed(() => userTypeGlyph(currentType.value));
|
||||
const userTypeBg = computed(() => userTypePillBg(currentType.value));
|
||||
/** 网盘存储卡图标:内联云形 SVG(同 treeGlyph 套路),绿描边置于柔光圆内(存储卡为浅色渐变描边底) */
|
||||
const cloudGlyph = `data:image/svg+xml,${encodeURIComponent([
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='#2f9e6b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'>",
|
||||
"<path d='M6.8 18.5a4.3 4.3 0 0 1-.5-8.56 5.6 5.6 0 0 1 10.75-1.06A3.9 3.9 0 0 1 17.4 18.5z'/>",
|
||||
"<path d='M9.5 14.2l1.9 1.9 3.6-3.9'/>",
|
||||
"</svg>",
|
||||
].join(""))}`;
|
||||
|
||||
/** 未认证底部弹层:单击「未认证」徽标从底部弹出身份证认证,复用 useIdCardVerify(与身份验证页同一套流程) */
|
||||
const idPopup = ref(false);
|
||||
const {
|
||||
imageUrl: idvImage,
|
||||
uploading: idvUploading,
|
||||
isVerified: idvVerified,
|
||||
buttonText: idvButtonText,
|
||||
onUploadIdCard,
|
||||
} = useIdCardVerify(() => {
|
||||
idPopup.value = false;
|
||||
void fetchStorage();
|
||||
});
|
||||
/** 仅未认证(U)可单击弹层去认证,其余身份为只读展示 */
|
||||
function onTapUserType(): void {
|
||||
if (currentType.value === "U") {
|
||||
idPopup.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchStorage(): Promise<void> {
|
||||
try {
|
||||
const res = await dmsFileService.GetMyStorageUsage();
|
||||
if (res) storage.value = res;
|
||||
}
|
||||
catch { /* 静默:卡片留占位,不打扰族谱列表主流程 */ }
|
||||
}
|
||||
|
||||
/** 点头像上传当前用户头像:单图 -> /DmsFile/UploadUserAvatar(后端落盘 UserAvatar 目录并回写 user_icon_img_path)-> 成功后重拉用量刷新卡片 */
|
||||
const avatarUploading = ref(false);
|
||||
function onUploadAvatar(): void {
|
||||
if (avatarUploading.value) {
|
||||
return;
|
||||
}
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: async (res: any) => {
|
||||
const filePath = String(res?.tempFilePaths?.[0] ?? "");
|
||||
const fileName = String(res?.tempFiles?.[0]?.name || `avatar-${Date.now()}.png`);
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
avatarUploading.value = true;
|
||||
await uploadFile({
|
||||
url: "/DmsFile/UploadUserAvatar",
|
||||
filePath,
|
||||
name: fileName,
|
||||
fileName: buildChunkFileName(fileName),
|
||||
});
|
||||
await fetchStorage();
|
||||
uni.showToast({ title: t("storage.avatarUploadedTip"), icon: "none" });
|
||||
}
|
||||
catch { /* uploadFile 已统一弹错,这里只补一个失败落点 */ }
|
||||
finally {
|
||||
avatarUploading.value = false;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** 关键字过滤:族谱名称/简介 前端包含匹配(列表量级小,不再走后端筛选链) */
|
||||
const filteredTrees = computed(() => {
|
||||
const kw = keyword.value.trim().toLowerCase();
|
||||
@@ -1366,18 +1483,67 @@ defineExpose({
|
||||
reloadIfList(): void {
|
||||
if (!inDetail.value) {
|
||||
loadTrees();
|
||||
void fetchStorage();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 列表态显示 tabbar,进详情(或弹层展开)收起 -->
|
||||
<app-page :hide-nav="true" :show-tabbar="!inDetail">
|
||||
<!-- 列表态显示 tabbar,进详情(或弹层展开)收起;未认证底部弹层也在列表态弹出,须一并隐 tabbar,否则盖住底部按钮 -->
|
||||
<app-page :hide-nav="true" :show-tabbar="!inDetail && !idPopup">
|
||||
<view class="tree-page" :style="[{ background: themeBackground }, themeVars]">
|
||||
<!-- ===== 列表态:软底分区面板(标题 + 搜索/新建/伸缩圆钮组 + 白底族谱卡) ===== -->
|
||||
<!-- 隐藏原生滚动条:否则 Chrome 滚动条占右侧 ~17px,面板左右留白不对称 -->
|
||||
<scroll-view v-if="!inDetail" scroll-y :show-scrollbar="false" class="tree-page__body tree-page__body--list">
|
||||
<!-- ===== 顶部两张卡片:用户身份 + 网盘用量 ===== -->
|
||||
<view class="home-cards">
|
||||
<view class="home-card home-card--user">
|
||||
<view class="home-card__sheen" />
|
||||
<view class="home-card__glow" />
|
||||
<image class="home-card__mark" :src="brandGlyph" mode="aspectFit" />
|
||||
<view class="home-card__avatar" @tap="onUploadAvatar">
|
||||
<image v-if="storage.AvatarUrl" class="home-card__avatar-img" :src="storage.AvatarUrl"
|
||||
mode="aspectFill" />
|
||||
<text v-else class="home-card__avatar-ph">{{ displayName ? displayName.slice(0, 1) : "?" }}</text>
|
||||
<view class="home-card__avatar-cam">
|
||||
<u-icon name="camera-fill" size="24" color="#ffffff" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="home-card__uinfo">
|
||||
<view class="home-card__uname-row">
|
||||
<text class="home-card__uname">{{ displayName || "-" }}</text>
|
||||
<view class="home-card__utype" :class="{ 'home-card__utype--tap': currentType === 'U' }"
|
||||
:style="{ background: userTypeBg }" @tap="onTapUserType">
|
||||
<image class="home-card__utype-icon" :src="userTypeIcon" mode="aspectFit" />
|
||||
<text class="home-card__utype-text">{{ userTypeText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="home-card__welcome">{{ t("storage.welcome") }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="home-card home-card--storage">
|
||||
<view class="home-card__sglow" />
|
||||
<view class="home-card__srow">
|
||||
<view class="home-card__stitle-wrap">
|
||||
<view class="home-card__sicon">
|
||||
<image class="home-card__sicon-img" :src="cloudGlyph" mode="aspectFit" />
|
||||
</view>
|
||||
<text class="home-card__stitle">{{ t("storage.title") }}</text>
|
||||
</view>
|
||||
<text class="home-card__spct" :class="{ 'home-card__spct--over': storageOver }">{{ storagePercentText
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="home-card__bar">
|
||||
<view class="home-card__bar-fill" :class="{ 'home-card__bar-fill--over': storageOver }"
|
||||
:style="{ width: storageBarWidth }" />
|
||||
</view>
|
||||
<view class="home-card__snums">
|
||||
<text class="home-card__snum">{{ t("storage.used") }} {{ storageUsedText }}</text>
|
||||
<text class="home-card__snum">{{ t("storage.total") }} {{ storageQuotaText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="tree-panel">
|
||||
<view class="tree-panel__head">
|
||||
<text class="tree-panel__title">{{ t("FamilyTreePage.listTitle") }}</text>
|
||||
@@ -1462,7 +1628,7 @@ defineExpose({
|
||||
<u-switch v-if="data.IsManager" :model-value="tree.PublicIndc === 'Y'" size="40"
|
||||
:active-color="primary" @change="onPublicToggle" />
|
||||
<text v-if="data.IsManager" class="ft-badge ft-badge--admin">{{ t("FamilyTreePage.managerTag")
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -1569,7 +1735,7 @@ defineExpose({
|
||||
<!-- 当前族员:从概览移入,夫妻/子女列表都是相对此人 -->
|
||||
<view v-if="loaded && currentPerson" class="ft-card">
|
||||
<view class="ft-card__head"><text class="ft-card__title">{{ t("FamilyTreePage.currentPerson")
|
||||
}}</text></view>
|
||||
}}</text></view>
|
||||
<view class="person-hero">
|
||||
<view class="person-hero__avatar"
|
||||
:style="avatarFallbackStyle(!!currentPerson?.AvatarUrl, currentPerson?.Gender)">
|
||||
@@ -1584,7 +1750,7 @@ defineExpose({
|
||||
</view>
|
||||
<view class="person-hero__chips">
|
||||
<text v-if="currentPerson?.PersonId" class="person-hero__chip">{{ personChipText(currentPerson)
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -1627,12 +1793,12 @@ defineExpose({
|
||||
<!-- 新增入口与行尾操作同一把闸:当前锚点不可编(未绑定/出支系)时隐藏 -->
|
||||
<view class="ft-card__head">
|
||||
<view class="ft-card__title-group"><text class="ft-card__title">{{ t("FamilyTreePage.spouseTitle")
|
||||
}}</text><text class="ft-card__count">{{ spouseMaps.length }}</text></view>
|
||||
}}</text><text class="ft-card__count">{{ spouseMaps.length }}</text></view>
|
||||
<view v-if="data.IsCanAmend" class="ft-card__add" @tap="openQuickCreate('spouse')"><u-icon
|
||||
name="plus" size="26" :color="primary" /><text>{{ t("FamilyTreePage.addSpouse") }}</text></view>
|
||||
</view>
|
||||
<view v-if="!visibleSpouses.length" class="ft-empty"><text>{{ t("FamilyTreePage.spouseEmpty")
|
||||
}}</text></view>
|
||||
}}</text></view>
|
||||
<view v-for="record in visibleSpouses" :key="record.SpouseId" class="ft-mrow">
|
||||
<view class="ft-av"
|
||||
:style="avatarFallbackStyle(!!personAvatar(record.SpouseId), personGender(record.SpouseId, record.Gender))">
|
||||
@@ -1668,13 +1834,13 @@ defineExpose({
|
||||
<view class="ft-card">
|
||||
<view class="ft-card__head">
|
||||
<view class="ft-card__title-group"><text class="ft-card__title">{{ t("FamilyTreePage.childTitle")
|
||||
}}</text><text class="ft-card__count">{{ childMaps.length }}</text></view>
|
||||
}}</text><text class="ft-card__count">{{ childMaps.length }}</text></view>
|
||||
<view v-if="data.IsCanAmend" class="ft-card__add" @tap="openQuickCreate('child')"><u-icon
|
||||
name="plus" size="26" :color="primary" /><text>{{ t("FamilyTreePage.addChildBtn") }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!visibleChildren.length" class="ft-empty"><text>{{ t("FamilyTreePage.childEmpty")
|
||||
}}</text></view>
|
||||
}}</text></view>
|
||||
<view v-for="record in visibleChildren" :key="record.ChildrenId" class="ft-mrow">
|
||||
<view class="ft-av"
|
||||
:style="avatarFallbackStyle(!!personAvatar(record.ChildrenId), personGender(record.ChildrenId, record.Gender))">
|
||||
@@ -1714,12 +1880,12 @@ defineExpose({
|
||||
<view v-if="data.IsManager && pendingPermissions.length" class="ft-card">
|
||||
<view class="ft-card__head">
|
||||
<view class="ft-card__title-group"><text class="ft-card__title">{{ t("FamilyTreePage.permPending")
|
||||
}}</text><text class="ft-card__count">{{ pendingPermissions.length }}</text></view>
|
||||
}}</text><text class="ft-card__count">{{ pendingPermissions.length }}</text></view>
|
||||
</view>
|
||||
<view v-for="record in pendingPermissions" :key="record.UserName" class="ft-perm-row">
|
||||
<view class="ft-perm-row__main"><text class="ft-perm-row__name">{{ record.UserLocalName ||
|
||||
record.UserName
|
||||
}}</text><text v-if="record.PersonLocalName" class="ft-perm-row__sub">{{ record.PersonLocalName
|
||||
}}</text><text v-if="record.PersonLocalName" class="ft-perm-row__sub">{{ record.PersonLocalName
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="ft-perm-ops">
|
||||
@@ -1738,14 +1904,14 @@ defineExpose({
|
||||
<view v-if="data.IsManager" class="ft-card">
|
||||
<view class="ft-card__head">
|
||||
<view class="ft-card__title-group"><text class="ft-card__title">{{ t("FamilyTreePage.permManager")
|
||||
}}</text><text class="ft-card__count">{{ managerPermissions.length }}</text></view>
|
||||
}}</text><text class="ft-card__count">{{ managerPermissions.length }}</text></view>
|
||||
</view>
|
||||
<view v-if="!managerPermissions.length" class="ft-empty"><text>{{ t("FamilyTreePage.permEmpty")
|
||||
}}</text></view>
|
||||
}}</text></view>
|
||||
<view v-for="record in managerPermissions" :key="record.UserName" class="ft-perm-row">
|
||||
<view class="ft-perm-row__main"><text class="ft-perm-row__name">{{ record.UserLocalName ||
|
||||
record.UserName
|
||||
}}</text><text class="ft-perm-row__sub">{{ record.ManagerIndc === "Y" ?
|
||||
}}</text><text class="ft-perm-row__sub">{{ record.ManagerIndc === "Y" ?
|
||||
t("FamilyTreePage.managerTag") :
|
||||
t("FamilyTreePage.memberTag") }}</text></view>
|
||||
<view class="ft-perm-ops">
|
||||
@@ -1976,7 +2142,7 @@ defineExpose({
|
||||
<view class="person-hero__line">
|
||||
<text class="rel-name">{{ record.SpouseSurname }}{{ record.SpouseGenealogyName }}</text>
|
||||
<text class="person-hero__gender">{{ genderText(personGender(record.SpouseId, record.Gender))
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="person-hero__chips">
|
||||
<text class="person-hero__chip">
|
||||
@@ -2013,7 +2179,7 @@ defineExpose({
|
||||
<text class="sub-label">{{ t("FamilyTreePage.marryDate") }}</text>
|
||||
<view class="sub-picker">
|
||||
<text class="sub-picker-text">{{ datePart(record.MarryDate) || t("AdminPage.notSetTip")
|
||||
}}</text>
|
||||
}}</text>
|
||||
<u-icon name="arrow-right" size="24" color="#c4c8cf" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -2029,7 +2195,7 @@ defineExpose({
|
||||
<view class="sub-picker">
|
||||
<text class="sub-picker-text">{{
|
||||
datePart(record.DivorceDate) || t("AdminPage.notSetTip")
|
||||
}}</text>
|
||||
}}</text>
|
||||
<u-icon name="arrow-right" size="24" color="#c4c8cf" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -2115,7 +2281,7 @@ defineExpose({
|
||||
<view class="person-hero__line">
|
||||
<text class="rel-name">{{ record.ChildrenSurname }}{{ record.ChildrenGenealogyName }}</text>
|
||||
<text class="person-hero__gender">{{ genderText(personGender(record.ChildrenId, record.Gender))
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="person-hero__chips">
|
||||
<text class="person-hero__chip">
|
||||
@@ -2226,7 +2392,7 @@ defineExpose({
|
||||
<text class="rel-name">{{ record.UserLocalName || record.UserName }}</text>
|
||||
<text class="rel-sub">{{
|
||||
record.ManagerIndc === "Y" ? t("FamilyTreePage.managerTag") : t("FamilyTreePage.memberTag")
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="perm-ops">
|
||||
<view class="perm-op perm-op--danger" @tap="rejectPermission(record)">
|
||||
@@ -2283,6 +2449,38 @@ defineExpose({
|
||||
|
||||
<!-- 族人档案弹层已取消:始祖卡单击不再弹窗,编辑走卡头「编辑资料」文字链 -->
|
||||
|
||||
<!-- ===== 未认证底部弹层:单击「未认证」徽标从底部弹出身份证认证(与身份验证页共用 useIdCardVerify) ===== -->
|
||||
<u-popup :model-value="idPopup" mode="bottom" round="24" @close="idPopup = false">
|
||||
<view class="ft-sheet">
|
||||
<view class="ft-sheet__head">
|
||||
<text class="ft-sheet__title">{{ t("IdentityVerificationPage.title") }}</text>
|
||||
<u-icon name="close" size="32" color="#8f959e" @click="idPopup = false" />
|
||||
</view>
|
||||
<text class="home-verify__intro">{{ t("IdentityVerificationPage.intro") }}</text>
|
||||
<view v-if="idvVerified" class="home-verify__verified">
|
||||
<u-icon name="checkmark-circle-fill" size="70" color="#52c41a" />
|
||||
<text class="home-verify__verified-text">{{ t("IdentityVerificationPage.verifiedDone") }}</text>
|
||||
</view>
|
||||
<template v-else>
|
||||
<view class="home-verify__thumb" @tap="onUploadIdCard">
|
||||
<image v-if="idvImage" class="home-verify__thumb-img" :src="idvImage" mode="aspectFill" />
|
||||
<view v-else class="home-verify__empty">
|
||||
<u-icon name="camera" size="44" color="#c4c8cf" />
|
||||
<text class="home-verify__empty-text">{{ t("IdentityVerificationPage.uploadBut") }}</text>
|
||||
</view>
|
||||
<view v-if="idvUploading" class="home-verify__mask">
|
||||
<text class="home-verify__mask-text">{{ t("IdentityVerificationPage.uploadingTip") }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="ft-sheet__foot">
|
||||
<view class="ft-sheet__btn" @tap="idPopup = false"><text>{{ t("AdminPage.cancelBut") }}</text></view>
|
||||
<view class="ft-sheet__btn ft-sheet__btn--primary" @tap="onUploadIdCard"><text>{{ idvButtonText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</u-popup>
|
||||
|
||||
<!-- ===== 编辑族谱信息弹层(仅名称/始祖谱名/简介/公开四字段,关系与成员分开维护) ===== -->
|
||||
<!-- ===== 交换文件导出弹层(信封加密在前端,密码只当密钥材料、后端不校验)===== -->
|
||||
<u-popup :model-value="exportVisible" mode="bottom" round="24" @close="exportVisible = false">
|
||||
@@ -2371,7 +2569,7 @@ defineExpose({
|
||||
<!-- 服务器文件列表限高滚动:文件多了不挤掉密码框/警告/按钮 -->
|
||||
<scroll-view v-if="!localFileName" scroll-y class="ft-exchange__list">
|
||||
<view v-if="importFilesLoading" class="ft-empty"><text>{{ t("FamilyTreePage.exchangeFileLoading")
|
||||
}}</text></view>
|
||||
}}</text></view>
|
||||
<view v-else-if="!importFiles.length" class="ft-empty"><text>{{ t(imScope === "SUB" ?
|
||||
"FamilyTreePage.exchangeFileEmptySub" : "FamilyTreePage.exchangeFileEmpty") }}</text></view>
|
||||
<view v-for="file in importFiles" :key="file.FileName" class="ft-exchange__row"
|
||||
@@ -2392,7 +2590,7 @@ defineExpose({
|
||||
<view v-if="backupLoading" class="ft-empty"><text>{{ t("FamilyTreePage.exchangeFileLoading") }}</text>
|
||||
</view>
|
||||
<view v-else-if="!backupFiles.length" class="ft-empty"><text>{{ t("FamilyTreePage.exchangeBackupEmpty")
|
||||
}}</text></view>
|
||||
}}</text></view>
|
||||
<view v-for="bk in backupFiles" :key="bk.FileName" class="ft-exchange__row"
|
||||
:class="{ 'ft-exchange__row--on': pickedBackup === bk.FileName }" @tap="pickedBackup = bk.FileName">
|
||||
<view class="ft-exchange__row-main">
|
||||
@@ -2458,7 +2656,7 @@ defineExpose({
|
||||
<view class="ft-sheet__foot">
|
||||
<view class="ft-sheet__btn" @tap="cancelTreeEdit"><text>{{ t("AdminPage.cancelBut") }}</text></view>
|
||||
<view class="ft-sheet__btn ft-sheet__btn--primary" @tap="saveTreeEdit"><text>{{ t("AdminPage.saveBut")
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -2507,6 +2705,350 @@ defineExpose({
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
/* ===== 顶部两张卡片:用户身份 + 网盘用量(白底圆角,与下方族谱面板同宽同调) ===== */
|
||||
.home-cards {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
margin: 0 0 22rpx;
|
||||
}
|
||||
|
||||
.home-card {
|
||||
box-sizing: border-box;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 24rpx;
|
||||
border-radius: 32rpx;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.home-card--user {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 30rpx;
|
||||
min-height: 236rpx;
|
||||
padding: 48rpx 44rpx;
|
||||
border-radius: 40rpx;
|
||||
background: var(--fg-gradient, linear-gradient(135deg, #2f9e6b 0%, #1f7d55 55%, #14664a 100%));
|
||||
box-shadow: 0 20rpx 48rpx rgba(0, 0, 0, 0.26), inset 0 2rpx 0 rgba(255, 255, 255, 0.30);
|
||||
}
|
||||
|
||||
/* 装饰层:斜向高光 + 右上柔光圆 + 品牌水印,纯装饰不拦截点击 */
|
||||
.home-card__sheen {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -30%;
|
||||
width: 55%;
|
||||
height: 100%;
|
||||
background: linear-gradient(115deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0));
|
||||
transform: skewX(-18deg);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-card__glow {
|
||||
position: absolute;
|
||||
top: -70rpx;
|
||||
right: -50rpx;
|
||||
width: 240rpx;
|
||||
height: 240rpx;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-card__mark {
|
||||
position: absolute;
|
||||
right: 24rpx;
|
||||
bottom: 18rpx;
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
opacity: 0.14;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-card__avatar {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
width: 128rpx;
|
||||
height: 128rpx;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
border: 4rpx solid rgba(255, 255, 255, 0.75);
|
||||
box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.20);
|
||||
}
|
||||
|
||||
.home-card__avatar-img {
|
||||
width: 128rpx;
|
||||
height: 128rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.home-card__avatar-cam {
|
||||
position: absolute;
|
||||
right: 2rpx;
|
||||
bottom: 2rpx;
|
||||
width: 44rpx;
|
||||
height: 44rpx;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
border: 2rpx solid #ffffff;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-card__avatar-ph {
|
||||
font-size: 60rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.home-card__uinfo {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.home-card__uname-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.home-card__uname {
|
||||
max-width: 340rpx;
|
||||
font-size: 42rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.home-card__welcome {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.home-card__utype {
|
||||
display: flex;
|
||||
align-self: center;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
padding: 7rpx 22rpx 7rpx 16rpx;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.5);
|
||||
border-radius: 999rpx;
|
||||
font-size: 26rpx;
|
||||
color: #ffffff;
|
||||
background: var(--fg-primary, #d98a3d);
|
||||
}
|
||||
|
||||
.home-card__utype--tap {
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.home-card__utype-icon {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.home-card__utype-text {
|
||||
color: #ffffff;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* 未认证底部弹层:身份证缩略图与说明(复用 ft-sheet 头部/底部按钮) */
|
||||
.home-verify__intro {
|
||||
margin-bottom: 20rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
color: #9aa0a6;
|
||||
}
|
||||
|
||||
.home-verify__thumb {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 300rpx;
|
||||
overflow: hidden;
|
||||
border: 2rpx dashed #d6d9de;
|
||||
border-radius: 16rpx;
|
||||
background-color: #f5f6f8;
|
||||
}
|
||||
|
||||
.home-verify__thumb-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.home-verify__empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.home-verify__empty-text {
|
||||
font-size: 26rpx;
|
||||
color: #9aa0a6;
|
||||
}
|
||||
|
||||
.home-verify__mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.home-verify__mask-text {
|
||||
font-size: 24rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.home-verify__verified {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
padding: 48rpx 0;
|
||||
}
|
||||
|
||||
.home-verify__verified-text {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.home-card--storage {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin: 0 16rpx;
|
||||
padding: 40rpx 44rpx;
|
||||
border: 2rpx solid transparent;
|
||||
border-radius: 40rpx;
|
||||
background:
|
||||
linear-gradient(135deg, #ffffff 0%, #f1f7f3 100%) padding-box,
|
||||
linear-gradient(135deg, rgba(47, 158, 107, 0.55), rgba(47, 158, 107, 0.05)) border-box;
|
||||
box-shadow: 0 16rpx 40rpx rgba(31, 45, 38, 0.10), inset 0 2rpx 0 rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.home-card__sglow {
|
||||
position: absolute;
|
||||
top: -60rpx;
|
||||
right: -40rpx;
|
||||
z-index: 0;
|
||||
width: 220rpx;
|
||||
height: 220rpx;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(47, 158, 107, 0.16), rgba(47, 158, 107, 0) 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-card__stitle-wrap {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.home-card__sicon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 16rpx;
|
||||
background: var(--fg-soft, #e6f6ec);
|
||||
}
|
||||
|
||||
.home-card__sicon-img {
|
||||
width: 34rpx;
|
||||
height: 34rpx;
|
||||
}
|
||||
|
||||
.home-card__srow {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 18rpx;
|
||||
}
|
||||
|
||||
.home-card__stitle {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #1f2329;
|
||||
}
|
||||
|
||||
.home-card__spct {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: var(--fg-primary, #d98a3d);
|
||||
}
|
||||
|
||||
.home-card__spct--over {
|
||||
color: #e5484d;
|
||||
}
|
||||
|
||||
.home-card__bar {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
height: 16rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #e9edf0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.home-card__bar-fill {
|
||||
height: 100%;
|
||||
border-radius: 999rpx;
|
||||
background: linear-gradient(90deg, var(--fg-primary, #d98a3d), #f0b877);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.home-card__bar-fill--over {
|
||||
background: linear-gradient(90deg, #e5484d, #ff8a80);
|
||||
}
|
||||
|
||||
.home-card__snums {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.home-card__snum {
|
||||
font-size: 26rpx;
|
||||
color: #7a827f;
|
||||
}
|
||||
|
||||
/* ===== 列表态分区面板:主题浅底圆角,标题与圆钮组同行,白底族谱卡嵌在其中 ===== */
|
||||
.tree-panel {
|
||||
padding: 28rpx;
|
||||
|
||||
@@ -4,6 +4,7 @@ export * from "./useAdminPick";
|
||||
export * from "./useAuthGuard";
|
||||
export * from "./useDmsFiles";
|
||||
export * from "./useFamilyGroups";
|
||||
export * from "./useIdCardVerify";
|
||||
export * from "./useLang";
|
||||
export * from "./useMediaShow";
|
||||
export * from "./usePublishAlbums";
|
||||
|
||||
@@ -53,6 +53,9 @@ export function buildExportFileName(
|
||||
|
||||
/** 文件字节数友好显示(列表行小字) */
|
||||
export function formatFileSize(size: number): string {
|
||||
if (size >= 1024 * 1024 * 1024) {
|
||||
return `${(size / 1024 / 1024 / 1024).toFixed(1)} GB`;
|
||||
}
|
||||
if (size >= 1024 * 1024) {
|
||||
return `${(size / 1024 / 1024).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
import { useLocale } from "uview-pro";
|
||||
import { computed, ref } from "vue";
|
||||
import { buildChunkFileName, uploadFile } from "@/common/http.interceptor";
|
||||
import { SecurityUserDisplayData } from "@/data/auto/securityUserDisplayData";
|
||||
import securityUserService from "@/service/security/securityUserService";
|
||||
import { useLoginProfileStore } from "@/stores";
|
||||
|
||||
/** 后端 UpdateSecurityUserIdCard 会把 UserType 置为 NORMAL_USERS("N")代表已认证;此处与后端口径保持一致 */
|
||||
const NORMAL_USERS = "N";
|
||||
|
||||
/**
|
||||
* 身份证认证流程(页面与首页底部弹层共用):
|
||||
* chooseImage 单图 → 复用同源后端 DmsFile/UploadIdCardFile(后端落盘 idcard 目录 + server-to-server 调 OCR,
|
||||
* 返回带识别结果的 FamilyPersonDisplayData)→ 把「全部识别信息」格式化写入 UserRemark,昵称取身份证姓名,
|
||||
* 再调 SecurityUser/UpdateSecurityUserIdCard 落库并把 UserType 置为 NORMAL_USERS(已认证)。
|
||||
*
|
||||
* @param onSuccess 认证成功(已落库 + 本地态已同步 + 已弹 toast)后的回调:
|
||||
* 页面传「延时返回」,首页弹层传「关闭弹层 + 重拉用量」。
|
||||
*/
|
||||
export function useIdCardVerify(onSuccess?: () => void) {
|
||||
const { t } = useLocale();
|
||||
const loginProfileStore = useLoginProfileStore();
|
||||
|
||||
const imageUrl = ref("");
|
||||
const remark = ref("");
|
||||
const recognizedName = ref("");
|
||||
const uploading = ref(false);
|
||||
const saving = ref(false);
|
||||
|
||||
const busy = computed(() => uploading.value || saving.value);
|
||||
/** 已认证(UserType=NORMAL_USERS):禁止重复认证,仅展示认证状态 */
|
||||
const isVerified = computed(
|
||||
() => loginProfileStore.userType === NORMAL_USERS,
|
||||
);
|
||||
const buttonText = computed(() => {
|
||||
if (uploading.value) {
|
||||
return t("IdentityVerificationPage.uploadingTip");
|
||||
}
|
||||
if (saving.value) {
|
||||
return t("IdentityVerificationPage.savingTip");
|
||||
}
|
||||
return t("IdentityVerificationPage.uploadBut");
|
||||
});
|
||||
|
||||
/** 出生日期归一为 yyyy-MM-dd(兼容 yyyyMMdd 与带分隔符/时间戳);不足 8 位数字则原样返回 */
|
||||
function formatBirth(raw: string): string {
|
||||
const digits = String(raw ?? "").replace(/\D/g, "");
|
||||
if (digits.length < 8) {
|
||||
return String(raw ?? "").trim();
|
||||
}
|
||||
return `${digits.slice(0, 4)}-${digits.slice(4, 6)}-${digits.slice(6, 8)}`;
|
||||
}
|
||||
|
||||
/** 取后端识别结果字段:兼容 PascalCase(服务端默认)与 camelCase(前端缓存转键) */
|
||||
function pick(info: any, pascal: string, camel: string): string {
|
||||
return String(info?.[pascal] ?? info?.[camel] ?? "").trim();
|
||||
}
|
||||
|
||||
/** 把全部识别信息拼成 UserRemark 文本(有值才成行,逐行「标签: 值」);返回拼接文本与身份证姓名 */
|
||||
function buildRemark(info: any): { text: string; name: string } {
|
||||
const name = pick(info, "CommonName", "commonName");
|
||||
const rows: string[] = [];
|
||||
const push = (label: string, val: string): void => {
|
||||
if (val) {
|
||||
rows.push(`${label}: ${val}`);
|
||||
}
|
||||
};
|
||||
push(t("FamilyPersonPage.commonName"), name);
|
||||
push(t("FamilyPersonPage.gender"), pick(info, "Gender", "gender"));
|
||||
push(
|
||||
t("FamilyPersonPage.birthDate"),
|
||||
formatBirth(pick(info, "BirthDate", "birthDate")),
|
||||
);
|
||||
push(t("FamilyPersonPage.nation"), pick(info, "Nation", "nation"));
|
||||
push(t("FamilyPersonPage.address"), pick(info, "Address", "address"));
|
||||
push(t("FamilyPersonPage.idNumber"), pick(info, "IdNumber", "idNumber"));
|
||||
push(t("FamilyPersonPage.issuer"), pick(info, "Issuer", "issuer"));
|
||||
push(t("FamilyPersonPage.validity"), pick(info, "Validity", "validity"));
|
||||
return { text: rows.join("\n"), name };
|
||||
}
|
||||
|
||||
/** 提交认证:昵称取身份证姓名(识别不到则沿用当前昵称),UserRemark 整体覆盖为识别信息 */
|
||||
async function save(): Promise<void> {
|
||||
try {
|
||||
saving.value = true;
|
||||
const payload = new SecurityUserDisplayData();
|
||||
payload.UserLocalName =
|
||||
recognizedName.value || loginProfileStore.userLocalName || "";
|
||||
payload.UserRemark = remark.value;
|
||||
await securityUserService.UpdateSecurityUserIdCard(payload);
|
||||
// 后端已将 UserType 置为 NORMAL_USERS、昵称改为身份证姓名;
|
||||
// 登录快照是登录时的旧值,这里同步本地态,返回「我的」/刷新首页即可立即显示「已认证」
|
||||
loginProfileStore.loginProfile.UserType = NORMAL_USERS;
|
||||
if (payload.UserLocalName) {
|
||||
loginProfileStore.loginProfile.UserLocalName = payload.UserLocalName;
|
||||
}
|
||||
uni.showToast({
|
||||
title: t("IdentityVerificationPage.success"),
|
||||
icon: "none",
|
||||
});
|
||||
onSuccess?.();
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 上传身份证:单图 → 后端 OCR → 拼 UserRemark(整体覆盖)→ UpdateSecurityUserIdCard 落库并置认证态 */
|
||||
function onUploadIdCard(): void {
|
||||
if (uploading.value || saving.value || isVerified.value) {
|
||||
return;
|
||||
}
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: async (res: any) => {
|
||||
const filePath = String(res?.tempFilePaths?.[0] ?? "");
|
||||
const fileName = String(
|
||||
res?.tempFiles?.[0]?.name || `idcard-${Date.now()}.jpg`,
|
||||
);
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
uploading.value = true;
|
||||
const physicalName = buildChunkFileName(fileName);
|
||||
imageUrl.value = filePath;
|
||||
const result = await uploadFile({
|
||||
url: "/DmsFile/UploadIdCardFile",
|
||||
filePath,
|
||||
name: fileName,
|
||||
fileName: physicalName,
|
||||
header: { FilePath: "idcard" },
|
||||
formData: { side: "auto" },
|
||||
});
|
||||
const info = result?.Data ?? result?.data ?? result;
|
||||
const { text, name } = buildRemark(info);
|
||||
if (!text) {
|
||||
uni.showToast({
|
||||
title: t("IdentityVerificationPage.noResult"),
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
remark.value = text;
|
||||
recognizedName.value = name;
|
||||
await save();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
uni.showToast({
|
||||
title: t("IdentityVerificationPage.failed"),
|
||||
icon: "none",
|
||||
});
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
imageUrl,
|
||||
remark,
|
||||
uploading,
|
||||
saving,
|
||||
busy,
|
||||
isVerified,
|
||||
buttonText,
|
||||
onUploadIdCard,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
export class DmsFileUsageViewEntity
|
||||
{
|
||||
public OwerId: string = "";
|
||||
public FileCount: number = 0;
|
||||
public UsedKb: number = 0;
|
||||
|
||||
static readonly OWER_ID : string ='OwerId';
|
||||
static readonly FILE_COUNT : string ='FileCount';
|
||||
static readonly USED_KB : string ='UsedKb';
|
||||
static readonly DB_NAME_DMS_FILE_USAGE_VIEW : string ='dms_file_usage_view';
|
||||
static readonly DB_NAME_FIELDS : string ='ower_id,file_count,used_kb';
|
||||
static readonly DB_OWER_ID : string ='ower_id';
|
||||
static readonly DB_FILE_COUNT : string ='file_count';
|
||||
static readonly DB_USED_KB : string ='used_kb';
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
export class StorageUsageData
|
||||
{
|
||||
public UserType: string = "";
|
||||
public AvatarUrl: string = "";
|
||||
public UsedKB: number = 0;
|
||||
public QuotaKB: number = 0;
|
||||
public Percent: number = 0;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
{
|
||||
"name": "en-US",
|
||||
"storage": {
|
||||
"title": "Cloud Storage Space",
|
||||
"used": "Used",
|
||||
"total": "Total",
|
||||
"welcome": "Welcome back to Youjiala, carry on the family memory",
|
||||
"typeUnauth": "Unverified",
|
||||
"typeNormal": "Standard",
|
||||
"typeVip": "VIP",
|
||||
"typeSvip": "SVIP",
|
||||
"avatarUploadedTip": "Avatar updated",
|
||||
"avatarUploadFailed": "Avatar upload failed"
|
||||
},
|
||||
"LoginForm": {
|
||||
"userLabel": "Username",
|
||||
"passwordLabel": "Password",
|
||||
@@ -14,7 +26,7 @@
|
||||
},
|
||||
"TabBar": {
|
||||
"home": "Home",
|
||||
"file": "Files",
|
||||
"file": "Cloud Drive",
|
||||
"media": "Media",
|
||||
"share": "Share",
|
||||
"mine": "Me"
|
||||
@@ -830,6 +842,11 @@
|
||||
"userLocalName": "Local Name",
|
||||
"userEngName": "English Name",
|
||||
"userMobile": "Mobile",
|
||||
"userType": "User Type",
|
||||
"userTypeUnauth": "Unverified",
|
||||
"userTypeNormal": "Standard",
|
||||
"userTypeVip": "VIP",
|
||||
"userTypeSvip": "SVIP",
|
||||
"userPassword": "Password",
|
||||
"createdDatetime": "Created Date",
|
||||
"account": "Account",
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
{
|
||||
"name": "zh-CN",
|
||||
"storage": {
|
||||
"title": "网盘存储空间",
|
||||
"used": "已使用",
|
||||
"total": "总容量",
|
||||
"welcome": "欢迎回到有家,传承家族记忆",
|
||||
"typeUnauth": "未认证",
|
||||
"typeNormal": "普通用户",
|
||||
"typeVip": "VIP",
|
||||
"typeSvip": "SVIP",
|
||||
"avatarUploadedTip": "头像已更新",
|
||||
"avatarUploadFailed": "头像上传失败"
|
||||
},
|
||||
"LoginForm": {
|
||||
"userLabel": "用户名",
|
||||
"passwordLabel": "密码",
|
||||
@@ -14,7 +26,7 @@
|
||||
},
|
||||
"TabBar": {
|
||||
"home": "首页",
|
||||
"file": "文件",
|
||||
"file": "网盘",
|
||||
"media": "多媒体",
|
||||
"share": "共享",
|
||||
"mine": "我的"
|
||||
@@ -830,6 +842,11 @@
|
||||
"userLocalName": "中文名称",
|
||||
"userEngName": "英文名称",
|
||||
"userMobile": "手机",
|
||||
"userType": "用户类型",
|
||||
"userTypeUnauth": "未认证",
|
||||
"userTypeNormal": "普通用户",
|
||||
"userTypeVip": "VIP",
|
||||
"userTypeSvip": "SVIP",
|
||||
"userPassword": "登录密码",
|
||||
"createdDatetime": "创建日期",
|
||||
"account": "账号",
|
||||
|
||||
@@ -1,59 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 身份验证页:从「我的」跳入(短地址 /identity-verification)。
|
||||
* 流程:chooseImage 单图 → 复用同源后端 DmsFile/UploadIdCardFile(后端落盘 idcard 目录 +
|
||||
* server-to-server 调同 docker 的 OCR,返回带识别结果的 FamilyPersonDisplayData,避免浏览器跨域)→
|
||||
* 把「全部识别信息」格式化写入 UserRemark,昵称取身份证姓名,再调 SecurityUser/UpdateSecurityUserIdCard
|
||||
* 落库并把 UserType 置为 NORMAL_USERS(已认证)。
|
||||
* 上传 + OCR + 落库 + 置认证态的完整流程抽到 useIdCardVerify(首页底部弹层共用同一套逻辑)。
|
||||
* 与 family-person 的身份证不同:那边把无列信息并入「简介」;这里 UserRemark 是真实列,整体覆盖为识别信息。
|
||||
* 注意:后端 UpdateSecurityUserIdCard 对「可查看全部用户」(管理员)会直接 return 不更新——普通用户自助认证场景。
|
||||
*/
|
||||
import { useLocale } from "uview-pro";
|
||||
import { computed, ref } from "vue";
|
||||
import { buildChunkFileName, uploadFile } from "@/common/http.interceptor";
|
||||
import { useAuthGuard, useThemeGradient, useThemeTokens } from "@/composables";
|
||||
import { SecurityUserDisplayData } from "@/data/auto/securityUserDisplayData";
|
||||
import { computed } from "vue";
|
||||
import { useAuthGuard, useIdCardVerify, useThemeGradient, useThemeTokens } from "@/composables";
|
||||
import { pageUrl } from "@/router/routes";
|
||||
import securityUserService from "@/service/security/securityUserService";
|
||||
import { useLoginProfileStore } from "@/stores";
|
||||
|
||||
const { t } = useLocale();
|
||||
useAuthGuard();
|
||||
|
||||
const loginProfileStore = useLoginProfileStore();
|
||||
|
||||
/** 后端 UpdateSecurityUserIdCard 会把 UserType 置为 NORMAL_USERS("N")代表已认证;此处与后端口径保持一致 */
|
||||
const NORMAL_USERS = "N";
|
||||
|
||||
const imageUrl = ref("");
|
||||
const remark = ref("");
|
||||
const recognizedName = ref("");
|
||||
const uploading = ref(false);
|
||||
const saving = ref(false);
|
||||
|
||||
const busy = computed(() => uploading.value || saving.value);
|
||||
const buttonText = computed(() => {
|
||||
if (uploading.value) {
|
||||
return t("IdentityVerificationPage.uploadingTip");
|
||||
}
|
||||
if (saving.value) {
|
||||
return t("IdentityVerificationPage.savingTip");
|
||||
}
|
||||
return t("IdentityVerificationPage.uploadBut");
|
||||
});
|
||||
|
||||
/** 已认证(UserType=NORMAL_USERS):禁止重复认证,仅展示认证状态 */
|
||||
const isVerified = computed(() => loginProfileStore.userType === NORMAL_USERS);
|
||||
|
||||
/** 返回:有历史则回退,冷启动直达时兜底切回「我的」tab */
|
||||
function onBack(): void {
|
||||
if (getCurrentPages().length > 1) {
|
||||
uni.navigateBack();
|
||||
}
|
||||
else {
|
||||
uni.switchTab({ url: pageUrl("mineTab") });
|
||||
}
|
||||
}
|
||||
/** 认证成功:短延时返回「我的」,让 toast 露出 */
|
||||
const { imageUrl, remark, uploading, busy, isVerified, buttonText, onUploadIdCard } = useIdCardVerify(() =>
|
||||
setTimeout(() => uni.navigateBack(), 800),
|
||||
);
|
||||
|
||||
/* 主题渐变底 + 主题色变量(与「我的」页同一接线口径) */
|
||||
const { themeBackground } = useThemeGradient();
|
||||
@@ -65,106 +28,13 @@ const themeVars = computed(() => ({
|
||||
"--fg-shadow": accentShadow.value,
|
||||
}));
|
||||
|
||||
/** 出生日期归一为 yyyy-MM-dd(兼容 yyyyMMdd 与带分隔符/时间戳);不足 8 位数字则原样返回 */
|
||||
function formatBirth(raw: string): string {
|
||||
const digits = String(raw ?? "").replace(/\D/g, "");
|
||||
if (digits.length < 8) {
|
||||
return String(raw ?? "").trim();
|
||||
/** 返回:有历史则回退,冷启动直达时兜底切回「我的」tab */
|
||||
function onBack(): void {
|
||||
if (getCurrentPages().length > 1) {
|
||||
uni.navigateBack();
|
||||
}
|
||||
return `${digits.slice(0, 4)}-${digits.slice(4, 6)}-${digits.slice(6, 8)}`;
|
||||
}
|
||||
|
||||
/** 取后端识别结果字段:兼容 PascalCase(服务端默认)与 camelCase(前端缓存转键) */
|
||||
function pick(info: any, pascal: string, camel: string): string {
|
||||
return String(info?.[pascal] ?? info?.[camel] ?? "").trim();
|
||||
}
|
||||
|
||||
/** 把全部识别信息拼成 UserRemark 文本(有值才成行,逐行「标签: 值」);返回拼接文本与身份证姓名 */
|
||||
function buildRemark(info: any): { text: string; name: string } {
|
||||
const name = pick(info, "CommonName", "commonName");
|
||||
const rows: string[] = [];
|
||||
const push = (label: string, val: string): void => {
|
||||
if (val) {
|
||||
rows.push(`${label}: ${val}`);
|
||||
}
|
||||
};
|
||||
push(t("FamilyPersonPage.commonName"), name);
|
||||
push(t("FamilyPersonPage.gender"), pick(info, "Gender", "gender"));
|
||||
push(t("FamilyPersonPage.birthDate"), formatBirth(pick(info, "BirthDate", "birthDate")));
|
||||
push(t("FamilyPersonPage.nation"), pick(info, "Nation", "nation"));
|
||||
push(t("FamilyPersonPage.address"), pick(info, "Address", "address"));
|
||||
push(t("FamilyPersonPage.idNumber"), pick(info, "IdNumber", "idNumber"));
|
||||
push(t("FamilyPersonPage.issuer"), pick(info, "Issuer", "issuer"));
|
||||
push(t("FamilyPersonPage.validity"), pick(info, "Validity", "validity"));
|
||||
return { text: rows.join("\n"), name };
|
||||
}
|
||||
|
||||
/** 上传身份证:单图 → 后端 OCR → 拼 UserRemark(整体覆盖)→ UpdateSecurityUserIdCard 落库并置认证态 */
|
||||
function onUploadIdCard(): void {
|
||||
if (uploading.value || saving.value || isVerified.value) {
|
||||
return;
|
||||
}
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: async (res: any) => {
|
||||
const filePath = String(res?.tempFilePaths?.[0] ?? "");
|
||||
const fileName = String(res?.tempFiles?.[0]?.name || `idcard-${Date.now()}.jpg`);
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
uploading.value = true;
|
||||
const physicalName = buildChunkFileName(fileName);
|
||||
imageUrl.value = filePath;
|
||||
const result = await uploadFile({
|
||||
url: "/DmsFile/UploadIdCardFile",
|
||||
filePath,
|
||||
name: fileName,
|
||||
fileName: physicalName,
|
||||
header: { FilePath: "idcard" },
|
||||
formData: { side: "auto" },
|
||||
});
|
||||
const info = result?.Data ?? result?.data ?? result;
|
||||
const { text, name } = buildRemark(info);
|
||||
if (!text) {
|
||||
uni.showToast({ title: t("IdentityVerificationPage.noResult"), icon: "none" });
|
||||
return;
|
||||
}
|
||||
remark.value = text;
|
||||
recognizedName.value = name;
|
||||
await save();
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
uni.showToast({ title: t("IdentityVerificationPage.failed"), icon: "none" });
|
||||
}
|
||||
finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** 提交认证:昵称取身份证姓名(识别不到则沿用当前昵称),UserRemark 整体覆盖为识别信息 */
|
||||
async function save(): Promise<void> {
|
||||
try {
|
||||
saving.value = true;
|
||||
const payload = new SecurityUserDisplayData();
|
||||
payload.UserLocalName = recognizedName.value || loginProfileStore.userLocalName || "";
|
||||
payload.UserRemark = remark.value;
|
||||
await securityUserService.UpdateSecurityUserIdCard(payload);
|
||||
// 后端已将 UserType 置为 NORMAL_USERS、昵称改为身份证姓名;
|
||||
// 登录快照是登录时的旧值,这里同步本地态,返回「我的」即可立即显示「已认证」
|
||||
loginProfileStore.loginProfile.UserType = NORMAL_USERS;
|
||||
if (payload.UserLocalName) {
|
||||
loginProfileStore.loginProfile.UserLocalName = payload.UserLocalName;
|
||||
}
|
||||
uni.showToast({ title: t("IdentityVerificationPage.success"), icon: "none" });
|
||||
// 成功后短延时返回「我的」,让 toast 露出
|
||||
setTimeout(() => uni.navigateBack(), 800);
|
||||
}
|
||||
finally {
|
||||
saving.value = false;
|
||||
else {
|
||||
uni.switchTab({ url: pageUrl("mineTab") });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -65,6 +65,17 @@ const sections = computed<AdminFormSection[]>(() => {
|
||||
{ label: t("UserPage.userLocalName"), prop: "UserLocalName", required: true },
|
||||
{ label: t("UserPage.userEngName"), prop: "UserEngName" },
|
||||
{ label: t("UserPage.userMobile"), prop: "UserMobile" },
|
||||
{
|
||||
label: t("UserPage.userType"),
|
||||
prop: "UserType",
|
||||
type: "select",
|
||||
options: [
|
||||
{ label: t("UserPage.userTypeUnauth"), value: "U" },
|
||||
{ label: t("UserPage.userTypeNormal"), value: "N" },
|
||||
{ label: t("UserPage.userTypeVip"), value: "V" },
|
||||
{ label: t("UserPage.userTypeSvip"), value: "S" },
|
||||
],
|
||||
},
|
||||
{ label: t("UserPage.createdDatetime"), prop: "CreatedDatetime", date: "datetime", lock: true },
|
||||
];
|
||||
// 密码只在编辑态出现:查看态没必要显示(即便是掩码)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { request,download } from "@/utils/request";
|
||||
import type { SelectOption } from "@/data/auto/selectOption";
|
||||
import type { DmsFolderData } from "@/data/auto/dmsFolderData";
|
||||
import type { FamilyPersonDisplayData } from "@/data/auto/familyPersonDisplayData";
|
||||
import type { StorageUsageData } from "@/data/auto/storageUsageData";
|
||||
import type { FamilyGroupFolderEntity } from "@/data/auto/familyGroupFolderEntity";
|
||||
|
||||
class DmsFileService{
|
||||
@@ -267,6 +268,24 @@ class DmsFileService{
|
||||
)
|
||||
};
|
||||
|
||||
async GetMyStorageUsage() {
|
||||
return request<StorageUsageData>(
|
||||
{
|
||||
url: "/DmsFile/GetMyStorageUsage",
|
||||
method: "post",
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
async UploadUserAvatar() {
|
||||
return request<string>(
|
||||
{
|
||||
url: "/DmsFile/UploadUserAvatar",
|
||||
method: "post",
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
async DownloadFile(data: number) {
|
||||
return request<any>(
|
||||
{
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path fill="#059669" d="M6.8 18.5a4.3 4.3 0 0 1-.5-8.56 5.6 5.6 0 0 1 10.75-1.06A3.9 3.9 0 0 1 17.4 18.5z"/>
|
||||
<path fill="none" stroke="#ffffff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" d="M12 16.4v-4.6M9.9 13.7 12 11.6l2.1 2.1"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 327 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#606266" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M6.8 18.5a4.3 4.3 0 0 1-.5-8.56 5.6 5.6 0 0 1 10.75-1.06A3.9 3.9 0 0 1 17.4 18.5z"/>
|
||||
<path d="M12 16.4v-4.6"/>
|
||||
<path d="M9.9 13.7 12 11.6l2.1 2.1"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 327 B |
@@ -18,7 +18,7 @@ export const useTabbarStore = defineStore(
|
||||
"tabbar",
|
||||
() => {
|
||||
const activeIndex = ref(0);
|
||||
// 顺序必须与 routes.ts 的 TAB_PAGES 逐项对齐(首页/文件/多媒体/共享/我的)。
|
||||
// 顺序必须与 routes.ts 的 TAB_PAGES 逐项对齐(首页/网盘/多媒体/共享/我的)。
|
||||
// 刻意不写 pagePath:u-tabbar 一旦拿到 pagePath 就会调 uni.switchTab,而本项目没有原生
|
||||
// tabBar,switchTab 会 fail。跳转统一由 app-tabbar 的 @change 用 reLaunch 完成,
|
||||
// 高亮由当前页面路由反推下标(见 app-tabbar 的 onMounted)。
|
||||
@@ -30,8 +30,10 @@ export const useTabbarStore = defineStore(
|
||||
},
|
||||
{
|
||||
langKey: "TabBar.file",
|
||||
iconPath: "file-text",
|
||||
selectedIconPath: "file-text-fill",
|
||||
// 网盘无对应 uview 字体图标,改用自定义云形 SVG(含 '/' → u-icon 走 <image> 渲染);
|
||||
// 图片图标不吃 color,故未选中/选中各烘一色(描边灰 #606266 / 实心绿 #059669)
|
||||
iconPath: "/static/tabbar/netdisk.svg",
|
||||
selectedIconPath: "/static/tabbar/netdisk-active.svg",
|
||||
},
|
||||
{
|
||||
langKey: "TabBar.media",
|
||||
|
||||
Reference in new issue
Block a user