From 10e5b1d26c2158414839c0f07f3495ff8c27a15c Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 25 Jan 2022 00:08:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8E=E5=8F=B0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=BD=93=E5=89=8D=E8=AF=B7=E6=B1=82=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E5=89=8D=E5=8F=B0=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/BootstrapAdmin.Web/App.razor.cs | 41 ++++++++++-------- .../BootstrapAdmin.Web/BootstrapAdmin.db | Bin 221184 -> 237568 bytes .../Components/AdminLogin.razor.cs | 2 - .../Controllers/AccountController.cs | 9 +++- .../BootstrapAdmin.Web/Pages/Home/Index.cs | 2 +- .../Services/BootstrapAppContext.cs | 6 +++ .../BootstrapAdmin.Web/Utils/LoginHelper.cs | 16 +++++-- 7 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/blazor/admin/BootstrapAdmin.Web/App.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/App.razor.cs index 5c03ed83..b451435a 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/App.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/App.razor.cs @@ -1,29 +1,32 @@ using BootstrapAdmin.Web.Services; -namespace BootstrapAdmin.Web +namespace BootstrapAdmin.Web; + +/// +/// +/// +public partial class App { /// /// /// - public partial class App + public string? Title { get; set; } + + [Inject] + [NotNull] + private BootstrapAppContext? AppContext { get; set; } + + [Inject] + [NotNull] + private NavigationManager? NavigationManager { get; set; } + + /// + /// + /// + protected override void OnInitialized() { - /// - /// - /// - public string? Title { get; set; } + base.OnInitialized(); - [Inject] - [NotNull] - private BootstrapAppContext? AppContext { get; set; } - - /// - /// - /// - protected override void OnInitialized() - { - base.OnInitialized(); - - //Title = DictHelper.RetrieveWebTitle(AppContext.AppId); - } + AppContext.BaseUri = NavigationManager.ToAbsoluteUri(NavigationManager.BaseUri); } } diff --git a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.db b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.db index e23ef3f5a294f75d75c4a68709b9174a2555a49c..94b23aac8eea873ed81ad3f868b5155b7c8d8059 100644 GIT binary patch delta 2067 zcmbVNTWnNS6usx%d32_oSFsQw=zvVY5H9C&&wZg#u=0Ksk+y(Z9-;}zqe^62LS$}& z#>61)&>jdz=|_n%!W0`U5EE)*^ixdm3(3$BV@UjfFF#Om-+Mcq!lys;F=x-(Ywx|* znq#AhW24EFGs1TjMR9tvOVHg*+XsG5gg;lBLN(#kV9HFrSxny8iw1|gZ>&|L@md?QB7Eer87BXpo=IYJ52PnEG<_fBOg=r zZZZrwR{gh4D3q?5lIrtd9a-0cW`|N|Q+<*?!c*ik8&PazeG6KVs)J|KZG}(6ZT@JW z1C0!H;9d9U)hnl!)STqX#DThE?MVDq>{0BwnibK5k-qS?(4A07eIB=Z5Yw_G+Kq+Gp2ywTed+NUYHO5oPKoTyL(LFYyP})jWp&=f zJ#XQuK3FY)QA^V;L3Eip>tTI@^4MJ}J5BXjuN4)V!5Ps_dH*;PvUCFH)pob(iC#jZ zhOP@sW_|#S8zZ<&ZFQH(9lhhE{XSf?OfHE0{yTgz;x6`?>~K-QB<}U%8YhHE8dnVu z1crLCN`z_5AQlzDJRXtgCiewEStQ4r)fqJ&0M&>od)@{PU(8cIqKm3TNA|R<{n7q| zIMUdsq~<19C-%Yeuf%W1acpkQ+UWjBF?=O-JA~9myapXq;F#y|9<|MFm7Se9LoiL#HlWkyzUo8O2Q}0YOydlug2g>J zj&zy*40mC7Q_zoR8Fi@bU4Rk71P}U+_WBoi#UCs^QN%UFG`;2ijVrs`_yi8q2!o>P zC81Y~Uz4oB5KFV+)Y+TZ@&`j3{P&4A#MCI)DeQOw40XRr?MCb6tYO$rfM7b5Xw)(p z;c{acmqLX$cim(frUNZ3%ci;!+%Xt=tzT1L0f9C)?;!D8)YzCK1o}{AG?>^&tmM+6MD{xEBv$cX{Qi9DCbQJE;9L;ZJfOvVVB{r{8dNHQ6&y{@Dhlj{=i)t#xmKAcHks8tJX z)BHpO2@>KE!(pbzP2INPV1D3D4W9KZ@E4XN49&0^xOV)xVbZfs91h21rY=nX`9h@i zscNEv$PI^sgt;adsLBc&OsVwu+(aE6qJwZlw{`FN>;97{JR^KnN#&BO68r0VAsl~; ztKiQy(awkrUxg{oghPd`?oMBJ<4)2YPz*CD7bcTq$8ibHxx+u_xNCjYn9L%esDZyg zHKn9_7>c&bb04DV<0w#MXq=kdf-3N%DL+-!Ll7bzzSpWyRD&SWJwtkl=_M-^z43Sv z2d6NDLHzn6goy5f^S|z&e*%dM%{Bx?fTUkxqwgQ}eeAv#I4+0?Kk6CuvSi^WFt!&q zXj@>YN(BTx7aXEKNN8WF?e5mc=@3J+ZJX2TKSmeC(U!@*n15^`xGo1C;EOO)`(zAw f7McmR0!v)Vsza#li61k~HZ6n8vCBXdOn3M{z5Xj(>eh%vj^0d0Vpjy1^^`$IS=K!l;@PF>86(Hp|wP1ZEt9FbZ|N^ zFKlmPVQgq`b9A%D)o}?2KLrK=B_&Oh&C@xPHs3CjrQa(F1O_Yw1^^``CzC$kCA0qD z0#K4b1PT!WX8;cv4loT { ["ReturnUrl"] = ReturnUrl, diff --git a/src/blazor/admin/BootstrapAdmin.Web/Controllers/AccountController.cs b/src/blazor/admin/BootstrapAdmin.Web/Controllers/AccountController.cs index 649f426a..d859826c 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Controllers/AccountController.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Controllers/AccountController.cs @@ -52,7 +52,9 @@ namespace BootstrapAdmin.Web.Controllers period = dictService.GetCookieExpiresPeriod(); } - return auth ? await SignInAsync(userName, LoginHelper.GetDefaultUrl(userName, returnUrl, appId, context.AppId, userService, dictService), persistent, period) : RedirectLogin(returnUrl); + context.UserName = userName; + context.BaseUri = new Uri($"{Request.Scheme}://{Request.Host}/"); + return auth ? await SignInAsync(userName, LoginHelper.GetDefaultUrl(context, returnUrl, appId, userService, dictService), persistent, period) : RedirectLogin(returnUrl); } private async Task SignInAsync(string userName, string returnUrl, bool persistent, int period = 0, string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme) @@ -139,7 +141,10 @@ namespace BootstrapAdmin.Web.Controllers { userService.TryCreateUserByPhone(phone, code, context.AppId, provider.Options.Roles); } - return auth ? await SignInAsync(phone, LoginHelper.GetDefaultUrl(phone, returnUrl, appId, context.AppId, userService, dictService), persistent, period, MobileSchema) : RedirectLogin(returnUrl); + + context.UserName = phone; + context.BaseUri = new Uri(Request.Path.Value!); + return auth ? await SignInAsync(phone, LoginHelper.GetDefaultUrl(context, returnUrl, appId, userService, dictService), persistent, period, MobileSchema) : RedirectLogin(returnUrl); } #endregion diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs index eb8f144b..d304721c 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs @@ -39,7 +39,7 @@ public class Index : ComponentBase protected override void OnInitialized() { // 查看是否自定义前台 - Url = LoginHelper.GetDefaultUrl(Context.UserName, null, null, Context.AppId, UsersService, DictsService); + Url = LoginHelper.GetDefaultUrl(Context, null, null, UsersService, DictsService); #if !DEBUG Navigation.NavigateTo(Url, true); diff --git a/src/blazor/admin/BootstrapAdmin.Web/Services/BootstrapAppContext.cs b/src/blazor/admin/BootstrapAdmin.Web/Services/BootstrapAppContext.cs index e90c779f..64a29c19 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Services/BootstrapAppContext.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Services/BootstrapAppContext.cs @@ -24,6 +24,12 @@ namespace BootstrapAdmin.Web.Services [NotNull] public string? DisplayName { get; internal set; } + /// + /// 获得/设置 应用程序基础地址 如 http://localhost:5210 + /// + [NotNull] + public Uri? BaseUri { get; set; } + /// /// 构造函数 /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/Utils/LoginHelper.cs b/src/blazor/admin/BootstrapAdmin.Web/Utils/LoginHelper.cs index 0b85bd60..8d6fbc78 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Utils/LoginHelper.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Utils/LoginHelper.cs @@ -1,4 +1,5 @@ using BootstrapAdmin.Web.Core; +using BootstrapAdmin.Web.Services; namespace BootstrapAdmin.Web.Utils; @@ -10,18 +11,21 @@ public static class LoginHelper /// /// /// - /// + /// /// /// - /// /// /// /// - public static string GetDefaultUrl(string userName, string? returnUrl, string? appId, string defaultAppId, IUser userService, IDict dictService) + public static string GetDefaultUrl(BootstrapAppContext context, string? returnUrl, string? appId, IUser userService, IDict dictService) { if (string.IsNullOrEmpty(returnUrl)) { // 查找 User 设置的默认应用 + var userName = context.UserName; + var defaultAppId = context.AppId; + var schema = context.BaseUri.Scheme; + var host = context.BaseUri.Host; appId ??= userService.GetAppIdByUserName(userName) ?? defaultAppId; if (appId == defaultAppId && dictService.GetEnableDefaultApp()) @@ -32,7 +36,11 @@ public static class LoginHelper if (!string.IsNullOrEmpty(appId)) { - returnUrl = dictService.GetHomeUrlByAppId(appId); + var appUrl = dictService.GetHomeUrlByAppId(appId); + if (!string.IsNullOrEmpty(appUrl)) + { + returnUrl = string.Format(appUrl, schema, host); + } } }