No Description

StudyMaterial.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * 文件资料
  3. * */
  4. var Promise = window.Promise;
  5. if(!Promise) {
  6. //IE 兼容
  7. Promise = JSZip.external.Promise;
  8. }
  9. $(function() {
  10. $('.tool_bars').authorizeButton();
  11. helper.getDropList.getProlistDrop($('#sc_pro'), '所有项目'); //项目下拉
  12. laydate.render({
  13. elem: '#sc_times',
  14. range: '~',
  15. theme: '#249fea',
  16. });
  17. initTable();
  18. //搜索
  19. $("#sc_btns").click(function() {
  20. initTable();
  21. })
  22. });
  23. function initTable() {
  24. //先销毁表格
  25. $('#table_all').bootstrapTable('destroy');
  26. //初始化表格,动态从服务器加载数据
  27. $('#table_all').bootstrapTable({
  28. method: "get", //使用get请求到服务器获取数据
  29. url: huayi.config.callcenter_url + "equipmentapi/api/StudyMaterialsInfo/getlistsbypage", //获取数据的Servlet地址
  30. contentType: "application/x-www-form-urlencoded",
  31. striped: true, //表格显示条纹
  32. pagination: true, //启动分页
  33. pageSize: 10, //每页显示的记录数
  34. pageNumber: 1, //当前第几页
  35. pageList: [10, 20, 50, 100], //记录数可选列表
  36. search: false, //是否启用查询
  37. showColumns: false, //显示下拉框勾选要显示的列
  38. showRefresh: false, //显示刷新按钮
  39. sidePagination: "server", //表示服务端请求
  40. //设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
  41. //设置为limit可以获取limit, offset, search, sort, order
  42. queryParamsType: "undefined",
  43. queryParams: function queryParams(params) { //设置查询参数
  44. var param = {
  45. pageindex: params.pageNumber,
  46. pagesize: params.pageSize,
  47. projectid: $('#sc_pro').val(),// 否 string 项目id
  48. // apptype: $('#sc_category').val(),// 否 int 应用分类(0android 1ios)
  49. keyword: $('#sc_keyWords').val(), // 否 string 模糊查询(版本名称,版本号)
  50. stime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[0],
  51. etime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[1],
  52. };
  53. return param;
  54. },
  55. responseHandler: function(res) {
  56. //格式化数据
  57. return {
  58. "total": res.data.total, //总页数
  59. "rows": res.data.rows, //数据
  60. };
  61. },
  62. onLoadSuccess: function(res) { //加载成功时执行
  63. //layer.msg("加载成功");
  64. $('.tool_downs').authorizeOperateButton();
  65. },
  66. onLoadError: function() { //加载失败时执行
  67. //layer.msg("加载数据失败", { time: 1500, icon: 2 });
  68. }
  69. });
  70. }
  71. //添加
  72. function btn_add() {
  73. layer.open({
  74. type: 2,
  75. maxmin: true,
  76. content: "template/addOrEditStudyMaterial.html", //iframe的url,no代表不显示滚动条
  77. title: '添加文件资料',
  78. area: ['80%', '90%'], //宽高
  79. });
  80. }
  81. //删除
  82. function btn_delete(del_id) {
  83. /*发送请求*/
  84. layer.confirm('您确定要删除当前资料吗?', {
  85. icon: 7,
  86. btn: ['确定', '取消'],
  87. yes: function(index, layero) {
  88. $.ajax({
  89. type: "post",
  90. url: huayi.config.callcenter_url + "equipmentapi/api/StudyMaterialsInfo/delete",
  91. dataType: 'json',
  92. async: true,
  93. data: {
  94. ids: del_id
  95. },
  96. success: function(data) {
  97. /*验证请求*/
  98. if(data.state == "success") {
  99. layer.msg("删除成功");
  100. $('#table_all').bootstrapTable('refresh');
  101. } else {
  102. layer.msg(data.message);
  103. }
  104. }
  105. })
  106. },
  107. });
  108. }
  109. //编辑
  110. function btn_edit(edit_id) {
  111. layer.open({
  112. type: 2,
  113. maxmin: true,
  114. content: "template/addOrEditStudyMaterial.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
  115. title: '编辑文件资料',
  116. area: ['80%', '90%'], //宽高
  117. });
  118. }
  119. function content(val, row) {
  120. if(val) {
  121. var codeContent = decodeURIComponent(val);
  122. codeContent = helper.filter.delHtmlTag(codeContent);
  123. codeContent = $.trim(codeContent);
  124. var cc = codeContent.length > 50 ? codeContent.substr(0, 50) + '...' : codeContent;
  125. return '<div title="' + codeContent + '">' + cc + '</div>';
  126. } else {
  127. return '-';
  128. }
  129. }
  130. //查看项目详情
  131. function btn_details(edit_id) {
  132. layer.open({
  133. type: 2,
  134. maxmin: true,
  135. content: "template/StudyMaterialDeail.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
  136. title: '查看文件资料详情',
  137. area: ['80%', '90%'], //宽高
  138. });
  139. }
  140. //格式化操作
  141. function formatterOperate(val, row) {
  142. return '<ul class="tool_downs">' +
  143. '<li><a class="aBtn" authorize="yes" id="HY_details_' + row.id + '" onclick="btn_details(\'' + row.id + '\')">详情</a><li>' +
  144. '<li><a class="aBtn" authorize="yes" id="HY_edit_' + row.id + '" onclick="btn_edit(\'' + row.id + '\')">编辑</a><li>' +
  145. '<li><a class="aBtn" authorize="yes" id="HY_delete_' + row.id + '" onclick="btn_delete(\'' + row.id + '\')">删除</a><li>' +
  146. '</ul>';
  147. }
  148. //格式化 附件
  149. function formatterMaterfile(val, row) {
  150. if(row.studymaterfile && row.studymaterfile.length > 0) {
  151. var strjson = encodeURIComponent(JSON.stringify(row.studymaterfile));
  152. return '<ul class="tool_downs">' +
  153. '<li><a class="aBtn" authorize="yes" id="HY_download_' + row.id + '" onclick="btn_download(\'' + strjson + '\')" title="点击下载附件"><i class="glyphicon glyphicon-paperclip"></i></a><li>' +
  154. '</ul>';
  155. }
  156. }
  157. /**
  158. * 下载附件
  159. * sfiles 附件信息
  160. * */
  161. function btn_download(sfiles) {
  162. var index = layer.load();
  163. sfiles = JSON.parse(decodeURIComponent(sfiles));
  164. if(sfiles.length > 1) {
  165. var zip = new JSZip();
  166. $.each(sfiles, function(i, v) {
  167. zip.file(v.filename, urlToPromise(v.fileurl), {
  168. binary: true
  169. });
  170. });
  171. zip.generateAsync({
  172. type: "blob"
  173. }).then(function(content) {
  174. //console.log(content);
  175. // see FileSaver.js
  176. layer.close(index);
  177. saveAs(content, "文件资料.zip");
  178. }, function(err) {
  179. layer.close(index);
  180. layer.confirm(err, {
  181. btn: ['确定'] //按钮
  182. });
  183. return;
  184. });
  185. } else {
  186. //详细见文档 http://danml.com/download.html
  187. var x = new XMLHttpRequest();
  188. x.open("GET", sfiles[0].fileurl, true);
  189. x.responseType = 'blob';
  190. x.onload = function(e) {
  191. download(x.response, sfiles[0].filename);
  192. layer.close(index);
  193. }
  194. x.send();
  195. }
  196. }
  197. /**
  198. * Fetch the content and return the associated promise.
  199. * @param {String} url the url of the content to fetch.
  200. * @return {Promise} the promise containing the data.
  201. */
  202. function urlToPromise(url) {
  203. return new Promise(function(resolve, reject) {
  204. JSZipUtils.getBinaryContent(url, function(err, data) {
  205. if(err) {
  206. reject(err);
  207. } else {
  208. resolve(data);
  209. }
  210. });
  211. });
  212. }