From 00cc42d56567cbd577c67e6e8dfcdd78a136d4ea Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Thu, 15 May 2025 16:05:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2=E5=92=8C?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=B8=82=E5=9C=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复饼图无法显示的问题,调整了图表初始化逻辑和容器尺寸 - 添加模板市场组件,实现模板点击和使用功能 - 优化首页布局,调整轮播图和创建问卷组件的顺序 - 添加搜索API接口,支持模板和banner搜索 - 修复问卷创建页面样式,使用van-cell组件优化布局 - 实现智能创建入口的跳转逻辑 - 优化代码格式,修正拼写错误和分号问题 --- components.d.ts | 3 +- src/api/anslysis/aiInsight.ts | 24 +++- src/api/home/search.ts | 11 ++ src/components/Analysis/Index.vue | 9 +- src/components/TemplateMarketItem/Index.vue | 85 +++----------- src/hooks/chart/usePieChart.ts | 71 ++++++------ src/router/index.ts | 2 +- src/utils/stringTranslate.ts | 18 +++ src/views/Home/Index.vue | 4 +- .../Home/components/CreateSurvey/Index.vue | 7 +- .../IntelligentGeneration/Index.vue | 12 +- .../Home/components/ImageSlider/Index.vue | 8 +- .../components/ImageSlider/hooks/useSlider.ts | 8 +- src/views/Home/components/NewSurvey/index.vue | 14 +-- src/views/HomeSearch/Hooks/useSurveySearch.ts | 34 ++++-- src/views/HomeSearch/Index.vue | 10 +- .../components/MineSurvey/Index.vue | 13 ++- .../components/TemplateMarket/Index.vue | 77 ++++++++++++- src/views/Survey/views/Analysis/Index.vue | 4 +- .../AnalysisInfo/hooks/pieSeries.ts | 23 ++-- .../views/Analysis/components/Wait/Index.vue | 29 +++-- .../views/Analysis/hooks/useAnalysis.ts | 53 ++++++--- src/views/Survey/views/Create/Index.vue | 108 +++++++++--------- 23 files changed, 389 insertions(+), 238 deletions(-) create mode 100644 src/api/home/search.ts create mode 100644 src/utils/stringTranslate.ts diff --git a/components.d.ts b/components.d.ts index 4dccc9c..68492ee 100644 --- a/components.d.ts +++ b/components.d.ts @@ -32,6 +32,7 @@ declare module 'vue' { RouterView: typeof import('vue-router')['RouterView'] VanActionSheet: typeof import('vant/es')['ActionSheet'] VanButton: typeof import('vant/es')['Button'] + VanCard: typeof import('vant/es')['Card'] VanCell: typeof import('vant/es')['Cell'] VanCellGroup: typeof import('vant/es')['CellGroup'] VanCheckbox: typeof import('vant/es')['Checkbox'] @@ -49,7 +50,6 @@ declare module 'vue' { VanRadioGroup: typeof import('vant/es')['RadioGroup'] VanRow: typeof import('vant/es')['Row'] VanSearch: typeof import('vant/es')['Search'] - VanSpace: typeof import('vant/es')['Space'] VanStepper: typeof import('vant/es')['Stepper'] VanSwipe: typeof import('vant/es')['Swipe'] VanSwipeItem: typeof import('vant/es')['SwipeItem'] @@ -58,7 +58,6 @@ declare module 'vue' { VanTabbar: typeof import('vant/es')['Tabbar'] VanTabbarItem: typeof import('vant/es')['TabbarItem'] VanTabs: typeof import('vant/es')['Tabs'] - VanTag: typeof import('vant/es')['Tag'] YLCascader: typeof import('./src/components/YLCascader.vue')['default'] YLInput: typeof import('./src/components/YLInput.vue')['default'] YLPicker: typeof import('./src/components/YLPicker.vue')['default'] diff --git a/src/api/anslysis/aiInsight.ts b/src/api/anslysis/aiInsight.ts index 1534fb9..9a533bd 100644 --- a/src/api/anslysis/aiInsight.ts +++ b/src/api/anslysis/aiInsight.ts @@ -8,18 +8,36 @@ import request from '@/utils/request'; export function analysisInsights(sn: string, params?: ParticalParams) { return request({ url: `/console/surveys/${sn}/analysis_insights_h5`, - params + data: {}, + method: 'post' }); } + /** * ai 洞察检查分析是否完成 * @param sn 循环题组sn * @param data {1|2} 1=AI样本标记;2=AI洞察 */ -export function checkAnalysisSatus(sn: string, data?: 1 | 2) { +export function checkAnalysisStatus(sn: string, data?: 1 | 2) { return request({ url: `/console/surveys/${sn}/status`, method: 'post', - data + data: { + type: data + } + }); +} + +/** + * 问题分析接口 + * @param sn + * @param data {import('@/api/types/analysis.js').AnalysisParam} + * @returns {Promise> | *} + */ +export function getAnalysis(sn: string) { + return request({ + url: `/console/surveys/${sn}/chart_analysis`, + method: 'post', + data: {} }); } diff --git a/src/api/home/search.ts b/src/api/home/search.ts new file mode 100644 index 0000000..fea27ac --- /dev/null +++ b/src/api/home/search.ts @@ -0,0 +1,11 @@ +import request from '@/utils/request'; + +export function getSearchInfo(keyword: string) { + return request({ + url: '/console/surveys/search', + method: 'get', + params: { + keyWord: keyword + } + }); +} diff --git a/src/components/Analysis/Index.vue b/src/components/Analysis/Index.vue index e24e46f..6a175f8 100644 --- a/src/components/Analysis/Index.vue +++ b/src/components/Analysis/Index.vue @@ -5,20 +5,21 @@ import { useSetPieChart } from '@/hooks/chart/usePieChart'; import { surveys } from '@/components/Analysis/hooks/useSurvey'; import { questionTypeMap } from '@/utils/question/typeMapping'; -// const info = defineModel('info', { required: true }); // series 信息 const series = defineModel('series', { required: true }); // 饼图 dom 结构 const pieChart = useTemplateRef('pieChart'); -useSetPieChart(pieChart, series.value, { title: false, ledge: false }); +useSetPieChart(pieChart, series, { title: false, legend: false }); diff --git a/src/components/TemplateMarketItem/Index.vue b/src/components/TemplateMarketItem/Index.vue index d609cb1..ec1ec75 100644 --- a/src/components/TemplateMarketItem/Index.vue +++ b/src/components/TemplateMarketItem/Index.vue @@ -1,72 +1,25 @@ diff --git a/src/hooks/chart/usePieChart.ts b/src/hooks/chart/usePieChart.ts index 44c7d6c..5d774bd 100644 --- a/src/hooks/chart/usePieChart.ts +++ b/src/hooks/chart/usePieChart.ts @@ -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; -const pieChart = ref(); -/** - * 定义数据集 - */ -// const series = ref([ -// { -// 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>, 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); }); diff --git a/src/router/index.ts b/src/router/index.ts index ebe0404..12c114b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -79,7 +79,7 @@ const router = createRouter({ component: () => import('../views/Survey/views/Publish/Index.vue') }, { - path: 'intelligentGeneration', + path: '/intelligentGeneration', name: 'intelligentGeneration', meta: { title: '智能创建' diff --git a/src/utils/stringTranslate.ts b/src/utils/stringTranslate.ts new file mode 100644 index 0000000..0d570f7 --- /dev/null +++ b/src/utils/stringTranslate.ts @@ -0,0 +1,18 @@ +export function escapeHTML (str: string, type = 'dom') { + if (type !== 'dom') { + const dom = document.createElement("div") + dom.textContent = str + + return dom.innerHTML + } else { + return str.replace(/[&<>"']/g, (match) => ({ + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }[match])); + + } + +} \ No newline at end of file diff --git a/src/views/Home/Index.vue b/src/views/Home/Index.vue index 8b67e2a..0f13d2e 100644 --- a/src/views/Home/Index.vue +++ b/src/views/Home/Index.vue @@ -45,9 +45,9 @@ onMounted(async () => {