67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
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);
|
||
}
|
||
|
||
}
|