XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

STHApplication

【MAUI】寄当家——安卓端交易管理系统

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using JiDangJia.Contracts;
using JiDangJia.Core;
using JiDangJia.Services;

namespace JiDangJia.Views;

public sealed class AboutPage : ContentPage
{
    private readonly VerticalStackLayout body=Ui.Stack();
    private readonly Label status=Ui.Text("",11,Ui.Muted);
    public AboutPage(){Title="关于我们";body.Padding=new Thickness(24,28);Content=new ScrollView{Content=body};Render();}
    protected override async void OnAppearing(){base.OnAppearing();try{await ContentClient.Refresh(true);Render();}catch{status.Text="当前显示上次同步的信息";}}
    private void Render()
    {
        var about=ContentClient.Current?.About??new AboutInfo();body.Clear();
        var logo=Ui.Card(Ui.Icon("home",Ui.Gold,64),24,new Thickness(22),Ui.Ink);logo.HorizontalOptions=LayoutOptions.Center;
        var name=Ui.Text(AppProduct.Name,24,bold:true);name.HorizontalTextAlignment=TextAlignment.Center;
        var version=Ui.Text("当前版本 "+AppInfo.Current.VersionString+"("+AppInfo.Current.BuildString+")",13,Ui.Muted);version.HorizontalTextAlignment=TextAlignment.Center;
        body.Add(logo);body.Add(name);body.Add(version);body.Add(Ui.Divider());
        body.Add(Ui.Text(about.Introduction.Length>0?about.Introduction:AppProduct.Name+",让每一笔往来清楚有据。",15));
        body.Add(Ui.Text("运营主体:"+(about.Operator.Length>0?about.Operator:"待填写"),12,Ui.Muted));
        if(about.Copyright.Length>0)body.Add(Ui.Text(about.Copyright,12,Ui.Muted));
        if(about.IcpNumber.Length>0)body.Add(Ui.Button(about.IcpNumber+" ›",()=>Browser.OpenAsync("https://beian.miit.gov.cn/",BrowserLaunchMode.SystemPreferred),false));
        body.Add(Ui.Button("用户协议与隐私政策",()=>Navigation.PushAsync(new LegalCenterPage()),false));
        body.Add(Ui.Button("客服与反馈",()=>Navigation.PushAsync(new SupportPage()),false));body.Add(status);
    }
}

public sealed class AboutAdminPage : ContentPage
{
    private AppContent? content;
    private readonly VerticalStackLayout body=Ui.Stack();
    public AboutAdminPage(){if(!AuthClient.Current.IsAdmin)throw new InvalidOperationException("需要管理员权限");Title="关于我们与备案信息";body.Padding=18;Content=new ScrollView{Content=body};}
    protected override async void OnAppearing(){base.OnAppearing();try{await Load();}catch(Exception ex){body.Clear();body.Add(Ui.Text(ex.Message,13,Ui.Red));}}
    private async Task Load()
    {
        using var data=await AuthClient.Current.AdminRequest("/content");content=data.RootElement.Deserialize<AppContent>(new JsonSerializerOptions(JsonSerializerDefaults.Web))??throw new InvalidOperationException("后台信息无效");
        var info=content.About??new AboutInfo();var fields=new FieldSet(new DbRow{["intro"]=info.Introduction,["operator"]=info.Operator,["copyright"]=info.Copyright,["icp"]=info.IcpNumber},[new("intro","软件介绍",FieldKind.Notes),new("operator","运营主体完整名称"),new("copyright","版权说明"),new("icp","备案号(备案完成后填写)")]);
        body.Clear();body.Add(Ui.Text("本页只更新当前软件的关于我们。备案号留空时不显示,填写后用户可点击进入工信部备案查询。",13,Ui.Muted));body.Add(Ui.Card(fields.View));body.Add(Ui.Button("保存并发布",async()=>
        {
            var row=fields.Read();using var result=await AuthClient.Current.AdminRequest("/about",new UpdateAboutRequest(content.Revision,new(row.Text("intro"),row.Text("operator"),row.Text("copyright"),row.Text("icp"))));
            var updated=result.RootElement.Deserialize<AppContent>(new JsonSerializerOptions(JsonSerializerDefaults.Web))??throw new InvalidOperationException("后台信息无效");ContentClient.Remember(updated);await DisplayAlertAsync("已发布","用户联网后自动同步,无需重新安装。","完成");await Load();
        }));
    }
}