2025-02-21 11:49:10 +08:00

67 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using QFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Networking;
/// <summary>
/// 下载Word脚本
/// </summary>
public class WebGLDownLoadFile : MonoSingleton<WebGLDownLoadFile>
{
[DllImport("__Internal")]
private static extern void WebGLDownloadWord(byte[] array, int size, string reportjson);
/// <summary>
/// 下载Word 方法
/// </summary>
public void Download(string json)
{
#region
//LabReprotData reprotData = new LabReprotData();
//// 转json
//string json = JsonUtility.ToJson(reprotData, true);
#endregion
// 调用携程下载数据
StartCoroutine(WebGLDownloadWord(json));
}
/// <summary>
/// 下载Word
/// </summary>
/// <param name="json">实验报告json</param>
/// <returns></returns>
IEnumerator WebGLDownloadWord(string json)
{
UnityWebRequest request = UnityWebRequest.Get(Global.reportDemoPath);
yield return request.SendWebRequest();
if (string.IsNullOrEmpty(request.error) == false)
{
Debug.Log("错误路径:" + request.error);
}
else
{
// 下载word
DownloadDocx(request.downloadHandler.data, json);
}
}
/// <summary>
/// 调用下载Word
/// </summary>
/// <param name="bytes">支持多种文件格式下载doc docx xml xlsx txt等</param>
/// <param name="reportjson">json数据</param>
public void DownloadDocx(byte[] bytes, string reportjson)
{
WebGLDownloadWord(bytes, bytes.Length, reportjson);
}
}