🆙优化bridge交互的参数;
完善web登录成功后回调插件的数据交互
This commit is contained in:
parent
07b119f3e9
commit
0aa3757b52
@ -1,10 +1,16 @@
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Web.WebView2.WinForms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AIProofread
|
||||
{
|
||||
public enum BridgeEvent
|
||||
{
|
||||
LoginSuccess
|
||||
}
|
||||
public delegate void BridgeEventHandler(object sender, EventArgs e);
|
||||
[ClassInterface(ClassInterfaceType.AutoDual)]
|
||||
[ComVisible(true)]
|
||||
public class Bridge
|
||||
@ -13,12 +19,49 @@ namespace AIProofread
|
||||
|
||||
private static readonly Dictionary<string, WebView2> webViewDict = new Dictionary<string, WebView2>();
|
||||
|
||||
private static readonly Dictionary<BridgeEvent, List<BridgeEventHandler>> eventHandlers = new Dictionary<BridgeEvent, List<BridgeEventHandler>>();
|
||||
|
||||
public void showDialog(string message)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加事件
|
||||
/// </summary>
|
||||
/// <param name="eventName"></param>
|
||||
/// <param name="handler"></param>
|
||||
public static void AddEventHandler(BridgeEvent eventName, BridgeEventHandler handler)
|
||||
{
|
||||
if (!eventHandlers.ContainsKey(eventName))
|
||||
{
|
||||
eventHandlers.Add(eventName, new List<BridgeEventHandler>());
|
||||
}
|
||||
eventHandlers[eventName].Add(handler);
|
||||
}
|
||||
public static void RemoveEventHandler(BridgeEvent eventName, BridgeEventHandler handler)
|
||||
{
|
||||
if (eventHandlers.ContainsKey(eventName))
|
||||
{
|
||||
eventHandlers[eventName].Remove(handler);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录成功后通知后端
|
||||
/// </summary>
|
||||
public void loginSuccess(string loginToken)
|
||||
{
|
||||
showDialog(string.Format("登录成功,token:{0}", loginToken));
|
||||
if (eventHandlers.ContainsKey(BridgeEvent.LoginSuccess))
|
||||
{
|
||||
foreach (var eventHandler in eventHandlers[BridgeEvent.LoginSuccess])
|
||||
{
|
||||
eventHandler(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取文档所有文本数据
|
||||
public string getAllText()
|
||||
{
|
||||
|
@ -5,15 +5,25 @@ namespace AIProofread.Controls
|
||||
{
|
||||
public partial class FormLogin : Form
|
||||
{
|
||||
|
||||
public event EventHandler OnLoginCompleted;
|
||||
public FormLogin()
|
||||
{
|
||||
InitializeComponent();
|
||||
Bridge.InitWebEnvAsync("login", web);
|
||||
Bridge.AddEventHandler(BridgeEvent.LoginSuccess, OnLoginSuccess);
|
||||
}
|
||||
|
||||
private void OnLoginSuccess(object sender, EventArgs e)
|
||||
{
|
||||
OnLoginCompleted?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void FormLogin_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.web.Source = new Uri(Config.WebPath("#login"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
2
AIProofread/Properties/Resources.Designer.cs
generated
2
AIProofread/Properties/Resources.Designer.cs
generated
@ -39,7 +39,7 @@ namespace AIProofread.Properties {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WordAddInTest2024.Properties.Resources", typeof(Resources).Assembly);
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AIProofread.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
|
@ -14,29 +14,41 @@ namespace AIProofread
|
||||
private FormLogin formLogin;
|
||||
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
|
||||
{
|
||||
formLogin = new FormLogin();
|
||||
btnLogin.Label = "用户\n登录";
|
||||
btnLogout.Label = "退出\n登录";
|
||||
}
|
||||
|
||||
// 处理是否登录的展示
|
||||
private void ToggleLogin()
|
||||
{
|
||||
if(!IS_LOGIN)
|
||||
{
|
||||
if(formLogin == null || formLogin.IsDisposed) { formLogin = new FormLogin(); }
|
||||
formLogin.Show();
|
||||
}
|
||||
IS_LOGIN = !IS_LOGIN;
|
||||
gpLogin.Visible = !IS_LOGIN;
|
||||
gpLogout.Visible = IS_LOGIN;
|
||||
}
|
||||
|
||||
private void btnLogin_Click(object sender, RibbonControlEventArgs e)
|
||||
// 当登录成功后的回调处理
|
||||
private void FormLogin_OnLoginCompleted(object sender, EventArgs e)
|
||||
{
|
||||
IS_LOGIN = true;
|
||||
ToggleLogin();
|
||||
formLogin.Close();
|
||||
formLogin = null;
|
||||
}
|
||||
|
||||
// 弹出登录窗口
|
||||
private void btnLogin_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
if (formLogin == null || formLogin.IsDisposed)
|
||||
{
|
||||
formLogin = new FormLogin();
|
||||
formLogin.OnLoginCompleted += FormLogin_OnLoginCompleted;
|
||||
}
|
||||
formLogin.ShowDialog();
|
||||
}
|
||||
|
||||
// 注销登录
|
||||
private void btnLogout_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
IS_LOGIN = false;
|
||||
ToggleLogin();
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Normal file
BIN
AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user