algorithm-add.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. $(function() {
  2. var params = window.location.href.split("?");
  3. if (params.length > 1) {
  4. values = params[1].split("&");
  5. if (values.length > 7) {
  6. var funcId = values[0].replace("id=", "");
  7. var algorithm_type = '';
  8. var algorithm_name = '';
  9. var algorithm_format = '';
  10. var device_name = '';
  11. var create_time = '';
  12. var algorithm_path = '';
  13. var remarks = '';
  14. if (funcId !== "0") {
  15. algorithm_type = decodeURI(values[1].replace("algorithm_type=", ""));
  16. algorithm_name = decodeURI(values[2].replace("algorithm_name=", ""));
  17. algorithm_format = decodeURI(values[3].replace("algorithm_format=", ""));
  18. device_name = decodeURI(values[4].replace("device_name=", ""));
  19. create_time = decodeURI(values[5].replace("create_time=", ""));
  20. algorithm_path = decodeURI(values[6].replace("algorithm_path=", ""));
  21. remarks = decodeURI(values[7].replace("remarks=", ""));
  22. }
  23. }
  24. }
  25. $("#algorithm_type").val(algorithm_type);
  26. $("#algorithm_name").val(algorithm_name);
  27. $("#algorithm_format").val(algorithm_format);
  28. $("#device_name").val(device_name);
  29. $("#create_time").val(create_time);
  30. $("#algorithm_path").val(algorithm_path);
  31. $("#remarks").val(remarks);
  32. layui.use("form", function() {
  33. layui.form.render();
  34. });
  35. layui.use(["form", "layer","upload", "laydate"], function() {
  36. $ = layui.jquery;
  37. var form = layui.form,
  38. layer = layui.layer;
  39. var upload = layui.upload;
  40. form.on("submit(save)", function(data) {
  41. var func = data.field;
  42. func.id = funcId;
  43. let url = "";
  44. if (func.id === "0") url = "api/algorithm/add";
  45. else url = "api/algorithm/edit";
  46. fetchJSON(url, func, "post", function(data) {
  47. if (data.status === 0) {
  48. var index = parent.layer.getFrameIndex(window.name);
  49. showMsg("修改成功", 1, 2000);
  50. parent.layer.close(index);
  51. } else {
  52. showMsg(data.msg, 2);
  53. }
  54. });
  55. return false;
  56. });
  57. upload.render({
  58. elem: '#file',
  59. url: urlBase + "api/algorithm/importData",
  60. accept: 'file', //普通文件
  61. headers: {
  62. "token": sessionStorage.getItem("token")
  63. },
  64. data: {},
  65. // accept: 'file',
  66. done: function(res) {
  67. if (res.status === 0) {
  68. $("#algorithm_path").val(res.msg);
  69. } else
  70. showMsg(res.msg, 2);
  71. }
  72. });
  73. });
  74. });