Commit 37973c96 authored by leon's avatar leon

feat: use request repleace eval

parent 1dc9a745
...@@ -40,6 +40,9 @@ const install = (Vue, vm) => { ...@@ -40,6 +40,9 @@ const install = (Vue, vm) => {
// 获取OPENID // 获取OPENID
const getOpenId = params => getHttp(`${baseUrl}/report/user/getOpenId`, params) const getOpenId = params => getHttp(`${baseUrl}/report/user/getOpenId`, params)
// 脚本转换
const jsScript = params => postHttp(`${reportUrl}/report/js/script`, params)
vm.$u.api = { vm.$u.api = {
getHttp, getHttp,
postHttp, postHttp,
...@@ -54,7 +57,8 @@ const install = (Vue, vm) => { ...@@ -54,7 +57,8 @@ const install = (Vue, vm) => {
changePassword, changePassword,
getAuthorizedList, getAuthorizedList,
authorizeOrUnauthorize, authorizeOrUnauthorize,
getOpenId getOpenId,
jsScript
} }
} }
......
...@@ -82,9 +82,9 @@ ...@@ -82,9 +82,9 @@
...this.elementInfo.option.bar, ...this.elementInfo.option.bar,
label: { label: {
...this.elementInfo.option.dataset, ...this.elementInfo.option.dataset,
formatter: (val) => { // formatter: (val) => {
return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, val) // return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, val)
} // }
}, },
animationDurationUpdate: 1000, animationDurationUpdate: 1000,
universalTransition: true, universalTransition: true,
...@@ -132,12 +132,21 @@ ...@@ -132,12 +132,21 @@
tooltip: { tooltip: {
show: this.elementInfo.option.dataset.show, show: this.elementInfo.option.dataset.show,
trigger: 'item', trigger: 'item',
formatter: (value) => { formatter: (val, ticket, callback) => {
if(!value.data) { if(!value.data) {
return "" return ""
} }
if(this.elementInfo.option.dataset.formatter) { if(this.elementInfo.option.dataset.formatter) {
return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, value) const params = {
script: tooltip.formatter,
data: JSON.stringify(val)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
return callback(ticket, Result)
}
})
} else { } else {
return `${value.data.name}:${value.data.value[2]}` return `${value.data.name}:${value.data.value[2]}`
} }
...@@ -166,6 +175,7 @@ ...@@ -166,6 +175,7 @@
show: this.elementInfo.option.dataset.show, show: this.elementInfo.option.dataset.show,
position: 'inside', position: 'inside',
formatter: (value) => { formatter: (value) => {
return this.elementInfo.option.dataset.show ? value.data.name : ""
if(this.elementInfo.option.dataset.formatter) { if(this.elementInfo.option.dataset.formatter) {
return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, value) return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, value)
} else { } else {
......
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
show: true, show: true,
position: 'right', position: 'right',
formatter: value => { formatter: value => {
return this.elementInfo.option.dataset.show ? `${value.data.name}:${value.data.value[2]}` : value.data.name
if(this.elementInfo.option.dataset.formatter) { if(this.elementInfo.option.dataset.formatter) {
return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, value) return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, value)
} else { } else {
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
option: {} option: {}
}, },
labelShow: false, // 记录当前设置的label.show的值 labelShow: false, // 记录当前设置的label.show的值
index: 0, // 记录dataZoom切换当前的下标 index: 0, // 记录dataZoom切换当前的下标
formatter: {}, // 记录formatter之后的对象
} }
}, },
components: { components: {
...@@ -72,14 +73,16 @@ ...@@ -72,14 +73,16 @@
images images
} = that.elementData.dataList } = that.elementData.dataList
var urls = [] var urls = []
var caches = uni.getStorageSync('cacheImages') var caches = uni.getStorageSync('cacheImages')
images.forEach(url => { if(images && image.length) {
if (caches.hasOwnProperty(url)) { images.forEach(url => {
urls.push(caches[url]) if (caches.hasOwnProperty(url)) {
} else { urls.push(caches[url])
urls.push(url) } else {
} urls.push(url)
}) }
})
}
// 特殊处理,如果preview为true,代表点击显示图片 // 特殊处理,如果preview为true,代表点击显示图片
if (preview) { if (preview) {
uni.previewImage({ uni.previewImage({
...@@ -118,7 +121,7 @@ ...@@ -118,7 +121,7 @@
} }
lastCount = count lastCount = count
} }
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'yAxis.show', true) this.$set(this.ec.option, 'yAxis.show', true)
this.$set(this.ec.option, 'yAxis.data', categories) this.$set(this.ec.option, 'yAxis.data', categories)
...@@ -148,7 +151,72 @@ ...@@ -148,7 +151,72 @@
this.cacheImages(images) this.cacheImages(images)
} }
}) })
}, },
// 获取label的formatter信息
async getLabelFormatter(series) {
const formatter = this.elementInfo.option.dataset.formatter
if(!formatter || !formatter.length) {
return
}
console.log(this.elementInfo.dataZoom)
var arr = [] // 当前显示的label,formatter需要阻塞线程
var all = [] // 除当前显示label之外的值,formatter可以在异步线程请求处理
const count = this.elementData.dataList.categories.length
var start = parseInt(this.elementInfo.dataZoom.start / 100 * count)
start = start > 1 ? start - 1 : start
const end = parseInt(this.elementInfo.dataZoom.end / 100 * count)
series.forEach(item => {
const data = item.data
const name = item.name
for (var i = 0; i < data.length; i++) {
if(i >= start && i <= end - 1) {
arr.push({seriesName: name, value:data[i]})
} else {
all.push({seriesName: name, value:data[i]})
}
}
})
// 把所有的请求加入req数组中
var req = []
arr.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
const params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
req.push(this.$u.api.jsScript(params))
}
})
// req的线程需要同步执行
await Promise.all(req).then(res => {
res.forEach(item => {
const {Status, Result} = item.data
if(Status === 'true') {
const data = item.config.data.data
const key = JSON.parse(data).value
this.formatter[key] = Result
}
})
})
// all的线程可以异步处理
all.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
let params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
this.formatter[item.value] = Result
}
})
}
})
},
/** /**
* *
* @param tooltip 表单的tooltip设置 * @param tooltip 表单的tooltip设置
...@@ -160,8 +228,20 @@ ...@@ -160,8 +228,20 @@
if (tooltip.formatter && tooltip.formatter.length) { if (tooltip.formatter && tooltip.formatter.length) {
return { return {
...tooltip, ...tooltip,
formatter: (val) => { formatter: (val ,ticket, callback) => {
return this.$u.common.converFunction(tooltip.formatter, val) const params = {
script: tooltip.formatter,
data: JSON.stringify(val)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
return callback(ticket, Result)
}
})
return "加载中......"
// return this.$u.common.converFunction(tooltip.formatter, val)
}, },
trigger: "axis" trigger: "axis"
} }
...@@ -183,9 +263,14 @@ ...@@ -183,9 +263,14 @@
...that.elementInfo.option.bar, ...that.elementInfo.option.bar,
label: { label: {
...that.elementInfo.option.dataset, ...that.elementInfo.option.dataset,
formatter: val => { formatter: val => {
return that.$u.common.converFunction(that.elementInfo.option.dataset if(this.formatter.hasOwnProperty(val.value)) {
.formatter, val) return this.formatter[val.value]
}
return val.value
// return that.$u.common.converFunction(that.elementInfo.option.dataset
// .formatter, val)
} }
} }
} }
...@@ -285,6 +370,7 @@ ...@@ -285,6 +370,7 @@
setChartDatas(event) { setChartDatas(event) {
const categories = this.elementData.dataList.datas[this.index].categories const categories = this.elementData.dataList.datas[this.index].categories
const series = this.elementData.dataList.datas[this.index].series const series = this.elementData.dataList.datas[this.index].series
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'yAxis.data', categories) this.$set(this.ec.option, 'yAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
}, },
labelShow: false, // 记录当前设置的label.show的值 labelShow: false, // 记录当前设置的label.show的值
index: 0, // 记录dataZoom切换当前的下标 index: 0, // 记录dataZoom切换当前的下标
formatter: {}, // 记录formatter之后的对象
} }
}, },
components: { components: {
...@@ -110,7 +111,8 @@ ...@@ -110,7 +111,8 @@
} }
lastCount = count lastCount = count
} }
const dealSeries = this.dealSeriesData(series) this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
this.$set(this.ec.option, 'dataZoom', this.elementInfo.dataZoom && this.elementInfo.dataZoom.show ? [{...this.elementInfo.dataZoom,...DATAZOOM_DEFAULT}] : [{show: false}]) this.$set(this.ec.option, 'dataZoom', this.elementInfo.dataZoom && this.elementInfo.dataZoom.show ? [{...this.elementInfo.dataZoom,...DATAZOOM_DEFAULT}] : [{show: false}])
...@@ -121,7 +123,73 @@ ...@@ -121,7 +123,73 @@
chart.setOption(option) chart.setOption(option)
} }
}) })
}, },
// 获取label的formatter信息
async getLabelFormatter(series) {
const formatter = this.elementInfo.option.dataset.formatter
if(!formatter || !formatter.length) {
return
}
var arr = [] // 当前显示的label,formatter需要阻塞线程
var all = [] // 除当前显示label之外的值,formatter可以在异步线程请求处理
const count = this.elementData.dataList.categories.length
var start = parseInt(this.elementInfo.dataZoom.start / 100 * count)
start = start > 1 ? start - 1 : start
const end = parseInt(this.elementInfo.dataZoom.end / 100 * count)
series.forEach(item => {
const data = item.data
const name = item.name
for (var i = 0; i < data.length; i++) {
if(i >= start && i <= end - 1) {
arr.push({seriesName: name, value:data[i]})
} else {
all.push({seriesName: name, value:data[i]})
}
}
})
// 把所有的请求加入req数组中
var req = []
arr.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
const params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
req.push(this.$u.api.jsScript(params))
}
})
// req的线程需要同步执行
await Promise.all(req).then(res => {
res.forEach(item => {
const {Status, Result} = item.data
if(Status === 'true') {
const data = item.config.data.data
const key = JSON.parse(data).value
this.formatter[key] = Result
}
})
})
console.log(all)
// all的线程可以异步处理
all.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
let params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
this.formatter[item.value] = Result
}
})
}
})
console.log(this.formatter)
},
/** /**
* *
* @param tooltip 表单的tooltip设置 * @param tooltip 表单的tooltip设置
...@@ -133,8 +201,21 @@ ...@@ -133,8 +201,21 @@
if (tooltip.formatter && tooltip.formatter.length) { if (tooltip.formatter && tooltip.formatter.length) {
return { return {
...tooltip, ...tooltip,
formatter: (val) => { formatter: (val, ticket, callback) => {
return this.$u.common.converFunction(tooltip.formatter, val) console.log(val)
const params = {
script: tooltip.formatter,
data: JSON.stringify(val)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
return callback(ticket, Result)
}
})
return "加载中......"
// return this.$u.common.converFunction(tooltip.formatter, val)
}, },
trigger: "axis" trigger: "axis"
} }
...@@ -154,8 +235,13 @@ ...@@ -154,8 +235,13 @@
let config = { let config = {
label: { label: {
...that.elementInfo.option.dataset, ...that.elementInfo.option.dataset,
formatter: val => { formatter: val => {
return that.$u.common.converFunction(that.elementInfo.option.dataset.formatter, val) if(this.formatter.hasOwnProperty(val.value)) {
return this.formatter[val.value]
}
return val.value
// return that.$u.common.converFunction(that.elementInfo.option.dataset.formatter, val)
} }
} }
} }
...@@ -244,6 +330,7 @@ ...@@ -244,6 +330,7 @@
setChartDatas() { setChartDatas() {
const categories = this.elementData.dataList.datas[this.index].categories const categories = this.elementData.dataList.datas[this.index].categories
const series = this.elementData.dataList.datas[this.index].series const series = this.elementData.dataList.datas[this.index].series
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
}, },
labelShow: false, // 记录当前设置的label.show的值 labelShow: false, // 记录当前设置的label.show的值
index: 0, // 记录dataZoom切换当前的下标 index: 0, // 记录dataZoom切换当前的下标
formatter: {}, // 记录formatter之后的对象
} }
}, },
components: { components: {
...@@ -96,6 +97,7 @@ ...@@ -96,6 +97,7 @@
} }
lastCount = count lastCount = count
} }
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
...@@ -107,6 +109,69 @@ ...@@ -107,6 +109,69 @@
chart.setOption(option) chart.setOption(option)
} }
}) })
},
// 获取label的formatter信息
async getLabelFormatter(series) {
const formatter = this.elementInfo.option.dataset.formatter
if(!formatter || !formatter.length) {
return
}
var arr = [] // 当前显示的label,formatter需要阻塞线程
var all = [] // 除当前显示label之外的值,formatter可以在异步线程请求处理
const count = this.elementData.dataList.categories.length
var start = parseInt(this.elementInfo.dataZoom.start / 100 * count)
start = start > 1 ? start - 1 : start
const end = parseInt(this.elementInfo.dataZoom.end / 100 * count)
series.forEach(item => {
const data = item.data
const name = item.name
for (var i = 0; i < data.length; i++) {
if(i >= start && i <= end - 1) {
arr.push({seriesName: name, value:data[i]})
} else {
all.push({seriesName: name, value:data[i]})
}
}
})
// 把所有的请求加入req数组中
var req = []
arr.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
const params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
req.push(this.$u.api.jsScript(params))
}
})
// req的线程需要同步执行
await Promise.all(req).then(res => {
res.forEach(item => {
const {Status, Result} = item.data
if(Status === 'true') {
const data = item.config.data.data
const key = JSON.parse(data).value
this.formatter[key] = Result
}
})
})
// all的线程可以异步处理
all.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
let params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
this.formatter[item.value] = Result
}
})
}
})
}, },
/** /**
* *
...@@ -119,8 +184,20 @@ ...@@ -119,8 +184,20 @@
if (tooltip.formatter && tooltip.formatter.length) { if (tooltip.formatter && tooltip.formatter.length) {
return { return {
...tooltip, ...tooltip,
formatter: (val) => { formatter: (val, ticket, callback) => {
return this.$u.common.converFunction(tooltip.formatter, val) const params = {
script: tooltip.formatter,
data: JSON.stringify(val)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
return callback(ticket, Result)
}
})
return "加载中......"
// return this.$u.common.converFunction(tooltip.formatter, val)
}, },
trigger: "axis" trigger: "axis"
} }
...@@ -142,9 +219,13 @@ ...@@ -142,9 +219,13 @@
...that.elementInfo.option.bar, ...that.elementInfo.option.bar,
label: { label: {
...that.elementInfo.option.dataset, ...that.elementInfo.option.dataset,
formatter: val => { formatter: val => {
return that.$u.common.converFunction(that.elementInfo.option.dataset if(this.formatter.hasOwnProperty(val.value)) {
.formatter, val) return this.formatter[val.value]
}
return val.value
// return that.$u.common.converFunction(that.elementInfo.option.dataset
// .formatter, val)
} }
} }
} }
...@@ -221,6 +302,7 @@ ...@@ -221,6 +302,7 @@
setChartDatas(event) { setChartDatas(event) {
const categories = this.elementData.dataList.datas[this.index].categories const categories = this.elementData.dataList.datas[this.index].categories
const series = this.elementData.dataList.datas[this.index].series const series = this.elementData.dataList.datas[this.index].series
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
}, },
labelShow: false, // 记录当前设置的label.show的值 labelShow: false, // 记录当前设置的label.show的值
index: 0, // 记录dataZoom切换当前的下标 index: 0, // 记录dataZoom切换当前的下标
formatter: {}, // 记录formatter之后的对象
} }
}, },
components: { components: {
...@@ -98,6 +99,8 @@ ...@@ -98,6 +99,8 @@
} }
lastCount = count lastCount = count
} }
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
...@@ -109,6 +112,73 @@ ...@@ -109,6 +112,73 @@
}) })
} }
}) })
},
// 获取label的formatter信息
async getLabelFormatter(series) {
const formatter = this.elementInfo.option.dataset.formatter
if(!formatter || !formatter.length) {
return
}
var arr = [] // 当前显示的label,formatter需要阻塞线程
var all = [] // 除当前显示label之外的值,formatter可以在异步线程请求处理
const count = this.elementData.dataList.categories.length
var start = parseInt(this.elementInfo.dataZoom.start / 100 * count)
start = start > 1 ? start - 1 : start
const end = parseInt(this.elementInfo.dataZoom.end / 100 * count)
series.forEach(item => {
const data = item.data
const name = item.name
for (var i = 0; i < data.length; i++) {
if(i >= start && i <= end - 1) {
arr.push({seriesName: name, value:data[i]})
} else {
all.push({seriesName: name, value:data[i]})
}
}
})
// 把所有的请求加入req数组中
var req = []
arr.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
const params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
req.push(this.$u.api.jsScript(params))
}
})
// req的线程需要同步执行
await Promise.all(req).then(res => {
res.forEach(item => {
const {Status, Result} = item.data
if(Status === 'true') {
const data = item.config.data.data
const key = JSON.parse(data).value
this.formatter[key] = Result
}
})
})
console.log(all)
// all的线程可以异步处理
all.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
let params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
this.formatter[item.value] = Result
}
})
}
})
}, },
/** /**
* *
...@@ -121,8 +191,19 @@ ...@@ -121,8 +191,19 @@
if (tooltip.formatter && tooltip.formatter.length) { if (tooltip.formatter && tooltip.formatter.length) {
return { return {
...tooltip, ...tooltip,
formatter: (val) => { formatter: (val, ticket, callback) => {
return this.$u.common.converFunction(tooltip.formatter, val) const params = {
script: tooltip.formatter,
data: JSON.stringify(val)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
return callback(ticket, Result)
}
})
return "加载中......"
// return this.$u.common.converFunction(tooltip.formatter, val)
}, },
trigger: "axis" trigger: "axis"
} }
...@@ -137,16 +218,19 @@ ...@@ -137,16 +218,19 @@
*/ */
dealSeriesData(data) { dealSeriesData(data) {
if (!data) return [] if (!data) return []
const that = this const that = this
const newData = data.map(item => { const newData = data.map(item => {
const config = { const config = {
type: 'line', type: 'line',
...that.elementInfo.option.line, ...that.elementInfo.option.line,
label: { label: {
...that.elementInfo.option.dataset, ...that.elementInfo.option.dataset,
formatter: val => { formatter: val => {
return that.$u.common.converFunction(that.elementInfo.option.dataset if(this.formatter.hasOwnProperty(val.value)) {
.formatter, val) return this.formatter[val.value]
}
return val.value
// return that.$u.common.converFunction(that.elementInfo.option.dataset.formatter, val)
}, },
} }
} }
...@@ -223,6 +307,7 @@ ...@@ -223,6 +307,7 @@
setChartDatas(event) { setChartDatas(event) {
const categories = this.elementData.dataList.datas[this.index].categories const categories = this.elementData.dataList.datas[this.index].categories
const series = this.elementData.dataList.datas[this.index].series const series = this.elementData.dataList.datas[this.index].series
this.getLabelFormatter(series)
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
......
...@@ -21,8 +21,9 @@ export default { ...@@ -21,8 +21,9 @@ export default {
return { return {
ec: { ec: {
lazyLoad:true, lazyLoad:true,
option: {} option: {},
} },
formatter: {}, // 记录formatter之后的对象
}; };
}, },
...@@ -55,7 +56,8 @@ export default { ...@@ -55,7 +56,8 @@ export default {
return chart return chart
}, },
initChart() { initChart() {
const { series } = this.elementData.dataList const { series } = this.elementData.dataList
this.getLabelFormatter(series)
this.$set(this.ec.option, 'series', this.dealSeriesData(series)) this.$set(this.ec.option, 'series', this.dealSeriesData(series))
if(chart) { if(chart) {
// 重新setOption,使得设置的formatter生效 // 重新setOption,使得设置的formatter生效
...@@ -75,7 +77,19 @@ export default { ...@@ -75,7 +77,19 @@ export default {
return { return {
...tooltip, ...tooltip,
formatter: (val) => { formatter: (val) => {
return this.$u.common.converFunction(tooltip.formatter, val) const params = {
script: tooltip.formatter,
data: JSON.stringify(val)
}
this.$u.api.jsScript(params).then(res => {
const {Status, Result} = res.data
if(Status === 'true') {
return callback(ticket, Result)
}
})
return "加载中......"
// return this.$u.common.converFunction(tooltip.formatter, val)
}, },
trigger: "item" trigger: "item"
} }
...@@ -86,6 +100,35 @@ export default { ...@@ -86,6 +100,35 @@ export default {
} }
}, },
// 获取label的formatter信息
async getLabelFormatter(series) {
const formatter = this.elementInfo.option.dataset.formatter
if(!formatter || !formatter.length) {
return
}
// 把所有的请求加入req数组中
var req = []
series.forEach(item => {
if(!this.formatter.hasOwnProperty(item.value)) {
const params = {
script: this.elementInfo.option.dataset.formatter,
data: JSON.stringify(item)
}
req.push(this.$u.api.jsScript(params))
}
})
// req的线程需要同步执行
await Promise.all(req).then(res => {
res.forEach(item => {
const {Status, Result} = item.data
if(Status === 'true') {
const data = item.config.data.data
const key = JSON.parse(data).value
this.formatter[key] = Result
}
})
})
},
dealSeriesData (data) { dealSeriesData (data) {
if(!data) return if(!data) return
const series = [{ const series = [{
...@@ -94,8 +137,13 @@ export default { ...@@ -94,8 +137,13 @@ export default {
...this.elementInfo.option.pie, ...this.elementInfo.option.pie,
label: { label: {
...this.elementInfo.option.dataset, ...this.elementInfo.option.dataset,
formatter: (val) => { formatter: (val) => {
return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, val) if(this.formatter.hasOwnProperty(val.value)) {
return this.formatter[val.value]
}
return val.value
// return this.$u.common.converFunction(this.elementInfo.option.dataset.formatter, val)
} }
}, },
labelLine: { labelLine: {
......
...@@ -34,7 +34,13 @@ export default { ...@@ -34,7 +34,13 @@ export default {
custom: { loading: false } custom: { loading: false }
}) })
if (dataProcessing) { if (dataProcessing) {
that.elementData.dataList = that.$u.common.converFunction(dataProcessing, res.data) // that.elementData.dataList = that.$u.common.converFunction(dataProcessing, res.data)
let params = {
script: dataProcessing,
data: JSON.stringify(res.data)
}
let r = await that.$u.api.jsScript(params)
that.elementData.dataList = r.data.Result
} else { } else {
that.elementData.dataList = JSON.parse(JSON.stringify(res.data.Result)) that.elementData.dataList = JSON.parse(JSON.stringify(res.data.Result))
} }
...@@ -42,11 +48,18 @@ export default { ...@@ -42,11 +48,18 @@ export default {
/** /**
* 全局数据 * 全局数据
*/ */
handlePublicData (value) { async handlePublicData (value) {
if (!this.vuex_globalData) return if (!this.vuex_globalData) return
const { dataProcessing } = { ...value } const { dataProcessing } = { ...value }
if (dataProcessing) { if (dataProcessing) {
this.elementData.dataList = this.$u.common.converFunction(dataProcessing, this.vuex_globalData) // this.elementData.dataList = this.$u.common.converFunction(dataProcessing, this.vuex_globalData)
let params = {
script: dataProcessing,
data: JSON.stringify(this.vuex_globalData)
}
let r = await this.$u.api.jsScript(params)
this.elementData.dataList = r.data.Result
} else { } else {
this.elementData.dataList = this.vuex_globalData this.elementData.dataList = this.vuex_globalData
} }
...@@ -61,7 +74,13 @@ export default { ...@@ -61,7 +74,13 @@ export default {
const { Status, Msg } = res.data; const { Status, Msg } = res.data;
if (Status == "true") { if (Status == "true") {
if(dataSetInfo.script) { if(dataSetInfo.script) {
that.elementData.dataList = that.$u.common.converFunction(dataSetInfo.script, res.data.Result) // that.elementData.dataList = that.$u.common.converFunction(dataSetInfo.script, res.data.Result)
let params = {
script: dataSetInfo.script,
data: JSON.stringify(res.data.Result)
}
let r = await that.$u.api.jsScript(params)
that.elementData.dataList = r.data.Result
} else { } else {
that.elementData.dataList = res.data.Result that.elementData.dataList = res.data.Result
} }
......
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