导出fun
/* 一、*/ exportFun() { let params = {}; let query = ''; this.formData.items.forEach(item = >{ params[item.field] = item.value; }); params.perfMonthFrom = params.perfMonthFrom ? formatDateTime(new Date(params.perfMonthFrom), 'yyyyMM') : ''; // 转换格式 params.perfMonthTo = params.perfMonthTo ? formatDateTime(new Date(params.perfMonthTo), 'yyyyMM') : ''; // 转换格式 for (let index in params) { query += index + '=' + params[index] + '&'; // 拼接 } let query2 = query.substr(0, query.length - 1); // 去掉最后那个“¥” const url = ` / adfda ? $ { query2 }`; window.open(url); }
/* 二、*/
var a = document.createElement('a'); let params = { params1: '', params2: '', params3: '' }; a.href = '/DataWzc?paraJson=' + encodeURI(JSON.stringify(params)); a.style.display = 'none'; document.body.appendChild(a); a.click(); a.remove();
/* 三、 */ let params = { params1: '', params2: '' }; let url = '/DataUrl?json=' + encodeURI(JSON.stringify(params)); axios.get(url).then(res = >{ try { console.log(res); console.log(res.data === 'success'); if (res.data === 'success') { // this.$Message.success(导出成功); this.$Modal.success({ content: '导出成功' }); this.$router.push('/sys/taskList'); } else { this.$Modal.error({ title: '提示', content: '提示信息' }); } } catch(error) { console.log(error); } }). catch(() = >{ this.$Modal.error({ title: '提示', content: '提示信息' }); });
/** 四、 */
handleExport() { const promise = new Promise(function(resolve, reject) { axios.get(url).then(resp = >{ if (resp.data.success) { resolve(resp.data.xx); } else { reject(new Error(error.msg)); } }); }); promise.then((xx) = >{ var str = this.parseParam({ params1, params2 }); var a = document.createElement('a'); a.href = '/dataUrl?' + str; a.download = '标题.xls'; a.style.display = 'none'; document.body.appendChild(a); a.click(); a.remove(); }); },