Compare commits
No commits in common. "9c38b187750058b2c7f9835ee6eaafa53373e82e" and "57ab939a677aaf8aef43f6dd5fe91729cb02c7a9" have entirely different histories.
9c38b18775
...
57ab939a67
|
|
@ -26,9 +26,6 @@ import { useChartDataFetch } from '@/hooks';
|
|||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore';
|
||||
import { EventBus } from '@/utils/eventBus';
|
||||
|
||||
|
||||
import { replaceSqlParams } from '@/utils/sqlHandler';
|
||||
|
||||
const props = defineProps({
|
||||
chartConfig: {
|
||||
type: Object as PropType<CreateComponentType>,
|
||||
|
|
@ -36,9 +33,6 @@ const props = defineProps({
|
|||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
const { w, h } = toRefs(props.chartConfig.attr)
|
||||
const {
|
||||
colors,
|
||||
|
|
@ -51,31 +45,37 @@ const {
|
|||
|
||||
|
||||
|
||||
console.log("props.chartConfig",props.chartConfig.option.showColumns);
|
||||
|
||||
|
||||
|
||||
|
||||
onMounted(()=>{
|
||||
const sql = JSON.parse(JSON.stringify(props.chartConfig.request.requestSQLContent)).sql;
|
||||
|
||||
const sql = props.chartConfig.request?.requestSQLContent?.sql;
|
||||
// 组件通信 获取列表中的信息
|
||||
EventBus.on(props.chartConfig.id+'dataupdate', (data) => {
|
||||
props.chartConfig.request.requestSQLContent.sql = replaceSqlParams(sql,{Id:data.id})
|
||||
// 数据callback处理(预览时触发)
|
||||
useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any) => {
|
||||
|
||||
// props.chartConfig.option.dataset = resData;
|
||||
let data = [];
|
||||
props.chartConfig.request.requestSQLContent.sql = replaceSqlParams(sql,{Id:data.id})
|
||||
|
||||
props.chartConfig.option.showColumns?.forEach((item,index)=>{
|
||||
let info = {
|
||||
title:item.zh_name,
|
||||
desc:resData[0][firstLetterToLowerCase(item.en_name)]
|
||||
}
|
||||
data.push(info);
|
||||
// 数据callback处理(预览时触发)
|
||||
useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any) => {
|
||||
// props.chartConfig.option.dataset = resData;
|
||||
let data = [];
|
||||
|
||||
props.chartConfig.option.showColumns?.forEach((item,index)=>{
|
||||
let info = {
|
||||
title:item.zh_name,
|
||||
desc:resData[0][firstLetterToLowerCase(item.en_name)]
|
||||
}
|
||||
data.push(info);
|
||||
|
||||
})
|
||||
|
||||
props.chartConfig.option.dataset.data = data;
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
props.chartConfig.option.dataset.data = data;
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
function firstLetterToLowerCase(str) {
|
||||
|
|
@ -87,6 +87,17 @@ const handlerShowColumns = ()=> {
|
|||
|
||||
}
|
||||
|
||||
|
||||
function replaceSqlParams(sql, params) {
|
||||
return sql.replace(/#\{([^}]+)\}/g, (match, p1) => {
|
||||
if (params.hasOwnProperty(p1)) {
|
||||
// 根据参数类型决定是否添加引号(简单实现)
|
||||
return typeof params[p1] === 'string' ? `'${params[p1]}'` : params[p1];
|
||||
}
|
||||
throw new Error(`缺少参数: ${p1}`);
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
|
||||
示例:
|
||||
|
||||
参数 sql : select * from tableName where 'Id' = #{id} and 'state' = #{state}
|
||||
|
||||
参数 params : {id:12343,state:1}
|
||||
|
||||
返回结果: select * from tableName where 'Id' = 12343 and 'state' = 1
|
||||
|
||||
*/
|
||||
|
||||
export function replaceSqlParams(sql, params) {
|
||||
return sql.replace(/#\{([^}]+)\}/g, (match, p1) => {
|
||||
if (params.hasOwnProperty(p1)) {
|
||||
return typeof params[p1] === 'string' ? `'${params[p1]}'` : params[p1];
|
||||
}
|
||||
throw new Error(`缺少参数: ${p1}`);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue