algorithm-add.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. let arr = [{
  2. id: 0,
  3. name: "预处理"
  4. },
  5. {
  6. id: 1,
  7. name: "特征提取"
  8. },
  9. {
  10. id: 2,
  11. name: "参数优化"
  12. },
  13. {
  14. id: 3,
  15. name: "故障诊断"
  16. },
  17. {
  18. id: 4,
  19. name: "寿命预测"
  20. },
  21. {
  22. id: 5,
  23. name: "其他"
  24. },
  25. ]
  26. var majorId = 0;
  27. $(function() {
  28. var params = window.location.href.split("?");
  29. if (params.length > 1) {
  30. values = params[1].split("&");
  31. if (values.length > 7) {
  32. var funcId = values[0].replace("id=", "");
  33. var algorithm_type = '';
  34. var algorithm_name = '';
  35. var algorithm_format = '';
  36. var device_name = '';
  37. var create_time = '';
  38. var algorithm_path = '';
  39. var remarks = '';
  40. if (funcId !== "0") {
  41. algorithm_type = decodeURI(values[1].replace("algorithm_type=", ""));
  42. // console.log(algorithm_type)
  43. algorithm_name = decodeURI(values[2].replace("algorithm_name=", ""));
  44. algorithm_format = decodeURI(values[3].replace("algorithm_format=", ""));
  45. device_name = decodeURI(values[4].replace("device_name=", ""));
  46. create_time = decodeURI(values[5].replace("create_time=", ""));
  47. algorithm_path = decodeURI(values[6].replace("algorithm_path=", ""));
  48. remarks = decodeURI(values[7].replace("remarks=", ""));
  49. }
  50. }
  51. }
  52. // $("#algorithm_typeSelect").find("option:selected").val(algorithm_type);
  53. $("#algorithm_name").val(algorithm_name);
  54. $("#algorithm_format").val(algorithm_format);
  55. $("#device_name").val(device_name);
  56. $("#create_time").val(create_time);
  57. $("#algorithm_path").val(algorithm_path);
  58. $("#remarks").val(remarks);
  59. layui.use("form", function() {
  60. layui.form.render();
  61. });
  62. layui.use(["form", "layer", "upload", "laydate"], function() {
  63. $ = layui.jquery;
  64. var form = layui.form,
  65. layer = layui.layer;
  66. var upload = layui.upload;
  67. form.on("select", function(data) {
  68. if (data.elem.id === "algorithm_typeSelect"){
  69. algorithm_type = data.elem[data.elem.selectedIndex].text;
  70. // console.log(algorithm_type)
  71. }
  72. })
  73. form.on("submit(save)", function(data) {
  74. var func = data.field;
  75. func.id = funcId;
  76. func.algorithm_type = algorithm_type
  77. let url = "";
  78. if (func.id === "0") url = "api/algorithm/add";
  79. else url = "api/algorithm/edit";
  80. fetchJSON(url, func, "post", function(data) {
  81. // console.log(data)
  82. if (data.status === 0) {
  83. var index = parent.layer.getFrameIndex(window.name);
  84. showMsg("修改成功", 1, 2000);
  85. parent.layer.close(index);
  86. } else {
  87. showMsg(data.msg, 2);
  88. }
  89. });
  90. return false;
  91. });
  92. upload.render({
  93. elem: '#file',
  94. url: urlBase + "api/algorithm/importData",
  95. accept: 'file', //普通文件
  96. headers: {
  97. "token": sessionStorage.getItem("token")
  98. },
  99. data: {},
  100. // accept: 'file',
  101. done: function(res) {
  102. if (res.status === 0) {
  103. $("#algorithm_path").val(res.msg);
  104. } else
  105. showMsg(res.msg, 2);
  106. }
  107. });
  108. function getAirType() {
  109. // console.log(bet, "121111111")
  110. $("#algorithm_typeSelect").empty();
  111. $("#algorithm_typeSelect").append($("<option>", {
  112. value: -1,
  113. text: "请选择"
  114. }));
  115. for (var i = 0; i < arr.length; i++) {
  116. $("#algorithm_typeSelect").append(
  117. $("<option>", {
  118. value: arr[i].id,
  119. text: arr[i].name,
  120. // selected: true
  121. })
  122. );
  123. }
  124. layui.use("form", function() {
  125. layui.form.render('select', 'aircraft_typeFilter');
  126. });
  127. // form.render('select');
  128. }
  129. getAirType()
  130. });
  131. });