优化搜索和模板市场功能
- 修复饼图无法显示的问题,调整了图表初始化逻辑和容器尺寸 - 添加模板市场组件,实现模板点击和使用功能 - 优化首页布局,调整轮播图和创建问卷组件的顺序 - 添加搜索API接口,支持模板和banner搜索 - 修复问卷创建页面样式,使用van-cell组件优化布局 - 实现智能创建入口的跳转逻辑 - 优化代码格式,修正拼写错误和分号问题
This commit is contained in:
@@ -1,61 +1,58 @@
|
||||
import { onMounted, ref, type ShallowRef, watch } from 'vue';
|
||||
import type { ECOption } from '@/utils/echarts';
|
||||
import { chart } from '@/utils/echarts';
|
||||
import { deleteLegend, deleteTitle, pieOption } from './data/pie';
|
||||
import { deleteLegend, deleteTitle } from './data/pie';
|
||||
|
||||
type dataOption = Partial<ECOption['data']>;
|
||||
|
||||
const pieChart = ref();
|
||||
/**
|
||||
* 定义数据集
|
||||
*/
|
||||
// const series = ref<dataOption[]>([
|
||||
// {
|
||||
// name: 'Access From',
|
||||
// type: 'pie',
|
||||
// radius: '50%',
|
||||
// data: [
|
||||
// { value: 1048, name: 'Search Engine' },
|
||||
// { value: 735, name: 'Direct' },
|
||||
// { value: 580, name: 'Email' },
|
||||
// { value: 484, name: 'Union Ads' },
|
||||
// { value: 300, name: 'Video Ads' }
|
||||
// ],
|
||||
// emphasis: {
|
||||
// itemStyle: {
|
||||
// shadowBlur: 10,
|
||||
// shadowOffsetX: 0,
|
||||
// shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ]);
|
||||
|
||||
/**
|
||||
* 饼图的 option
|
||||
*/
|
||||
const option = ref(pieOption);
|
||||
// const option = ref(pieOption);
|
||||
|
||||
function useSetPieChart(
|
||||
dom: Readonly<ShallowRef<HTMLSpanElement | null>>,
|
||||
series: any,
|
||||
opts: optsType = {}
|
||||
): void {
|
||||
if (!series) return;
|
||||
for (const item in opts) {
|
||||
if (item === 'legend') !opts[item] && deleteLegend();
|
||||
else if (item === 'title') !opts[item] && deleteTitle();
|
||||
}
|
||||
// 图表实例
|
||||
let pieChart: any;
|
||||
|
||||
// 检测边界范围 dom 和 data 是否存在
|
||||
onMounted(() => {
|
||||
if (!dom || series.data.length === 0) return;
|
||||
if (!dom.value) {
|
||||
console.error('饼图DOM元素不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 在 dom 挂载之后,显示饼图
|
||||
pieChart.value = chart.init(dom.value);
|
||||
pieChart.value.setOption(option.value, opts);
|
||||
pieChart = chart.init(dom.value);
|
||||
|
||||
if (series.value) {
|
||||
// 创建完整的配置对象
|
||||
const fullOption = {
|
||||
series: [
|
||||
{
|
||||
type: 'pie',
|
||||
radius: '50%',
|
||||
data: series.value.data || []
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// 设置图表选项
|
||||
pieChart.setOption(fullOption, opts);
|
||||
|
||||
// 强制重绘以确保显示
|
||||
setTimeout(() => {
|
||||
pieChart.resize();
|
||||
}, 100);
|
||||
} else {
|
||||
console.error('饼图数据不存在');
|
||||
}
|
||||
});
|
||||
|
||||
// 如果 data 变动,重新生成图表
|
||||
// 如果 data 变动,重新生成图表w
|
||||
watch(series, (value) => {
|
||||
pieChart.value.setOption(value, opts);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user