Commit ff485e77 by yuwei

Feature: 看板中图表加入定时器,实现实时数据展示

Update: axios请求动态控制加载loading层
Bugfix: 修复一些小问题
parent 723226d3
...@@ -11,6 +11,8 @@ public class BoardConfig implements Serializable { ...@@ -11,6 +11,8 @@ public class BoardConfig implements Serializable {
private static final long serialVersionUID=1L; private static final long serialVersionUID=1L;
@NotEmpty(message = "指标不能为空") @NotEmpty(message = "布局不能为空")
private List<BoardItem> layout; private List<BoardItem> layout;
private List<BoardTimer> interval;
} }
package cn.datax.service.data.visual.api.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class BoardTimer implements Serializable {
private static final long serialVersionUID=1L;
private String id;
private Integer milliseconds;
}
...@@ -64,6 +64,9 @@ export function buildDataChart(data) { ...@@ -64,6 +64,9 @@ export function buildDataChart(data) {
export function dataParser(data) { export function dataParser(data) {
return request({ return request({
url: '/data/visual/charts/data/parser', url: '/data/visual/charts/data/parser',
headers: {
'showLoading': false
},
method: 'post', method: 'post',
data: data data: data
}) })
......
...@@ -18,16 +18,20 @@ service.interceptors.request.use( ...@@ -18,16 +18,20 @@ service.interceptors.request.use(
if (hasToken) { if (hasToken) {
config.headers['Authorization'] = 'Bearer ' + hasToken config.headers['Authorization'] = 'Bearer ' + hasToken
} }
loadingInstance = Loading.service({ if (config.headers.showLoading !== false) {
lock: true, loadingInstance = Loading.service({
text: '数据加载中,请稍后...', lock: true,
spinner: 'el-icon-loading', text: '数据加载中,请稍后...',
background: 'rgba(0, 0, 0, 0.7)' spinner: 'el-icon-loading',
}) background: 'rgba(0, 0, 0, 0.7)'
})
}
return config return config
}, },
error => { error => {
loadingInstance.close() if (error.config.headers.showLoading !== false) {
loadingInstance.close()
}
Message.error('请求错误') Message.error('请求错误')
console.log(error) console.log(error)
return Promise.reject(error) return Promise.reject(error)
...@@ -37,7 +41,9 @@ service.interceptors.request.use( ...@@ -37,7 +41,9 @@ service.interceptors.request.use(
// response interceptor // response interceptor
service.interceptors.response.use( service.interceptors.response.use(
response => { response => {
loadingInstance.close() if (response.config.headers.showLoading !== false) {
loadingInstance.close()
}
const code = response.data.code || 200 const code = response.data.code || 200
if (code === 500) { if (code === 500) {
Message.error(response.data.msg || '系统错误') Message.error(response.data.msg || '系统错误')
...@@ -47,7 +53,9 @@ service.interceptors.response.use( ...@@ -47,7 +53,9 @@ service.interceptors.response.use(
} }
}, },
error => { error => {
loadingInstance.close() if (error.config.headers.showLoading !== false) {
loadingInstance.close()
}
console.log(error.response) console.log(error.response)
if (error.response.status) { if (error.response.status) {
switch (error.response.status) { switch (error.response.status) {
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
</div> </div>
<div> <div>
<i class="el-icon-delete" @click="handleDeleteChart(item.i)" /> <i class="el-icon-delete" @click="handleDeleteChart(item.i)" />
<i class="el-icon-setting" @click="handleTimerChart(item.i)" />
</div> </div>
</div> </div>
<chart-panel v-if="getChartItem(item.i).visible" :key="item.i" :ref="`charts${item.i}`" :chart-schema="getChartItem(item.i).chartSchema" :chart-data="getChartItem(item.i).data" :chart-style="{height: `${item.h * 30 + 10 * (item.h - 1) - 60}px`}" /> <chart-panel v-if="getChartItem(item.i).visible" :key="item.i" :ref="`charts${item.i}`" :chart-schema="getChartItem(item.i).chartSchema" :chart-data="getChartItem(item.i).data" :chart-style="{height: `${item.h * 30 + 10 * (item.h - 1) - 60}px`}" />
...@@ -114,6 +115,7 @@ export default { ...@@ -114,6 +115,7 @@ export default {
dataBoard: {}, dataBoard: {},
dataChartList: [], dataChartList: [],
layout: [], layout: [],
interval: [],
charts: [], charts: [],
drawer: false drawer: false
} }
...@@ -189,6 +191,24 @@ export default { ...@@ -189,6 +191,24 @@ export default {
this.charts.splice(this.charts.findIndex(item => item.id === id), 1) this.charts.splice(this.charts.findIndex(item => item.id === id), 1)
this.$set(this.dataChartList.find(item => item.id === id), 'disabled', false) this.$set(this.dataChartList.find(item => item.id === id), 'disabled', false)
}, },
handleTimerChart(id) {
this.$prompt('请输入定时时间间隔,输入0不定时(单位毫秒,1000 毫秒 = 1 秒)', '提示', {
showClose: false,
closeOnClickModal: false,
confirmButtonText: '确定',
cancelButtonText: '取消',
inputPattern: /^(0|\+?[1-9][0-9]*)$/,
inputErrorMessage: '格式不正确',
inputValue: '5000'
}).then(({ value }) => {
const timer = this.interval.find(item => item.id === id)
if (timer) {
this.$set(timer, 'milliseconds', value)
} else {
this.interval.push({ id: id, milliseconds: value })
}
}).catch(() => {})
},
handlePreview() { handlePreview() {
const route = this.$router.resolve({ path: `/visual/board/view/${this.dataBoard.id}` }) const route = this.$router.resolve({ path: `/visual/board/view/${this.dataBoard.id}` })
window.open(route.href, '_blank') window.open(route.href, '_blank')
...@@ -213,7 +233,8 @@ export default { ...@@ -213,7 +233,8 @@ export default {
id: this.dataBoard.id, id: this.dataBoard.id,
boardThumbnail: this.dataBoard.boardThumbnail, boardThumbnail: this.dataBoard.boardThumbnail,
boardConfig: { boardConfig: {
layout: this.layout layout: this.layout,
interval: this.interval
} }
} }
buildDataBoard(data).then(response => { buildDataBoard(data).then(response => {
...@@ -227,7 +248,6 @@ export default { ...@@ -227,7 +248,6 @@ export default {
window.close() window.close()
}, },
handleResize(i, newH, newW, newHPx, newWPx) { handleResize(i, newH, newW, newHPx, newWPx) {
console.log('handleResize', i)
if (this.charts.find(chart => chart.id === i).visible) { if (this.charts.find(chart => chart.id === i).visible) {
this.$refs[`charts${i}`][0].$children[0].$emit('resized') this.$refs[`charts${i}`][0].$children[0].$emit('resized')
} }
......
...@@ -57,7 +57,9 @@ export default { ...@@ -57,7 +57,9 @@ export default {
return { return {
dataBoard: {}, dataBoard: {},
layout: [], layout: [],
charts: [] interval: [],
charts: [],
timers: []
} }
}, },
created() { created() {
...@@ -69,11 +71,15 @@ export default { ...@@ -69,11 +71,15 @@ export default {
if (response.success) { if (response.success) {
this.dataBoard = response.data this.dataBoard = response.data
this.layout = this.dataBoard.boardConfig ? JSON.parse(JSON.stringify(this.dataBoard.boardConfig.layout)) : [] this.layout = this.dataBoard.boardConfig ? JSON.parse(JSON.stringify(this.dataBoard.boardConfig.layout)) : []
this.interval = this.dataBoard.boardConfig ? JSON.parse(JSON.stringify(this.dataBoard.boardConfig.interval)) : []
const charts = this.dataBoard.charts ? JSON.parse(JSON.stringify(this.dataBoard.charts)) : [] const charts = this.dataBoard.charts ? JSON.parse(JSON.stringify(this.dataBoard.charts)) : []
charts.forEach((item, index, arr) => { charts.forEach((item, index, arr) => {
this.parserChart(item) this.parserChart(item)
}) })
this.charts = charts this.charts = charts
this.$nextTick(() => {
this.initTimer()
})
} }
}) })
}, },
...@@ -94,7 +100,29 @@ export default { ...@@ -94,7 +100,29 @@ export default {
}, },
getChartItem(id) { getChartItem(id) {
return this.charts.find(chart => chart.id === id) return this.charts.find(chart => chart.id === id)
},
initTimer() {
this.interval.forEach((item, index) => {
if (item.milliseconds && item.milliseconds > 0) {
const timer = setInterval(() => {
const chart = this.charts.find(chart => chart.id === item.id)
if (chart.chartConfig) {
dataParser(JSON.parse(chart.chartConfig)).then(response => {
if (response.success) {
this.$set(chart, 'data', response.data.data)
}
})
}
}, item.milliseconds)
this.timers.push(timer)
}
})
} }
},
beforeDestroy() {
this.timers.map((item) => {
clearInterval(item)
})
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment