NEZ-1788 feat:联调后端接口

This commit is contained in:
zhangyu
2022-05-24 15:04:46 +08:00
parent c7cd680bdf
commit f14d2a5bb8
5 changed files with 126 additions and 164 deletions

View File

@@ -19,7 +19,8 @@
<i class="nz-icon-create-square nz-icon"></i> <i class="nz-icon-create-square nz-icon"></i>
</button> </button>
<top-tool-more-options <top-tool-more-options
:delete-objs="batchDeleteObjs" ref="topTool"
:delete-objs="batchDeleteObjs"
id="asset-list" id="asset-list"
:params="filter" :params="filter"
:params-type="paramsType" :params-type="paramsType"
@@ -29,9 +30,10 @@
export-url="visual/panel/export" export-url="visual/panel/export"
import-url="visual/panel/import" import-url="visual/panel/import"
@afterImport="getTableData" @afterImport="getTableData"
:showCur="false"
:link="obj" :link="obj"
:showLock="from === fromRoute.asset" :showLock="from === fromRoute.asset"
:exportBoxShow="true"
@export="exportType"
@panelLockChange="panelLockChange" @panelLockChange="panelLockChange"
> >
<template v-slot:after> <template v-slot:after>
@@ -41,9 +43,6 @@
<el-dropdown-item v-has="'main_edit'"> <el-dropdown-item v-has="'main_edit'">
<div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div> <div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item v-has="'main_edit'">
<div id="chart-htmltopdf" @click="htmlToPdf"><i class="nz-icon nz-icon-export-pdf"></i>{{ $t('overall.downloadToPdf') }}</div>
</el-dropdown-item>
</template> </template>
</top-tool-more-options> </top-tool-more-options>
</div> </div>
@@ -53,12 +52,12 @@
<i class="nz-icon nz-icon-create-square"></i> <i class="nz-icon nz-icon-create-square"></i>
</button> </button>
<top-tool-more-options <top-tool-more-options
:delete-objs="batchDeleteObjs" ref="topTool"
:delete-objs="batchDeleteObjs"
id="asset-list" id="asset-list"
:link="obj" :link="obj"
:params="filter" :params="filter"
:permissions="{import: 'main_add', export: 'main_edit'}" :permissions="{import: 'main_add', export: 'main_edit'}"
:showCur="false"
:params-type="paramsType" :params-type="paramsType"
:showLock="from === fromRoute.endpoint" :showLock="from === fromRoute.endpoint"
class="top-tool-export margin-r-10" class="top-tool-export margin-r-10"
@@ -66,6 +65,8 @@
:export-url="'visual/panel/export'" :export-url="'visual/panel/export'"
:import-url="'visual/panel/import'" :import-url="'visual/panel/import'"
@afterImport="getTableData" @afterImport="getTableData"
:exportBoxShow="true"
@export="exportType"
@panelLockChange="panelLockChange" @panelLockChange="panelLockChange"
> >
<template v-slot:after> <template v-slot:after>
@@ -75,9 +76,6 @@
<el-dropdown-item v-has="'main_edit'"> <el-dropdown-item v-has="'main_edit'">
<div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div> <div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item v-has="'main_edit'">
<div id="chart-htmltopdf" @click="htmlToPdf"><i class="nz-icon nz-icon-export-pdf"></i>{{ $t('overall.downloadToPdf') }}</div>
</el-dropdown-item>
</template> </template>
</top-tool-more-options> </top-tool-more-options>
</div> </div>
@@ -153,9 +151,10 @@ import topToolMoreOptions from '@/components/common/popBox/topToolMoreOptions'
import detailViewRightMixin from '@/components/common/mixin/detailViewRightMixin' import detailViewRightMixin from '@/components/common/mixin/detailViewRightMixin'
import { randomcolor } from '@/components/common/js/radomcolor/randomcolor' import { randomcolor } from '@/components/common/js/radomcolor/randomcolor'
import htmlToPdfMixin from '@/components/common/mixin/htmlToPdfMixin' import htmlToPdfMixin from '@/components/common/mixin/htmlToPdfMixin'
import exportHtmlMixin from '@/components/common/mixin/exportHtml'
export default { export default {
name: 'panelTabNew', name: 'panelTabNew',
mixins: [subDataListMixin, detailViewRightMixin, htmlToPdfMixin], mixins: [subDataListMixin, detailViewRightMixin, htmlToPdfMixin, exportHtmlMixin],
props: { props: {
from: String, from: String,
obj: Object, obj: Object,
@@ -770,6 +769,14 @@ export default {
} else { } else {
this.showScreenLoading(false) this.showScreenLoading(false)
} }
this.$refs.topTool.closeDialog()
},
exportType (type) {
if (type === 'PDF') {
this.htmlToPdf()
} else {
this.exportToHtml(this.obj.name)
}
} }
}, },
mounted () { mounted () {

View File

@@ -1,6 +1,4 @@
import JSZip from 'jszip' import bus from '@/libs/bus'
import { saveAs } from 'file-saver'
import Vue from 'vue'
export default { export default {
data () { data () {
return { return {
@@ -8,84 +6,47 @@ export default {
} }
}, },
methods: { methods: {
exportHtml () { exportToHtml (name) {
// 创建一个JSZIP实例 const params = {
const zip = new JSZip() format: 'html',
// 在zip压缩包中创建一个文件夹用来放相关依赖 panelId: this.showPanel.id,
const panel = zip.folder('panel') start: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[0])),
const packages = panel.folder('packages') end: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[0]))
const fileArr = [] }
let filename = [] this.$get('/visual/panel/snapshot', params, 'blob').then(res => {
// 引入含有html字符串的js文件构造html文件 const self = this
this.returnHtml().then((modules) => { let fileName = name
panel.file('index.html', modules) const resFileName = ''
Vue.http.get('components/chart/panelTemp/jsData.json').then((res) => { if (resFileName) {
filename = res.body.data fileName = resFileName
for (const i in res.body.data) { }
fileArr.push(Vue.http.get(`components/chart/${res.body.data[i]}`)) if (res.type == 'application/json') {
const reader = new FileReader() // 创建一个FileReader实例
reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示
reader.onload = function () { // 读取完成后,**获取reader.result**
const { msg } = JSON.parse(reader.result)
self.$message.error(msg) // 弹出错误提示
} }
Promise.all(fileArr).then((contents) => { return
for (const i in contents) { }
packages.file(filename[i], contents[i].data) if (window.navigator.msSaveOrOpenBlob) {
} // 兼容ie11
// console.log(chartList) const blobObject = new Blob([res])
// packages.file('vue/chartList.vue', chartList) window.navigator.msSaveOrOpenBlob(blobObject, fileName + '.html')
zip.generateAsync({ } else {
type: 'blob' const blob = new Blob([res])
}).then((content) => { const link = document.createElement('a')
// 此处采用file-saver的saveAs方法和直接创建a标签下载的效果是一样的只是saveAs写起来更简便写 const href = window.URL.createObjectURL(blob) // 下载链接
saveAs(content, `${this.fileName}.zip`) link.href = href
}) link.download = fileName + '.html' // 下载后文件名
}) document.body.appendChild(link)
}) link.click() // 点击下载
}) document.body.removeChild(link) // 下载完成移除元素
}, window.URL.revokeObjectURL(href) // 释放blob对象
returnHtml (data) { }
data = [{ this.$refs.topTool.closeDialog()
id: 1 }, error => {
}] this.$message.error('123')
let str = ''
str += `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Panel</title>
</head>
<script src="./packages/panelTemp/js/vue.js"></script>
<script src="./packages/panelTemp/js/echarts.js"></script>
<script src="./packages/panelTemp/js/httpVueLoader.js"></script>
<body>
<div id="app">
<div>
<chartList
:data-list="dataList"
:isExportHtml="true"
></chartList>
</div>
{{message}}
</div>
</body>
<script type="text/javascript">
var app = new Vue({
el: '#app',
components:{
chartList: httpVueLoader('/packages/chartList.vue')
},
data: {
message: 'Hello Vue!',
dataList: ${JSON.stringify(data)}
},
mounted () {
// axios.get('./data.json').then(res=>{
// console.log(res)
// })
}
})
</script>
</html>
`
return new Promise(resolve => {
resolve(str)
}) })
} }
} }

View File

@@ -53,7 +53,7 @@
<div class="export-box"> <div class="export-box">
<span class="export-title">File format</span> <span class="export-title">File format</span>
<el-radio-group v-model="importBox.format" size="small"> <el-radio-group v-model="importBox.format" size="small">
<el-radio-button :label="item.value" v-for="(item,index) in formatArr" :key="index" :disabled="item.value!==1">{{item.name}}</el-radio-button> <el-radio-button :label="item.value" v-for="(item,index) in formatArr" :key="index">{{item.name}}</el-radio-button>
</el-radio-group> </el-radio-group>
</div> </div>
</div> </div>
@@ -153,7 +153,10 @@ export default {
type: String, type: String,
default: '' default: ''
}, },
deleteObjs: Array deleteObjs: Array,
exportBoxShow: {
type: Boolean, default: false
}
}, },
computed: { computed: {
language () { return this.$store.getters.getLanguage } language () { return this.$store.getters.getLanguage }
@@ -175,8 +178,8 @@ export default {
{ name: 'XLSX', value: 1 }, { name: 'XLSX', value: 1 },
{ name: 'CSV', value: 2 }, { name: 'CSV', value: 2 },
{ name: 'JSON', value: 3 } { name: 'JSON', value: 3 }
] ],
suffix: '.xlsx'
} }
}, },
mounted () { mounted () {
@@ -279,6 +282,7 @@ export default {
this.importFile = null this.importFile = null
this.importBox.value = 1 this.importBox.value = 1
this.importBox.record = 'all' this.importBox.record = 'all'
this.importBox.format = 1
}) })
}, 200) }, 200)
}, },
@@ -350,7 +354,7 @@ export default {
params.language = localStorage.getItem('nz-language') || 'en' params.language = localStorage.getItem('nz-language') || 'en'
params.format = this.importBox.format params.format = this.importBox.format
delete params.statistics delete params.statistics
this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + '.xlsx') this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + this.suffix)
this.closeDialog() this.closeDialog()
}, },
exportAll () { exportAll () {
@@ -384,7 +388,7 @@ export default {
params.language = localStorage.getItem('nz-language') || 'en' params.language = localStorage.getItem('nz-language') || 'en'
params.format = this.importBox.format params.format = this.importBox.format
delete params.statistics delete params.statistics
this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + '.xlsx') this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + this.suffix)
this.closeDialog() this.closeDialog()
}, },
exportRecords () { exportRecords () {
@@ -419,10 +423,25 @@ export default {
params.format = this.importBox.format params.format = this.importBox.format
params.ids = this.deleteObjs.map(item => item.id).join(',') params.ids = this.deleteObjs.map(item => item.id).join(',')
delete params.statistics delete params.statistics
this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + '.xlsx') this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + this.suffix)
this.closeDialog() this.closeDialog()
}, },
exportData () { exportData () {
if (this.importBox.format == 1) {
this.suffix = '.xlsx'
} else if (this.importBox.format == 2) {
this.suffix = '.csv'
} else if (this.importBox.format == 3) {
this.suffix = '.json'
} else if (this.importBox.format == 4) {
this.suffix = '.pdf'
this.$emit('export', 'PDF')
return
} else if (this.importBox.format == 5) {
this.suffix = '.html'
this.$emit('export', 'Html')
return
}
if (this.importBox.record === 'all') { if (this.importBox.record === 'all') {
this.exportAll() this.exportAll()
} else if (this.importBox.record === 'current') { } else if (this.importBox.record === 'current') {
@@ -481,7 +500,19 @@ export default {
this.importBox.width = '600px' this.importBox.width = '600px'
} else if (type == 2) { // export } else if (type == 2) { // export
this.importBox.title = this.$t('overall.exportExcel') this.importBox.title = this.$t('overall.exportExcel')
this.importBox.width = '580px' this.importBox.width = this.exportBoxShow ? '850px' : '580px'
if (this.exportBoxShow) {
this.formatArr = [
{ name: 'XLSX', value: 1 },
{ name: 'CSV', value: 2 },
{ name: 'JSON', value: 3 },
{ name: 'PDF', value: 4 },
{ name: 'Html', value: 5 }]
} else {
this.formatArr = [{ name: 'XLSX', value: 1 },
{ name: 'CSV', value: 2 },
{ name: 'JSON', value: 3 }]
}
} }
}, },
getTimeString () { getTimeString () {
@@ -497,6 +528,13 @@ export default {
}, },
formatNum (num) { formatNum (num) {
return num > 9 ? num : '0' + num return num > 9 ? num : '0' + num
},
exportHtml () {
this.$emit('export', this.exportHtmlType)
},
closeExportHtml () {
this.exportHtmlType = 'PDF'
this.$emit('closeExportBox')
} }
}, },
watch: { watch: {

View File

@@ -49,6 +49,7 @@
<top-tool-more-options <top-tool-more-options
:delete-objs="batchDeleteObjs" :delete-objs="batchDeleteObjs"
ref="topTool"
id="panel" id="panel"
:params="filter" :params="filter"
:permissions="{ :permissions="{
@@ -60,6 +61,8 @@
export-file-name="chart" export-file-name="chart"
export-url="/visual/panel/export" export-url="/visual/panel/export"
import-url="/visual/panel/import" import-url="/visual/panel/import"
:exportBoxShow="true"
@export="exportType"
@afterImport="afterImport" @afterImport="afterImport"
> >
<template v-slot:before> <template v-slot:before>
@@ -74,13 +77,6 @@
<el-dropdown-item v-has="'panel_view'"> <el-dropdown-item v-has="'panel_view'">
<div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div> <div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item v-has="'main_add'">
<div id="chart-htmltopdf" @click="htmlToPdf"><i class="nz-icon nz-icon-export-pdf"></i>{{ $t('overall.downloadToPdf') }}</div>
</el-dropdown-item>
<el-dropdown-item v-has="'main_add'">
<!-- <div id="chart-export-html" @click="exportHtml"><i class="nz-icon nz-icon-download1"></i>{{ $t('overall.downloadToPdf') }}</div>-->
<div id="chart-export-html" @click="exportData"><i class="nz-icon nz-icon-download1"></i>{{ $t('overall.downloadToPdf') }}</div>
</el-dropdown-item>
</template> </template>
</top-tool-more-options> </top-tool-more-options>
</div> </div>
@@ -274,7 +270,9 @@ export default {
scrollbarWrap: null, scrollbarWrap: null,
batchDeleteObjs: [], batchDeleteObjs: [],
nowTimeType: {}, nowTimeType: {},
showTopLine: false showTopLine: false,
// 导出html 以及 pdf的弹窗
exportBoxShow: false
} }
}, },
components: { components: {
@@ -865,60 +863,14 @@ export default {
} else { } else {
this.showScreenLoading(false) this.showScreenLoading(false)
} }
this.$refs.topTool.closeDialog()
}, },
exportData () { exportType (type) {
this.scrollbarWrap.scrollTop = this.scrollbarWrap.scrollHeight if (type === 'PDF') {
this.$refs.chartList.onScroll(this.scrollbarWrap.scrollTop) this.htmlToPdf()
let flag = true } else {
let timer = setInterval(() => { this.exportToHtml(this.showPanel.name)
flag = true }
this.$refs.chartList.copyDataList.forEach(chart => {
if (chart.type !== 'group') {
flag = flag && chart.loaded
} else if (chart.collapse) {
chart.children.forEach(groupChart => {
flag = flag && groupChart.loaded
})
}
})
if (flag) {
clearInterval(timer)
timer = null
setTimeout(() => {
this.dataList.forEach(item => {
if (item.type === 'group') {
item.chartData = [item.children]
item.loaded = false
}
if (item.type === 'group' && !item.param.collapse) {
item.children.forEach(child => {
child.chartData = this.$refs.chartList.$refs['chart' + item.id][0].$refs.chart.$refs['chart' + item.id].$refs.chartList.$refs['chart' + child.id][0].chartData
item.loaded = false
})
} else {
item.chartData = this.$refs.chartList.$refs['chart' + item.id][0].chartData
item.loaded = false
}
})
const data = JSON.stringify(this.dataList)
const blob = new Blob([data], { type: '' })
FileSaver.saveAs(blob, 'ceshi.json')
// const a = document.createElement('a')
// const url = window.URL.createObjectURL(
// new Blob([this.gethtml()], {
// type: ''
// })
// )
// a.href = url
// a.download = 'file.html'
// a.click()
// window.URL.revokeObjectURL(url)
}, 2000)
}
}, 200)
},
gethtml () {
} }
}, },
created () { created () {

View File

@@ -72,11 +72,15 @@ axios.interceptors.response.use(
return Promise.reject(error) return Promise.reject(error)
} }
) )
export function get (url, params) { export function get (url, params, responseType) {
const config = {
params: params
}
if (responseType) {
config.responseType = responseType
}
return new Promise((resolve) => { return new Promise((resolve) => {
axios.get(url, { axios.get(url, config).then(response => {
params: params
}).then(response => {
if (url.indexOf('/sys/license/token') !== -1) { if (url.indexOf('/sys/license/token') !== -1) {
resolve({ resolve({
data: response.data, data: response.data,