Index.cshtml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. @{
  2. Layout = null;
  3. }
  4. <script src="~/js/jquery-3.4.1.min.js"></script>
  5. <script>
  6. $(document).ready(function() {
  7. //document.location = '@Url.Action("Index","SmartFuel")';
  8. //document.location = "http://localhost:8384/SmartFuel";
  9. getWebConsoleAPI(["webapi", ["WebConsole"]], function (apiPath) {
  10. //console.log("Joy home page index ready api path" + apiPath);
  11. if (apiPath === null || apiPath === undefined || apiPath === "") {
  12. document.location = '@Url.Action("Index","SmartFuel")';
  13. return;
  14. }
  15. var href = window.location.href;
  16. var path = window.location.pathname;
  17. let basicUrl = href.slice(0, href.indexOf(path));
  18. var serviceUrl = basicUrl + apiPath;
  19. $.ajax({
  20. url: serviceUrl,
  21. datatype: "application/json",
  22. type: 'post',
  23. contentType: "application/json;charset=utf-8;",
  24. beforeSend: function () {
  25. },
  26. success: function (data) {
  27. console.log(data);
  28. //alert("success get config:" + data.LayoutConfig.IndexPageUrl);
  29. if (data !== null && data.LayoutConfig && data.LayoutConfig.IndexPageUrl) {
  30. document.location = data.LayoutConfig.IndexPageUrl;
  31. } else {
  32. document.location = '@Url.Action("Index","SmartFuel")';
  33. }
  34. },
  35. error: function (err) {
  36. console.log(err);
  37. //alert("error happens");
  38. document.location = '@Url.Action("Index","SmartFuel")';
  39. }
  40. });
  41. });
  42. });
  43. function getWebConsoleAPI(parameter, callBack) {
  44. var href = window.location.href;
  45. var path = window.location.pathname;
  46. let basicUrl = href.slice(0, href.indexOf(path));
  47. var serviceUrl = basicUrl + "/u/?apitype=service&an=ShowMeApi&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  48. $.ajax({
  49. url: serviceUrl,
  50. datatype: "application/json",
  51. type: 'post',
  52. contentType: "application/json;charset=utf-8;",
  53. data: JSON.stringify(parameter),
  54. beforeSend: function () {
  55. },
  56. success: function (data) {
  57. console.log(data);
  58. if (data !== null && Array.isArray(data) && data.length > 0) {
  59. if (callBack !== null) callBack(data[0].Path);
  60. } else {
  61. if (callBack !== null) callBack(null);
  62. }
  63. },
  64. error: function (err) {
  65. console.log(err);
  66. if (callBack !== null) callBack(null);
  67. }
  68. });
  69. }
  70. </script>