using Microsoft.Web.WebView2.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProductionControl
{
    public partial class FrmWeb : Form
    {  
       public FrmWeb(string subject,string subUrl,string baseUrl= "http://127.0.0.1:18082/static/index.html#/")
        {
            InitializeComponent();
            //this.webView1.CoreWebView2InitializationCompleted += new EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs>(this.WebView2InitializationCompleted);

            //
            this.Text = subject;
            this.webView1.Source= new Uri(baseUrl+subUrl);
        }

        private void FrmWeb_Load(object sender, EventArgs e)
        { 
        }

        private void WebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
        {
            this.webView1.CoreWebView2.AddHostObjectToScript("customHost", this);
        }

        private void callJs()
        {
            //webView调用js的方法示例1
            //string data = JsonConvert.SerializeObject(jsonObj);
            //this.webView1.CoreWebView2.ExecuteScriptAsync($"calcLatLng({data})");

            //-----------
            //js调用winform的方法 对应AddHostObjectToScript方法
            //获取主机对象
            //var hostObject = window.chrome.webview.hostObjects.customHost;
            ////调用winform的方法
            //hostObject.currentTile($(this).attr("src"));
        }
    }
}
