main #54
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("IMTest")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5274f0d22d4fe646d03a3bc0ea6621d299074816")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1df3a0f30e469671b3e81d88574871d99c98af1a")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("IMTest")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("IMTest")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
7390b702e3c578dad3a8fa4fa4cc93b25ccd34a9b353beca60372a7182717d73
|
||||
9546071857f1b0fa09bedf887ca476b7ecfa579752230651321c2a145e579c92
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
is_global = true
|
||||
build_property.TargetFramework = net8.0
|
||||
build_property.TargetFrameworkIdentifier = .NETCoreApp
|
||||
build_property.TargetFrameworkVersion = v8.0
|
||||
build_property.TargetPlatformMinVersion =
|
||||
build_property.UsingMicrosoftNETSdkWeb =
|
||||
build_property.ProjectTypeGuids =
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
// <auto-generated/>
|
||||
global using global::System;
|
||||
global using global::System.Collections.Generic;
|
||||
global using global::System.IO;
|
||||
global using global::System.Linq;
|
||||
global using global::System.Net.Http;
|
||||
global using global::System.Threading;
|
||||
global using global::System.Threading.Tasks;
|
||||
global using global::Xunit;
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Linq;
|
||||
global using System.Net.Http;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
global using Xunit;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -49,7 +49,7 @@
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
},
|
||||
"SdkAnalysisLevel": "9.0.300"
|
||||
"SdkAnalysisLevel": "10.0.100"
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
@ -96,7 +96,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.102/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -141,7 +141,7 @@
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
},
|
||||
"SdkAnalysisLevel": "9.0.300"
|
||||
"SdkAnalysisLevel": "10.0.100"
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
@ -155,6 +155,10 @@
|
||||
"target": "Package",
|
||||
"version": "[12.0.0, )"
|
||||
},
|
||||
"MassTransit.RabbitMQ": {
|
||||
"target": "Package",
|
||||
"version": "[8.5.5, )"
|
||||
},
|
||||
"Microsoft.AspNetCore.Authentication.JwtBearer": {
|
||||
"target": "Package",
|
||||
"version": "[8.0.21, )"
|
||||
@ -219,7 +223,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.102/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\nanxun\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.14.1</NuGetToolVersion>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">7.0.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\nanxun\.nuget\packages\" />
|
||||
|
||||
@ -53,6 +53,57 @@
|
||||
"build/netstandard1.0/coverlet.collector.targets": {}
|
||||
}
|
||||
},
|
||||
"MassTransit/8.5.5": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"MassTransit.Abstractions": "8.5.5",
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
|
||||
"Microsoft.Extensions.Diagnostics.HealthChecks": "8.0.0",
|
||||
"Microsoft.Extensions.Hosting.Abstractions": "8.0.0",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
|
||||
"Microsoft.Extensions.Options": "8.0.0"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net8.0/MassTransit.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/MassTransit.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"MassTransit.Abstractions/8.5.5": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/net8.0/MassTransit.Abstractions.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/MassTransit.Abstractions.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"MassTransit.RabbitMQ/8.5.5": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"MassTransit": "8.5.5",
|
||||
"RabbitMQ.Client": "7.1.2"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net8.0/MassTransit.RabbitMqTransport.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/MassTransit.RabbitMqTransport.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Microsoft.AspNetCore.Authentication.Abstractions/2.3.0": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
@ -664,6 +715,38 @@
|
||||
"buildTransitive/net6.0/_._": {}
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.Diagnostics.HealthChecks/8.0.0": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions": "8.0.0",
|
||||
"Microsoft.Extensions.Hosting.Abstractions": "8.0.0",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
|
||||
"Microsoft.Extensions.Options": "8.0.0"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions/8.0.0": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.FileProviders.Abstractions/8.0.0": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
@ -1360,6 +1443,23 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"RabbitMQ.Client/7.1.2": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"System.IO.Pipelines": "8.0.0",
|
||||
"System.Threading.RateLimiting": "8.0.0"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net8.0/RabbitMQ.Client.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/RabbitMQ.Client.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0": {
|
||||
"type": "package",
|
||||
"runtimeTargets": {
|
||||
@ -2655,6 +2755,22 @@
|
||||
"buildTransitive/net6.0/_._": {}
|
||||
}
|
||||
},
|
||||
"System.Threading.RateLimiting/8.0.0": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/net8.0/System.Threading.RateLimiting.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net8.0/System.Threading.RateLimiting.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"build": {
|
||||
"buildTransitive/net6.0/_._": {}
|
||||
}
|
||||
},
|
||||
"System.Threading.Tasks/4.3.0": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
@ -2859,6 +2975,7 @@
|
||||
"dependencies": {
|
||||
"AutoMapper": "12.0.1",
|
||||
"AutoMapper.Extensions.Microsoft.DependencyInjection": "12.0.0",
|
||||
"MassTransit.RabbitMQ": "8.5.5",
|
||||
"Microsoft.AspNetCore.Authentication.JwtBearer": "8.0.21",
|
||||
"Microsoft.AspNetCore.SignalR": "1.2.0",
|
||||
"Microsoft.VisualStudio.Azure.Containers.Tools.Targets": "1.22.1",
|
||||
@ -2987,6 +3104,69 @@
|
||||
"coverlet.collector.nuspec"
|
||||
]
|
||||
},
|
||||
"MassTransit/8.5.5": {
|
||||
"sha512": "bSg8k5q+rP1s+dIGXLLbctqDGdIkfDjdxwNWtCUH7xNCN9ZuM7mqSPQPIFgaYIi34e81m4FqAqo4CAHuWPkhRA==",
|
||||
"type": "package",
|
||||
"path": "masstransit/8.5.5",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"NuGet.README.md",
|
||||
"lib/net472/MassTransit.dll",
|
||||
"lib/net472/MassTransit.xml",
|
||||
"lib/net8.0/MassTransit.dll",
|
||||
"lib/net8.0/MassTransit.xml",
|
||||
"lib/net9.0/MassTransit.dll",
|
||||
"lib/net9.0/MassTransit.xml",
|
||||
"lib/netstandard2.0/MassTransit.dll",
|
||||
"lib/netstandard2.0/MassTransit.xml",
|
||||
"masstransit.8.5.5.nupkg.sha512",
|
||||
"masstransit.nuspec",
|
||||
"mt-logo-small.png"
|
||||
]
|
||||
},
|
||||
"MassTransit.Abstractions/8.5.5": {
|
||||
"sha512": "0mn2Ay17dD6z5tgSLjbVRlldSbL9iowzFEfVgVfBXVG5ttz9dSWeR4TrdD6pqH93GWXp4CvSmF8i1HqxLX7DZw==",
|
||||
"type": "package",
|
||||
"path": "masstransit.abstractions/8.5.5",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"NuGet.README.md",
|
||||
"lib/net472/MassTransit.Abstractions.dll",
|
||||
"lib/net472/MassTransit.Abstractions.xml",
|
||||
"lib/net8.0/MassTransit.Abstractions.dll",
|
||||
"lib/net8.0/MassTransit.Abstractions.xml",
|
||||
"lib/net9.0/MassTransit.Abstractions.dll",
|
||||
"lib/net9.0/MassTransit.Abstractions.xml",
|
||||
"lib/netstandard2.0/MassTransit.Abstractions.dll",
|
||||
"lib/netstandard2.0/MassTransit.Abstractions.xml",
|
||||
"masstransit.abstractions.8.5.5.nupkg.sha512",
|
||||
"masstransit.abstractions.nuspec",
|
||||
"mt-logo-small.png"
|
||||
]
|
||||
},
|
||||
"MassTransit.RabbitMQ/8.5.5": {
|
||||
"sha512": "UxWn4o90YVMF9PBkJeoskOFPneh6YtnI1fLJHtvZiSAG0eoiRrWPGa+6FQCvjkQ/ljCKfjzok2eGZc/vmNZ01A==",
|
||||
"type": "package",
|
||||
"path": "masstransit.rabbitmq/8.5.5",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"NuGet.README.md",
|
||||
"lib/net472/MassTransit.RabbitMqTransport.dll",
|
||||
"lib/net472/MassTransit.RabbitMqTransport.xml",
|
||||
"lib/net8.0/MassTransit.RabbitMqTransport.dll",
|
||||
"lib/net8.0/MassTransit.RabbitMqTransport.xml",
|
||||
"lib/net9.0/MassTransit.RabbitMqTransport.dll",
|
||||
"lib/net9.0/MassTransit.RabbitMqTransport.xml",
|
||||
"lib/netstandard2.0/MassTransit.RabbitMqTransport.dll",
|
||||
"lib/netstandard2.0/MassTransit.RabbitMqTransport.xml",
|
||||
"masstransit.rabbitmq.8.5.5.nupkg.sha512",
|
||||
"masstransit.rabbitmq.nuspec",
|
||||
"mt-logo-small.png"
|
||||
]
|
||||
},
|
||||
"Microsoft.AspNetCore.Authentication.Abstractions/2.3.0": {
|
||||
"sha512": "ve6uvLwKNRkfnO/QeN9M8eUJ49lCnWv/6/9p6iTEuiI6Rtsz+myaBAjdMzLuTViQY032xbTF5AdZF5BJzJJyXQ==",
|
||||
"type": "package",
|
||||
@ -3887,6 +4067,44 @@
|
||||
"useSharedDesignerContext.txt"
|
||||
]
|
||||
},
|
||||
"Microsoft.Extensions.Diagnostics.HealthChecks/8.0.0": {
|
||||
"sha512": "P9SoBuVZhJPpALZmSq72aQEb9ryP67EdquaCZGXGrrcASTNHYdrUhnpgSwIipgM5oVC+dKpRXg5zxobmF9xr5g==",
|
||||
"type": "package",
|
||||
"path": "microsoft.extensions.diagnostics.healthchecks/8.0.0",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"Icon.png",
|
||||
"THIRD-PARTY-NOTICES.TXT",
|
||||
"lib/net462/Microsoft.Extensions.Diagnostics.HealthChecks.dll",
|
||||
"lib/net462/Microsoft.Extensions.Diagnostics.HealthChecks.xml",
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.dll",
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.xml",
|
||||
"lib/netstandard2.0/Microsoft.Extensions.Diagnostics.HealthChecks.dll",
|
||||
"lib/netstandard2.0/Microsoft.Extensions.Diagnostics.HealthChecks.xml",
|
||||
"microsoft.extensions.diagnostics.healthchecks.8.0.0.nupkg.sha512",
|
||||
"microsoft.extensions.diagnostics.healthchecks.nuspec"
|
||||
]
|
||||
},
|
||||
"Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions/8.0.0": {
|
||||
"sha512": "AT2qqos3IgI09ok36Qag9T8bb6kHJ3uT9Q5ki6CySybFsK6/9JbvQAgAHf1pVEjST0/N4JaFaCbm40R5edffwg==",
|
||||
"type": "package",
|
||||
"path": "microsoft.extensions.diagnostics.healthchecks.abstractions/8.0.0",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"Icon.png",
|
||||
"THIRD-PARTY-NOTICES.TXT",
|
||||
"lib/net462/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll",
|
||||
"lib/net462/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.xml",
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll",
|
||||
"lib/net8.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.xml",
|
||||
"lib/netstandard2.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll",
|
||||
"lib/netstandard2.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.xml",
|
||||
"microsoft.extensions.diagnostics.healthchecks.abstractions.8.0.0.nupkg.sha512",
|
||||
"microsoft.extensions.diagnostics.healthchecks.abstractions.nuspec"
|
||||
]
|
||||
},
|
||||
"Microsoft.Extensions.FileProviders.Abstractions/8.0.0": {
|
||||
"sha512": "ZbaMlhJlpisjuWbvXr4LdAst/1XxH3vZ6A0BsgTphZ2L4PGuxRLz7Jr/S7mkAAnOn78Vu0fKhEgNF5JO3zfjqQ==",
|
||||
"type": "package",
|
||||
@ -4801,6 +5019,23 @@
|
||||
"pomelo.entityframeworkcore.mysql.nuspec"
|
||||
]
|
||||
},
|
||||
"RabbitMQ.Client/7.1.2": {
|
||||
"sha512": "y3c6ulgULScWthHw5PLM1ShHRLhxg0vCtzX/hh61gRgNecL3ZC3WoBW2HYHoXOVRqTl99Br9E7CZEytGZEsCyQ==",
|
||||
"type": "package",
|
||||
"path": "rabbitmq.client/7.1.2",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"README.md",
|
||||
"icon.png",
|
||||
"lib/net8.0/RabbitMQ.Client.dll",
|
||||
"lib/net8.0/RabbitMQ.Client.xml",
|
||||
"lib/netstandard2.0/RabbitMQ.Client.dll",
|
||||
"lib/netstandard2.0/RabbitMQ.Client.xml",
|
||||
"rabbitmq.client.7.1.2.nupkg.sha512",
|
||||
"rabbitmq.client.nuspec"
|
||||
]
|
||||
},
|
||||
"runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0": {
|
||||
"sha512": "HdSSp5MnJSsg08KMfZThpuLPJpPwE5hBXvHwoKWosyHHfe8Mh5WKT0ylEOf6yNzX6Ngjxe4Whkafh5q7Ymac4Q==",
|
||||
"type": "package",
|
||||
@ -8051,6 +8286,35 @@
|
||||
"useSharedDesignerContext.txt"
|
||||
]
|
||||
},
|
||||
"System.Threading.RateLimiting/8.0.0": {
|
||||
"sha512": "7mu9v0QDv66ar3DpGSZHg9NuNcxDaaAcnMULuZlaTpP9+hwXhrxNGsF5GmLkSHxFdb5bBc1TzeujsRgTrPWi+Q==",
|
||||
"type": "package",
|
||||
"path": "system.threading.ratelimiting/8.0.0",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"Icon.png",
|
||||
"LICENSE.TXT",
|
||||
"THIRD-PARTY-NOTICES.TXT",
|
||||
"buildTransitive/net461/System.Threading.RateLimiting.targets",
|
||||
"buildTransitive/net462/_._",
|
||||
"buildTransitive/net6.0/_._",
|
||||
"buildTransitive/netcoreapp2.0/System.Threading.RateLimiting.targets",
|
||||
"lib/net462/System.Threading.RateLimiting.dll",
|
||||
"lib/net462/System.Threading.RateLimiting.xml",
|
||||
"lib/net6.0/System.Threading.RateLimiting.dll",
|
||||
"lib/net6.0/System.Threading.RateLimiting.xml",
|
||||
"lib/net7.0/System.Threading.RateLimiting.dll",
|
||||
"lib/net7.0/System.Threading.RateLimiting.xml",
|
||||
"lib/net8.0/System.Threading.RateLimiting.dll",
|
||||
"lib/net8.0/System.Threading.RateLimiting.xml",
|
||||
"lib/netstandard2.0/System.Threading.RateLimiting.dll",
|
||||
"lib/netstandard2.0/System.Threading.RateLimiting.xml",
|
||||
"system.threading.ratelimiting.8.0.0.nupkg.sha512",
|
||||
"system.threading.ratelimiting.nuspec",
|
||||
"useSharedDesignerContext.txt"
|
||||
]
|
||||
},
|
||||
"System.Threading.Tasks/4.3.0": {
|
||||
"sha512": "LbSxKEdOUhVe8BezB/9uOGGppt+nZf6e1VFyw6v3DN6lqitm0OSn2uXMOdtP0M3W4iMcqcivm2J6UgqiwwnXiA==",
|
||||
"type": "package",
|
||||
@ -8541,7 +8805,7 @@
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
},
|
||||
"SdkAnalysisLevel": "9.0.300"
|
||||
"SdkAnalysisLevel": "10.0.100"
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
@ -8588,8 +8852,16 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.102/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"logs": [
|
||||
{
|
||||
"code": "Undefined",
|
||||
"level": "Warning",
|
||||
"warningLevel": 1,
|
||||
"message": "读取缓存文件 C:\\Users\\nanxun\\Documents\\IM\\backend\\IMTest\\obj\\project.nuget.cache 时遇到问题: '<' is an invalid start of a property name. Expected a '\"'. Path: $ | LineNumber: 2 | BytePositionInLine: 0."
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "/x8TFp9yNjk=",
|
||||
"dgSpecHash": "j7OjEXb1ZGE=",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\nanxun\\Documents\\IM\\backend\\IMTest\\IMTest.csproj",
|
||||
"expectedPackageFiles": [
|
||||
@ -8,6 +8,9 @@
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\automapper.extensions.microsoft.dependencyinjection\\12.0.0\\automapper.extensions.microsoft.dependencyinjection.12.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\castle.core\\5.1.1\\castle.core.5.1.1.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\coverlet.collector\\6.0.0\\coverlet.collector.6.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\masstransit\\8.5.5\\masstransit.8.5.5.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\masstransit.abstractions\\8.5.5\\masstransit.abstractions.8.5.5.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\masstransit.rabbitmq\\8.5.5\\masstransit.rabbitmq.8.5.5.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.aspnetcore.authentication.abstractions\\2.3.0\\microsoft.aspnetcore.authentication.abstractions.2.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.aspnetcore.authentication.jwtbearer\\8.0.21\\microsoft.aspnetcore.authentication.jwtbearer.8.0.21.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.aspnetcore.authorization\\2.3.0\\microsoft.aspnetcore.authorization.2.3.0.nupkg.sha512",
|
||||
@ -43,6 +46,8 @@
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.dependencyinjection\\8.0.1\\microsoft.extensions.dependencyinjection.8.0.1.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.dependencyinjection.abstractions\\8.0.2\\microsoft.extensions.dependencyinjection.abstractions.8.0.2.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.diagnostics.abstractions\\8.0.1\\microsoft.extensions.diagnostics.abstractions.8.0.1.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.diagnostics.healthchecks\\8.0.0\\microsoft.extensions.diagnostics.healthchecks.8.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.diagnostics.healthchecks.abstractions\\8.0.0\\microsoft.extensions.diagnostics.healthchecks.abstractions.8.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.fileproviders.abstractions\\8.0.0\\microsoft.extensions.fileproviders.abstractions.8.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.hosting.abstractions\\8.0.1\\microsoft.extensions.hosting.abstractions.8.0.1.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\microsoft.extensions.logging\\8.0.1\\microsoft.extensions.logging.8.0.1.nupkg.sha512",
|
||||
@ -72,6 +77,7 @@
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\nuget.frameworks\\6.5.0\\nuget.frameworks.6.5.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\pipelines.sockets.unofficial\\2.2.8\\pipelines.sockets.unofficial.2.2.8.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\pomelo.entityframeworkcore.mysql\\8.0.3\\pomelo.entityframeworkcore.mysql.8.0.3.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\rabbitmq.client\\7.1.2\\rabbitmq.client.7.1.2.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl\\4.3.0\\runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl\\4.3.0\\runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl\\4.3.0\\runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
@ -148,6 +154,7 @@
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.text.regularexpressions\\4.3.0\\system.text.regularexpressions.4.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.threading\\4.3.0\\system.threading.4.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.threading.channels\\8.0.0\\system.threading.channels.8.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.threading.ratelimiting\\8.0.0\\system.threading.ratelimiting.8.0.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.threading.tasks\\4.3.0\\system.threading.tasks.4.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.threading.tasks.extensions\\4.3.0\\system.threading.tasks.extensions.4.3.0.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\system.threading.timer\\4.3.0\\system.threading.timer.4.3.0.nupkg.sha512",
|
||||
@ -162,5 +169,15 @@
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\xunit.extensibility.execution\\2.5.3\\xunit.extensibility.execution.2.5.3.nupkg.sha512",
|
||||
"C:\\Users\\nanxun\\.nuget\\packages\\xunit.runner.visualstudio\\2.5.3\\xunit.runner.visualstudio.2.5.3.nupkg.sha512"
|
||||
],
|
||||
"logs": []
|
||||
"logs": [
|
||||
{
|
||||
"code": "Undefined",
|
||||
"level": "Warning",
|
||||
"message": "读取缓存文件 C:\\Users\\nanxun\\Documents\\IM\\backend\\IMTest\\obj\\project.nuget.cache 时遇到问题: '<' is an invalid start of a property name. Expected a '\"'. Path: $ | LineNumber: 2 | BytePositionInLine: 0.",
|
||||
"projectPath": "C:\\Users\\nanxun\\Documents\\IM\\backend\\IMTest\\IMTest.csproj",
|
||||
"warningLevel": 1,
|
||||
"filePath": "C:\\Users\\nanxun\\Documents\\IM\\backend\\IMTest\\IMTest.csproj",
|
||||
"targetGraphs": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,88 +0,0 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Services;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IM_API.Application.EventHandlers
|
||||
{
|
||||
public class ConversationEventHandler : IEventHandler<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IConversationService _conversationService;
|
||||
private readonly ILogger<ConversationEventHandler> _logger;
|
||||
private readonly ImContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
public ConversationEventHandler(
|
||||
IConversationService conversationService,
|
||||
ILogger<ConversationEventHandler> logger,
|
||||
ImContext imContext,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
_logger = logger;
|
||||
_context = imContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/*
|
||||
* 此方法有并发问题,当双方同时第一次发送消息时,
|
||||
* 会出现同时创建的情况,其中一方会报错,
|
||||
* 导致也未走到更新逻辑,会话丢失
|
||||
*/
|
||||
public async Task Handle(MessageCreatedEvent @event)
|
||||
{
|
||||
//此处仅处理私聊会话创建
|
||||
if (@event.ChatType == ChatType.GROUP)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var conversation = await _context.Conversations.FirstOrDefaultAsync(
|
||||
x => x.UserId == @event.MsgSenderId && x.TargetId == @event.MsgRecipientId
|
||||
);
|
||||
//如果首次发消息则创建双方会话
|
||||
if (conversation is null)
|
||||
{
|
||||
Conversation senderCon = _mapper.Map<Conversation>(@event);
|
||||
Conversation ReceptCon = _mapper.Map<Conversation>(@event);
|
||||
ReceptCon.UserId = @event.MsgRecipientId;
|
||||
ReceptCon.TargetId = @event.MsgSenderId;
|
||||
ReceptCon.UnreadCount += 1;
|
||||
ReceptCon.LastReadMessageId = null;
|
||||
_context.Conversations.AddRange(senderCon,ReceptCon);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Conversation senderCon = conversation;
|
||||
Conversation? ReceptCon = await _context.Conversations.FirstOrDefaultAsync(
|
||||
x => x.UserId == @event.MsgRecipientId && x.TargetId == @event.MsgSenderId);
|
||||
if (ReceptCon is null)
|
||||
{
|
||||
_logger.LogError("ConversationEventHandlerError:接收者会话对象缺失!Event:{Event}", JsonConvert.SerializeObject(@event));
|
||||
throw new BaseException(CodeDefine.SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
//更新发送者conversation
|
||||
senderCon.UnreadCount = 0;
|
||||
senderCon.LastReadMessageId = @event.MessageId;
|
||||
senderCon.LastMessage = @event.MessageContent;
|
||||
senderCon.LastMessageTime = DateTime.Now;
|
||||
//更新接收者conversation
|
||||
ReceptCon.UnreadCount += 1;
|
||||
ReceptCon.LastMessage = @event.MessageContent;
|
||||
senderCon.LastMessageTime = DateTime.Now;
|
||||
_context.Conversations.UpdateRange(senderCon, ReceptCon);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddConversationHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
public Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Models;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddSignalRHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly ImContext _context;
|
||||
public FriendAddSignalRHandler(ImContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var @event = context.Message;
|
||||
|
||||
var RequestfriendShip = new Friend()
|
||||
{
|
||||
Avatar = @event.ResponseUser.Avatar,
|
||||
UserId = @event.RequestUser.Id,
|
||||
RemarkName = @event.RequestInfo.NickName,
|
||||
Created = @event.RequestInfo.Created,
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Services;
|
||||
using IM_API.Tools;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class ConversationEventHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IConversationService _conversationService;
|
||||
private readonly ILogger<ConversationEventHandler> _logger;
|
||||
private readonly ImContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
public ConversationEventHandler(
|
||||
IConversationService conversationService,
|
||||
ILogger<ConversationEventHandler> logger,
|
||||
ImContext imContext,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
_logger = logger;
|
||||
_context = imContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
|
||||
if (@event.ChatType == ChatType.PRIVATE)
|
||||
{
|
||||
Conversation? userAConversation = await _context.Conversations.FirstOrDefaultAsync(
|
||||
x => x.UserId == @event.MsgSenderId && x.TargetId == @event.MsgRecipientId
|
||||
);
|
||||
Conversation? userBConversation = await _context.Conversations.FirstOrDefaultAsync(
|
||||
x => x.UserId == @event.MsgRecipientId && x.TargetId == @event.MsgSenderId
|
||||
);
|
||||
if (userAConversation is null || userBConversation is null)
|
||||
{
|
||||
_logger.LogError("消息事件更新会话信息失败:{@event}", @event);
|
||||
}
|
||||
userAConversation.LastMessage = @event.MessageContent;
|
||||
userAConversation.LastReadMessageId = @event.MessageId;
|
||||
userAConversation.LastMessageTime = @event.MessageCreated;
|
||||
userBConversation.LastMessage = @event.MessageContent;
|
||||
userBConversation.UnreadCount += 1;
|
||||
userBConversation.LastMessageTime = @event.MessageCreated;
|
||||
_context.UpdateRange(userAConversation, userBConversation);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class SignalREventHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IMapper _mapper;
|
||||
public SignalREventHandler(IHubContext<ChatHub> hub, IMapper mapper)
|
||||
{
|
||||
_hub = hub;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if (@event.ChatType == Models.ChatType.PRIVATE)
|
||||
{
|
||||
MessageBaseDto messageBaseDto = new MessageBaseDto
|
||||
{
|
||||
MsgId = @event.MessageId.ToString(),
|
||||
ChatType = @event.ChatType.ToString(),
|
||||
Content = @event.MessageContent,
|
||||
GroupMemberId = null,
|
||||
ReceiverId = @event.MsgRecipientId,
|
||||
SenderId = @event.MsgSenderId,
|
||||
TimeStamp = @event.MessageCreated,
|
||||
Type = @event.MessageMsgType.ToString()
|
||||
};
|
||||
await _hub.Clients.Users(@event.MsgRecipientId.ToString()).SendAsync("ReceiveMessage", messageBaseDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers
|
||||
{
|
||||
public class SignalREventHandler : IEventHandler<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
public SignalREventHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Handle(MessageCreatedEvent @event)
|
||||
{
|
||||
var streamKey = @event.StreamKey;
|
||||
await _hub.Clients.Group(streamKey).SendAsync(SignalRMethodDefine.ReceiveMessage, @event);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
backend/IM_API/Configs/MQConfig.cs
Normal file
40
backend/IM_API/Configs/MQConfig.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using IM_API.Application.EventHandlers.FriendAddHandler;
|
||||
using IM_API.Application.EventHandlers.MessageCreatedHandler;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Configs
|
||||
{
|
||||
public static class MQConfig
|
||||
{
|
||||
public static IServiceCollection AddRabbitMQ(this IServiceCollection services, RabbitMqOptions options)
|
||||
{
|
||||
services.AddMassTransit(x =>
|
||||
{
|
||||
x.AddConsumer<ConversationEventHandler>();
|
||||
x.AddConsumer<SignalREventHandler>();
|
||||
x.AddConsumer<FriendAddConversationHandler>();
|
||||
x.AddConsumer<FriendAddSignalRHandler>();
|
||||
|
||||
x.UsingRabbitMq((ctx,cfg) =>
|
||||
{
|
||||
cfg.Host(options.Host, "/", h =>
|
||||
{
|
||||
h.Username(options.Username);
|
||||
h.Password(options.Password);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
public class RabbitMqOptions
|
||||
{
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get;set; }
|
||||
}
|
||||
}
|
||||
@ -26,20 +26,22 @@ namespace IM_API.Configs
|
||||
.ForMember(dest => dest.IsDeleted,opt => opt.MapFrom(src => 0))
|
||||
;
|
||||
//好友信息模型转换
|
||||
CreateMap<Friend, FriendInfoDto>();
|
||||
CreateMap<Friend, FriendInfoDto>()
|
||||
.ForMember(dest => dest.UserInfo, opt => opt.MapFrom(src => src.FriendNavigation))
|
||||
;
|
||||
//好友请求通过后新增好友关系
|
||||
CreateMap<FriendRequest, Friend>()
|
||||
.ForMember(dest => dest.UserId , opt => opt.MapFrom(src => src.RequestUser))
|
||||
.ForMember(dest => dest.FriendId , opt => opt.MapFrom(src => src.ResponseUser))
|
||||
.ForMember(dest => dest.StatusEnum , opt =>opt.MapFrom(src => FriendStatus.Added))
|
||||
.ForMember(dest => dest.RemarkName , opt => opt.MapFrom(src => src.ResponseUserNavigation.NickName))
|
||||
.ForMember(dest => dest.Created , opt => opt.MapFrom(src => DateTime.Now))
|
||||
CreateMap<FriendRequestDto, Friend>()
|
||||
.ForMember(dest => dest.UserId , opt => opt.MapFrom(src => src.FromUserId))
|
||||
.ForMember(dest => dest.FriendId , opt => opt.MapFrom(src => src.ToUserId))
|
||||
.ForMember(dest => dest.StatusEnum , opt =>opt.MapFrom(src => FriendStatus.Pending))
|
||||
.ForMember(dest => dest.RemarkName , opt => opt.MapFrom(src => src.RemarkName))
|
||||
.ForMember(dest => dest.Created , opt => opt.MapFrom(src => DateTime.UtcNow))
|
||||
;
|
||||
//发起好友请求转换请求对象
|
||||
CreateMap<FriendRequestDto, FriendRequest>()
|
||||
.ForMember(dest => dest.RequestUser , opt => opt.MapFrom(src => src.FromUserId))
|
||||
.ForMember(dest => dest.ResponseUser , opt => opt.MapFrom(src => src.ToUserId))
|
||||
.ForMember(dest => dest.Created , opt => opt.MapFrom(src => DateTime.Now))
|
||||
.ForMember(dest => dest.Created , opt => opt.MapFrom(src => DateTime.UtcNow))
|
||||
.ForMember(dest => dest.StateEnum , opt => opt.MapFrom(src => FriendRequestState.Pending))
|
||||
.ForMember(dest => dest.Description , opt => opt.MapFrom(src => src.Description))
|
||||
;
|
||||
@ -52,6 +54,7 @@ namespace IM_API.Configs
|
||||
.ForMember(dest => dest.ReceiverId, opt => opt.MapFrom(src => src.Recipient))
|
||||
.ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
|
||||
.ForMember(dest => dest.TimeStamp, opt => opt.MapFrom(src => src.Created))
|
||||
.ForMember(dest => dest.GroupMemberId , opt => opt.MapFrom(src => src.GroupMemberId))
|
||||
;
|
||||
CreateMap<MessageBaseDto, Message>()
|
||||
.ForMember(dest => dest.Sender, opt => opt.MapFrom(src => src.SenderId))
|
||||
@ -62,6 +65,7 @@ namespace IM_API.Configs
|
||||
.ForMember(dest => dest.Recipient, opt => opt.MapFrom(src => src.ReceiverId))
|
||||
.ForMember(dest => dest.StreamKey, opt => opt.Ignore() )
|
||||
.ForMember(dest => dest.StateEnum, opt => opt.MapFrom(src => MessageState.Sent))
|
||||
.ForMember(dest => dest.GroupMemberId, opt => opt.MapFrom(src => src.GroupMemberId))
|
||||
.ForMember(dest => dest.ChatType, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.MsgType, opt => opt.Ignore())
|
||||
;
|
||||
@ -97,9 +101,28 @@ namespace IM_API.Configs
|
||||
.ForMember(dest => dest.TargetId, opt => opt.MapFrom(src => src.MsgRecipientId))
|
||||
.ForMember(dest => dest.UnreadCount, opt => opt.MapFrom(src => 0))
|
||||
.ForMember(dest => dest.StreamKey, opt => opt.MapFrom(src => src.StreamKey))
|
||||
.ForMember(dest => dest.LastMessageTime, opt => opt.MapFrom(src => DateTime.Now))
|
||||
.ForMember(dest => dest.LastMessageTime, opt => opt.MapFrom(src => DateTime.UtcNow))
|
||||
;
|
||||
|
||||
//创建会话对象
|
||||
CreateMap<Conversation, ConversationDto>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.LastMessage, opt => opt.MapFrom(src => src.LastMessage))
|
||||
.ForMember(dest => dest.LastReadMessage, opt => opt.MapFrom(src => src.LastReadMessage))
|
||||
.ForMember(dest => dest.LastReadMessageId, opt => opt.MapFrom(src => src.LastReadMessageId))
|
||||
.ForMember(dest => dest.ChatType, opt => opt.MapFrom(src => src.ChatType))
|
||||
.ForMember(dest => dest.DateTime, opt => opt.MapFrom(src => src.LastMessageTime))
|
||||
.ForMember(dest => dest.TargetId, opt => opt.MapFrom(src => src.TargetId))
|
||||
.ForMember(dest => dest.UnreadCount, opt => opt.MapFrom(src => src.UnreadCount))
|
||||
.ForMember(dest => dest.UserId, opt => opt.MapFrom(src => src.UserId));
|
||||
|
||||
CreateMap<Friend, ConversationDto>()
|
||||
.ForMember(dest => dest.TargetAvatar, opt => opt.MapFrom(src => src.Avatar))
|
||||
.ForMember(dest => dest.TargetName, opt => opt.MapFrom(src => src.RemarkName));
|
||||
|
||||
CreateMap<Group, ConversationDto>()
|
||||
.ForMember(dest => dest.TargetAvatar, opt => opt.MapFrom(src => src.Avatar))
|
||||
.ForMember(dest => dest.TargetName, opt => opt.MapFrom(src => src.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,6 @@ namespace IM_API.Configs
|
||||
services.AddTransient<IMessageSevice, MessageService>();
|
||||
services.AddTransient<IConversationService, ConversationService>();
|
||||
services.AddScoped<IEventBus, InMemoryEventBus>();
|
||||
services.AddScoped<IEventHandler<MessageCreatedEvent>, SignalREventHandler>();
|
||||
services.AddScoped<IEventHandler<MessageCreatedEvent>, ConversationEventHandler>();
|
||||
services.AddSingleton<IJWTService, JWTService>();
|
||||
services.AddSingleton<IRefreshTokenService, RedisRefreshTokenService>();
|
||||
return services;
|
||||
|
||||
@ -53,6 +53,7 @@ namespace IM_API.Controllers
|
||||
return Ok(res);
|
||||
}
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(BaseResponse<LoginDto>),StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> Refresh(RefreshDto dto)
|
||||
{
|
||||
(bool ok,int userId) = await _refreshTokenService.ValidateRefreshTokenAsync(dto.refreshToken);
|
||||
|
||||
@ -28,6 +28,14 @@ namespace IM_API.Controllers
|
||||
var res = new BaseResponse<List<ConversationDto>>(list);
|
||||
return Ok(res);
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get([FromQuery]int conversationId)
|
||||
{
|
||||
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var conversation = await _conversationSerivice.GetConversationByIdAsync(int.Parse(userIdStr), conversationId);
|
||||
var res = new BaseResponse<ConversationDto>(conversation);
|
||||
return Ok(res);
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Clear()
|
||||
{
|
||||
|
||||
@ -44,12 +44,12 @@ namespace IM_API.Controllers
|
||||
/// <param name="desc"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Requests(bool isReceived,int page,int limit,bool desc)
|
||||
public async Task<IActionResult> Requests(int page,int limit,bool desc)
|
||||
{
|
||||
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
int userId = int.Parse(userIdStr);
|
||||
var list = await _friendService.GetFriendRequestListAsync(userId,isReceived,page,limit,desc);
|
||||
var res = new BaseResponse<List<FriendRequest>>(list);
|
||||
var list = await _friendService.GetFriendRequestListAsync(userId,page,limit,desc);
|
||||
var res = new BaseResponse<List<FriendRequestResDto>>(list);
|
||||
return Ok(res);
|
||||
}
|
||||
/// <summary>
|
||||
@ -59,7 +59,9 @@ namespace IM_API.Controllers
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> HandleRequest([FromRoute]int id, [FromBody]FriendRequestHandleDto dto)
|
||||
public async Task<IActionResult> HandleRequest(
|
||||
[FromRoute]int id, [FromBody]FriendRequestHandleDto dto
|
||||
)
|
||||
{
|
||||
await _friendService.HandleFriendRequestAsync(new HandleFriendRequestDto()
|
||||
{
|
||||
|
||||
@ -3,6 +3,7 @@ using IM_API.Interface.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace IM_API.Controllers
|
||||
@ -33,5 +34,13 @@ namespace IM_API.Controllers
|
||||
await _messageService.SendGroupMessageAsync(int.Parse(userIdstr), dto.ReceiverId, dto);
|
||||
return Ok(new BaseResponse<object?>());
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetMessageList([Required]int conversationId, int? msgId, int? pageSize)
|
||||
{
|
||||
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var msgList = await _messageService.GetMessagesAsync(int.Parse(userIdStr), conversationId, msgId, pageSize, false);
|
||||
var res = new BaseResponse<List<MessageBaseDto>>(msgList);
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
backend/IM_API/Domain/Events/FriendAddEvent.cs
Normal file
24
backend/IM_API/Domain/Events/FriendAddEvent.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using IM_API.Dtos;
|
||||
|
||||
namespace IM_API.Domain.Events
|
||||
{
|
||||
public record FriendAddEvent:DomainEvent
|
||||
{
|
||||
public override string EventType => "IM.FRIENDS_FRIEND_ADD";
|
||||
/// <summary>
|
||||
/// 发起请求用户
|
||||
/// </summary>
|
||||
public UserInfoDto RequestUser { get; set; }
|
||||
/// <summary>
|
||||
/// 接受请求用户
|
||||
/// </summary>
|
||||
public UserInfoDto ResponseUser { get; set; }
|
||||
|
||||
public FriendRequestResDto RequestInfo { get; set; }
|
||||
/// <summary>
|
||||
/// 好友关系创建时间
|
||||
/// </summary>
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -73,6 +73,10 @@ namespace IM_API.Dtos
|
||||
this.Code = codeDefine.Code;
|
||||
this.Message = codeDefine.Message;
|
||||
}
|
||||
public BaseResponse() { }
|
||||
public BaseResponse()
|
||||
{
|
||||
this.Code = CodeDefine.SUCCESS.Code;
|
||||
this.Message = CodeDefine.SUCCESS.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,6 @@ namespace IM_API.Dtos
|
||||
/// 对方头像
|
||||
/// </summary>
|
||||
public string? TargetAvatar { get; set; }
|
||||
public virtual Message? LastReadMessage { get; set; }
|
||||
public MessageBaseDto? LastReadMessage { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ namespace IM_API.Dtos
|
||||
public string RemarkName { get; init; } = string.Empty;
|
||||
|
||||
public string? Avatar { get; init; }
|
||||
public UserInfoDto UserInfo { get; init; }
|
||||
}
|
||||
|
||||
public record FriendRequestHandleDto
|
||||
|
||||
@ -4,7 +4,7 @@ namespace IM_API.Dtos
|
||||
{
|
||||
public class FriendRequestDto
|
||||
{
|
||||
public int FromUserId { get; set; }
|
||||
public int? FromUserId { get; set; }
|
||||
public int ToUserId { get; set; }
|
||||
[Required(ErrorMessage = "备注名必填")]
|
||||
[StringLength(20, ErrorMessage = "备注名不能超过20位字符")]
|
||||
|
||||
36
backend/IM_API/Dtos/FriendRequestResDto.cs
Normal file
36
backend/IM_API/Dtos/FriendRequestResDto.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using IM_API.Models;
|
||||
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class FriendRequestResDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请人
|
||||
/// </summary>
|
||||
public int RequestUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被申请人
|
||||
/// </summary>
|
||||
public int ResponseUser { get; set; }
|
||||
public string Avatar { get; set; }
|
||||
public string NickName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请时间
|
||||
/// </summary>
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请附言
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请状态(0:待通过,1:拒绝,2:同意,3:拉黑)
|
||||
/// </summary>
|
||||
public FriendRequestState State { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,16 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public record MessageBaseDto(
|
||||
string Type,string ChatType, string? MsgId,int SenderId,int ReceiverId,string Content,DateTime TimeStamp);
|
||||
public record MessageBaseDto
|
||||
{
|
||||
// 使用 { get; init; } 确保对象创建后不可修改,且支持无参构造
|
||||
public string Type { get; init; } = default!;
|
||||
public string ChatType { get; init; } = default!;
|
||||
public string? MsgId { get; init; }
|
||||
public int SenderId { get; init; }
|
||||
public int ReceiverId { get; init; }
|
||||
public int? GroupMemberId { get; init; }
|
||||
public string Content { get; init; } = default!;
|
||||
public DateTime TimeStamp { get; init; }
|
||||
public MessageBaseDto() { }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
using IM_API.Dtos;
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Security.Claims;
|
||||
@ -10,10 +14,14 @@ namespace IM_API.Hubs
|
||||
{
|
||||
private IMessageSevice _messageService;
|
||||
private readonly IConversationService _conversationService;
|
||||
public ChatHub(IMessageSevice messageService, IConversationService conversationService)
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly IMapper _mapper;
|
||||
public ChatHub(IMessageSevice messageService, IConversationService conversationService, IEventBus eventBus, IMapper mapper)
|
||||
{
|
||||
_messageService = messageService;
|
||||
_conversationService = conversationService;
|
||||
_eventBus = eventBus;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async override Task OnConnectedAsync()
|
||||
@ -32,7 +40,7 @@ namespace IM_API.Hubs
|
||||
}
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
public async Task SendPrivateMessage(MessageBaseDto dto)
|
||||
public async Task SendMessage(MessageBaseDto dto)
|
||||
{
|
||||
if (!Context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
@ -41,8 +49,27 @@ namespace IM_API.Hubs
|
||||
return;
|
||||
}
|
||||
var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
await _messageService.SendPrivateMessageAsync(int.Parse(userIdStr),dto.ReceiverId,dto);
|
||||
await Clients.Users(dto.ReceiverId.ToString()).SendAsync("ReceiveMessage", userIdStr, dto.Content);
|
||||
MessageBaseDto msgInfo = null;
|
||||
if(dto.ChatType.ToLower() == ChatType.PRIVATE.ToString().ToLower())
|
||||
{
|
||||
msgInfo = await _messageService.SendPrivateMessageAsync(int.Parse(userIdStr), dto.ReceiverId, dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
msgInfo = await _messageService.SendGroupMessageAsync(int.Parse(userIdStr), dto.ReceiverId, dto);
|
||||
}
|
||||
return;
|
||||
}
|
||||
public async Task ClearUnreadCount(int conversationId)
|
||||
{
|
||||
if (!Context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
await Clients.Caller.SendAsync("ReceiveMessage", new BaseResponse<object?>(CodeDefine.AUTH_FAILED));
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
await _conversationService.ClearUnreadCountAsync(int.Parse(userIdStr), conversationId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
|
||||
<PackageReference Include="MassTransit.RabbitMQ" Version="8.5.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.21" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.21">
|
||||
|
||||
@ -29,5 +29,18 @@ namespace IM_API.Interface.Services
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<string>> GetUserAllStreamKeyAsync(int userId);
|
||||
/// <summary>
|
||||
/// 获取单个conversation信息
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <returns></returns>
|
||||
Task<ConversationDto> GetConversationByIdAsync(int userId, int conversationId);
|
||||
/// <summary>
|
||||
/// 清空未读消息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> ClearUnreadCountAsync(int userId, int conversationId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ namespace IM_API.Interface.Services
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<FriendRequest>> GetFriendRequestListAsync(int userId,bool isReceived,int page,int limit, bool desc);
|
||||
Task<List<FriendRequestResDto>> GetFriendRequestListAsync(int userId,int page,int limit, bool desc);
|
||||
/// <summary>
|
||||
/// 处理好友请求
|
||||
/// </summary>
|
||||
|
||||
@ -11,7 +11,7 @@ namespace IM_API.Interface.Services
|
||||
/// <param name="receiverId">接收人</param>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SendPrivateMessageAsync(int senderId,int receiverId,MessageBaseDto dto);
|
||||
Task<MessageBaseDto> SendPrivateMessageAsync(int senderId,int receiverId,MessageBaseDto dto);
|
||||
/// <summary>
|
||||
/// 发送群聊消息
|
||||
/// </summary>
|
||||
@ -19,26 +19,16 @@ namespace IM_API.Interface.Services
|
||||
/// <param name="groupId">接收群id</param>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SendGroupMessageAsync(int senderId,int groupId,MessageBaseDto dto);
|
||||
Task<MessageBaseDto> SendGroupMessageAsync(int senderId,int groupId,MessageBaseDto dto);
|
||||
/// <summary>
|
||||
/// 获取私聊消息列表
|
||||
/// 获取消息列表
|
||||
/// </summary>
|
||||
/// <param name="userAId"></param>
|
||||
/// <param name="userBId"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="conversationId">会话id(用于获取指定用户间聊天消息)</param>
|
||||
/// <param name="msgId">消息id</param>
|
||||
/// <param name="pageSize">获取消息数量</param>
|
||||
/// <param name="desc"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<MessageBaseDto>> GetPrivateMessagesAsync(int userAId,int userBId,int page,int pageSize,bool desc);
|
||||
/// <summary>
|
||||
/// 获取群聊消息列表
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="desc"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<MessageBaseDto>> GetGroupMessagesAsync(int groupId, int page, int pageSize, bool desc);
|
||||
Task<List<MessageBaseDto>> GetMessagesAsync(int userId, int conversationId,int? msgId,int? pageSize,bool desc);
|
||||
/// <summary>
|
||||
/// 获取未读消息数
|
||||
/// </summary>
|
||||
|
||||
@ -1,16 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal;
|
||||
|
||||
namespace IM_API.Models;
|
||||
|
||||
public partial class ImContext : DbContext
|
||||
{
|
||||
public ImContext()
|
||||
{
|
||||
}
|
||||
|
||||
public ImContext(DbContextOptions<ImContext> options)
|
||||
: base(options)
|
||||
{
|
||||
@ -50,10 +45,6 @@ public partial class ImContext : DbContext
|
||||
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
|
||||
=> optionsBuilder.UseMySql("server=frp-era.com;port=26582;database=IM;user=product;password=12345678", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.44-mysql"));
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
@ -547,6 +538,9 @@ public partial class ImContext : DbContext
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("发送时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.GroupMemberId)
|
||||
.HasComment("若为群消息则表示具体的成员id")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.MsgType)
|
||||
.HasComment("消息类型\r\n(0:文本,1:图片,2:语音,3:视频,4:文件,5:语音聊天,6:视频聊天)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
|
||||
@ -1,732 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal;
|
||||
|
||||
namespace IM_API.Models;
|
||||
|
||||
public partial class ImDbContext : DbContext
|
||||
{
|
||||
public ImDbContext()
|
||||
{
|
||||
}
|
||||
|
||||
public ImDbContext(DbContextOptions<ImDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Admin> Admins { get; set; }
|
||||
|
||||
public virtual DbSet<Conversation> Conversations { get; set; }
|
||||
|
||||
public virtual DbSet<Device> Devices { get; set; }
|
||||
|
||||
public virtual DbSet<File> Files { get; set; }
|
||||
|
||||
public virtual DbSet<Friend> Friends { get; set; }
|
||||
|
||||
public virtual DbSet<FriendRequest> FriendRequests { get; set; }
|
||||
|
||||
public virtual DbSet<Group> Groups { get; set; }
|
||||
|
||||
public virtual DbSet<GroupInvite> GroupInvites { get; set; }
|
||||
|
||||
public virtual DbSet<GroupMember> GroupMembers { get; set; }
|
||||
|
||||
public virtual DbSet<GroupRequest> GroupRequests { get; set; }
|
||||
|
||||
public virtual DbSet<LoginLog> LoginLogs { get; set; }
|
||||
|
||||
public virtual DbSet<Message> Messages { get; set; }
|
||||
|
||||
public virtual DbSet<Notification> Notifications { get; set; }
|
||||
|
||||
public virtual DbSet<Permission> Permissions { get; set; }
|
||||
|
||||
public virtual DbSet<Permissionarole> Permissionaroles { get; set; }
|
||||
|
||||
public virtual DbSet<Role> Roles { get; set; }
|
||||
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
|
||||
=> optionsBuilder.UseMySql("server=frp-era.com;port=26582;database=IM;user=product;password=12345678", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.44-mysql"));
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.UseCollation("latin1_swedish_ci")
|
||||
.HasCharSet("latin1");
|
||||
|
||||
modelBuilder.Entity<Admin>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("admins")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.RoleId, "RoleId");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Password)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("密码");
|
||||
entity.Property(e => e.RoleId)
|
||||
.HasComment("角色")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.State)
|
||||
.HasComment("状态(0:正常,2:封禁) ")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Updated)
|
||||
.HasComment("更新时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Username)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("用户名");
|
||||
|
||||
entity.HasOne(d => d.Role).WithMany(p => p.Admins)
|
||||
.HasForeignKey(d => d.RoleId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("admins_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Conversation>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("conversations")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.UserId, "Userid");
|
||||
|
||||
entity.HasIndex(e => e.LastReadMessageId, "lastReadMessageId");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.ChatType).HasColumnType("int(11)");
|
||||
entity.Property(e => e.LastReadMessageId)
|
||||
.HasComment("最后一条已读消息ID ")
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("lastMessageId");
|
||||
entity.Property(e => e.StreamKey)
|
||||
.HasMaxLength(255)
|
||||
.HasComment("消息推送唯一标识符");
|
||||
entity.Property(e => e.TargetId)
|
||||
.HasComment("对方ID(群聊为群聊ID,单聊为单聊ID) ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.UnreadCount)
|
||||
.HasComment("未读消息数 ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("用户")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.User).WithMany(p => p.Conversations)
|
||||
.HasForeignKey(d => d.UserId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("conversations_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Device>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("devices")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.UserId, "Userid");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Dtype)
|
||||
.HasComment("设备类型(\r\n0:Android,1:Ios,2:PC,3:Pad,4:未知)")
|
||||
.HasColumnType("tinyint(4)")
|
||||
.HasColumnName("DType");
|
||||
entity.Property(e => e.LastLogin)
|
||||
.HasComment("最后一次登录 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("设备所属用户 ")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.User).WithMany(p => p.Devices)
|
||||
.HasForeignKey(d => d.UserId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("devices_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<File>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("files")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.MessageId, "Messageld");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.MessageId)
|
||||
.HasComment("关联消息ID ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("文件名 ");
|
||||
entity.Property(e => e.Size)
|
||||
.HasComment("文件大小(单位:KB) ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Type)
|
||||
.HasMaxLength(10)
|
||||
.HasComment("文件类型 ");
|
||||
entity.Property(e => e.Url)
|
||||
.HasMaxLength(100)
|
||||
.HasComment("文件储存URL ")
|
||||
.HasColumnName("URL");
|
||||
|
||||
entity.HasOne(d => d.Message).WithMany(p => p.Files)
|
||||
.HasForeignKey(d => d.MessageId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("files_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Friend>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("friends")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.Id, "ID");
|
||||
|
||||
entity.HasIndex(e => new { e.UserId, e.FriendId }, "Userld");
|
||||
|
||||
entity.HasIndex(e => e.FriendId, "用户2id");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Avatar)
|
||||
.HasMaxLength(255)
|
||||
.HasComment("好友头像");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("好友关系创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.FriendId)
|
||||
.HasComment("用户2ID")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.RemarkName)
|
||||
.HasMaxLength(20)
|
||||
.HasComment("好友备注名");
|
||||
entity.Property(e => e.Status)
|
||||
.HasComment("当前好友关系状态\r\n(0:待通过,1:已添加,2:已拒绝,3:已拉黑)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("用户ID")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.FriendNavigation).WithMany(p => p.FriendFriendNavigations)
|
||||
.HasForeignKey(d => d.FriendId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("用户2id");
|
||||
|
||||
entity.HasOne(d => d.User).WithMany(p => p.FriendUsers)
|
||||
.HasForeignKey(d => d.UserId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("用户id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<FriendRequest>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("friend_request")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.RequestUser, "RequestUser");
|
||||
|
||||
entity.HasIndex(e => e.ResponseUser, "ResponseUser");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("申请时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Description)
|
||||
.HasComment("申请附言 ")
|
||||
.HasColumnType("text");
|
||||
entity.Property(e => e.RequestUser)
|
||||
.HasComment("申请人 ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.ResponseUser)
|
||||
.HasComment("被申请人 ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.State)
|
||||
.HasComment("申请状态(0:待通过,1:拒绝,2:同意,3:拉黑) ")
|
||||
.HasColumnType("tinyint(4)");
|
||||
|
||||
entity.HasOne(d => d.RequestUserNavigation).WithMany(p => p.FriendRequestRequestUserNavigations)
|
||||
.HasForeignKey(d => d.RequestUser)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("friend_request_ibfk_1");
|
||||
|
||||
entity.HasOne(d => d.ResponseUserNavigation).WithMany(p => p.FriendRequestResponseUserNavigations)
|
||||
.HasForeignKey(d => d.ResponseUser)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("friend_request_ibfk_2");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Group>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("groups")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.GroupMaster, "GroupMaster");
|
||||
|
||||
entity.HasIndex(e => e.Id, "ID");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.AllMembersBanned)
|
||||
.HasComment("全员禁言(0允许发言,2全员禁言)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Announcement)
|
||||
.HasComment("群公告")
|
||||
.HasColumnType("text");
|
||||
entity.Property(e => e.Auhority)
|
||||
.HasComment("群权限\r\n(0:需管理员同意,1:任意人可加群,2:不允许任何人加入)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("群聊创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.GroupMaster)
|
||||
.HasComment("群主")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(20)
|
||||
.HasComment("群聊名称");
|
||||
entity.Property(e => e.Status)
|
||||
.HasComment("群聊状态\r\n(1:正常,2:封禁)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
|
||||
entity.HasOne(d => d.GroupMasterNavigation).WithMany(p => p.Groups)
|
||||
.HasForeignKey(d => d.GroupMaster)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("groups_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<GroupInvite>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("group_invite")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.GroupId, "GroupId");
|
||||
|
||||
entity.HasIndex(e => e.InviteUser, "InviteUser");
|
||||
|
||||
entity.HasIndex(e => e.InvitedUser, "InvitedUser");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.GroupId)
|
||||
.HasComment("群聊编号")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.InviteUser)
|
||||
.HasComment("邀请用户")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.InvitedUser)
|
||||
.HasComment("被邀请用户")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.State)
|
||||
.HasComment("当前状态(0:待被邀请人同意\r\n1:被邀请人已同意)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
|
||||
entity.HasOne(d => d.Group).WithMany(p => p.GroupInvites)
|
||||
.HasForeignKey(d => d.GroupId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("group_invite_ibfk_2");
|
||||
|
||||
entity.HasOne(d => d.InviteUserNavigation).WithMany(p => p.GroupInviteInviteUserNavigations)
|
||||
.HasForeignKey(d => d.InviteUser)
|
||||
.HasConstraintName("group_invite_ibfk_1");
|
||||
|
||||
entity.HasOne(d => d.InvitedUserNavigation).WithMany(p => p.GroupInviteInvitedUserNavigations)
|
||||
.HasForeignKey(d => d.InvitedUser)
|
||||
.HasConstraintName("group_invite_ibfk_3");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<GroupMember>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("group_member")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.GroupId, "Groupld");
|
||||
|
||||
entity.HasIndex(e => e.Id, "ID");
|
||||
|
||||
entity.HasIndex(e => e.UserId, "Userld");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasDefaultValueSql("'1970-01-01 00:00:00'")
|
||||
.HasComment("加入群聊时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.GroupId)
|
||||
.HasComment("群聊编号")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Role)
|
||||
.HasComment("成员角色(0:普通成员,1:管理员,2:群主)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("用户编号")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.Group).WithMany(p => p.GroupMemberGroups)
|
||||
.HasForeignKey(d => d.GroupId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("group_member_ibfk_2");
|
||||
|
||||
entity.HasOne(d => d.User).WithMany(p => p.GroupMemberUsers)
|
||||
.HasForeignKey(d => d.UserId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("group_member_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<GroupRequest>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("group_request")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.GroupId, "GroupId");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Description)
|
||||
.HasComment("入群附言")
|
||||
.HasColumnType("text");
|
||||
entity.Property(e => e.GroupId)
|
||||
.HasComment("群聊编号\r\n")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.State)
|
||||
.HasComment("申请状态(0:待管理员同意,1:已拒绝,2:已同意)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("申请人 ")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.Group).WithMany(p => p.GroupRequests)
|
||||
.HasForeignKey(d => d.GroupId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("group_request_ibfk_1");
|
||||
|
||||
entity.HasOne(d => d.GroupNavigation).WithMany(p => p.GroupRequests)
|
||||
.HasForeignKey(d => d.GroupId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("group_request_ibfk_2");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<LoginLog>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("login_log")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.UserId, "Userld");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Dtype)
|
||||
.HasComment("设备类型(通Devices/DType) ")
|
||||
.HasColumnType("tinyint(4)")
|
||||
.HasColumnName("DType");
|
||||
entity.Property(e => e.Logined)
|
||||
.HasComment("登录时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.State)
|
||||
.HasComment("登录状态(0:登陆成功,1:未验证,2:已被拒绝) ")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("登录用户 ")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.User).WithMany(p => p.LoginLogs)
|
||||
.HasForeignKey(d => d.UserId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("login_log_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Message>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("messages")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.Sender, "Sender");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.ChatType)
|
||||
.HasComment("聊天类型\r\n(0:私聊,1:群聊)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Content)
|
||||
.HasComment("消息内容 ")
|
||||
.HasColumnType("text");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("发送时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.MsgType)
|
||||
.HasComment("消息类型\r\n(0:文本,1:图片,2:语音,3:视频,4:文件,5:语音聊天,6:视频聊天)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Recipient)
|
||||
.HasComment("接收者(私聊为用户ID,群聊为群聊ID) ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Sender)
|
||||
.HasComment("发送者 ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.State)
|
||||
.HasComment("消息状态(0:已发送,1:已撤回) ")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.StreamKey)
|
||||
.HasMaxLength(255)
|
||||
.HasComment("消息推送唯一标识符");
|
||||
|
||||
entity.HasOne(d => d.SenderNavigation).WithMany(p => p.Messages)
|
||||
.HasForeignKey(d => d.Sender)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("messages_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Notification>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("notifications")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.UserId, "Userld");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Content)
|
||||
.HasComment("通知内容")
|
||||
.HasColumnType("text");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Ntype)
|
||||
.HasComment("通知类型(0:文本)")
|
||||
.HasColumnType("tinyint(4)")
|
||||
.HasColumnName("NType");
|
||||
entity.Property(e => e.Title)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("通知标题");
|
||||
entity.Property(e => e.UserId)
|
||||
.HasComment("接收人(为空为全体通知)")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.User).WithMany(p => p.Notifications)
|
||||
.HasForeignKey(d => d.UserId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("notifications_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Permission>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("permissions")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Code)
|
||||
.HasComment("权限编码 ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("权限名称 ");
|
||||
entity.Property(e => e.Ptype)
|
||||
.HasComment("权限类型(0:增,1:删,2:改,3:查) ")
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("PType");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Permissionarole>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("permissionarole")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.PermissionId, "Permissionld");
|
||||
|
||||
entity.HasIndex(e => e.RoleId, "Roleld");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.PermissionId)
|
||||
.HasComment("权限 ")
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.RoleId)
|
||||
.HasComment("角色 ")
|
||||
.HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.Permission).WithMany(p => p.Permissionaroles)
|
||||
.HasForeignKey(d => d.PermissionId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("permissionarole_ibfk_2");
|
||||
|
||||
entity.HasOne(d => d.Role).WithMany(p => p.Permissionaroles)
|
||||
.HasForeignKey(d => d.RoleId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("permissionarole_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Role>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("roles")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Created)
|
||||
.HasComment("创建时间 ")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Description)
|
||||
.HasComment("角色描述 ")
|
||||
.HasColumnType("text");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(20)
|
||||
.HasComment("角色名称 ");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<User>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("users")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.Id, "ID");
|
||||
|
||||
entity.HasIndex(e => e.Username, "Username").IsUnique();
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("ID");
|
||||
entity.Property(e => e.Avatar)
|
||||
.HasMaxLength(255)
|
||||
.HasComment("用户头像链接");
|
||||
entity.Property(e => e.Created)
|
||||
.HasDefaultValueSql("'1970-01-01 00:00:00'")
|
||||
.HasComment("创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.IsDeleted)
|
||||
.HasComment("软删除标识\r\n0:账号正常\r\n1:账号已删除")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.NickName)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("用户昵称");
|
||||
entity.Property(e => e.OnlineStatus)
|
||||
.HasComment("用户在线状态\r\n0(默认):不在线\r\n1:在线")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Password)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("密码");
|
||||
entity.Property(e => e.Status)
|
||||
.HasDefaultValueSql("'1'")
|
||||
.HasComment("账户状态\r\n(0:未激活,1:正常,2:封禁)")
|
||||
.HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Updated)
|
||||
.HasComment("修改时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.Username)
|
||||
.HasMaxLength(50)
|
||||
.HasComment("唯一用户名");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
@ -49,6 +49,11 @@ public partial class Message
|
||||
/// </summary>
|
||||
public string StreamKey { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 若为群消息则表示具体的成员id
|
||||
/// </summary>
|
||||
public int? GroupMemberId { get; set; }
|
||||
|
||||
public virtual ICollection<Conversation> Conversations { get; set; } = new List<Conversation>();
|
||||
|
||||
public virtual ICollection<File> Files { get; set; } = new List<File>();
|
||||
|
||||
@ -3,6 +3,7 @@ using IM_API.Configs;
|
||||
using IM_API.Filters;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@ -32,6 +33,8 @@ namespace IM_API
|
||||
//×¢Èëredis
|
||||
var redis = ConnectionMultiplexer.Connect(redisConStr);
|
||||
builder.Services.AddSingleton<IConnectionMultiplexer>(redis);
|
||||
|
||||
builder.Services.AddRabbitMQ(configuration.GetSection("RabbitMqOptions").Get<RabbitMqOptions>());
|
||||
|
||||
builder.Services.AddAllService(configuration);
|
||||
|
||||
@ -44,7 +47,13 @@ namespace IM_API
|
||||
policy.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyOrigin();
|
||||
.AllowCredentials()
|
||||
.SetIsOriginAllowed(origin =>
|
||||
{
|
||||
// 允许所有来自本地或特定网段的请求
|
||||
var host = new Uri(origin).Host;
|
||||
return host == "localhost" || host.StartsWith("192.168.");
|
||||
});
|
||||
});
|
||||
});
|
||||
//ƾ֤´¦Àí
|
||||
@ -86,11 +95,7 @@ namespace IM_API
|
||||
context.Token = accessToken;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
},
|
||||
OnAuthenticationFailed = context =>
|
||||
{
|
||||
Console.WriteLine("Authentication failed: " + context.Exception.Message);
|
||||
@ -101,6 +106,10 @@ namespace IM_API
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.Filters.Add<GlobalExceptionFilter>();
|
||||
}).AddJsonOptions(options =>
|
||||
{
|
||||
// 保持 ISO 8601 格式
|
||||
options.JsonSerializerOptions.Converters.Add(new UtcDateTimeConverter());
|
||||
});
|
||||
builder.Services.AddModelValidation(configuration);
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using IM_API.Dtos;
|
||||
using AutoMapper;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
@ -10,9 +11,11 @@ namespace IM_API.Services
|
||||
public class ConversationService : IConversationService
|
||||
{
|
||||
private readonly ImContext _context;
|
||||
public ConversationService(ImContext context)
|
||||
private readonly IMapper _mapper;
|
||||
public ConversationService(ImContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
#region 删除用户会话
|
||||
public async Task<bool> ClearConversationsAsync(int userId)
|
||||
@ -26,47 +29,41 @@ namespace IM_API.Services
|
||||
#region 获取用户会话列表
|
||||
public async Task<List<ConversationDto>> GetConversationsAsync(int userId)
|
||||
{
|
||||
var privateQuery = from c in _context.Conversations
|
||||
join f in _context.Friends on new { c.UserId, c.TargetId}
|
||||
equals new { UserId = f.UserId, TargetId = f.FriendId}
|
||||
where c.UserId == userId && c.ChatType == (int)ChatType.PRIVATE
|
||||
select new ConversationDto
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
TargetId = c.TargetId,
|
||||
LastReadMessageId = c.LastReadMessageId,
|
||||
LastReadMessage = c.LastReadMessage,
|
||||
UnreadCount = c.UnreadCount,
|
||||
ChatType = c.ChatType,
|
||||
LastMessage = c.LastMessage,
|
||||
TargetAvatar = f.Avatar,
|
||||
TargetName = f.RemarkName,
|
||||
DateTime = c.LastMessageTime
|
||||
// 1. 获取私聊会话
|
||||
var privateList = await (from c in _context.Conversations
|
||||
join f in _context.Friends on new { c.UserId, c.TargetId }
|
||||
equals new { UserId = f.UserId, TargetId = f.FriendId }
|
||||
where c.UserId == userId && c.ChatType == (int)ChatType.PRIVATE
|
||||
select new { c, f.Avatar, f.RemarkName })
|
||||
.ToListAsync();
|
||||
|
||||
};
|
||||
// 2. 获取群聊会话
|
||||
var groupList = await (from c in _context.Conversations
|
||||
join g in _context.Groups on c.TargetId equals g.Id
|
||||
where c.UserId == userId && c.ChatType == (int)ChatType.GROUP
|
||||
select new { c, g.Avatar, g.Name })
|
||||
.ToListAsync();
|
||||
|
||||
var groupQuery = from c in _context.Conversations
|
||||
join g in _context.Groups on c.TargetId equals g.Id
|
||||
where c.UserId == userId && c.ChatType == (int)ChatType.GROUP
|
||||
select new ConversationDto
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
TargetId = c.TargetId,
|
||||
LastReadMessageId = c.LastReadMessageId,
|
||||
LastReadMessage = c.LastReadMessage,
|
||||
UnreadCount = c.UnreadCount,
|
||||
ChatType = c.ChatType,
|
||||
LastMessage = c.LastMessage,
|
||||
TargetAvatar = g.Avatar,
|
||||
TargetName = g.Name,
|
||||
DateTime = c.LastMessageTime
|
||||
};
|
||||
return await privateQuery
|
||||
.Concat(groupQuery)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ToListAsync();
|
||||
var privateDtos = privateList.Select(x =>
|
||||
{
|
||||
var dto = _mapper.Map<ConversationDto>(x.c);
|
||||
dto.TargetAvatar = x.Avatar;
|
||||
dto.TargetName = x.RemarkName;
|
||||
return dto;
|
||||
});
|
||||
|
||||
var groupDtos = groupList.Select(x =>
|
||||
{
|
||||
var dto = _mapper.Map<ConversationDto>(x.c);
|
||||
dto.TargetAvatar = x.Avatar;
|
||||
dto.TargetName = x.Name;
|
||||
return dto;
|
||||
});
|
||||
|
||||
// 4. 合并并排序
|
||||
return privateDtos.Concat(groupDtos)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ToList();
|
||||
}
|
||||
#endregion
|
||||
#region 删除单个会话
|
||||
@ -81,6 +78,7 @@ namespace IM_API.Services
|
||||
|
||||
|
||||
#endregion
|
||||
#region 获取用户所有统一聊天凭证
|
||||
public async Task<List<string>> GetUserAllStreamKeyAsync(int userId)
|
||||
{
|
||||
return await _context.Conversations.Where(x => x.UserId == userId)
|
||||
@ -88,5 +86,53 @@ namespace IM_API.Services
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取单个会话信息
|
||||
public async Task<ConversationDto> GetConversationByIdAsync(int userId, int conversationId)
|
||||
{
|
||||
var conversation = await _context.Conversations
|
||||
.Include(x => x.LastReadMessage)
|
||||
.FirstOrDefaultAsync(
|
||||
x => x.UserId == userId && x.Id == conversationId
|
||||
);
|
||||
if (conversation is null) throw new BaseException(CodeDefine.CONVERSATION_NOT_FOUND);
|
||||
var dto = _mapper.Map<ConversationDto>(conversation);
|
||||
//dto.LastReadMessage = _mapper.Map<MessageBaseDto>(conversation);
|
||||
if(conversation.ChatType == (int)ChatType.PRIVATE)
|
||||
{
|
||||
var friendInfo = await _context.Friends.FirstOrDefaultAsync(
|
||||
x => x.UserId == userId && x.FriendId == conversation.TargetId
|
||||
);
|
||||
if (friendInfo is null) throw new BaseException(CodeDefine.FRIEND_RELATION_NOT_FOUND);
|
||||
_mapper.Map(friendInfo,dto);
|
||||
}
|
||||
if(conversation.ChatType == (int)ChatType.GROUP)
|
||||
{
|
||||
var groupInfo = await _context.Groups.FirstOrDefaultAsync(
|
||||
x => x.Id == conversation.TargetId
|
||||
);
|
||||
if (groupInfo is null) throw new BaseException(CodeDefine.GROUP_NOT_FOUND);
|
||||
_mapper.Map(groupInfo, dto);
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public async Task<bool> ClearUnreadCountAsync(int userId, int conversationId)
|
||||
{
|
||||
var conversation = await _context.Conversations.FirstOrDefaultAsync(x => x.UserId == userId && x.Id == conversationId);
|
||||
if (conversation is null) throw new BaseException(CodeDefine.CONVERSATION_NOT_FOUND);
|
||||
var message = await _context.Messages
|
||||
.Where(x => x.StreamKey == conversation.StreamKey)
|
||||
.OrderByDescending(x => x.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
conversation.LastReadMessage = message;
|
||||
conversation.UnreadCount = 0;
|
||||
_context.Conversations.Update(conversation);
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ namespace IM_API.Services
|
||||
|
||||
public async Task<List<FriendInfoDto>> GetFriendListAsync(int userId, int page, int limit, bool desc)
|
||||
{
|
||||
var query = _context.Friends.Where(x => x.UserId == userId && x.Status == (sbyte)FriendStatus.Added);
|
||||
var query = _context.Friends.Include(u => u.FriendNavigation).Where(x => x.UserId == userId && x.Status == (sbyte)FriendStatus.Added);
|
||||
if (desc)
|
||||
{
|
||||
query = query.OrderByDescending(x => x.UserId);
|
||||
@ -73,23 +73,29 @@ namespace IM_API.Services
|
||||
}
|
||||
#endregion
|
||||
#region 获取好友请求列表
|
||||
public async Task<List<FriendRequest>> GetFriendRequestListAsync(int userId, bool isReceived, int page, int limit, bool desc)
|
||||
public async Task<List<FriendRequestResDto>> GetFriendRequestListAsync(int userId, int page, int limit, bool desc)
|
||||
{
|
||||
var query = _context.FriendRequests.AsQueryable();
|
||||
//是否为请求方
|
||||
if (isReceived)
|
||||
{
|
||||
query = _context.FriendRequests.Where(x => x.ResponseUser == userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
query = _context.FriendRequests.Where(x => x.RequestUser == userId);
|
||||
}
|
||||
if (desc)
|
||||
{
|
||||
query = query.OrderByDescending(x => x.Id);
|
||||
}
|
||||
var friendRequestList = await query.Skip((page - 1 * limit)).Take(limit).ToListAsync();
|
||||
var query = _context.FriendRequests
|
||||
.Include(x => x.ResponseUserNavigation)
|
||||
.Include(x => x.RequestUserNavigation)
|
||||
.Where(
|
||||
x => (x.ResponseUser == userId) ||
|
||||
x.RequestUser == userId
|
||||
)
|
||||
.Select(s => new FriendRequestResDto
|
||||
{
|
||||
Id = s.Id,
|
||||
RequestUser = s.RequestUser,
|
||||
ResponseUser = s.ResponseUser,
|
||||
Avatar = s.RequestUser == userId ? s.ResponseUserNavigation.Avatar : s.RequestUserNavigation.Avatar,
|
||||
Created = s.Created,
|
||||
NickName = s.RequestUser == userId ? s.ResponseUserNavigation.NickName : s.RequestUserNavigation.NickName,
|
||||
Description = s.Description,
|
||||
State = (FriendRequestState)s.State
|
||||
})
|
||||
;
|
||||
query = query.OrderByDescending(x => x.Id);
|
||||
var friendRequestList = await query.Skip(((page - 1) * limit)).Take(limit).ToListAsync();
|
||||
return friendRequestList;
|
||||
}
|
||||
#endregion
|
||||
@ -154,18 +160,17 @@ namespace IM_API.Services
|
||||
if (alreadyExists)
|
||||
throw new BaseException(CodeDefine.FRIEND_REQUEST_EXISTS);
|
||||
|
||||
var friendShip = await _context.Friends.FirstOrDefaultAsync(x => x.UserId == dto.FromUserId && x.FriendId == dto.ToUserId);
|
||||
|
||||
//检查是否被对方拉黑
|
||||
bool isBlocked = await _context.Friends.AnyAsync(x =>
|
||||
x.UserId == dto.FromUserId && x.FriendId == dto.ToUserId && x.Status == (sbyte)FriendStatus.Blocked
|
||||
);
|
||||
bool isBlocked = friendShip != null && friendShip.StatusEnum == FriendStatus.Blocked;
|
||||
if (isBlocked)
|
||||
throw new BaseException(CodeDefine.FRIEND_REQUEST_REJECTED);
|
||||
|
||||
if (friendShip != null)
|
||||
throw new BaseException(CodeDefine.ALREADY_FRIENDS);
|
||||
//生成实体
|
||||
var friendRequst = _mapper.Map<FriendRequest>(dto);
|
||||
var friend = _mapper.Map<Friend>(friendRequst);
|
||||
_context.FriendRequests.Add(friendRequst);
|
||||
_context.Friends.Add(friend);
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IM_API.Services
|
||||
@ -13,21 +16,53 @@ namespace IM_API.Services
|
||||
private readonly ImContext _context;
|
||||
private readonly ILogger<MessageService> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
public MessageService(ImContext context, ILogger<MessageService> logger, IMapper mapper)
|
||||
//废弃,此处已使用rabbitMQ替代
|
||||
//private readonly IEventBus _eventBus;
|
||||
private readonly IPublishEndpoint _endpoint;
|
||||
public MessageService(
|
||||
ImContext context, ILogger<MessageService> logger, IMapper mapper, IEventBus eventBus,
|
||||
IPublishEndpoint publishEndpoint
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
//_eventBus = eventBus;
|
||||
_endpoint = publishEndpoint;
|
||||
}
|
||||
|
||||
public Task<List<MessageBaseDto>> GetGroupMessagesAsync(int groupId, int page, int pageSize, bool desc)
|
||||
public async Task<List<MessageBaseDto>> GetMessagesAsync(int userId, int conversationId, int? msgId, int? pageSize, bool desc)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<List<MessageBaseDto>> GetPrivateMessagesAsync(int userAId, int userBId, int page, int pageSize, bool desc)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//获取会话信息,用于获取双方聊天的唯一标识streamkey
|
||||
Conversation? conversation = await _context.Conversations.FirstOrDefaultAsync(
|
||||
x => x.Id == conversationId && x.UserId == userId
|
||||
);
|
||||
if (conversation is null) throw new BaseException(CodeDefine.CONVERSATION_NOT_FOUND);
|
||||
var query = _context.Messages.AsQueryable();
|
||||
if(msgId != null)
|
||||
{
|
||||
query = query.Where(
|
||||
x => x.StreamKey == conversation.StreamKey && x.Id < msgId.Value
|
||||
)
|
||||
.OrderByDescending(x => x.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.Where(
|
||||
x => x.StreamKey == conversation.StreamKey && x.Id > conversation.LastReadMessageId
|
||||
);
|
||||
}
|
||||
if(pageSize != null)
|
||||
{
|
||||
query = query.Take(pageSize.Value);
|
||||
}
|
||||
var msgList = await query
|
||||
.ToListAsync();
|
||||
msgList = msgList
|
||||
.OrderBy(x => x.Created)
|
||||
.ThenBy(t => t.Id)
|
||||
.ToList();
|
||||
return _mapper.Map<List<MessageBaseDto>>(msgList);
|
||||
}
|
||||
|
||||
public Task<int> GetUnreadCountAsync(int userId)
|
||||
@ -55,7 +90,7 @@ namespace IM_API.Services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#region 发送群消息
|
||||
public async Task<bool> SendGroupMessageAsync(int senderId, int groupId, MessageBaseDto dto)
|
||||
public async Task<MessageBaseDto> SendGroupMessageAsync(int senderId, int groupId, MessageBaseDto dto)
|
||||
{
|
||||
//判断群存在
|
||||
var isExist = await _context.Groups.AnyAsync(x => x.Id == groupId);
|
||||
@ -65,15 +100,18 @@ namespace IM_API.Services
|
||||
if (!isMember) throw new BaseException(CodeDefine.NO_GROUP_PERMISSION);
|
||||
var message = _mapper.Map<Message>(dto);
|
||||
message.Sender = senderId;
|
||||
message.StreamKey = StreamKeyBuilder.Group(groupId);
|
||||
message.StreamKey = StreamKeyBuilder.Group(
|
||||
|
||||
groupId);
|
||||
_context.Messages.Add(message);
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
await _endpoint.Publish(_mapper.Map<MessageCreatedEvent>(message));
|
||||
return _mapper.Map<MessageBaseDto>(message);
|
||||
|
||||
}
|
||||
#endregion
|
||||
#region 发送私聊消息
|
||||
public async Task<bool> SendPrivateMessageAsync(int senderId, int receiverId, MessageBaseDto dto)
|
||||
public async Task<MessageBaseDto> SendPrivateMessageAsync(int senderId, int receiverId, MessageBaseDto dto)
|
||||
{
|
||||
bool isExist = await _context.Friends.AnyAsync(x => x.FriendId == receiverId);
|
||||
if (!isExist) throw new BaseException(CodeDefine.FRIEND_RELATION_NOT_FOUND);
|
||||
@ -83,7 +121,8 @@ namespace IM_API.Services
|
||||
message.StreamKey = StreamKeyBuilder.Private(dto.SenderId, dto.ReceiverId);
|
||||
_context.Messages.Add(message);
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
await _endpoint.Publish(_mapper.Map<MessageCreatedEvent>(message));
|
||||
return _mapper.Map<MessageBaseDto>(message);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -53,8 +53,8 @@ namespace IM_API.Services
|
||||
if (json.IsNullOrEmpty) return (false,-1);
|
||||
try
|
||||
{
|
||||
var doc = JsonConvert.DeserializeObject<JsonElement>(json);
|
||||
var userId = doc.GetProperty("UserId").GetInt32();
|
||||
using var doc = JsonDocument.Parse(json.ToString());
|
||||
var userId = doc.RootElement.GetProperty("UserId").GetInt32();
|
||||
return (true,userId);
|
||||
}
|
||||
catch
|
||||
|
||||
18
backend/IM_API/Tools/UTCConverter.cs
Normal file
18
backend/IM_API/Tools/UTCConverter.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace IM_API.Tools
|
||||
{
|
||||
public class UtcDateTimeConverter : System.Text.Json.Serialization.JsonConverter<DateTime>
|
||||
{
|
||||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
=> reader.GetDateTime();
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||
{
|
||||
// 如果 Kind 已经是 Utc,直接输出。
|
||||
// 如果不是,先 SpecifyKind 再输出,确保不会发生时区偏移计算
|
||||
var utcDate = value.Kind == DateTimeKind.Utc ? value : DateTime.SpecifyKind(value, DateTimeKind.Utc);
|
||||
writer.WriteStringValue(utcDate.ToString("yyyy-MM-ddTHH:mm:ssZ"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,5 +16,11 @@
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=frp-era.com;Port=26582;Database=IM;User=product;Password=12345678;",
|
||||
"Redis": "192.168.5.100:6379"
|
||||
},
|
||||
"RabbitMQOptions": {
|
||||
"Host": "192.168.5.100",
|
||||
"Port": 5672,
|
||||
"Username": "test",
|
||||
"Password": "123456"
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,3 +71,12 @@ public WeatherForecastController(IDemo demo)
|
||||
## 4. 模型类字段使用规范
|
||||
|
||||
### 4.1 类中状态相关字段,例如:Status,返回值为sbyte。若类中有同名字段+后缀Enum,则优先使用后者,StatusEnum。
|
||||
|
||||
## 5.数据库相关
|
||||
|
||||
### 5.1 若数据库表结构更新,请在软件包控制台执行如下命令:
|
||||
|
||||
```cmd
|
||||
Scaffold-DbContext "Name=ConnectionStrings:DefaultConnection" Pomelo.EntityFrameworkCore.MySql -OutputDir Models -Context ImContext -Force -NoOnConfiguring
|
||||
```
|
||||
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
allprojects {
|
||||
repositories {
|
||||
maven { url = uri("https://maven.aliyun.com/repository/google") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/public") }
|
||||
google()
|
||||
mavenCentral()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,4 +2,6 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
|
||||
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
|
||||
# ??????????
|
||||
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.14-all.zip
|
||||
@ -11,6 +11,8 @@ pluginManagement {
|
||||
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
|
||||
|
||||
repositories {
|
||||
maven { url = uri("https://maven.aliyun.com/repository/google") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/public") }
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
|
||||
14
frontend/app/lib/app.dart
Normal file
14
frontend/app/lib/app.dart
Normal file
@ -0,0 +1,14 @@
|
||||
import 'package:app/core/router/app_router.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
title: '测试应用',
|
||||
routerConfig:appRouter
|
||||
);
|
||||
}
|
||||
}
|
||||
5
frontend/app/lib/core/constants/app_colors.dart
Normal file
5
frontend/app/lib/core/constants/app_colors.dart
Normal file
@ -0,0 +1,5 @@
|
||||
import 'dart:ui';
|
||||
|
||||
class AppColors {
|
||||
static const Color primaryColor = Color(0xFF4FDBFF); // 微信绿
|
||||
}
|
||||
0
frontend/app/lib/core/constants/app_strings.dart
Normal file
0
frontend/app/lib/core/constants/app_strings.dart
Normal file
0
frontend/app/lib/core/constants/assets_path.dart
Normal file
0
frontend/app/lib/core/constants/assets_path.dart
Normal file
26
frontend/app/lib/core/router/app_router.dart
Normal file
26
frontend/app/lib/core/router/app_router.dart
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
import 'package:app/features/auth/pages/login_page.dart';
|
||||
import 'package:app/features/home/pages/index_page.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../features/home/pages/main_page.dart';
|
||||
|
||||
final appRouter = GoRouter(
|
||||
initialLocation: '/auth/login',
|
||||
routes: [
|
||||
GoRoute(path: '/auth/login', builder: (context, state) => const LoginPage()),
|
||||
ShellRoute(
|
||||
builder: (context, state, child) {
|
||||
return MainPage(child: child);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const IndexPage()
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
|
||||
);
|
||||
167
frontend/app/lib/features/auth/bloc/login_page_state.dart
Normal file
167
frontend/app/lib/features/auth/bloc/login_page_state.dart
Normal file
@ -0,0 +1,167 @@
|
||||
import 'package:app/core/constants/app_colors.dart';
|
||||
import 'package:app/features/auth/pages/login_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoginPageState extends State<LoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text("找回密码", style: TextStyle(color: Colors.grey)),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
// 1. 品牌Logo/头像区域
|
||||
Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryColor.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person_rounded,
|
||||
size: 60,
|
||||
color: AppColors.primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
"登录您的聊天账号",
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// 2. 账号输入框 (极简下划线风格)
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "账号 / 邮箱 / 手机号",
|
||||
labelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
|
||||
floatingLabelStyle: const TextStyle(color: AppColors.primaryColor),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: const UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: AppColors.primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// 3. 密码输入框
|
||||
TextField(
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: "请输入密码",
|
||||
labelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
|
||||
floatingLabelStyle: const TextStyle(color: AppColors.primaryColor),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: const UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: AppColors.primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// 4. 登录按钮 (圆润大按钮)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
"登 录",
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 5. 注册/切换登录方式
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"注册账号",
|
||||
style: TextStyle(color: Color(0xFF576B95)),
|
||||
), // 经典的链接蓝
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
child: VerticalDivider(color: Colors.grey),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"验证码登录",
|
||||
style: TextStyle(color: Color(0xFF576B95)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 80),
|
||||
// 6. 底部协议 (社交App必有)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: true,
|
||||
activeColor: AppColors.primaryColor,
|
||||
onChanged: (v) {},
|
||||
),
|
||||
const Text(
|
||||
"我已阅读并同意",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"《用户协议》",
|
||||
style: TextStyle(color: Color(0xFF576B95), fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"与",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"《隐私政策》",
|
||||
style: TextStyle(color: Color(0xFF576B95), fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
12
frontend/app/lib/features/auth/pages/login_page.dart
Normal file
12
frontend/app/lib/features/auth/pages/login_page.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:app/features/auth/bloc/login_page_state.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return LoginPageState();
|
||||
}
|
||||
|
||||
}
|
||||
10
frontend/app/lib/features/home/bloc/index_page_state.dart
Normal file
10
frontend/app/lib/features/home/bloc/index_page_state.dart
Normal file
@ -0,0 +1,10 @@
|
||||
import 'package:app/features/home/pages/index_page.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class IndexPageState extends State<IndexPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text('test');
|
||||
}
|
||||
|
||||
}
|
||||
19
frontend/app/lib/features/home/bloc/main_page_state.dart
Normal file
19
frontend/app/lib/features/home/bloc/main_page_state.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'package:app/features/home/pages/main_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MainPageState extends State<MainPage> {
|
||||
|
||||
int count = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(count.toString()),
|
||||
backgroundColor: Colors.blue,
|
||||
),
|
||||
body: widget.child
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
12
frontend/app/lib/features/home/pages/index_page.dart
Normal file
12
frontend/app/lib/features/home/pages/index_page.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:app/features/home/bloc/index_page_state.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class IndexPage extends StatefulWidget {
|
||||
const IndexPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return IndexPageState();
|
||||
}
|
||||
|
||||
}
|
||||
13
frontend/app/lib/features/home/pages/main_page.dart
Normal file
13
frontend/app/lib/features/home/pages/main_page.dart
Normal file
@ -0,0 +1,13 @@
|
||||
import 'package:app/features/home/bloc/main_page_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
final Widget child;
|
||||
const MainPage({super.key,required this.child});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return MainPageState();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,178 +1,10 @@
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
import 'package:app/app.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(
|
||||
const MaterialApp(home: IMLoginPage(), debugShowCheckedModeBanner: false),
|
||||
);
|
||||
void main(List<String> args){
|
||||
|
||||
class IMLoginPage extends StatefulWidget {
|
||||
const IMLoginPage({super.key});
|
||||
usePathUrlStrategy();
|
||||
|
||||
@override
|
||||
State<IMLoginPage> createState() => _IMLoginPageState();
|
||||
}
|
||||
|
||||
class _IMLoginPageState extends State<IMLoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 主题色定义:这里用类似微信的深绿或经典的社交蓝
|
||||
const Color primaryColor = Color(0xFF07C160); // 微信绿,你也可以换成 0xFF0084FF (社交蓝)
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text("找回密码", style: TextStyle(color: Colors.grey)),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
// 1. 品牌Logo/头像区域
|
||||
Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
color: primaryColor.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person_rounded,
|
||||
size: 60,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
"登录您的聊天账号",
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// 2. 账号输入框 (极简下划线风格)
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "账号 / 邮箱 / 手机号",
|
||||
labelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
|
||||
floatingLabelStyle: const TextStyle(color: primaryColor),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: const UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// 3. 密码输入框
|
||||
TextField(
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: "请输入密码",
|
||||
labelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
|
||||
floatingLabelStyle: const TextStyle(color: primaryColor),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: const UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// 4. 登录按钮 (圆润大按钮)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
"登 录",
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 5. 注册/切换登录方式
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"注册账号",
|
||||
style: TextStyle(color: Color(0xFF576B95)),
|
||||
), // 经典的链接蓝
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
child: VerticalDivider(color: Colors.grey),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"验证码登录",
|
||||
style: TextStyle(color: Color(0xFF576B95)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 80),
|
||||
// 6. 底部协议 (社交App必有)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: true,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (v) {},
|
||||
),
|
||||
const Text(
|
||||
"我已阅读并同意",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"《用户协议》",
|
||||
style: TextStyle(color: Color(0xFF576B95), fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"与",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"《隐私政策》",
|
||||
style: TextStyle(color: Color(0xFF576B95), fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@ -6,7 +6,7 @@ packages:
|
||||
description:
|
||||
name: async
|
||||
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.13.0"
|
||||
boolean_selector:
|
||||
@ -14,7 +14,7 @@ packages:
|
||||
description:
|
||||
name: boolean_selector
|
||||
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
characters:
|
||||
@ -22,7 +22,7 @@ packages:
|
||||
description:
|
||||
name: characters
|
||||
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
clock:
|
||||
@ -30,7 +30,7 @@ packages:
|
||||
description:
|
||||
name: clock
|
||||
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
collection:
|
||||
@ -38,7 +38,7 @@ packages:
|
||||
description:
|
||||
name: collection
|
||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.19.1"
|
||||
cupertino_icons:
|
||||
@ -46,7 +46,7 @@ packages:
|
||||
description:
|
||||
name: cupertino_icons
|
||||
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.0.8"
|
||||
fake_async:
|
||||
@ -54,7 +54,7 @@ packages:
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.3"
|
||||
flutter:
|
||||
@ -67,7 +67,7 @@ packages:
|
||||
description:
|
||||
name: flutter_lints
|
||||
sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.0.0"
|
||||
flutter_test:
|
||||
@ -75,12 +75,25 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
go_router:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: go_router
|
||||
sha256: eff94d2a6fc79fa8b811dde79c7549808c2346037ee107a1121b4a644c745f2a
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "17.0.1"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "11.0.2"
|
||||
leak_tracker_flutter_testing:
|
||||
@ -88,7 +101,7 @@ packages:
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.10"
|
||||
leak_tracker_testing:
|
||||
@ -96,7 +109,7 @@ packages:
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
lints:
|
||||
@ -104,15 +117,23 @@ packages:
|
||||
description:
|
||||
name: lints
|
||||
sha256: a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.0.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.12.17"
|
||||
material_color_utilities:
|
||||
@ -120,7 +141,7 @@ packages:
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.11.1"
|
||||
meta:
|
||||
@ -128,7 +149,7 @@ packages:
|
||||
description:
|
||||
name: meta
|
||||
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.17.0"
|
||||
path:
|
||||
@ -136,7 +157,7 @@ packages:
|
||||
description:
|
||||
name: path
|
||||
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
sky_engine:
|
||||
@ -149,7 +170,7 @@ packages:
|
||||
description:
|
||||
name: source_span
|
||||
sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.10.1"
|
||||
stack_trace:
|
||||
@ -157,7 +178,7 @@ packages:
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.12.1"
|
||||
stream_channel:
|
||||
@ -165,7 +186,7 @@ packages:
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
string_scanner:
|
||||
@ -173,7 +194,7 @@ packages:
|
||||
description:
|
||||
name: string_scanner
|
||||
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
term_glyph:
|
||||
@ -181,7 +202,7 @@ packages:
|
||||
description:
|
||||
name: term_glyph
|
||||
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.2.2"
|
||||
test_api:
|
||||
@ -189,7 +210,7 @@ packages:
|
||||
description:
|
||||
name: test_api
|
||||
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.7.7"
|
||||
vector_math:
|
||||
@ -197,7 +218,7 @@ packages:
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
vm_service:
|
||||
@ -205,9 +226,9 @@ packages:
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "15.0.2"
|
||||
sdks:
|
||||
dart: ">=3.10.4 <4.0.0"
|
||||
flutter: ">=3.18.0-18.0.pre.54"
|
||||
flutter: ">=3.35.0"
|
||||
|
||||
@ -31,9 +31,13 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
flutter_web_plugins:
|
||||
sdk: flutter
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.8
|
||||
go_router: ^17.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
@ -5,15 +5,14 @@
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:app/features/auth/pages/login_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:app/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const IMLoginPage());
|
||||
await tester.pumpWidget(const LoginPage());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
||||
@ -1 +1,4 @@
|
||||
VITE_API_BASE_URL = http://192.168.5.116:7070/api
|
||||
#VITE_API_BASE_URL = http://localhost:5202/api
|
||||
#VITE_SIGNALR_BASE_URL = http://localhost:5202/chat
|
||||
VITE_API_BASE_URL = https://im.test.nxsir.cn/api
|
||||
VITE_SIGNALR_BASE_URL = https://im.test.nxsir.cn/chat/
|
||||
205
frontend/web/package-lock.json
generated
205
frontend/web/package-lock.json
generated
@ -8,10 +8,12 @@
|
||||
"name": "web",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@microsoft/signalr": "^10.0.0",
|
||||
"@vuelidate/core": "^2.0.3",
|
||||
"@vuelidate/validators": "^2.0.4",
|
||||
"axios": "^1.13.2",
|
||||
"feather-icons": "^4.29.2",
|
||||
"idb": "^8.0.3",
|
||||
"pinia": "^3.0.3",
|
||||
"vee-validate": "^4.15.1",
|
||||
"vue": "^3.5.22",
|
||||
@ -103,6 +105,7 @@
|
||||
"integrity": "sha512-2BCOP7TN8M+gVDj7/ht3hsaO/B/n5oDbiAyyvnRlNOs+u1o+JWNYTQrmpuNp1/Wq2gcFrI01JAW+paEKDMx/CA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.3",
|
||||
@ -655,6 +658,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
@ -701,6 +705,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
@ -1458,6 +1463,40 @@
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/signalr": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/signalr/-/signalr-10.0.0.tgz",
|
||||
"integrity": "sha512-0BRqz/uCx3JdrOqiqgFhih/+hfTERaUfCZXFB52uMaZJrKaPRzHzMuqVsJC/V3pt7NozcNXGspjKiQEK+X7P2w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"eventsource": "^2.0.2",
|
||||
"fetch-cookie": "^2.0.3",
|
||||
"node-fetch": "^2.6.7",
|
||||
"ws": "^7.5.10"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/signalr/node_modules/ws": {
|
||||
"version": "7.5.10",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
||||
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
@ -2613,12 +2652,25 @@
|
||||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.5"
|
||||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.15.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@ -2822,6 +2874,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.8.9",
|
||||
"caniuse-lite": "^1.0.30001746",
|
||||
@ -3436,6 +3489,7 @@
|
||||
"integrity": "sha512-XyLmROnACWqSxiGYArdef1fItQd47weqB7iwtfr9JHwRrqIXZdcFMvvEcL9xHCmL0SNsOvF0c42lWyM1U5dgig==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.8.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@ -3497,6 +3551,7 @@
|
||||
"integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"eslint-config-prettier": "bin/cli.js"
|
||||
},
|
||||
@ -3716,6 +3771,24 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/eventsource": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-2.0.2.tgz",
|
||||
"integrity": "sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/execa": {
|
||||
"version": "9.6.0",
|
||||
"resolved": "https://registry.npmjs.org/execa/-/execa-9.6.0.tgz",
|
||||
@ -3831,6 +3904,31 @@
|
||||
"core-js": "^3.1.3"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-cookie": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-cookie/-/fetch-cookie-2.2.0.tgz",
|
||||
"integrity": "sha512-h9AgfjURuCgA2+2ISl8GbavpUdR+WGAM2McW/ovn4tVccegp8ZqCKWSBR8uRdM8dDNlx5WdKRWxBYUwteLDCNQ==",
|
||||
"license": "Unlicense",
|
||||
"dependencies": {
|
||||
"set-cookie-parser": "^2.4.8",
|
||||
"tough-cookie": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-cookie/node_modules/tough-cookie": {
|
||||
"version": "4.1.4",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.4.tgz",
|
||||
"integrity": "sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"psl": "^1.1.33",
|
||||
"punycode": "^2.1.1",
|
||||
"universalify": "^0.2.0",
|
||||
"url-parse": "^1.5.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/figures": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-6.1.0.tgz",
|
||||
@ -4230,6 +4328,12 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/idb": {
|
||||
"version": "8.0.3",
|
||||
"resolved": "https://registry.npmjs.org/idb/-/idb-8.0.3.tgz",
|
||||
"integrity": "sha512-LtwtVyVYO5BqRvcsKuB2iUMnHwPVByPCXFXOpuU96IZPPoPN6xjOGxZQ74pgSVVLQWtUOYgyeL4GE98BY5D3wg==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
@ -4813,6 +4917,48 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch/node_modules/tr46": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
||||
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/node-fetch/node_modules/webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/node-fetch/node_modules/whatwg-url": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tr46": "~0.0.3",
|
||||
"webidl-conversions": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-releases": {
|
||||
"version": "2.0.23",
|
||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.23.tgz",
|
||||
@ -5127,6 +5273,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.11",
|
||||
"picocolors": "^1.1.1",
|
||||
@ -5166,6 +5313,7 @@
|
||||
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
@ -5224,16 +5372,33 @@
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/psl": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz",
|
||||
"integrity": "sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"punycode": "^2.3.1"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/lupomontero"
|
||||
}
|
||||
},
|
||||
"node_modules/punycode": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
||||
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/querystringify": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
|
||||
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/queue-microtask": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
||||
@ -5265,6 +5430,12 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/requires-port": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||
"integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/resolve-from": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
||||
@ -5411,6 +5582,12 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/set-cookie-parser": {
|
||||
"version": "2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
|
||||
"integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
@ -5760,6 +5937,7 @@
|
||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@ -5938,6 +6116,15 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz",
|
||||
"integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/unplugin-utils": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/unplugin-utils/-/unplugin-utils-0.3.1.tgz",
|
||||
@ -6009,6 +6196,16 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/url-parse": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz",
|
||||
"integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"querystringify": "^2.1.1",
|
||||
"requires-port": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
@ -6035,6 +6232,7 @@
|
||||
"integrity": "sha512-ITcnkFeR3+fI8P1wMgItjGrR10170d8auB4EpMLPqmx6uxElH3a/hHGQabSHKdqd4FXWO1nFIp9rRn7JQ34ACQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.25.0",
|
||||
"fdir": "^6.5.0",
|
||||
@ -6296,6 +6494,7 @@
|
||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@ -6309,6 +6508,7 @@
|
||||
"integrity": "sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/chai": "^5.2.2",
|
||||
"@vitest/expect": "3.2.4",
|
||||
@ -6394,6 +6594,7 @@
|
||||
"resolved": "https://registry.npmjs.org/vue/-/vue-3.5.22.tgz",
|
||||
"integrity": "sha512-toaZjQ3a/G/mYaLSbV+QsQhIdMo9x5rrqIpYRObsJ6T/J+RyCSFwN2LHNVH9v8uIcljDNa3QzPVdv3Y6b9hAJQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@vue/compiler-dom": "3.5.22",
|
||||
"@vue/compiler-sfc": "3.5.22",
|
||||
@ -6423,7 +6624,6 @@
|
||||
"integrity": "sha512-CydUvFOQKD928UzZhTp4pr2vWz1L+H99t7Pkln2QSPdvmURT0MoC4wUccfCnuEaihNsu9aYYyk+bep8rlfkUXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"debug": "^4.4.0",
|
||||
"eslint-scope": "^8.2.0",
|
||||
@ -6448,7 +6648,6 @@
|
||||
"integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
||||
},
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"dev": "vite --host",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"test:unit": "vitest",
|
||||
@ -15,10 +15,12 @@
|
||||
"format": "prettier --write src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/signalr": "^10.0.0",
|
||||
"@vuelidate/core": "^2.0.3",
|
||||
"@vuelidate/validators": "^2.0.4",
|
||||
"axios": "^1.13.2",
|
||||
"feather-icons": "^4.29.2",
|
||||
"idb": "^8.0.3",
|
||||
"pinia": "^3.0.3",
|
||||
"vee-validate": "^4.15.1",
|
||||
"vue": "^3.5.22",
|
||||
|
||||
@ -7,8 +7,19 @@
|
||||
|
||||
<script setup>
|
||||
import Alert from '@/components/messages/Alert.vue';
|
||||
</script>
|
||||
import { onMounted } from 'vue';
|
||||
import { useAuthStore } from './stores/auth';
|
||||
//import { useSignalRStore } from './stores/signalr';
|
||||
|
||||
onMounted(async () => {
|
||||
const { useSignalRStore } = await import('./stores/signalr');
|
||||
const authStore = useAuthStore();
|
||||
const signalRStore = useSignalRStore();
|
||||
if(authStore.token){
|
||||
signalRStore.initSignalR();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
|
||||
#app {
|
||||
|
||||
180
frontend/web/src/components/addMenu.vue
Normal file
180
frontend/web/src/components/addMenu.vue
Normal file
@ -0,0 +1,180 @@
|
||||
<template>
|
||||
<div class="add-menu-container" v-click-outside="closeMenu">
|
||||
<button class="add-btn" :class="{ active: isShow }" @click="toggleMenu">
|
||||
<span class="plus-icon">+</span>
|
||||
</button>
|
||||
|
||||
<Transition name="pop">
|
||||
<div v-if="isShow" class="menu-card">
|
||||
<div class="arrow"></div>
|
||||
|
||||
<div class="menu-list">
|
||||
<div class="menu-item" v-for="(item, index) in props.menuList" :key="index" @click="handleAction(item.action)">
|
||||
<i class="icon" v-html="item.icon"></i>
|
||||
<span>{{item.text}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, defineProps, onMounted, defineEmits } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
menuList: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['actionActive'])
|
||||
|
||||
const isShow = ref(false);
|
||||
|
||||
const toggleMenu = () => {
|
||||
isShow.value = !isShow.value;
|
||||
};
|
||||
|
||||
const closeMenu = () => {
|
||||
isShow.value = false;
|
||||
};
|
||||
|
||||
const handleAction = (type) => {
|
||||
emit('actionActive', type);
|
||||
isShow.value = false; // 点击后关闭
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 自定义指令:点击外部区域关闭菜单
|
||||
* 也可以使用第三方库如 @vueuse/core 的 onClickOutside
|
||||
*/
|
||||
const vClickOutside = {
|
||||
mounted(el, binding) {
|
||||
el.clickOutsideEvent = (event) => {
|
||||
if (!(el === event.target || el.contains(event.target))) {
|
||||
binding.value();
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', el.clickOutsideEvent);
|
||||
},
|
||||
unmounted(el) {
|
||||
document.removeEventListener('click', el.clickOutsideEvent);
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.add-menu-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* 加号按钮样式 */
|
||||
.add-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #dbdbdb;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.add-btn:hover {
|
||||
background: #cccbcb;
|
||||
}
|
||||
/*
|
||||
.add-btn.active {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
}
|
||||
*/
|
||||
|
||||
.plus-icon {
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
/* 弹出卡片容器 */
|
||||
.menu-card {
|
||||
position: absolute;
|
||||
top: 45px;
|
||||
right: 0;
|
||||
width: 100px;
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
z-index: 100;
|
||||
transform-origin: top right;
|
||||
}
|
||||
|
||||
/* 小三角 */
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: 12px;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 6px solid transparent;
|
||||
border-right: 6px solid transparent;
|
||||
border-bottom: 6px solid white;
|
||||
}
|
||||
|
||||
/* 列表样式 */
|
||||
.menu-list {
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 5px 5px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.menu-item:first-child:hover {
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
.menu-item:last-child:hover {
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-right: 5px;
|
||||
font-size: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
/*width: 20px;*/
|
||||
}
|
||||
|
||||
.menu-item span {
|
||||
font-size: 12px;
|
||||
/*font-weight: 400;*/
|
||||
}
|
||||
|
||||
/* 弹出动画 */
|
||||
.pop-enter-active, .pop-leave-active {
|
||||
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
.pop-enter-from, .pop-leave-to {
|
||||
opacity: 0;
|
||||
transform: scale(0.9) translateY(-10px);
|
||||
}
|
||||
</style>
|
||||
256
frontend/web/src/components/groups/GroupChatModal.vue
Normal file
256
frontend/web/src/components/groups/GroupChatModal.vue
Normal file
@ -0,0 +1,256 @@
|
||||
<template>
|
||||
<div class="modal-overlay" @click.self="$emit('close')">
|
||||
<div class="chat-modal">
|
||||
<div class="modal-header">
|
||||
<div class="header-top">
|
||||
<h3>群聊</h3>
|
||||
<button class="close-btn" @click="$emit('close')">×</button>
|
||||
</div>
|
||||
<div class="search-bar">
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
placeholder="搜索群组..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-list">
|
||||
<TransitionGroup name="list">
|
||||
<div
|
||||
v-for="group in filteredGroups"
|
||||
:key="group.id"
|
||||
class="chat-item"
|
||||
@click="handleSelect(group)"
|
||||
>
|
||||
<div
|
||||
class="avatar"
|
||||
:style="{ background: group.avatar ? `url(${group.avatar}) center/cover` : group.color }"
|
||||
>
|
||||
{{ group.avatar ? '' : group.name.charAt(0) }}
|
||||
</div>
|
||||
|
||||
<div class="chat-info">
|
||||
<div class="chat-name">{{ group.name }}</div>
|
||||
<!--<div class="chat-preview">{{ group.lastMsg }}</div>-->
|
||||
</div>
|
||||
<!--
|
||||
<div class="chat-meta">
|
||||
<span class="time">{{ group.time }}</span>
|
||||
<span v-if="group.unread" class="unread">{{ group.unread }}</span>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
|
||||
</TransitionGroup>
|
||||
|
||||
<div v-if="filteredGroups.length === 0" class="empty-state">
|
||||
未找到相关群聊
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, defineProps } from 'vue';
|
||||
|
||||
// 检查你的代码,确保 default 是一个返回数组的函数,且逗号、括号一一对应
|
||||
const props = defineProps({
|
||||
initialGroups: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ id: 1, name: '产品设计交流群', lastMsg: '张三: 确认一下原型图', time: '14:30', unread: 3, color: 'linear-gradient(45deg, #007AFF, #5AC8FA)' },
|
||||
{ id: 2, name: '技术研发部', lastMsg: '王五: Bug已修复并上线', time: '12:05', unread: 0, color: 'linear-gradient(45deg, #4CD964, #5AC8FA)' },
|
||||
{ id: 3, name: '周末户外徒步', lastMsg: '李四: 记得带雨伞', time: '昨天', unread: 12, color: 'linear-gradient(45deg, #FF9500, #FFCC00)' },
|
||||
{ id: 4, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' }, // 确保这里没有多余或缺失的逗号
|
||||
{ id: 5, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 6, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 7, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 8, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 9, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' }
|
||||
]
|
||||
}
|
||||
}); // 检查这里是否漏掉了右括号 )
|
||||
|
||||
|
||||
const emit = defineEmits(['close', 'select']);
|
||||
const searchQuery = ref('');
|
||||
|
||||
// 搜索过滤逻辑
|
||||
const filteredGroups = computed(() => {
|
||||
return props.initialGroups.filter(g =>
|
||||
g.name.toLowerCase().includes(searchQuery.value.toLowerCase())
|
||||
);
|
||||
});
|
||||
|
||||
const handleSelect = (group) => {
|
||||
emit('select', group);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 遮罩层 */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
backdrop-filter: blur(4px);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* 弹出层主容器 */
|
||||
.chat-modal {
|
||||
width: 360px;
|
||||
max-height: 80vh;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
backdrop-filter: blur(20px);
|
||||
border-radius: 28px;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
/* 头部样式 */
|
||||
.modal-header {
|
||||
padding: 20px 20px 10px;
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.header-top h3 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
color: #1d1d1f;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: #eee;
|
||||
border: none;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
font-size: 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* 搜索框 */
|
||||
.search-bar input {
|
||||
width: 100%;
|
||||
padding: 10px 15px;
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 列表滚动区 */
|
||||
.chat-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.chat-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-radius: 18px;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
cursor: pointer;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.chat-item:hover {
|
||||
background: rgba(0, 122, 255, 0.08);
|
||||
}
|
||||
|
||||
/* 头像 */
|
||||
.avatar {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 15px;
|
||||
margin-right: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chat-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.chat-name {
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
color: #1d1d1f;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.chat-preview {
|
||||
font-size: 13px;
|
||||
color: #86868b;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.chat-meta {
|
||||
text-align: right;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 12px;
|
||||
color: #86868b;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.unread {
|
||||
background: #007AFF;
|
||||
color: white;
|
||||
font-size: 11px;
|
||||
padding: 2px 7px;
|
||||
border-radius: 10px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 列表过渡动画 */
|
||||
.list-enter-active, .list-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.list-enter-from, .list-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateX(-10px);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 0;
|
||||
color: #86868b;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
0
frontend/web/src/components/user/RequestFriend.vue
Normal file
0
frontend/web/src/components/user/RequestFriend.vue
Normal file
399
frontend/web/src/components/user/SearchUser.vue
Normal file
399
frontend/web/src/components/user/SearchUser.vue
Normal file
@ -0,0 +1,399 @@
|
||||
<template>
|
||||
<transition name="fade">
|
||||
<div v-if="modelValue" class="modal-mask" @click.self="close">
|
||||
<div class="modal-container">
|
||||
|
||||
<div class="modal-header">
|
||||
<div class="header-title">
|
||||
<button v-if="step === 2" class="btn-back-icon" @click="step = 1">←</button>
|
||||
<h2>{{ step === 1 ? '添加好友' : '验证信息' }}</h2>
|
||||
</div>
|
||||
<button class="icon-close" @click="close">×</button>
|
||||
</div>
|
||||
|
||||
<div v-if="step === 1" class="step-wrapper">
|
||||
<div class="search-box">
|
||||
<input
|
||||
v-model="keyword"
|
||||
type="text"
|
||||
placeholder="输入 ID / 手机号"
|
||||
@keyup.enter="onSearch"
|
||||
/>
|
||||
<button class="search-btn" @click="onSearch" :disabled="loading">
|
||||
<span v-if="!loading">搜索</span>
|
||||
<span v-else class="spinner"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<transition name="fade-slide">
|
||||
<div v-if="userResult" class="user-card">
|
||||
<div class="user-info">
|
||||
<img :src="userResult.avatar || defaultAvatar" class="avatar" />
|
||||
<div class="detail">
|
||||
<span class="name">{{ userResult.nickName }}</span>
|
||||
<span class="id">ID: {{ userResult.username }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="add-action-btn" @click="goToAddForm">添加好友</button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="hasSearched && !userResult" class="empty-state">
|
||||
未找到该用户,请检查输入
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
|
||||
<div v-if="step === 2" class="step-wrapper form-container">
|
||||
<div class="form-item">
|
||||
<label>备注名</label>
|
||||
<input
|
||||
v-model="form.remark"
|
||||
placeholder="为好友起个备注吧"
|
||||
class="form-input"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label>验证信息</label>
|
||||
<textarea
|
||||
v-model="form.description"
|
||||
placeholder="我是..."
|
||||
rows="3"
|
||||
class="form-textarea"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="btn-submit"
|
||||
@click="submitAdd"
|
||||
:disabled="submitting"
|
||||
>
|
||||
{{ submitting ? '发送中...' : '提交申请' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { friendService } from '@/services/friend';
|
||||
import { useMessage } from '../messages/useAlert';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: Boolean
|
||||
});
|
||||
const emit = defineEmits(['update:modelValue', 'success']);
|
||||
const message = useMessage();
|
||||
|
||||
// 基础状态
|
||||
const step = ref(1);
|
||||
const loading = ref(false);
|
||||
const submitting = ref(false);
|
||||
const hasSearched = ref(false);
|
||||
const defaultAvatar = 'https://api.dicebear.com/7.x/adventurer/svg?seed=Lucky';
|
||||
|
||||
// 数据
|
||||
const keyword = ref('');
|
||||
const userResult = ref(null);
|
||||
const form = reactive({
|
||||
remark: '',
|
||||
description: '你好,想加你为好友'
|
||||
});
|
||||
|
||||
const close = () => {
|
||||
emit('update:modelValue', false);
|
||||
// 延迟重置,避免动画没做完就变白
|
||||
setTimeout(() => {
|
||||
step.value = 1;
|
||||
userResult.value = null;
|
||||
hasSearched.value = false;
|
||||
keyword.value = '';
|
||||
form.remark = '';
|
||||
form.description = '你好,想加你为好友';
|
||||
}, 300);
|
||||
};
|
||||
|
||||
// 搜索逻辑
|
||||
const onSearch = async () => {
|
||||
if (!keyword.value.trim()) return;
|
||||
loading.value = true;
|
||||
hasSearched.value = false;
|
||||
try {
|
||||
const res = await friendService.findUser(keyword.value);
|
||||
userResult.value = res.data;
|
||||
if (res.data) {
|
||||
form.remark = res.data.nickName; // 默认备注为昵称
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
hasSearched.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
const goToAddForm = () => {
|
||||
step.value = 2;
|
||||
};
|
||||
|
||||
// 提交逻辑
|
||||
const submitAdd = async () => {
|
||||
if (submitting.value) return;
|
||||
submitting.value = true;
|
||||
const res = await friendService.requestFriend({
|
||||
toUserId: userResult.value.id, // 根据你后端字段调整
|
||||
remarkName: form.remark,
|
||||
description: form.description
|
||||
});
|
||||
if(res.code == 0){
|
||||
message.success('已发送好友请求');
|
||||
}else{
|
||||
message.error(res.message);
|
||||
}
|
||||
submitting.value = false;
|
||||
close();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 1. 基础布局与遮罩 */
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
backdrop-filter: blur(10px);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-container {
|
||||
background: #ffffff;
|
||||
width: 380px;
|
||||
border-radius: 28px;
|
||||
padding: 28px;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 2. 头部样式 */
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.header-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 700;
|
||||
color: #1d1d1f;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.btn-back-icon {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
color: #007aff;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.icon-close {
|
||||
background: #f5f5f7;
|
||||
border: none;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
color: #86868b;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.icon-close:hover {
|
||||
background: #e8e8ed;
|
||||
color: #1d1d1f;
|
||||
}
|
||||
|
||||
/* 3. 搜索区域 */
|
||||
.search-box {
|
||||
display: flex;
|
||||
background: #f5f5f7;
|
||||
border-radius: 14px;
|
||||
padding: 6px;
|
||||
margin-bottom: 20px;
|
||||
transition: all 0.3s;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.search-box:focus-within {
|
||||
background: #fff;
|
||||
border-color: #007aff;
|
||||
box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
|
||||
}
|
||||
|
||||
.search-box input {
|
||||
flex: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 10px 14px;
|
||||
outline: none;
|
||||
font-size: 14px;
|
||||
color: #1d1d1f;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0 18px;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.search-btn:disabled {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
/* 4. 用户卡片 */
|
||||
.user-card {
|
||||
background: #f5f5f7;
|
||||
border-radius: 20px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border-radius: 50%;
|
||||
margin-bottom: 12px;
|
||||
background: #fff;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.name {
|
||||
font-weight: 700;
|
||||
font-size: 17px;
|
||||
color: #1d1d1f;
|
||||
}
|
||||
|
||||
.id {
|
||||
font-size: 13px;
|
||||
color: #86868b;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.add-action-btn {
|
||||
width: 100%;
|
||||
background: #007aff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.add-action-btn:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
/* 5. 表单样式 */
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.form-item label {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #86868b;
|
||||
margin-bottom: 8px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-input, .form-textarea {
|
||||
width: 100%;
|
||||
background: #f5f5f7;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 12px;
|
||||
padding: 12px 16px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form-input:focus, .form-textarea:focus {
|
||||
background: #fff;
|
||||
border-color: #007aff;
|
||||
}
|
||||
|
||||
.btn-submit {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 14px;
|
||||
border-radius: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* 6. 动画与反馈 */
|
||||
.spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid rgba(255,255,255,0.3);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.fade-enter-active, .fade-leave-active { transition: opacity 0.3s; }
|
||||
.fade-enter-from, .fade-leave-to { opacity: 0; }
|
||||
|
||||
.fade-slide-enter-active {
|
||||
transition: all 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
|
||||
}
|
||||
.fade-slide-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
color: #86868b;
|
||||
font-size: 14px;
|
||||
padding: 30px 0;
|
||||
}
|
||||
</style>
|
||||
14
frontend/web/src/handler/messageHandler.js
Normal file
14
frontend/web/src/handler/messageHandler.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { useConversationStore } from "@/stores/conversation"
|
||||
|
||||
export const messageHandler = (msg) => {
|
||||
const conversationStore = useConversationStore();
|
||||
const conversation = conversationStore.conversations.find(x => x.targetId == msg.senderId || x.targetId == msg.receiverId);
|
||||
conversation.lastMessage = msg.content;
|
||||
if (conversation.targetId == msg.receiverId) {
|
||||
conversation.unreadCount = 0;
|
||||
} else {
|
||||
conversation.unreadCount += 1;
|
||||
}
|
||||
conversation.dateTime = new Date().toISOString();
|
||||
|
||||
}
|
||||
@ -11,7 +11,10 @@ const routes = [
|
||||
{
|
||||
path: '/',
|
||||
component: MainView,
|
||||
|
||||
redirect: '/messages',
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/messages',
|
||||
@ -32,7 +35,30 @@ const routes = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{ path: '/contacts', name: 'userContacts', component: () => import('@/views/contact/ContactList.vue') },
|
||||
{
|
||||
path: '/contacts',
|
||||
name: 'userContacts',
|
||||
redirect: '/contacts/index',
|
||||
component: () => import('@/views/contact/ContactList.vue'),
|
||||
children: [
|
||||
{
|
||||
path: '/contacts/index',
|
||||
name: "contactDefault",
|
||||
component: () => import('@/views/contact/ContactDefault.vue')
|
||||
},
|
||||
{
|
||||
path: '/contacts/info/:id',
|
||||
name: 'contactInfo',
|
||||
component: () => import('@/views/contact/UserInfoContent.vue'),
|
||||
props: true
|
||||
},
|
||||
{
|
||||
path: '/contacts/requests',
|
||||
name: 'friendRequests',
|
||||
component: () => import('@/views/contact/FriendRequestList.vue')
|
||||
}
|
||||
]
|
||||
},
|
||||
{ path: '/settings', name: 'userSettings', component: () => import('@/views/settings/SettingMenu.vue') }
|
||||
],
|
||||
meta: {
|
||||
@ -42,6 +68,7 @@ const routes = [
|
||||
{
|
||||
path: '/index',
|
||||
component: MainView,
|
||||
redirect: '/messages',
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
@ -56,10 +83,18 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const authStore = useAuthStore();
|
||||
if (to.path == '/auth/login') {
|
||||
if (authStore.isLoggedIn) {
|
||||
message.info('已登录,即将跳转...');
|
||||
next('/');
|
||||
}
|
||||
next();
|
||||
}
|
||||
if (to.meta.requiresAuth && !authStore.isLoggedIn) {
|
||||
message.info('未登录,即将跳转...');
|
||||
next('auth/login');
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
next();
|
||||
}
|
||||
})
|
||||
|
||||
@ -2,10 +2,15 @@ import axios from 'axios'
|
||||
import { useMessage } from '@/components/messages/useAlert';
|
||||
import router from '@/router';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { authService } from './auth';
|
||||
|
||||
const message = useMessage();
|
||||
const authStore = useAuthStore();
|
||||
|
||||
let waitqueue = [];
|
||||
let isRefreshing = false;
|
||||
const authURL = ['/auth/login', '/auth/register', '/auth/refresh'];
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000/api', // 从环境变量中读取基础 URL
|
||||
timeout: 10000,
|
||||
@ -31,16 +36,49 @@ api.interceptors.response.use(
|
||||
response => {
|
||||
return response.data;
|
||||
},
|
||||
err => {
|
||||
if (err.response) {
|
||||
switch (err.response.status) {
|
||||
async err => {
|
||||
const { config, response } = err;
|
||||
if (response) {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
if (authURL.some(x => config.url.includes(x))) {
|
||||
authStore.logout();
|
||||
message.error('未登录,请登录后操作。');
|
||||
router.push('/auth/login')
|
||||
break;
|
||||
}
|
||||
if (config._retry) {
|
||||
break;
|
||||
}
|
||||
|
||||
config._retry = true;
|
||||
// 已经在刷新 → 排队
|
||||
if (isRefreshing) {
|
||||
return new Promise(resolve => {
|
||||
waitqueue.push(token => {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
resolve(api(config))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
isRefreshing = true;
|
||||
const refreshToken = authStore.refreshToken;
|
||||
if (refreshToken != null && refreshToken != '') {
|
||||
const res = await authService.refresh(refreshToken)
|
||||
authStore.setLoginInfo(res.data.token, res.data.refreshToken, res.data.userInfo)
|
||||
waitqueue.forEach(cb => cb(authStore.token));
|
||||
waitqueue = [];
|
||||
config.headers.Authorization = `Bearer ${authStore.token}`
|
||||
return api(config)
|
||||
}
|
||||
authStore.logout();
|
||||
message.error('未登录,请登录后操作。');
|
||||
router.push('/auth/login')
|
||||
break;
|
||||
case 400:
|
||||
if (err.response.data && err.response.data.code == 1003) {
|
||||
message.error(err.response.data.message);
|
||||
if (response.data && response.data.code == 1003) {
|
||||
message.error(response.data.message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@ -13,5 +13,11 @@ export const authService = {
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
register: (data) => request.post('/auth/register', data)
|
||||
register: (data) => request.post('/auth/register', data),
|
||||
/**
|
||||
* 刷新用户凭证
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
refresh: (refreshToken) => request.post('/auth/refresh', { refreshToken })
|
||||
}
|
||||
@ -8,7 +8,25 @@ export const friendService = {
|
||||
* @param {*} limit 页大小
|
||||
* @returns
|
||||
*/
|
||||
getFriendList: (page = 1, limit = 100) => request.get(`/friend/list?page=${page}&limit=${limit}`)
|
||||
|
||||
getFriendList: (page = 1, limit = 100) => request.get(`/friend/list?page=${page}&limit=${limit}`),
|
||||
/**
|
||||
* 搜索好友
|
||||
* @param {*} username
|
||||
* @returns
|
||||
*/
|
||||
|
||||
findUser: (username) => request.get(`/user/findbyusername?username=${username}`),
|
||||
/**
|
||||
* 申请添加好友
|
||||
* @param {*} params
|
||||
* @returns
|
||||
*/
|
||||
requestFriend: (params) => request.post('/friend/request', params),
|
||||
/**
|
||||
* 获取好友请求列表
|
||||
* @param {*} page
|
||||
* @param {*} limit
|
||||
* @returns
|
||||
*/
|
||||
getFriendRequests: (page = 1, limit = 100) => request.get(`/friend/requests?page=${page}&limit=${limit}`)
|
||||
}
|
||||
@ -11,5 +11,25 @@ export const messageService = {
|
||||
* 清空所有会话消息
|
||||
* @returns
|
||||
*/
|
||||
clearConversation: () => request.post('')
|
||||
clearConversation: () => request.post(''),
|
||||
/**
|
||||
* 获取单个会话信息
|
||||
* @param {*} conversationId
|
||||
* @returns
|
||||
*/
|
||||
getConversationById: (conversationId) => request.get(`/conversation/get?conversationId=${conversationId}`),
|
||||
/**
|
||||
* 获取历史消息列表
|
||||
* @param {*} conversationId 指定会话
|
||||
* @param {*} msgId
|
||||
* @param {*} pageSize
|
||||
* @returns
|
||||
*/
|
||||
getHistoryMessages: (conversationId, msgId, pageSize = 10) => request.get(`/message/getmessageList?conversationId=${conversationId}&msgId=${msgId}&pageSize=${pageSize}`),
|
||||
/**
|
||||
* 获取最新消息
|
||||
* @param {*} conversationId
|
||||
* @returns
|
||||
*/
|
||||
getMessages: (conversationId) => request.get(`/message/getmessageList?conversationId=${conversationId}`)
|
||||
}
|
||||
21
frontend/web/src/services/useBrowserNotification.js
Normal file
21
frontend/web/src/services/useBrowserNotification.js
Normal file
@ -0,0 +1,21 @@
|
||||
export function useBrowserNotification() {
|
||||
const requestPermission = async () => {
|
||||
if ("Notification" in window && Notification.permission === "default") {
|
||||
await Notification.requestPermission();
|
||||
}
|
||||
};
|
||||
|
||||
const send = (title, options = {}) => {
|
||||
if ("Notification" in window && Notification.permission === "granted") {
|
||||
// 如果页面正处于激活状态,通常不需要弹窗提醒,以免干扰用户
|
||||
/*
|
||||
if (document.visibilityState === 'visible' && document.hasFocus()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
return new Notification(title, options);
|
||||
}
|
||||
};
|
||||
|
||||
return { requestPermission, send };
|
||||
}
|
||||
@ -4,10 +4,35 @@ import { defineStore } from 'pinia'
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref(localStorage.getItem('user_token') || '');
|
||||
const refreshToken = ref(localStorage.getItem('refresh_token') || '');
|
||||
const userInfo = ref(localStorage.getItem('user_info') || '');
|
||||
const userInfo = ref(JSON.parse(localStorage.getItem('user_info')) || {});
|
||||
|
||||
//判断是否已登录
|
||||
const isLoggedIn = computed(() => !!token.value);
|
||||
const isLoggedIn = computed(() => !!refreshToken.value);
|
||||
/**
|
||||
* 安全解析 JWT
|
||||
*/
|
||||
const getPayload = (t) => {
|
||||
try {
|
||||
const base64Url = t.split('.')[1];
|
||||
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
||||
// 处理 Unicode 字符解码
|
||||
return JSON.parse(decodeURIComponent(atob(base64).split('').map(c =>
|
||||
'%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
|
||||
).join('')));
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// 检查 Token 是否过期
|
||||
const isTokenExpired = computed(() => {
|
||||
if (!token.value) return true;
|
||||
const payload = getPayload(token.value);
|
||||
if (!payload || !payload.exp) return true;
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
return (payload.exp - now) < 30; // 预留 30 秒缓冲
|
||||
});
|
||||
|
||||
/**
|
||||
* 登录成功保存状态
|
||||
@ -15,12 +40,13 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
* @param {*} user 用户信息
|
||||
*/
|
||||
function setLoginInfo(newToken, newRefreshToken, user) {
|
||||
console.log(`设置凭证:\ntoken:${newToken}\nrefreshToken:${newRefreshToken}`)
|
||||
token.value = newToken;
|
||||
refreshToken.value = newRefreshToken
|
||||
userInfo.value = user;
|
||||
localStorage.setItem('user_token', newToken);
|
||||
localStorage.setItem('refresh_token', refreshToken)
|
||||
localStorage.setItem('user_info', user)
|
||||
localStorage.setItem('refresh_token', newRefreshToken)
|
||||
localStorage.setItem('user_info', JSON.stringify(user))
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,10 +55,11 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
function logout() {
|
||||
token.value = '';
|
||||
userInfo.value = null;
|
||||
refreshToken.value = ''
|
||||
localStorage.removeItem('user_token');
|
||||
localStorage.removeItem('refresh_token')
|
||||
localStorage.removeItem('user_info')
|
||||
}
|
||||
|
||||
return { token, userInfo, isLoggedIn, setLoginInfo, logout };
|
||||
return { token, refreshToken, userInfo, isLoggedIn, isTokenExpired, setLoginInfo, logout };
|
||||
})
|
||||
|
||||
108
frontend/web/src/stores/chat.js
Normal file
108
frontend/web/src/stores/chat.js
Normal file
@ -0,0 +1,108 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { messagesDb } from "@/utils/db/messageDB";
|
||||
import { messageService } from "@/services/message";
|
||||
|
||||
export const useChatStore = defineStore('chat', {
|
||||
state: () => ({
|
||||
activeSessionId: null,
|
||||
activeConversationId: null,
|
||||
messages: [],
|
||||
pageSize: 20
|
||||
}),
|
||||
actions: {
|
||||
// 抽取统一的排序去重方法
|
||||
pushAndSortMessages(newMsgs) {
|
||||
const combined = [...this.messages, ...newMsgs];
|
||||
// 1. 根据 msgId 或唯一 key 去重
|
||||
const uniqueMap = new Map();
|
||||
combined.forEach(m => uniqueMap.set(m.msgId || m.id, m));
|
||||
|
||||
// 2. 转换为数组并按时间戳升序排序 (旧的在前,新的在后)
|
||||
this.messages = Array.from(uniqueMap.values()).sort((a, b) => {
|
||||
return new Date(a.timeStamp).getTime() - new Date(b.timeStamp).getTime();
|
||||
});
|
||||
},
|
||||
async addMessage(msg, sessionId) {
|
||||
await messagesDb.save({ ...msg, sessionId, isLoading: false });
|
||||
this.messages.push({ ...msg, sessionId })
|
||||
},
|
||||
/**
|
||||
* 切换会话加载当前会话消息列表
|
||||
* @param {*} sessionId
|
||||
*/
|
||||
async swtichSession(sessionId, conversationId) {
|
||||
this.activeSessionId = sessionId;
|
||||
this.activeConversationId = conversationId;
|
||||
this.messages = [];
|
||||
//先从浏览器缓存加载一部分消息列表
|
||||
const localHistory = await messagesDb.getPageMessages(sessionId, new Date().toISOString(), this.pageSize);
|
||||
console.log(localHistory)
|
||||
if (localHistory.length > 0) {
|
||||
this.messages = localHistory;
|
||||
} else {
|
||||
//如果本地没有消息数据则从后端拉取数据
|
||||
const conversation = (await messageService.getConversationById(this.activeConversationId)).data;
|
||||
const serverHistoryMsg = await this.fetchHistoryFromServer(this.activeConversationId, conversation.lastReadMessageId);
|
||||
//对消息进行过滤,防止重复消息
|
||||
const filterMsg = serverHistoryMsg.filter(m => !this.messages.find(exist => exist.msgId === m.msgId));
|
||||
this.pushAndSortMessages([...filterMsg, ...this.messages]);
|
||||
}
|
||||
//拉取新消息
|
||||
this.fetchNewMsgFromServier(this.activeConversationId).then((newMsg) => {
|
||||
//去重
|
||||
const filterNewMsg = newMsg.filter(m => !this.messages.find(exist => exist.msgId === m.msgId));
|
||||
this.pushAndSortMessages([...filterNewMsg, ...this.messages])
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 从服务器加载新消息
|
||||
* @param {*} sessionId
|
||||
* @returns
|
||||
*/
|
||||
async fetchNewMsgFromServier(conversationId) {
|
||||
const newMsg = (await messageService.getMessages(conversationId)).data;
|
||||
if (newMsg.length > 0) {
|
||||
const sessionId = this.activeSessionId;
|
||||
await Promise.all(newMsg.map(msg =>
|
||||
messagesDb.save({ ...msg, sessionId })
|
||||
));
|
||||
return newMsg;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 从服务器加载历史消息
|
||||
* @param {*} sessionId
|
||||
* @param {*} msgId
|
||||
* @returns
|
||||
*/
|
||||
async fetchHistoryFromServer(conversationId, msgId) {
|
||||
const res = (await messageService.getHistoryMessages(conversationId, msgId, this.pageSize)).data;
|
||||
|
||||
if (res.length > 0) {
|
||||
const sessionId = this.activeSessionId;
|
||||
await Promise.all(res.map(msg =>
|
||||
messagesDb.save({ ...msg, sessionId })
|
||||
));
|
||||
return res;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 加载更多历史消息
|
||||
*/
|
||||
async loadMoreMessages() {
|
||||
const lastTimeStamp = this.messages.length > 0 ? this.messages[0].timeStamp : new Date().toISOString();
|
||||
const history = await messagesDb.getPageMessages(this.activeSessionId, lastTimeStamp, this.pageSize);
|
||||
if (history.length > 0) {
|
||||
this.messages = [...history, ...this.messages]
|
||||
} else {
|
||||
const fetchMsg = await this.fetchHistoryFromServer(this.conversationId, this.messages[0].msgId);
|
||||
const newMsgs = fetchMsg.filter(m => !this.messages.find(exist => exist.msgId === m.msgId));
|
||||
this.pushAndSortMessages([...newMsgs, ...this.messages])
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
45
frontend/web/src/stores/contact.js
Normal file
45
frontend/web/src/stores/contact.js
Normal file
@ -0,0 +1,45 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { contactDb } from "@/utils/db/contactDB";
|
||||
import { friendService } from "@/services/friend";
|
||||
import { useMessage } from "@/components/messages/useAlert";
|
||||
|
||||
export const useContactStore = defineStore('contact', {
|
||||
state: () => ({
|
||||
contacts: [],
|
||||
|
||||
}),
|
||||
actions: {
|
||||
async addContact(contact) {
|
||||
this.contacts.push(contact);
|
||||
await contactDb.save(contact);
|
||||
},
|
||||
async loadContactList() {
|
||||
if (this.contacts.length == 0) {
|
||||
this.contacts = await contactDb.getAll();
|
||||
}
|
||||
this.fetchContactFromServer();
|
||||
},
|
||||
async fetchContactFromServer() {
|
||||
const message = useMessage();
|
||||
const res = await friendService.getFriendList();
|
||||
if (res.code == 0) {
|
||||
const localMap = new Map(this.contacts.map(item => [item.id, item]));
|
||||
res.data.forEach(item => {
|
||||
const existingItem = localMap.get(item.id);
|
||||
if (existingItem) {
|
||||
// --- 局部更新 ---
|
||||
// 使用 Object.assign 将新数据合并到旧对象上,保持响应式引用
|
||||
Object.assign(existingItem, item);
|
||||
} else {
|
||||
// --- 插入新会话 ---
|
||||
this.contacts.push(item);
|
||||
}
|
||||
// 同步到本地数据库
|
||||
contactDb.save(item);
|
||||
});
|
||||
} else {
|
||||
message.error(res.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
72
frontend/web/src/stores/conversation.js
Normal file
72
frontend/web/src/stores/conversation.js
Normal file
@ -0,0 +1,72 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { messageService } from "@/services/message";
|
||||
import { conversationDb } from "@/utils/db/conversationDB";
|
||||
import { useMessage } from "@/components/messages/useAlert";
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
export const useConversationStore = defineStore('conversation', {
|
||||
state: () => ({
|
||||
conversations: []
|
||||
}),
|
||||
// stores/conversation.js
|
||||
getters: {
|
||||
// 始终根据时间戳倒序排列
|
||||
sortedConversations: (state) => {
|
||||
return [...state.conversations].sort((a, b) =>
|
||||
new Date(b.dateTime) - new Date(a.dateTime)
|
||||
);
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async addConversation(conversation) {
|
||||
await conversationDb.save(conversation);
|
||||
this.conversations.unshift(conversation)
|
||||
},
|
||||
/**
|
||||
* 加载当前会话消息列表
|
||||
*/
|
||||
async loadUserConversations() {
|
||||
if (this.conversations.length == 0) {
|
||||
try {
|
||||
const covnersationsCache = await conversationDb.getAll();
|
||||
if (covnersationsCache && covnersationsCache.length > 0) {
|
||||
covnersationsCache.sort((a, b) => {
|
||||
return new Date(a.dateTime) - new Date(b.dateTime);
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('读取本地会话缓存失败...');
|
||||
console.log('读取本地会话缓存失败:', e);
|
||||
}
|
||||
}
|
||||
await this.fetchConversationsFromServier()
|
||||
},
|
||||
/**
|
||||
* 从服务器加载新消息
|
||||
* @param {*} sessionId
|
||||
* @returns
|
||||
*/
|
||||
async fetchConversationsFromServier() {
|
||||
const newConversations = (await messageService.getConversations()).data;
|
||||
if (newConversations.length > 0) {
|
||||
// 1. 将当前的本地数据转为 Map,方便通过 ID 快速查找 (O(1) 复杂度)
|
||||
const localMap = new Map(this.conversations.map(item => [item.id, item]));
|
||||
newConversations.forEach(item => {
|
||||
const existingItem = localMap.get(item.id);
|
||||
if (existingItem) {
|
||||
// --- 局部更新 ---
|
||||
// 使用 Object.assign 将新数据合并到旧对象上,保持响应式引用
|
||||
Object.assign(existingItem, item);
|
||||
} else {
|
||||
// --- 插入新会话 ---
|
||||
this.conversations.unshift(item);
|
||||
}
|
||||
// 同步到本地数据库
|
||||
conversationDb.save(item);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
102
frontend/web/src/stores/signalr.js
Normal file
102
frontend/web/src/stores/signalr.js
Normal file
@ -0,0 +1,102 @@
|
||||
import { defineStore } from "pinia";
|
||||
import * as signalR from '@microsoft/signalr';
|
||||
import { useMessage } from "@/components/messages/useAlert";
|
||||
import { useAuthStore } from "./auth";
|
||||
import { useChatStore } from "./chat";
|
||||
import { authService } from "@/services/auth";
|
||||
import { generateSessionId } from "@/utils/sessionIdTools";
|
||||
import { messageHandler } from "@/handler/messageHandler";
|
||||
import { useBrowserNotification } from "@/services/useBrowserNotification";
|
||||
import { useConversationStore } from "./conversation";
|
||||
|
||||
export const useSignalRStore = defineStore('signalr', {
|
||||
state: () => ({
|
||||
connection: null,
|
||||
isConnected: false
|
||||
}),
|
||||
actions: {
|
||||
async initSignalR() {
|
||||
const message = useMessage()
|
||||
const authStore = useAuthStore()
|
||||
const url = import.meta.env.VITE_SIGNALR_BASE_URL || 'http://localhost:5202/chat/';
|
||||
this.connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl(url,
|
||||
{
|
||||
|
||||
accessTokenFactory: async () => {
|
||||
if (authStore.isTokenExpired) {
|
||||
const res = await authService.refresh(authStore.refreshToken)
|
||||
authStore.setLoginInfo(res.data.token, res.data.refreshToken, res.data.userInfo)
|
||||
}
|
||||
return authStore.token;
|
||||
}
|
||||
})
|
||||
.withAutomaticReconnect()
|
||||
.build();
|
||||
this.registerHandlers();
|
||||
try {
|
||||
await this.connection.start();
|
||||
this.isConnected = true;
|
||||
console.log('SignalR建立通信成功!')
|
||||
} catch (e) {
|
||||
message.error('与服务器建立通信失败,请检查网络连接...');
|
||||
}
|
||||
},
|
||||
registerHandlers() {
|
||||
const chatStore = useChatStore()
|
||||
const browserNotification = useBrowserNotification();
|
||||
|
||||
this.connection.on('ReceiveMessage', (msg) => {
|
||||
const sessionId = generateSessionId(msg.senderId, msg.receiverId);
|
||||
messageHandler(msg);
|
||||
chatStore.addMessage(msg, sessionId);
|
||||
const conversation = useConversationStore().conversations.find(x => x.targetId == msg.senderId);
|
||||
browserNotification.send(`${conversation.targetName}发来一条消息`, {
|
||||
body: msg.content,
|
||||
icon: conversation.targetAvatar
|
||||
});
|
||||
});
|
||||
|
||||
this.connection.onclose(() => { this.isConnected = false });
|
||||
this.connection.onreconnected(() => { this.isConnected = true });
|
||||
|
||||
},
|
||||
/**
|
||||
* 通过signalr发送消息
|
||||
* @param {*} msg
|
||||
* @returns
|
||||
*/
|
||||
async sendMsg(msg) {
|
||||
const message = useMessage()
|
||||
const chatStore = useChatStore()
|
||||
if (!this.isConnected) {
|
||||
message.error('与服务器连接中断,请重连后尝试...');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 后端 Hub 定义的方法名通常为 SendMessage
|
||||
// 参数顺序需要与后端 ChatHub 中的方法签名一致
|
||||
if (msg.msgId == null) {
|
||||
msg.msgId = self.crypto.randomUUID();
|
||||
}
|
||||
const sessionId = generateSessionId(msg.senderId, msg.receiverId);
|
||||
this.connection.invoke("SendMessage", msg).then(() => {
|
||||
const msga = chatStore.messages.find(x => x.msgId == msg.msgId)
|
||||
if (msga.isLoading) {
|
||||
msga.isLoading = false;
|
||||
}
|
||||
})
|
||||
;
|
||||
chatStore.addMessage({ ...msg, isLoading: true }, sessionId);
|
||||
messageHandler(msg);
|
||||
console.log("消息发送成功!");
|
||||
} catch (err) {
|
||||
console.error("消息发送失败:", err);
|
||||
message.error("消息发送失败");
|
||||
}
|
||||
},
|
||||
async clearUnreadCount(conversationId) {
|
||||
await this.connection.invoke("ClearUnreadCount", conversationId)
|
||||
}
|
||||
}
|
||||
})
|
||||
10
frontend/web/src/utils/codeHelper.js
Normal file
10
frontend/web/src/utils/codeHelper.js
Normal file
@ -0,0 +1,10 @@
|
||||
export function getChatCodeStr(code) {
|
||||
switch (code) {
|
||||
case 0:
|
||||
return '私聊'
|
||||
case 1:
|
||||
return '群聊'
|
||||
default:
|
||||
return '未知类型'
|
||||
}
|
||||
}
|
||||
26
frontend/web/src/utils/db/baseDb.js
Normal file
26
frontend/web/src/utils/db/baseDb.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { openDB } from "idb";
|
||||
|
||||
const DBNAME = 'IM_DB';
|
||||
const STORE_NAME = 'messages';
|
||||
const CONVERSARION_STORE_NAME = 'conversations';
|
||||
const CONTACT_STORE_NAME = 'contacts';
|
||||
|
||||
export const dbPromise = openDB(DBNAME, 4, {
|
||||
upgrade(db) {
|
||||
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
||||
const store = db.createObjectStore(STORE_NAME, { keyPath: 'msgId' });
|
||||
store.createIndex('by-sessionId', 'sessionId');
|
||||
store.createIndex('by-time', 'timeStamp');
|
||||
store.createIndex('by-session-time', ['sessionId', 'timeStamp']);
|
||||
}
|
||||
if (!db.objectStoreNames.contains(CONVERSARION_STORE_NAME)) {
|
||||
const store = db.createObjectStore(CONVERSARION_STORE_NAME, { keyPath: 'id' });
|
||||
store.createIndex('by-id', 'id');
|
||||
}
|
||||
if (!db.objectStoreNames.contains(CONTACT_STORE_NAME)) {
|
||||
const store = db.createObjectStore(CONTACT_STORE_NAME, { keyPath: 'id' });
|
||||
store.createIndex('by-id', 'id');
|
||||
store.createIndex('by-username', 'username');
|
||||
}
|
||||
}
|
||||
})
|
||||
18
frontend/web/src/utils/db/contactDB.js
Normal file
18
frontend/web/src/utils/db/contactDB.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { dbPromise } from "./baseDb"
|
||||
|
||||
const STORE_NAME = 'contacts';
|
||||
|
||||
export const contactDb = {
|
||||
async save(contact) {
|
||||
(await dbPromise).put(STORE_NAME, contact);
|
||||
},
|
||||
async getById(id) {
|
||||
return (await dbPromise).getFromIndex(STORE_NAME, 'by-id', id);
|
||||
},
|
||||
async getByUsername(username) {
|
||||
return (await dbPromise).getFromIndex(STORE_NAME, 'by-username', username);
|
||||
},
|
||||
async getAll() {
|
||||
return (await dbPromise).getAll(STORE_NAME);
|
||||
}
|
||||
}
|
||||
18
frontend/web/src/utils/db/conversationDB.js
Normal file
18
frontend/web/src/utils/db/conversationDB.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { dbPromise } from "./baseDb";
|
||||
|
||||
const STORE_NAME = 'conversations';
|
||||
|
||||
export const conversationDb = {
|
||||
async save(conversation) {
|
||||
(await dbPromise).put(STORE_NAME, conversation);
|
||||
},
|
||||
async getById(id) {
|
||||
return (await dbPromise).getFromIndex(STORE_NAME, 'by-id', id);
|
||||
},
|
||||
async getAll() {
|
||||
return (await dbPromise).getAll(STORE_NAME);
|
||||
},
|
||||
async clearAll() {
|
||||
(await dbPromise).clear(STORE_NAME);
|
||||
}
|
||||
}
|
||||
40
frontend/web/src/utils/db/messageDB.js
Normal file
40
frontend/web/src/utils/db/messageDB.js
Normal file
@ -0,0 +1,40 @@
|
||||
import { dbPromise } from "./baseDb";
|
||||
|
||||
const STORE_NAME = 'messages';
|
||||
|
||||
export const messagesDb = {
|
||||
async save(msg) {
|
||||
return (await dbPromise).put(STORE_NAME, msg);
|
||||
},
|
||||
async getBySession(sessionId) {
|
||||
return (await dbPromise).getAllFromIndex(STORE_NAME, 'by-sessionId', sessionId);
|
||||
},
|
||||
async clearAll() {
|
||||
return (await dbPromise).clear(STORE_NAME);
|
||||
},
|
||||
async getPageMessages(sessionId, beforeTimeStamp, limit = 20) {
|
||||
const db = await dbPromise;
|
||||
const tx = db.transaction(STORE_NAME, 'readonly');
|
||||
const index = tx.store.index('by-session-time'); // 使用复合索引
|
||||
|
||||
// 定义范围:从 [sessionId, 最早时间] 到 [sessionId, beforeTimeStamp)
|
||||
// 注意:IDBKeyRange.bound([sessionId, ""], [sessionId, beforeTimeStamp], false, true)
|
||||
// 或者简单使用 upperbound 限制最大值
|
||||
const range = IDBKeyRange.upperBound([sessionId, beforeTimeStamp], true);
|
||||
|
||||
// 'prev' 表示从最新的往回找(倒序)
|
||||
let cursor = await index.openCursor(range, 'prev');
|
||||
const results = [];
|
||||
|
||||
while (cursor && results.length < limit) {
|
||||
// 关键安全检查:因为 upperBound 可能会越界捞到其他 sessionId 的数据
|
||||
//(复合索引的特性决定了 sessionId 不一致的数据会排在后面)
|
||||
if (cursor.value.sessionId !== sessionId) break;
|
||||
|
||||
results.unshift(cursor.value); // 放入结果集开头,保证返回的是时间升序
|
||||
cursor = await cursor.continue();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
18
frontend/web/src/utils/formatDate.js
Normal file
18
frontend/web/src/utils/formatDate.js
Normal file
@ -0,0 +1,18 @@
|
||||
export function formatDate(dateStr) {
|
||||
const date = new Date(dateStr);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0'); // 补零
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
const nowDate = new Date();
|
||||
if (year == nowDate.getFullYear() && month == String(nowDate.getMonth() + 1).padStart(2, '0') && day == String(nowDate.getDate()).padStart(2, '0')) {
|
||||
return `${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
if (year == nowDate.getFullYear()) {
|
||||
return `${month}/${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
11
frontend/web/src/utils/sessionIdTools.js
Normal file
11
frontend/web/src/utils/sessionIdTools.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 生成唯一的会话 ID (私聊)
|
||||
* @param {string|number} id1 用户A的ID
|
||||
* @param {string|number} id2 用户B的ID
|
||||
*/
|
||||
export const generateSessionId = (id1, id2) => {
|
||||
// 1. 转换为字符串并放入数组
|
||||
// 2. 排序(确保顺序一致性)
|
||||
// 3. 用下划线或其他分隔符拼接
|
||||
return [String(id1), String(id2)].sort().join('_');
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user