From 43323e386f879a9e84bdaa2c173bff0caee2a5bc Mon Sep 17 00:00:00 2001 From: czj Date: Wed, 13 May 2026 10:35:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LAEPS/App.xaml.cs | 8 +- MainModule/MainModule.cs | 1 - MainModule/ViewModels/MainViewModel.cs | 136 +----------- MainModule/ViewModels/PostDetailViewModel.cs | 138 ------------- MainModule/Views/MainView.xaml | 205 +------------------ MainModule/Views/MainView.xaml.cs | 12 +- MainModule/Views/PostDetailView.xaml | 108 ---------- MainModule/Views/PostDetailView.xaml.cs | 28 --- 8 files changed, 9 insertions(+), 627 deletions(-) delete mode 100644 MainModule/ViewModels/PostDetailViewModel.cs delete mode 100644 MainModule/Views/PostDetailView.xaml delete mode 100644 MainModule/Views/PostDetailView.xaml.cs diff --git a/LAEPS/App.xaml.cs b/LAEPS/App.xaml.cs index cfaef7c..71d9f99 100644 --- a/LAEPS/App.xaml.cs +++ b/LAEPS/App.xaml.cs @@ -53,10 +53,10 @@ namespace LAEPS protected override void OnInitialized() { //初始化数据库 - DatabaseConfig.SetTenant(10001); - DatabaseConfig.InitMySql("127.0.0.1",3306,"LAEPS","root","123456"); - DatabaseConfig.CreateDatabaseAndCheckConnection(createDatabase: true, checkConnection: true); - SqlSugarContext.InitDatabase(); + //DatabaseConfig.SetTenant(10001); + //DatabaseConfig.InitMySql("127.0.0.1",3306,"LAEPS","root","123456"); + //DatabaseConfig.CreateDatabaseAndCheckConnection(createDatabase: true, checkConnection: true); + //SqlSugarContext.InitDatabase(); //显示登录窗口 var login=Container.Resolve(); var re=Container.Resolve(); diff --git a/MainModule/MainModule.cs b/MainModule/MainModule.cs index fb3b851..80581dd 100644 --- a/MainModule/MainModule.cs +++ b/MainModule/MainModule.cs @@ -15,7 +15,6 @@ namespace MainModule public void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.RegisterForNavigation("MainView"); - containerRegistry.RegisterForNavigation("PostDetailView"); } } } diff --git a/MainModule/ViewModels/MainViewModel.cs b/MainModule/ViewModels/MainViewModel.cs index 53e10b7..79c1e02 100644 --- a/MainModule/ViewModels/MainViewModel.cs +++ b/MainModule/ViewModels/MainViewModel.cs @@ -10,146 +10,16 @@ namespace MainModule.ViewModels { public class MainViewModel : NavigateViewModelBase { - #region 属性 - - private ObservableCollection _posts; - public ObservableCollection Posts - { - get => _posts; - set => SetProperty(ref _posts, value); - } - - private string _searchKeyword; - public string SearchKeyword - { - get => _searchKeyword; - set => SetProperty(ref _searchKeyword, value); - } - - #endregion - - #region 命令 - - public ICommand CreatePostCommand { get; set; } - public ICommand SearchCommand { get; set; } - public ICommand CategorySelectCommand { get; set; } - - #endregion + #region 私有字段 private IContainerProvider _containerProvider; - private IPostService _postService; - private IDialogService _dialogService; + #endregion public MainViewModel(IContainerProvider containerProvider ) : base(containerProvider) { _containerProvider=containerProvider; - _postService = containerProvider.Resolve(); - _dialogService = containerProvider.Resolve(); - InitializeCommands(); - LoadPosts(); } - private void InitializeCommands() - { - CreatePostCommand = new DelegateCommand(OnCreatePost); - SearchCommand = new AsyncDelegateCommand(OnSearch); - CategorySelectCommand = new AsyncDelegateCommand(OnCategorySelect); - } - - #region 命令处理 - - private async void OnCreatePost() - { - // 这里可以导航到发帖页面 - ShowInfoMessageBox("跳转到发帖页面",null); - } - - private async Task OnSearch() - { - // 执行搜索逻辑 - if (!string.IsNullOrWhiteSpace(SearchKeyword)) - { - await SearchPostsAsync(SearchKeyword); - } - } - - private async Task OnCategorySelect(string category) - { - // 按分类筛选帖子 - await FilterPostsByCategoryAsync(category); - } - - #endregion - - #region 业务方法 - - private async Task LoadPosts() - { - try - { - var result = await _postService.GetRecommendedPostsAsync(20); - if (result.IsSuccess) - { - Posts = new ObservableCollection(result.Data); - } - else - { - ShowErrorMessageBox("帖子加载错误",null); - } - } - catch (Exception ex) - { - ShowErrorMessageBox($"加载帖子异常: {ex.Message}", null); - } - } - - private async Task SearchPostsAsync(string keyword) - { - try - { - var result = await _postService.SearchPostsAsync(keyword); - if (result.IsSuccess) - { - Posts = new ObservableCollection(result.Data); - } - else - { - ShowErrorMessageBox("查询帖子失败", null); - } - } - catch (Exception ex) - { - // 处理异常 - ShowErrorMessageBox($"查询帖子异常: {ex.Message}", null); - } - } - - private async Task FilterPostsByCategoryAsync(string category) - { - if (category == "全部") - { - await LoadPosts(); // 重新加载所有帖子 - return; - } - - try - { - var result = await _postService.GetPostsByCategoryAsync(category, 20); - if (result.IsSuccess) - { - Posts = new ObservableCollection(result.Data); - } - else - { - ShowErrorMessageBox("加载分类子失败", null); - } - } - catch (Exception ex) - { - ShowErrorMessageBox($"获取分类帖子异常: {ex.Message}", null); - } - } - - #endregion + } } diff --git a/MainModule/ViewModels/PostDetailViewModel.cs b/MainModule/ViewModels/PostDetailViewModel.cs deleted file mode 100644 index 9effc65..0000000 --- a/MainModule/ViewModels/PostDetailViewModel.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Model.Entity; -using Prism.Commands; -using Prism.Ioc; -using Service.Interface; -using System.Windows.Input; -using UIShare.ViewModelBase; - -namespace MainModule.ViewModels -{ - public class PostDetailViewModel : NavigateViewModelBase - { - #region 属性 - - private PostEntity _selectedPost; - public PostEntity SelectedPost - { - get => _selectedPost; - set => SetProperty(ref _selectedPost, value); - } - - #endregion - - #region 命令 - - public ICommand LikePostCommand { get; set; } - public ICommand FavoritePostCommand { get; set; } - public ICommand SharePostCommand { get; set; } - - #endregion - - #region 私有字段 - private IContainerProvider _containerProvider; - private IPostService _postService; - private IDialogService _dialogService; - #endregion - - public PostDetailViewModel(IContainerProvider containerProvider) : base(containerProvider) - { - _containerProvider = containerProvider; - _postService = containerProvider.Resolve(); - _dialogService = containerProvider.Resolve(); - InitializeCommands(); - } - - private void InitializeCommands() - { - LikePostCommand = new DelegateCommand(OnLikePost); - FavoritePostCommand = new DelegateCommand(OnFavoritePost); - SharePostCommand = new DelegateCommand(OnSharePost); - } - - #region 命令处理 - - private async void OnLikePost() - { - if (SelectedPost != null) - { - SelectedPost.LikeCount++; - // 在实际应用中,这里应该调用服务更新数据库 - var result = await _postService.UpdatePostAsync(SelectedPost); - if (!result.IsSuccess) - { - var dialogParams = new DialogParameters(); - dialogParams.Add("Title", "错误"); - dialogParams.Add("Message", "点赞失败" + result.Msg); - dialogParams.Add("Icon", "error"); - dialogParams.Add("ShowOk", true); - _dialogService.ShowDialog("MessageBox", dialogParams); - } - } - } - - private async void OnFavoritePost() - { - if (SelectedPost != null) - { - var dialogParams = new DialogParameters(); - dialogParams.Add("Title", "提示"); - dialogParams.Add("Message", "帖子已收藏"); - dialogParams.Add("Icon", "info"); - dialogParams.Add("ShowOk", true); - _dialogService.ShowDialog("MessageBox", dialogParams, result => - { - if (result.Result == ButtonResult.OK) - { - // 用户点击了确定 - } - }); - } - } - - private async void OnSharePost() - { - if (SelectedPost != null) - { - var dialogParams = new DialogParameters(); - dialogParams.Add("Title", "提示"); - dialogParams.Add("Message", "分享功能待实现"); - dialogParams.Add("Icon", "info"); - dialogParams.Add("ShowOk", true); - _dialogService.ShowDialog("MessageBox", dialogParams, result => - { - if (result.Result == ButtonResult.OK) - { - // 用户点击了确定 - } - }); - } - } - - #endregion - - #region 业务方法 - - public async void LoadPostDetails(PostEntity post) - { - if (post != null) - { - SelectedPost = post; - // 增加浏览量 - SelectedPost.ViewCount++; - // 在实际应用中,这里应该调用服务更新数据库 - var result = await _postService.UpdatePostAsync(SelectedPost); - if (!result.IsSuccess) - { - var dialogParams = new DialogParameters(); - dialogParams.Add("Title", "错误"); - dialogParams.Add("Message", "加载帖子详情失败" + result.Msg); - dialogParams.Add("Icon", "error"); - dialogParams.Add("ShowOk", true); - _dialogService.ShowDialog("MessageBox", dialogParams); - } - } - } - - #endregion - } -} \ No newline at end of file diff --git a/MainModule/Views/MainView.xaml b/MainModule/Views/MainView.xaml index c275540..7b634b1 100644 --- a/MainModule/Views/MainView.xaml +++ b/MainModule/Views/MainView.xaml @@ -15,208 +15,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -