@page "/system/role/list" @inject ILogger Logger 角色管理 角色管理 角色列表
@if (context.IsSystemRole) { } else { } @if (context.Enabled) { } else { } 编辑 @if (!context.IsSystemRole) { 删除 }

@code { [SupplyParameterFromQuery] int? Page { get; set; } [SupplyParameterFromQuery(Name = "size")] int? PageSize { get; set; } [SupplyParameterFromForm] RoleSearch search { get; set; } = default!; [SupplyParameterFromForm] RoleModel model { get; set; } = default!; Form editform = null!; PagingList PagingList = new(); bool loading { get; set; } = true; bool drawerVisible; bool isSave = false; protected override void OnInitialized() { search ??= new RoleSearch(); model ??= new RoleModel(); base.OnInitialized(); } protected override async Task OnParametersSetAsync() { await LoadList(); } private async Task LoadList() { loading = true; var url = "/api/role/search"; var apiResult = await HttpService.GetPagingList(url, search ?? new RoleSearch(), Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20)); if (apiResult.Success) { if (apiResult.Data != null) { PagingList = apiResult.Data; } } loading = false; StateHasChanged(); } private void OnSearch(int page) { var queryString = search.BuildQueryString(); if (string.IsNullOrEmpty(queryString)) { if (page > 1) { Navigation.NavigateTo($"/system/role/list?page={page}"); } else { Navigation.NavigateTo($"/system/role/list"); } } else { if (page > 1) { Navigation.NavigateTo($"/system/role/list?page={page}&{queryString}"); } else { Navigation.NavigateTo($"/system/role/list?{queryString}"); } } } void OnCreateClick() { model = new(); drawerVisible = true; } void OnEditPermissionClick(Role role) { Navigation.NavigateTo($"/system/role/permission/{role.Id}"); } void OnEditClick(Role role) { model = role.Adapt(); drawerVisible = true; } async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id) { var url = $"/api/role/delete/{id}"; var apiResult = await HttpService.Post>(url, new()); if (apiResult.Success) { await LoadList(); await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" }); } else { await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" }); } } async Task OnFormFinish() { if (editform.Validate()) { var apiResult = new ApiResult(); if (model != null) { if (model.Id > 0) { var url = $"api/role/edit"; apiResult = await HttpService.Post>(url, model); } else { var url = $"api/role/add"; apiResult = await HttpService.Post>(url, model); } if (apiResult.Success) { ModalService.Success(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" }); CloseDrawer(); await LoadList(); } else { await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = apiResult.Message }); } } } StateHasChanged(); } private void OnPageChanged(PaginationEventArgs args) { OnSearch(args.Page); } void CloseDrawer() { drawerVisible = false; editform.Reset(); } }