Nessuna descrizione

StudyMaterial.js 6.1KB

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