_EnvInfo.cshtml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. @using WeApp.Helpers
  2. @{
  3. string id = "env-info";
  4. }
  5. @Html.Partial("__/_AreaBox", $"演练信息#{id}")
  6. <div style="display: none" id="@id-pre">
  7. </div>
  8. @using (Html.BeginScripts())
  9. {
  10. <script id="env-info-script">
  11. var $envInfoBody = $('#@id .box-body');
  12. $envInfoBody.html($('#@id-pre').html());
  13. var env_infos = [],timer_env;
  14. function LoadEveInfo(delay) {
  15. clearTimeout(timer_env);
  16. $.get({
  17. url: "/content/data/envInfo.json",
  18. success: (arr) => {
  19. while (arr.length != 0) {
  20. var index = Math.floor(Math.random() * arr.length); // 这里使arr.length
  21. env_infos.push(arr[index]);
  22. arr.splice(index, 1);
  23. }
  24. RenderEnvInfo(delay);
  25. }
  26. });
  27. }
  28. function RenderEnvInfo(delayNum) {
  29. if (env_infos.length) {
  30. var env = env_infos.pop();
  31. var html = `
  32. <div class="px-6 env-info">
  33. <span>${env.source?env.source+":":""}<span>${env.info}</span></span>
  34. <span>${new Date().format("hh:mm:ss")}</span>
  35. </div>`;
  36. $envInfoBody.append(html);
  37. window.Scroll2Bottom($('#@id').find('.scroll-box'));
  38. var delay = delayNum ? 1 + Math.random() * 2 : 50 + Math.random() * 10;
  39. delayNum--;
  40. timer_env = setTimeout(() => { RenderEnvInfo(delayNum)}, 1000 * delay);
  41. } else {
  42. LoadEveInfo();
  43. }
  44. }
  45. $(function () {
  46. LoadEveInfo(10);
  47. });
  48. </script>
  49. }