国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9KB

  1. function checkSubmit(t) {
  2. if (document.addcontent.title.value == "") {
  3. ShowMsg(`${t}不能为空`);
  4. document.addcontent.title.focus();
  5. return false;
  6. }
  7. if (document.addcontent.typeid.value == 0) {
  8. ShowMsg("请您选择文档所属栏目");
  9. return false;
  10. }
  11. }
  12. function SelectFile(sform, stype) {
  13. let s = sform.split(".");
  14. if (s.length === 2) {
  15. let frm = document.getElementsByName(s[0]);
  16. let ipt = document.getElementsByName(s[1]);
  17. let tmp = document.createElement("input");
  18. tmp.id = 'field'+s[1];
  19. tmp.type = "file";
  20. tmp.style.display = 'none';
  21. if ($(`#${tmp.id}`).length === 0) {
  22. $(frm).append(tmp);
  23. }
  24. $(`#${tmp.id}`).click();
  25. $(`#${tmp.id}`).off('change').change(function (val) {
  26. const f = val.target.files[0];
  27. var formData = new FormData();
  28. var fileData = f;
  29. formData.append('file', fileData);
  30. $.ajax({
  31. url: 'api.php?action=upload&type='+stype,
  32. type: 'POST',
  33. data: formData,
  34. processData: false,
  35. contentType: false,
  36. success: function (result) {
  37. if (result.code === 0) {
  38. $(ipt).val(result.data);
  39. } else {
  40. ShowMsg("文件上传失败,错误原因:"+result.msg);
  41. }
  42. },
  43. error: function (xhr, status, error) {
  44. ShowMsg("文件上传失败");//处理上传失败后的回调
  45. }
  46. });
  47. })
  48. }
  49. }
  50. function SelectImage(sform, stype) {
  51. if (stype == 'big') {
  52. stype = "litpic";
  53. }
  54. SelectFile(sform, stype);
  55. }
  56. function SelectSoft(sform, stype='soft') {
  57. SelectFile(sform, stype);
  58. }
  59. function SelectMedia(sform, stype='media') {
  60. SelectFile(sform, stype);
  61. }