| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- /**
- * 文件资料
- * */
- var Promise = window.Promise;
- if(!Promise) {
- //IE 兼容
- Promise = JSZip.external.Promise;
- }
- $(function() {
- $('.tool_bars').authorizeButton();
- helper.getDropList.getProlistDrop($('#sc_pro'), '所有项目'); //项目下拉
- laydate.render({
- elem: '#sc_times',
- range: '~',
- theme: '#249fea',
- });
- initTable();
- //搜索
- $("#sc_btns").click(function() {
- initTable();
- })
- });
- function initTable() {
- //先销毁表格
- $('#table_all').bootstrapTable('destroy');
- //初始化表格,动态从服务器加载数据
- $('#table_all').bootstrapTable({
- method: "get", //使用get请求到服务器获取数据
- url: huayi.config.callcenter_url + "equipmentapi/api/StudyMaterialsInfo/getlistsbypage", //获取数据的Servlet地址
- contentType: "application/x-www-form-urlencoded",
- striped: true, //表格显示条纹
- pagination: true, //启动分页
- pageSize: 10, //每页显示的记录数
- pageNumber: 1, //当前第几页
- pageList: [10, 20, 50, 100], //记录数可选列表
- search: false, //是否启用查询
- showColumns: false, //显示下拉框勾选要显示的列
- showRefresh: false, //显示刷新按钮
- sidePagination: "server", //表示服务端请求
- //设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
- //设置为limit可以获取limit, offset, search, sort, order
- queryParamsType: "undefined",
- queryParams: function queryParams(params) { //设置查询参数
- var param = {
- pageindex: params.pageNumber,
- pagesize: params.pageSize,
- projectid: $('#sc_pro').val(),// 否 string 项目id
- // apptype: $('#sc_category').val(),// 否 int 应用分类(0android 1ios)
- keyword: $('#sc_keyWords').val(), // 否 string 模糊查询(版本名称,版本号)
- stime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[0],
- etime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[1],
- };
- return param;
- },
- responseHandler: function(res) {
- //格式化数据
- return {
- "total": res.data.total, //总页数
- "rows": res.data.rows, //数据
- };
- },
- onLoadSuccess: function(res) { //加载成功时执行
- //layer.msg("加载成功");
- $('.tool_downs').authorizeOperateButton();
- },
- onLoadError: function() { //加载失败时执行
- //layer.msg("加载数据失败", { time: 1500, icon: 2 });
- }
- });
- }
- //添加
- function btn_add() {
- layer.open({
- type: 2,
- maxmin: true,
- content: "template/addOrEditStudyMaterial.html", //iframe的url,no代表不显示滚动条
- title: '添加文件资料',
- area: ['80%', '90%'], //宽高
- });
- }
- //删除
- function btn_delete(del_id) {
- /*发送请求*/
- layer.confirm('您确定要删除当前资料吗?', {
- icon: 7,
- btn: ['确定', '取消'],
- yes: function(index, layero) {
- $.ajax({
- type: "post",
- url: huayi.config.callcenter_url + "equipmentapi/api/StudyMaterialsInfo/delete",
- dataType: 'json',
- async: true,
- data: {
- ids: del_id
- },
- success: function(data) {
- /*验证请求*/
- if(data.state == "success") {
- layer.msg("删除成功");
- $('#table_all').bootstrapTable('refresh');
- } else {
- layer.msg(data.message);
- }
- }
- })
- },
- });
- }
- //编辑
- function btn_edit(edit_id) {
- layer.open({
- type: 2,
- maxmin: true,
- content: "template/addOrEditStudyMaterial.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
- title: '编辑文件资料',
- area: ['80%', '90%'], //宽高
- });
- }
- function content(val, row) {
- if(val) {
- var codeContent = decodeURIComponent(val);
- codeContent = helper.filter.delHtmlTag(codeContent);
- codeContent = $.trim(codeContent);
- var cc = codeContent.length > 50 ? codeContent.substr(0, 50) + '...' : codeContent;
- return '<div title="' + codeContent + '">' + cc + '</div>';
- } else {
- return '-';
- }
- }
- //查看项目详情
- function btn_details(edit_id) {
- layer.open({
- type: 2,
- maxmin: true,
- content: "template/StudyMaterialDeail.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
- title: '查看文件资料详情',
- area: ['80%', '90%'], //宽高
- });
- }
- //格式化操作
- function formatterOperate(val, row) {
- return '<ul class="tool_downs">' +
- '<li><a class="aBtn" authorize="yes" id="HY_details_' + row.id + '" onclick="btn_details(\'' + row.id + '\')">详情</a><li>' +
- '<li><a class="aBtn" authorize="yes" id="HY_edit_' + row.id + '" onclick="btn_edit(\'' + row.id + '\')">编辑</a><li>' +
- '<li><a class="aBtn" authorize="yes" id="HY_delete_' + row.id + '" onclick="btn_delete(\'' + row.id + '\')">删除</a><li>' +
- '</ul>';
- }
- //格式化 附件
- function formatterMaterfile(val, row) {
- if(row.studymaterfile && row.studymaterfile.length > 0) {
- var strjson = encodeURIComponent(JSON.stringify(row.studymaterfile));
- return '<ul class="tool_downs">' +
- '<li><a class="aBtn" authorize="yes" id="HY_download_' + row.id + '" onclick="btn_download(\'' + strjson + '\')" title="点击下载附件"><i class="glyphicon glyphicon-paperclip"></i></a><li>' +
- '</ul>';
- }
- }
- /**
- * 下载附件
- * sfiles 附件信息
- * */
- function btn_download(sfiles) {
- var index = layer.load();
- sfiles = JSON.parse(decodeURIComponent(sfiles));
- if(sfiles.length > 1) {
- var zip = new JSZip();
- $.each(sfiles, function(i, v) {
- zip.file(v.filename, urlToPromise(v.fileurl), {
- binary: true
- });
- });
- zip.generateAsync({
- type: "blob"
- }).then(function(content) {
- //console.log(content);
- // see FileSaver.js
- layer.close(index);
- saveAs(content, "文件资料.zip");
- }, function(err) {
- layer.close(index);
- layer.confirm(err, {
- btn: ['确定'] //按钮
- });
- return;
- });
- } else {
- //详细见文档 http://danml.com/download.html
- var x = new XMLHttpRequest();
- x.open("GET", sfiles[0].fileurl, true);
- x.responseType = 'blob';
- x.onload = function(e) {
- download(x.response, sfiles[0].filename);
- layer.close(index);
- }
- x.send();
- }
- }
- /**
- * Fetch the content and return the associated promise.
- * @param {String} url the url of the content to fetch.
- * @return {Promise} the promise containing the data.
- */
- function urlToPromise(url) {
- return new Promise(function(resolve, reject) {
- JSZipUtils.getBinaryContent(url, function(err, data) {
- if(err) {
- reject(err);
- } else {
- resolve(data);
- }
- });
- });
- }
|