Merge branch 'master' of github.com:gcpaas/DataRoom

main
wu.jian2 2 years ago
commit 803b2e0f6e

@ -60,7 +60,7 @@
<clickhouse.version>0.3.2</clickhouse.version> <clickhouse.version>0.3.2</clickhouse.version>
<commons-io.version>2.2</commons-io.version> <commons-io.version>2.2</commons-io.version>
<okhttp3.version>4.9.1</okhttp3.version> <okhttp3.version>4.9.1</okhttp3.version>
<dataset.core.version>1.0.1.2023072703.Alpha</dataset.core.version> <dataset.core.version>1.0.1.2023072801.Alpha</dataset.core.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>

@ -147,19 +147,23 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12"> <el-col :span="21">
<el-form-item <el-form-item
label="标签" label="请求地址"
prop="labelIds" prop="config.url"
> >
<LabelSelect <el-input
:dataset-id="datasetId" v-model="dataForm.config.url"
:id-list="dataForm.labelIds" autocomplete="off"
@commit="(ids) =>{dataForm.labelIds = ids}" class="bs-el-input"
placeholder="请输入静态请求地址或动态请求地址,动态请求地址必须以${baseUrl}开头"
clearable
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row>
<el-col :span="12">
<el-form-item <el-form-item
label="请求类型" label="请求类型"
prop="config.method" prop="config.method"
@ -176,21 +180,31 @@
</el-radio-button> </el-radio-button>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-col>
<el-col :span="12">
<el-form-item <el-form-item
label="请求地址" label="标签"
prop="config.url" prop="labelIds"
> >
<el-input <LabelSelect
v-model="dataForm.config.url" :dataset-id="datasetId"
autocomplete="off" :id-list="dataForm.labelIds"
class="bs-el-input" @commit="(ids) =>{dataForm.labelIds = ids}"
placeholder="请输入静态请求地址或动态请求地址,动态请求地址必须以${baseUrl}开头"
clearable
/> />
</el-form-item> </el-form-item>
<el-form-item </el-col>
</el-row>
<el-tabs
v-model="activeName"
class="bs-el-tabs tabs-box"
>
<el-tab-pane
label="请求头" label="请求头"
name="head"
>
<el-form-item
prop="config.headers" prop="config.headers"
label-width="0px"
> >
<el-button <el-button
type="primary" type="primary"
@ -203,6 +217,7 @@
:key="index" :key="index"
:gutter="10" :gutter="10"
:span="21" :span="21"
style="margin-top: 10px"
> >
<el-col :span="5"> <el-col :span="5">
<el-form-item <el-form-item
@ -247,9 +262,14 @@
</el-col> </el-col>
</el-row> </el-row>
</el-form-item> </el-form-item>
<el-form-item </el-tab-pane>
<el-tab-pane
label="请求参数" label="请求参数"
name="param"
>
<el-form-item
prop="config.params" prop="config.params"
label-width="0px"
:rules="dataForm.config.method==='get'?rules.params:[{ required: false}]" :rules="dataForm.config.method==='get'?rules.params:[{ required: false}]"
> >
<el-button <el-button
@ -263,6 +283,7 @@
:key="index" :key="index"
:gutter="10" :gutter="10"
:span="21" :span="21"
style="margin-top: 10px"
> >
<el-col :span="7"> <el-col :span="7">
<el-form-item <el-form-item
@ -307,10 +328,15 @@
</el-col> </el-col>
</el-row> </el-row>
</el-form-item> </el-form-item>
<el-form-item </el-tab-pane>
<el-tab-pane
v-if="dataForm.config.method === 'post'" v-if="dataForm.config.method === 'post'"
label="请求体" label="请求体"
name="second"
>
<el-form-item
prop="requestScript" prop="requestScript"
label-width="0px"
> >
<el-input <el-input
v-model="dataForm.config.body" v-model="dataForm.config.body"
@ -320,9 +346,14 @@
clearable clearable
/> />
</el-form-item> </el-form-item>
<el-form-item </el-tab-pane>
<el-tab-pane
label="请求脚本" label="请求脚本"
name="reqScript"
>
<el-form-item
prop="requestScript" prop="requestScript"
label-width="0px"
> >
<codemirror <codemirror
v-model.trim="dataForm.config.requestScript" v-model.trim="dataForm.config.requestScript"
@ -330,9 +361,14 @@
class="code" class="code"
/> />
</el-form-item> </el-form-item>
<el-form-item </el-tab-pane>
<el-tab-pane
label="响应脚本" label="响应脚本"
name="respScript"
>
<el-form-item
prop="responseScript" prop="responseScript"
label-width="0px"
> >
<codemirror <codemirror
v-model.trim="dataForm.config.responseScript" v-model.trim="dataForm.config.responseScript"
@ -340,6 +376,8 @@
class="code" class="code"
/> />
</el-form-item> </el-form-item>
</el-tab-pane>
</el-tabs>
</el-form> </el-form>
<div <div
v-if="isEdit" v-if="isEdit"
@ -479,6 +517,7 @@
> >
<div class="bs-table-box"> <div class="bs-table-box">
<el-table <el-table
v-if="dataPreviewList && dataPreviewList.length"
align="center" align="center"
:data="dataPreviewList" :data="dataPreviewList"
max-height="400" max-height="400"
@ -498,6 +537,7 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-empty v-else />
</div> </div>
</el-tab-pane> </el-tab-pane>
<el-tab-pane <el-tab-pane
@ -629,6 +669,7 @@ export default {
} }
} }
return { return {
activeName: 'head',
options: [{ options: [{
value: 'string', value: 'string',
label: '字符串' label: '字符串'
@ -688,7 +729,6 @@ export default {
completeSingle: true completeSingle: true
} }
}, },
activeName: 'data',
dataPreviewList: [], dataPreviewList: [],
outputFieldList: [], outputFieldList: [],
structurePreviewListCopy: [], structurePreviewListCopy: [],
@ -878,54 +918,6 @@ export default {
}) })
this.fieldDesc = fieldDesc this.fieldDesc = fieldDesc
}, },
// //
// replaceParams (paramsList) {
// this.newDataForm = _.cloneDeep(this.dataForm)
// this.newDataForm.config.url = this.evalStrFunc(paramsList, this.newDataForm.config.url)
// this.newDataForm.config.headers = this.evalArrFunc(paramsList, this.newDataForm.config.headers)
// this.newDataForm.config.params = this.evalArrFunc(paramsList, this.newDataForm.config.params)
// this.newDataForm.config.body = this.evalStrFunc(paramsList, this.newDataForm.config.body)
// },
// evalStrFunc (paramsList, string) {
// // name, value { name: '', token: '123'}
// const params = paramsList.reduce((acc, cur) => {
// acc[cur.name] = cur.value
// return acc
// }, {})
// // url ${xxx} ${params.xxx}
// const str = string.replace(/\$\{(\w+)\}/g, (match, p1) => {
// return '${params.' + p1 + '}'
// })
// const transformStr = ''
// // ${}, 使eval
// eval('transformStr = `' + str + '`')
// return transformStr
// },
// evalArrFunc (paramsList, arr) {
// // name, value { name: '', token: '123'}
// const params = paramsList.reduce((acc, cur) => {
// acc[cur.name] = cur.value
// return acc
// }, {})
//
// // name, value { _name: '${name}', _token: '${token}'}
// const paramsListObj = arr.reduce((acc, cur) => {
// acc[cur.key] = cur.value
// return acc
// }, {})
// //
// const paramsListStr = JSON.stringify(paramsListObj)
//
// // url ${xxx} ${params.xxx}
// const str = paramsListStr.replace(/\$\{(\w+)\}/g, (match, p1) => {
// return '${params.' + p1 + '}'
// })
// const transformStr = ''
// // ${}, 使eval
// eval('transformStr = `' + str + '`')
// const obj = JSON.parse(transformStr)
// return obj
// },
// //
getPramsList () { getPramsList () {
const paramNames1 = this.getValName(this.dataForm.config.url) const paramNames1 = this.getValName(this.dataForm.config.url)
@ -977,10 +969,10 @@ export default {
if (this.dataForm.config.requestType === 'frontend') { if (this.dataForm.config.requestType === 'frontend') {
// this.replaceParams(this.dataForm.config.paramsList) // this.replaceParams(this.dataForm.config.paramsList)
axiosFormatting({ ...this.dataForm.config }).then((res) => { axiosFormatting({ ...this.dataForm.config }).then((res) => {
this.dataPreviewList = res.data this.dataPreviewList = res.data && Array.isArray(res.data) ? res.data : []
// //
this.updateOoutputFieldList(this.dataPreviewList) this.updateOoutputFieldList(this.dataPreviewList)
console.log(res) this.$message.success('解析并执行成功')
}) })
} else { } else {
// //
@ -991,7 +983,7 @@ export default {
dataSetType: 'http' dataSetType: 'http'
} }
datasetExecuteTest(executeParams).then(res => { datasetExecuteTest(executeParams).then(res => {
this.dataPreviewList = res this.dataPreviewList = res.data && Array.isArray(res.data) ? res.data : []
// //
this.updateOoutputFieldList(this.dataPreviewList) this.updateOoutputFieldList(this.dataPreviewList)
this.$message.success('解析并执行成功') this.$message.success('解析并执行成功')
@ -1223,4 +1215,7 @@ export default {
.tree-box { .tree-box {
padding: 0; padding: 0;
} }
.tabs-box{
margin-left: 45px;
}
</style> </style>

@ -655,7 +655,11 @@ export default {
getData () { getData () {
const executeParams = { const executeParams = {
dataSourceId: this.dataForm.sourceId, dataSourceId: this.dataForm.sourceId,
script: this.dataForm.fieldInfo.join(','), script:JSON.stringify({
fieldInfo: this.dataForm.fieldInfo,//
tableName: this.dataForm.tableName,
repeatStatus: this.dataForm.repeatStatus
}) ,
// //
params: [], params: [],
dataSetType: 'original', dataSetType: 'original',
@ -856,7 +860,11 @@ export default {
if (!this.dataForm.sourceId || !this.dataForm.tableName) return if (!this.dataForm.sourceId || !this.dataForm.tableName) return
const executeParams = { const executeParams = {
dataSourceId: this.dataForm.sourceId, dataSourceId: this.dataForm.sourceId,
script: this.dataForm.fieldInfo.join(','), script:JSON.stringify({
fieldInfo: this.dataForm.fieldInfo,//
tableName: this.dataForm.tableName,
repeatStatus: this.dataForm.repeatStatus
}) ,
// //
params: [], params: [],
dataSetType: 'original', dataSetType: 'original',

@ -71,28 +71,13 @@ export default {
pageCode: this.pageCode, pageCode: this.pageCode,
size: size, size: size,
type: config.type type: config.type
}).then((res) => { }).then(async (res) => {
let _res = _.cloneDeep(res)
// 如果是http数据集的前端代理则需要调封装的axios请求 // 如果是http数据集的前端代理则需要调封装的axios请求
// if (data.executionByFrontend) {
// axiosFormatting(data.data).then(res => {
// config = this.dataFormatting(config, res)
// this.changeChartConfig(config)
// })
// }
// if (data.datasetType !== 'http' && data.executionByFrontend) {
// try {
// const scriptAfterReplacement = data.data.replace(/\${(.*?)}/g, (match, p) => {
// // 根据parmas的key获取value
// return `'${this.config.dataSource?.params[p]}' || '${p}'`
// })
// // eslint-disable-next-line no-new-func
// const scriptMethod = new Function(scriptAfterReplacement)
// data.data = scriptMethod()
// } catch (error) {
// console.error('数据集脚本执行失败', error)
// }
// }
if (res.executionByFrontend) { if (res.executionByFrontend) {
if (res.data.datasetType === 'http') {
_res = await axiosFormatting(res.data)
}
if (res.data.datasetType === 'js') { if (res.data.datasetType === 'js') {
try { try {
const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => { const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => {
@ -101,13 +86,13 @@ export default {
}) })
// eslint-disable-next-line no-new-func // eslint-disable-next-line no-new-func
const scriptMethod = new Function(scriptAfterReplacement) const scriptMethod = new Function(scriptAfterReplacement)
res.data = scriptMethod() _res.data = scriptMethod()
} catch (error) { } catch (error) {
console.error('JS数据集脚本执行失败', error) console.error('JS数据集脚本执行失败', error)
} }
} }
} }
config = this.dataFormatting(config, res) config = this.dataFormatting(config, _res)
this.changeChartConfig(config) this.changeChartConfig(config)
}).catch((err) => { }).catch((err) => {
console.error(err) console.error(err)
@ -132,15 +117,13 @@ export default {
filterList: filterList || this.filterList filterList: filterList || this.filterList
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getUpdateChartInfo(params).then((res) => { getUpdateChartInfo(params).then(async (res) => {
let _res = _.cloneDeep(res)
// 如果是http数据集的前端代理则需要调封装的axios请求 // 如果是http数据集的前端代理则需要调封装的axios请求
// if (data.executionByFrontend) {
// axiosFormatting(data.data).then(res => {
// config = this.dataFormatting(config, res)
// this.changeChartConfig(config)
// })
// }
if (res.executionByFrontend) { if (res.executionByFrontend) {
if (res.data.datasetType === 'http') {
_res = await axiosFormatting(res.data)
}
if (res.data.datasetType === 'js') { if (res.data.datasetType === 'js') {
try { try {
const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => { const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => {
@ -149,14 +132,13 @@ export default {
}) })
// eslint-disable-next-line no-new-func // eslint-disable-next-line no-new-func
const scriptMethod = new Function(scriptAfterReplacement) const scriptMethod = new Function(scriptAfterReplacement)
res.data = scriptMethod() _res.data = scriptMethod()
} catch (error) { } catch (error) {
console.error('JS数据集脚本执行失败', error) console.error('JS数据集脚本执行失败', error)
} }
} }
} }
config = this.dataFormatting(config, res) config = this.dataFormatting(config, _res)
this.changeChartConfig(config)
if (this.chart) { if (this.chart) {
// 单指标组件和多指标组件的changeData传参不同 // 单指标组件和多指标组件的changeData传参不同
if (['Liquid', 'Gauge', 'RingProgress'].includes(config.chartType)) { if (['Liquid', 'Gauge', 'RingProgress'].includes(config.chartType)) {

@ -35,12 +35,10 @@ export default function axiosFormatting (customConfig) {
instance.interceptors.response.use(response => { instance.interceptors.response.use(response => {
if (response.data.code === 200) { if (response.data.code === 200) {
// 执行响应脚本 // 执行响应脚本
const resp = _.cloneDeep(response.data) // eslint-disable-next-line no-new-func
eval(newCustomConfig.responseScript) const getResp = new Function('response', newCustomConfig.responseScript)
Message({ const resp = getResp(response)
message: '执行成功', console.log(resp)
type: 'success'
})
return Promise.resolve(resp) return Promise.resolve(resp)
} else { } else {
Message({ Message({
@ -80,7 +78,7 @@ function replaceUrlParam (url, paramName, paramValue) {
} }
// 将参数的值替换掉其他配置中对应属性的值 // 将参数的值替换掉其他配置中对应属性的值
function replaceParams (customConfig) { function replaceParams (customConfig) {
let newConfig = _.cloneDeep(customConfig) const newConfig = _.cloneDeep(customConfig)
newConfig.url = evalStrFunc(newConfig.paramsList, newConfig.url) newConfig.url = evalStrFunc(newConfig.paramsList, newConfig.url)
newConfig.headers = evalArrFunc(newConfig.paramsList, newConfig.headers) newConfig.headers = evalArrFunc(newConfig.paramsList, newConfig.headers)
newConfig.params = evalArrFunc(newConfig.paramsList, newConfig.params) newConfig.params = evalArrFunc(newConfig.paramsList, newConfig.params)

Loading…
Cancel
Save