uploading.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. $(function() {
  2. var params = window.location.href.split("?");
  3. if (params.length > 1) {
  4. values = params[1].split("&");
  5. if (values.length > 1) {
  6. var funcId = values[0].replace("id=", "");
  7. var algorithm_path = "";//资料
  8. //var purpose = "";
  9. if (funcId !== "0") {
  10. algorithm_path = decodeURI(values[1].replace("algorithm_path=", ""));//资料
  11. }
  12. }
  13. }
  14. $("#algorithm_path").val(algorithm_path);//资料
  15. // if (isHide === "1") {
  16. // $("#flag").attr("checked", "checked");
  17. // }
  18. layui.use("form", function() {
  19. layui.form.render();
  20. });
  21. layui.use(["form", "layer","upload"], function() {
  22. $ = layui.jquery;
  23. var form = layui.form,
  24. layer = layui.layer;
  25. var upload = layui.upload;
  26. //监听提交
  27. form.on("switch(hide)", function(data) {
  28. isHide = data.elem.checked ? 1 : 0;
  29. });
  30. form.on("submit(save)", function(data) {
  31. if ($("#algorithm_path").val().trim() === "") {
  32. showMsg("没有选择文件", 2);
  33. $("#algorithm_path").focus();
  34. return false;
  35. }
  36. var func = data.field;
  37. //var str = $("#hide").val()
  38. //func.hide = str === "on" ? 1 : 0;
  39. func.id = funcId;
  40. func.algorithm_path = file
  41. //func.flag = isHide;
  42. // let url = "";
  43. var url = "api/algorithm/add";
  44. fetchJSON(url, func, "post", function(data) {
  45. if (data.status === 0) {
  46. var index = parent.layer.getFrameIndex(window.name);
  47. showMsg("上传成功", 1, 2000);
  48. parent.layer.close(index);
  49. } else {
  50. showMsg(data.msg, 2);
  51. }
  52. });
  53. return false;
  54. });
  55. upload.render({
  56. elem: '#algorithm_path',
  57. url: urlBase + "api/algorithm/importData" ,//改成您自己的上传接口
  58. headers: {
  59. "token":sessionStorage.getItem("token")
  60. },
  61. data: {},
  62. accept: 'file',
  63. // exts: 'xls|xlsx',
  64. done: function(res){
  65. if (res.status === 0) {
  66. var index = parent.layer.getFrameIndex(window.name);
  67. showMsg("上传成功", 1, 2000);
  68. parent.layer.close(index);
  69. }else{
  70. var index = parent.layer.getFrameIndex(window.name);
  71. showMsg("上传失败", 1, 2000);
  72. parent.layer.close(index);
  73. }
  74. }
  75. });
  76. });
  77. });