123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import axios from 'axios'
- import {Message} from 'element-ui'
- import {saveAs} from 'file-saver'
- import {getToken} from '@/utils/auth'
- import errorCode from '@/utils/errorCode'
- import {blobValidate} from "@/utils/elf";
- import Cookies from "js-cookie";
- const baseURL = process.env.VUE_APP_BASE_API
- export default {
- windTowerStatus(urls, startTime, endTime, equipmentId) {
- var url = baseURL + urls + "?startTime=" + encodeURI(startTime) + "&endTime=" + encodeURI(endTime) + "&equipmentId=" + encodeURI(equipmentId);
- axios({
- method: 'get',
- url: url,
- responseType: 'blob',
- headers: {'Authorization': 'Bearer ' + getToken()}
- }).then(async (res) => {
- const isLogin = await blobValidate(res.data);
- if (isLogin) {
- const blob = new Blob([res.data])
- this.saveAs(blob, decodeURI(res.headers['content-disposition'].split('=')[1]))
- } else {
- this.printErrMsg(res.data);
- }
- })
- Cookies.set("exportDataLoading", true, {expires: 60});
- },
- exportAllData(urls, eqId) {
- var url = baseURL + urls + "?equipmentId=" + encodeURI(eqId);
- axios({
- method: 'get',
- url: url,
- responseType: 'blob',
- headers: {'Authorization': 'Bearer ' + getToken()}
- }).then(async (res) => {
- const isLogin = await blobValidate(res.data);
- if (isLogin) {
- const blob = new Blob([res.data])
- this.saveAs(blob, decodeURI(res.headers['content-disposition'].split('=')[1]))
- } else {
- this.printErrMsg(res.data);
- }
- Cookies.set("exportLoading", true, {expires: 60});
- })
- },
- name(urls, path, name, type) {
- var url = baseURL + urls + "?path=" + encodeURI(path) + "&name=" + encodeURI(name) + "&type=" + encodeURI(type);
- axios({
- method: 'get',
- url: url,
- responseType: 'blob',
- headers: {'Authorization': 'Bearer ' + getToken()}
- }).then(async (res) => {
- const isLogin = await blobValidate(res.data);
- if (isLogin) {
- const blob = new Blob([res.data])
- this.saveAs(blob, decodeURI(res.headers['content-disposition'].split('=')[1]))
- } else {
- this.printErrMsg(res.data);
- }
- })
- },
- resource(resource) {
- var url = baseURL + "/common/download/resource?resource=" + encodeURI(resource);
- axios({
- method: 'get',
- url: url,
- responseType: 'blob',
- headers: {'Authorization': 'Bearer ' + getToken()}
- }).then(async (res) => {
- const isLogin = await blobValidate(res.data);
- if (isLogin) {
- const blob = new Blob([res.data])
- this.saveAs(blob, decodeURI(res.headers['download-filename']))
- } else {
- this.printErrMsg(res.data);
- }
- })
- },
- zip(url, name) {
- var url = baseURL + url
- axios({
- method: 'get',
- url: url,
- responseType: 'blob',
- headers: {'Authorization': 'Bearer ' + getToken()}
- }).then(async (res) => {
- const isLogin = await blobValidate(res.data);
- if (isLogin) {
- const blob = new Blob([res.data], {type: 'application/zip'})
- this.saveAs(blob, name)
- } else {
- this.printErrMsg(res.data);
- }
- })
- },
- saveAs(text, name, opts) {
- saveAs(text, name, opts);
- },
- async printErrMsg(data) {
- const resText = await data.text();
- const rspObj = JSON.parse(resText);
- const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
- Message.error(errMsg);
- }
- }
|