commonFile.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * 公共附件管理初始化
  3. */
  4. var CommonFile = {
  5. id: "CommonFileTable", //表格id
  6. seItem: null, //选中的条目
  7. table: null,
  8. layerIndex: -1
  9. };
  10. /**
  11. * 初始化表格的列
  12. */
  13. CommonFile.initColumn = function () {
  14. return [
  15. {field: 'selectItem', radio: true},
  16. {title: '附件原名', field: 'originalName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "20%"},
  17. {title: '下载地址', field: 'id', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "40%",
  18. formatter: function (value, row, index) {
  19. return "<a href=\'javascript:void(0)\' onclick=\"CommonFile.downloadFileById('" + value + "')\">" + row.url + "</a>";
  20. }
  21. },
  22. {title: '备注', field: 'description', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "20%"},
  23. {title: '上传时间', field: 'createTime', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "10%"},
  24. {title: '创建用户', field: 'createUser', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "10%"},
  25. ];
  26. };
  27. CommonFile.downloadFileById = function (id) {
  28. window.location.href = Feng.ctxPath + "/common/api/downloadFile/type/4/id/" + id;
  29. }
  30. /**
  31. * 检查是否选中
  32. */
  33. CommonFile.check = function () {
  34. var selected = $('#' + this.id).bootstrapTable('getSelections');
  35. if (selected.length == 0) {
  36. Feng.info("请先选中表格中的某一记录!");
  37. return false;
  38. } else {
  39. CommonFile.seItem = selected[0];
  40. return true;
  41. }
  42. };
  43. /**
  44. * 点击添加公共附件
  45. */
  46. CommonFile.openAddCommonFile = function () {
  47. var index = layer.open({
  48. type: 1,
  49. title: '添加公共附件',
  50. area: ['800px', '420px'], //宽高
  51. fix: false, //不固定
  52. maxmin: true,
  53. content: "<form id=\"commonFileForm\" action=\"" + Feng.ctxPath + "/admin/common_file/add\" method=\"post\" enctype=\"multipart/form-data\" target=\"hiddenIframe\">\n" +
  54. " <div class=\"panel panel-default\">\n" +
  55. " <div class=\"panel-heading\" style=\"font-weight: bold\">附件材料</div>\n" +
  56. " <div class=\"panel-body\">\n" +
  57. " <input type=\"text\" style=\"display: none\" id=\"index\" name=\"index\" >\n" +
  58. " <input type=\"file\" style=\"display: none\" id=\"fileUrl\" name=\"fileUrl\" onchange=\"CommonFile.fileChange(this)\">\n" +
  59. " <input class=\"form-control\" id=\"fileInput\" onclick=\"$('#fileUrl').click()\">\n" +
  60. " </div>\n" +
  61. " <div class=\"panel-heading\" style=\"font-weight: bold\">备注</div>\n" +
  62. " <div class=\"panel-body\">\n" +
  63. " <textarea class=\"form-control\" id=\"description\" name=\"description\"></textarea>\n" +
  64. " </div>\n" +
  65. " </div>\n" +
  66. " </form>",
  67. btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;提交', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
  68. btnAlign: 'c',
  69. yes: function (index, layero) {
  70. $("#index").val(index);
  71. $("#commonFileForm")[0].submit();
  72. }
  73. });
  74. this.layerIndex = index;
  75. };
  76. /**
  77. * 删除公共附件
  78. */
  79. CommonFile.delete = function () {
  80. if (this.check()) {
  81. var operation = function () {
  82. var ajax = new $ax(Feng.ctxPath + "/admin/common_file/delete", function (data) {
  83. if (data.code == 200) {
  84. Feng.success(data.msg);
  85. CommonFile.table.refresh();
  86. } else {
  87. Feng.info(data.msg);
  88. }
  89. }, function (data) {
  90. Feng.error("删除失败!" + data.responseJSON.message + "!");
  91. });
  92. ajax.set("id", CommonFile.seItem.id);
  93. ajax.start();
  94. }
  95. Feng.confirm("确认删除吗?", operation);
  96. }
  97. };
  98. CommonFile.fileChange = function (context) {
  99. if (!Feng.chkFileInvalid(context.files[0], 5, 20)) {
  100. return;
  101. }
  102. var file = $(context).val();
  103. var pos = file.lastIndexOf("\\");
  104. $("#fileInput").val(file.substring(pos + 1));
  105. }
  106. CommonFile.callback = function (data) {
  107. if (data.code == 200) {
  108. Feng.success(data.msg);
  109. layer.close(data.obj);
  110. CommonFile.table.refresh();
  111. } else {
  112. Feng.info(data.msg);
  113. }
  114. }
  115. $(function () {
  116. var defaultColunms = CommonFile.initColumn();
  117. var table = new BSTable(CommonFile.id, "/admin/common_file/list", defaultColunms);
  118. table.setPaginationType("server");
  119. CommonFile.table = table.init();
  120. });