diff --git a/Assets/Scripts/Controller/ScoreController.cs b/Assets/Scripts/Controller/ScoreController.cs index 5a31979b..546d008c 100644 --- a/Assets/Scripts/Controller/ScoreController.cs +++ b/Assets/Scripts/Controller/ScoreController.cs @@ -1,7 +1,9 @@ +using Newtonsoft.Json; using QFramework; using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using TMPro; using UnityEngine; using UnityEngine.SocialPlatforms.Impl; @@ -48,6 +50,29 @@ public class ScoreController : MonoSingleton } + public string GetModuleDictJson(string name = "") + { + var resultDict = new Dictionary(); + resultDict.Add("name", name); + foreach (var dataPair in moduleDict) + { + var data = dataPair.Value; + if (data.scoreDict != null) + { + foreach (var scoreStepPair in data.scoreDict) + { + var scoreStep = scoreStepPair.Value; + string key = $"{scoreStep.step}{scoreStep.name}"; + resultDict[key] = scoreStep.value; + + resultDict.Add(key + "Time", string.IsNullOrEmpty(scoreStep.time) == true ? "" : scoreStep.time); + } + } + } + + return JsonConvert.SerializeObject(resultDict); + } + private void OnStart(OnModuleStart start) { @@ -84,6 +109,8 @@ public class ScoreController : MonoSingleton { scoreDict[key].value = 0; } + DateTime currentTime = DateTime.Now; + scoreDict[key].time = currentTime.ToString(scoreDict[key].timeFormat); } else { diff --git a/Assets/Scripts/Tools/AsposeHelper.cs b/Assets/Scripts/Tools/AsposeHelper.cs index 2fdf7b4a..14300c27 100644 --- a/Assets/Scripts/Tools/AsposeHelper.cs +++ b/Assets/Scripts/Tools/AsposeHelper.cs @@ -9,34 +9,77 @@ public class AsposeHelper : MonoBehaviour { + //public static void Writer(string json, Action callback = null) + //{ + // // 加载Word文档 + // Document doc = new Document(Global.reportDemoPath); + + // JObject jObject = JObject.Parse(json); + + // foreach (JProperty property in jObject.Properties()) + // { + // string key = property.Name; + // string value = property.Value.ToString(); + // doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions()); + // } + + // string filePath = ChinarFileController.SaveProject(Path.GetFileName(Global.reportDemoPath).Split('.')[1]); + // if (string.IsNullOrEmpty(filePath) == false) + // { + // doc.Save(filePath); + // } + // callback?.Invoke(); + // // 替换文本 + // //SaveWithDialog(doc, callback); + // //Debug.Log("文档处理完成,新文档已保存到: " + outputFilePath); + //} + public static void Writer(string json, Action callback = null) { // 加载Word文档 Document doc = new Document(Global.reportDemoPath); - JObject jObject = JObject.Parse(json); - - foreach (JProperty property in jObject.Properties()) - { - string key = property.Name; - string value = property.Value.ToString(); - doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions()); - } + JToken jToken = JToken.Parse(json); + TraverseAndReplace(jToken, doc); string filePath = ChinarFileController.SaveProject(Path.GetFileName(Global.reportDemoPath).Split('.')[1]); - if (string.IsNullOrEmpty(filePath) == false) + if (!string.IsNullOrEmpty(filePath)) { doc.Save(filePath); } callback?.Invoke(); - // 替换文本 - //SaveWithDialog(doc, callback); - //Debug.Log("文档处理完成,新文档已保存到: " + outputFilePath); - - - } + private static void TraverseAndReplace(JToken jToken, Document doc) + { + if (jToken.Type == JTokenType.Object) + { + foreach (JProperty property in ((JObject)jToken).Properties()) + { + if (property.Value.Type == JTokenType.Object || property.Value.Type == JTokenType.Array) + { + TraverseAndReplace(property.Value, doc); + } + else + { + string key = property.Name; + string value = property.Value.ToString(); + doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions()); + } + } + } + else if (jToken.Type == JTokenType.Array) + { + foreach (JToken item in jToken) + { + TraverseAndReplace(item, doc); + } + } + } + + + + //private static void SaveWithDialog(Document doc, Action callback) //{ // SaveFileDialog dialog = new SaveFileDialog(); diff --git a/Assets/Scripts/UI/UIScore.cs b/Assets/Scripts/UI/UIScore.cs index 25e192ed..41a5b380 100644 --- a/Assets/Scripts/UI/UIScore.cs +++ b/Assets/Scripts/UI/UIScore.cs @@ -58,11 +58,7 @@ namespace QFramework.Example public string GetScoreDataJson() { - var data = new LabReprotData(); - data.realname = InputName.text; - data.biaobencaiji_1_buzhou_1 = "[1111]"; - string json = JsonConvert.SerializeObject(data); - return json; + return ScoreController.Instance.GetModuleDictJson(InputName.text); } @@ -131,9 +127,9 @@ namespace QFramework.Example this.Score.text = score.ToString(); this.Sum.text = sum.ToString(); -//#if UNITY_WEBGL -// LYTWebGLHelper.Instance.UpLoadData((int)score, stepNames, maxScore, scores); -//#endif + //#if UNITY_WEBGL + // LYTWebGLHelper.Instance.UpLoadData((int)score, stepNames, maxScore, scores); + //#endif } protected override void OnShow() diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index bc81aa7b..2dfa2d9f 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -1,5 +1,6 @@ using QFramework; using QFramework.Example; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -73,6 +74,8 @@ namespace XMLTool public string sum; public string bind; public float value; + public string time; + public string timeFormat = "yyyy-MM-dd HH:mm:ss"; } @@ -431,6 +434,7 @@ namespace XMLTool name = item.Attribute("name")?.Value, sum = item.Attribute("sum")?.Value, bind = item.Attribute("bind")?.Value, + timeFormat = item.Attribute("timeFormat")?.Value, }); } }