article-list-add.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. let majorId = 0;
  2. let arr =[
  3. {
  4. id:0,
  5. name:"随机资料"
  6. },
  7. {
  8. id:1,
  9. name:"技术通报"
  10. },
  11. {
  12. id:2,
  13. name:"研究文章"
  14. },
  15. ]
  16. $(function() {
  17. var params = window.location.href.split("?");
  18. if (params.length > 1) {
  19. values = params[1].split("&");
  20. if (values.length > 10) {
  21. var funcId = values[0].replace("id=", "");
  22. var functi = ""; //标题
  23. var funcauthor = ""; //作者
  24. var functime = ""; //输入时间
  25. var funckey = ""; //关键字
  26. var funcdes = ""; //概述
  27. var funcmajorId = ""; //专业
  28. var funcmajorName = ""; //专业名
  29. var funcarticleType = ""; //文章类型
  30. var funcfilePath = ""; //文件路径
  31. var funcfile = "" //选择文件
  32. if (funcId !== "0") {
  33. functi = decodeURI(values[1].replace("title=", "")); //标题
  34. funcauthor = decodeURI(values[2].replace("author=", "")); //作者
  35. functime = decodeURI(values[3].replace("input_time=", "")); //输入时间
  36. funckey = decodeURI(values[4].replace("keywords=", "")); //关键字
  37. funcdes = decodeURI(values[5].replace("description=", "")); //概述
  38. funcmajorId = decodeURI(values[6].replace("major_id=", "")); //专业
  39. funcmajorName = decodeURI(values[7].replace("major_name=", "")); //专业名
  40. funcarticleType = decodeURI(values[8].replace("article_type=", "")); //文章类型
  41. // funcfilePath = decodeURI(values[9].replace("file_path=", "")); //文件路径
  42. funcfile = decodeURI(values[10].replace("file=", "")); //选择文件
  43. }
  44. }
  45. }
  46. $("#title").val(functi); //标题
  47. $("#author").val(funcauthor); //作者
  48. $("#input_time").val(functime); //输入时间
  49. $("#keywords").val(funckey); //关键字
  50. $("#description").val(funcdes); //概述
  51. $("#major_id").val(funcmajorId); //专业
  52. $("#major_name").val(funcmajorName); //专业名
  53. $("#article_type").val(funcarticleType); //文章类型
  54. // $("#file_path").val(funcfilePath); //文件路径
  55. $("#file").val(funcfile); //选择文件
  56. // if (isHide === "1") {
  57. // $("#flag").attr("checked", "checked");
  58. // }
  59. getArticleType();
  60. layui.use(["form", "layer","upload"], function() {
  61. $ = layui.jquery;
  62. var form = layui.form,
  63. layer = layui.layer;
  64. //监听提交
  65. var upload = layui.upload;
  66. form.on("submit(save)", function(data) {
  67. if ($("#title").val().trim() === "") {
  68. showMsg("标题不能为空", 2);
  69. $("#title").focus();
  70. return false;
  71. }
  72. if ($("#author").val().trim() === "") {
  73. showMsg("作者不能为空", 2);
  74. $("#author").focus();
  75. return false;
  76. }
  77. if ($("#input_time").val().trim() === "") {
  78. showMsg("输入时间不能为空", 2);
  79. $("#input_time").focus();
  80. return false;
  81. }
  82. if ($("#keywords").val().trim() === "") {
  83. showMsg("关键字不能为空", 2);
  84. $("#keywords").focus();
  85. return false;
  86. }
  87. if ($("#description").val().trim() === "") {
  88. showMsg("概述不能为空", 2);
  89. $("#author").focus();
  90. return false;
  91. }
  92. if ($("#major_id").val().trim() === "") {
  93. showMsg("专业不能为空", 2);
  94. $("#major_id").focus();
  95. return false;
  96. }
  97. if ($("#major_name").val().trim() === "") {
  98. showMsg("专业名不能为空", 2);
  99. $("#major_name").focus();
  100. return false;
  101. }
  102. if ($("#article_type").val().trim() === "") {
  103. showMsg("文章类型不能为空", 2);
  104. $("#article_type").focus();
  105. return false;
  106. }
  107. if ($("#file_path").val().trim() === "") {
  108. showMsg("上传文件不能为空", 2);
  109. $("#file_path").focus();
  110. return false;
  111. }
  112. var func = data.field;
  113. func.id = funcId;
  114. fetchJSON("api/article/add", func, "post", function(data) {
  115. if (data.status === 0) {
  116. var index = parent.layer.getFrameIndex(window.name);
  117. showMsg("上传成功", 1, 2000);
  118. parent.layer.close(index);
  119. } else {
  120. showMsg(data.msg, 2);
  121. }
  122. });
  123. return false;
  124. });
  125. upload.render({
  126. elem: '#fileSelector',
  127. url: urlBase + "api/article/import",
  128. //accept: 'file', //普通文件
  129. headers: {
  130. "token":sessionStorage.getItem("token")
  131. },
  132. data: {},
  133. accept: 'file',
  134. done: function(res) {
  135. if(res.status === 0)
  136. {
  137. $("#file_path").val(res.msg);
  138. }
  139. else
  140. showMsg(res.msg, 2);
  141. }
  142. });
  143. //专业
  144. function getMajor() {
  145. fetchJSON("api/major/listAll", {}, "get", function(bet) {
  146. if (bet.status === 0) {
  147. $("#major_id").empty();
  148. $("#major_id").append($("<option>", {
  149. value: -1,
  150. text: "请选择"
  151. }));
  152. for (var i = 0; i < bet.data.length; i++) {
  153. if (bet.data[i].id === majorId) {
  154. $("#major_id").append(
  155. $("<option>", {
  156. // value: bet.data[i].id,
  157. text: bet.data[i].id,
  158. selected: true
  159. })
  160. );
  161. } else {
  162. $("#major_id").append(
  163. $("<option>", {
  164. // value: bet.data[i].id,
  165. text: bet.data[i].id
  166. })
  167. );
  168. }
  169. }
  170. form.render('select');
  171. } else {
  172. showMsg(bet.msg, 2);
  173. }
  174. });
  175. };
  176. getMajor()
  177. //专业名
  178. function getMajorName() {
  179. fetchJSON("api/major/listAll", {}, "get", function(bet) {
  180. if (bet.status === 0) {
  181. $("#major_name").empty();
  182. $("#major_name").append($("<option>", {
  183. value: -1,
  184. text: "请选择"
  185. }));
  186. for (var i = 0; i < bet.data.length; i++) {
  187. if (bet.data[i].id === majorId) {
  188. $("#major_name").append(
  189. $("<option>", {
  190. // value: bet.data[i].id,
  191. text: bet.data[i].major,
  192. selected: true
  193. })
  194. );
  195. } else {
  196. $("#major_name").append(
  197. $("<option>", {
  198. // value: bet.data[i].id,
  199. text: bet.data[i].major
  200. })
  201. );
  202. }
  203. }
  204. form.render('select');
  205. } else {
  206. showMsg(bet.msg, 2);
  207. }
  208. });
  209. };
  210. getMajorName()
  211. });
  212. });
  213. //文章类型
  214. function getArticleType() {
  215. $("#article_type").append($("<option>", {
  216. value: -1,
  217. text: "请选择"
  218. }));
  219. for (var i = 0; i < arr.length; i++) {
  220. $("#article_type").append(
  221. $("<option>", {
  222. // value: arr[i].id,
  223. text: arr[i].name
  224. })
  225. );
  226. }
  227. };