From 2c6f86bfc6c17bf5a541a90f49b6252639325b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=B1=E8=BE=BE?= Date: Tue, 11 Mar 2025 16:21:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=96=B0=E5=A2=9E=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E8=AE=BE=E8=AE=A1=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E9=97=AE=E5=8D=B7=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增问卷设计相关接口: snQuestions, saveQuestion, sync, questionDetails - 实现问卷创建功能,包括生成问卷模板和保存问卷标题、介绍等信息 -优化内容可编辑组件,增加失焦时保存内容的功能 - 更新环境变量和代理配置,以适应新的后端接口地址 --- .env | 2 +- .env.development | 2 +- src/api/design/index.js | 31 +++ src/api/home/index.js | 10 + src/components/contenteditable.vue | 35 ++- src/stores/counter.ts | 7 +- src/stores/modules/common.ts | 232 ++---------------- src/utils/request.js | 17 +- .../CreateSurvey/Hooks/useRequestHooks.ts | 24 +- .../Home/components/CreateSurvey/Index.vue | 61 ++++- src/views/Survey/views/Create/Index.vue | 53 +++- vite.config.ts | 12 +- 12 files changed, 222 insertions(+), 264 deletions(-) create mode 100644 src/api/design/index.js diff --git a/.env b/.env index 996e123..91b536c 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ # .env -VITE_APP_BASE_URL=http://192.168.3.7:15001/ +VITE_APP_BASE_URL=http://192.168.8.165:15011/ VITE_APP_ENV=development VITE_APP_CURRENTMODE=dev VITE_APP_BASEOSS=https://diaoyan-files.automark.cc diff --git a/.env.development b/.env.development index 7bceb85..b5cc42d 100644 --- a/.env.development +++ b/.env.development @@ -1,5 +1,5 @@ # .env.development -VITE_APP_BASEURL=http://192.168.3.7:15001/api/ +VITE_APP_BASEURL=http://192.168.8.165:15011/ VITE_APP_ENV=development VITE_APP_CURRENTMODE=dev VITE_APP_BASEOSS=https://diaoyan-files.automark.cc diff --git a/src/api/design/index.js b/src/api/design/index.js new file mode 100644 index 0000000..a01a619 --- /dev/null +++ b/src/api/design/index.js @@ -0,0 +1,31 @@ +import request from '@/utils/request.js'; +export function snQuestions(params) { + return request({ + url: `/console/surveys/${params.sn}/questions`, + method: 'get' + }); +} +// 操作编辑 +export function saveQuestion(params) { + return request({ + url: `console/surveys/${params.sn}/questions`, + method: 'post', + data: params + }); +} +export function sync(params) { + return request({ + url: `console/surveys/${params.sn}/sync`, + method: 'post', + data: params + }); +} +export function questionDetails(params) { + // let sn = params.sn; + // delete params.sn; + return request({ + url: `console/surveys/${params.sn}/details`, + method: 'post', + data: params + }); +} diff --git a/src/api/home/index.js b/src/api/home/index.js index a63a33b..ba0fa30 100644 --- a/src/api/home/index.js +++ b/src/api/home/index.js @@ -7,3 +7,13 @@ export function getQuestionList(params) { params }); } +export function consoleSurveys(params) { + return request({ + url: '/console/surveys', + method: 'post', + data: { + ...params, + source: '1' + } + }); +} diff --git a/src/components/contenteditable.vue b/src/components/contenteditable.vue index 01338d2..cf0b12a 100644 --- a/src/components/contenteditable.vue +++ b/src/components/contenteditable.vue @@ -23,7 +23,7 @@ const props = defineProps({ const editor = ref(null); const editorAction = ref(null); -const emit = defineEmits(['update:modelValue']); +const emit = defineEmits(['update:modelValue', 'blur']); const save = (e) => { emit('update:modelValue', e.innerHTML); }; @@ -42,6 +42,9 @@ const functions = { }; const funEvent = (item) => { + // 保持焦点在编辑器 + const selection = window.getSelection(); + selection.getRangeAt(0); functions[item.fun](); }; @@ -81,16 +84,40 @@ const actions = [ fun: 'italic' } ]; +const checkContains = (element, target) => { + try { + return element?.contains(target) ?? false; + } catch (e) { + console.error('Contains check failed:', e); + return false; + } +}; onMounted(() => { editor.value.addEventListener('focus', () => { showAction.value = true; }); - editor.value.addEventListener('blur', () => { - setTimeout(() => { + + // 如果点击了 editor 与 editorAction 其他地方就触发保存 + + document.addEventListener('click', (e) => { + if (!editor.value || !editorAction.value) return; + + const target = e.composedPath?.()?.[0] || e.target; + const isEditor = checkContains(editor.value, target); + const isActionBar = checkContains(editorAction.value, target); + + if (!isEditor && !isActionBar) { showAction.value = false; - }); + save(editor.value); + emit('blur', editor.value); + } }); + // editor.value.addEventListener('blur', () => { + // setTimeout(() => { + // showAction.value = false; + // }); + // }); document.addEventListener('resize', () => { showAction.value = false; }); diff --git a/src/stores/counter.ts b/src/stores/counter.ts index 646a644..3015b5c 100644 --- a/src/stores/counter.ts +++ b/src/stores/counter.ts @@ -15,7 +15,10 @@ const modules = Object.entries(modulesFiles).reduce( export const useCounterStore = defineStore('counter', () => { // 引入 common 模块 const commonStore = useCommonStore(); - const { questionsInfo } = storeToRefs(commonStore); + const ques = storeToRefs(commonStore); + + // 暴露 fetchQuestionInfo 方法 + const { fetchQuestionInfo, setQuestionInfo } = commonStore; // 返回需要暴露的内容 - return { commonStore, questionsInfo, modules }; + return { commonStore, modules, fetchQuestionInfo, ...ques, setQuestionInfo }; }); diff --git a/src/stores/modules/common.ts b/src/stores/modules/common.ts index 1989863..bc77f9d 100644 --- a/src/stores/modules/common.ts +++ b/src/stores/modules/common.ts @@ -9,27 +9,20 @@ export const useCommonStore = defineStore('common', { state: () => ({ questionsInfo: { survey: { - id: '', - introduction: - '

为优化活动服务品质,烦请完成问卷,感谢配合!您的反馈至关重要!(此提示语为默认提示语,您可选择自行输入本问卷的提示语)

', - pages: [ - [24, 27, 26, 1], - [2, 3, 4, 5, 6, 7], - [8, 9, 10, 11, 12, 13, 14], - [15, 16, 17, 18, 19, 20, 21], - [28, 22] - ], - sn: '', + id: 9577, + introduction: '

123

', + pages: [[]], + sn: 'oxywX8W6', status: 0, - title: '

问卷标题

', + title: '报名签到问卷 ', detail_pages: [], group_pages: [], is_one_page_one_question: 0, last_question_index: 0, is_three_d_permissions: 0, is_dept: 1, - last_title: 'Q5', - project_name: '', + last_title: 'Q0', + project_name: '报名签到问卷 ', quota_end_content: '

\n

很抱歉,本次调研不太适合您的情况,感谢您的参与!

', quota_end_url: '', @@ -44,220 +37,21 @@ export const useCommonStore = defineStore('common', { end_jump_status: 0, end_jump_standing_time: 0, success_end_content: - '

\n

您已完成本次调研,感谢您的参与!

\n

【成功完成】

', + '

\n

您已完成本次调研,感谢您的参与!

\n

【成功完成】

', success_end_url: '', success_end_url_select: 0, success_standing_time: 0, - template_type: 300, - local_pages: [ - { - pages: [], - is_short_time: 0, - short_time: '', - is_show: 0, - use_type: 0 - }, - { - pages: [], - is_short_time: 0, - short_time: '', - is_show: 0, - use_type: 0 - }, - { - pages: [], - is_short_time: 0, - short_time: '', - is_show: 0, - use_type: 0 - }, - { - pages: [], - is_short_time: 0, - short_time: '', - is_show: 0, - use_type: 0 - }, - { - pages: [], - is_short_time: 0, - short_time: '', - is_show: 0, - use_type: 0 - } - ] + template_type: 0, + local_pages: [] }, - logics: [ - { - logic: [ - { - value: '', - location: 0, - date: '', - time: '', - type: 0, - row_type: 0, - cell_type: 0, - logic: 'if', - operator: '=', - is_answer: 1, - is_select: 0, - row_index: 0, - cell_index: 0, - question_type: 1, - question_index: 24, - relation_question_index: 0, - relation_question_row_index: 0, - relation_question_cell_index: 0, - is_option_group: 0, - option_index: 1, - skip_type: null, - question_id: null - } - ], - skip_question_index: 27, - skip_type: 0, - id: 472148, - question_index: 24, - question_id: '17852294' - }, - { - logic: [ - { - value: '', - location: 0, - date: '', - time: '', - type: 0, - row_type: 0, - cell_type: 0, - logic: 'if', - operator: '=', - is_answer: 1, - is_select: 0, - row_index: 0, - cell_index: 0, - question_type: 1, - question_index: 24, - relation_question_index: 0, - relation_question_row_index: 0, - relation_question_cell_index: 0, - is_option_group: 0, - option_index: 0, - skip_type: null, - question_id: null - } - ], - skip_type: 0, - id: 472149, - question_index: 24, - question_id: '17852294' - }, - { - logic: [ - { - value: '', - location: 0, - date: '', - time: '', - type: 0, - row_type: 0, - cell_type: 0, - logic: 'if', - operator: '=', - is_answer: 1, - is_select: 0, - row_index: 0, - cell_index: 0, - question_type: 1, - question_index: 24, - relation_question_index: 0, - relation_question_row_index: 0, - relation_question_cell_index: 0, - is_option_group: 0, - option_index: 0, - skip_type: null, - question_id: null - } - ], - skip_type: 0, - id: 472151, - question_index: 24, - question_id: '17852294' - }, - { - logic: [ - { - logic: 'if', - question_index: 30, - question_type: 1, - is_answer: 1, - operator: '=', - option_index: 2, - relation_question_index: 0, - type: 0, - is_option_group: 0, - group_index: null - }, - { - logic: 'and', - question_index: 30, - question_type: 1, - is_answer: 1, - operator: '=', - option_index: 1, - relation_question_index: 0, - type: 0, - is_option_group: 1, - group_index: 1 - } - ], - skip_question_index: 0, - skip_type: 1, - id: 472152, - question_index: 24, - question_id: '17852294' - }, - { - logic: [ - { - logic: 'if', - question_index: 30, - question_type: 1, - is_answer: 0, - operator: '=', - option_index: 0, - relation_question_index: 0, - type: 0 - } - ], - skip_type: 1, - id: '28fe4d64-81eb-4937-a082-c519ac74374f', - question_index: 24, - question_id: '17852294' - }, - { - logic: [ - { - operator: '=', - is_answer: 1, - question_type: 1, - logic: 'always' - } - ], - skip_type: 1, - id: '459f781f-8db0-4663-b2d1-9ddad627078e', - question_index: 24, - question_id: '17852294' - } - ], - + logics: [], questions: [], cycle_pages: null } }), actions: { async fetchQuestionInfo(questionInfo) { + console.log(questionInfo, 456); try { if (!questionInfo) return; @@ -276,6 +70,8 @@ export const useCommonStore = defineStore('common', { } }, setQuestionInfo(questionInfo) { + console.log(questionInfo, 9998); + console.log(this); this.questionsInfo = questionInfo; } }, diff --git a/src/utils/request.js b/src/utils/request.js index 93bd32c..16fd215 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -4,13 +4,9 @@ import axios from 'axios'; // import { A_COMMON_CLEAR_TOKEN } from '@/stores/constance/constance.common.js'; import * as config from '@/config.js'; - -console.log(config.default); // import {proxyUrl} from config.default -// - const NODE_ENV = import.meta.env.VITE_APP_ENV; -const baseURL = NODE_ENV === 'production' ? config.default.proxyUrl : '/backend-api'; +const baseURL = NODE_ENV === 'production' ? config.default.proxyUrl : 'http://192.168.8.165:15011/'; // axios.defaults.withCredentials = true; @@ -31,7 +27,8 @@ service.interceptors.request.use( if (!config.headers.remoteIp) { config.baseURL += '/api'; } - // config.headers.remoteIp = localStorage.getItem('plantIp') || '127.0.0.1'; + delete config.headers.host; + config.headers.remoteIp = localStorage.getItem('plantIp') || '127.0.0.1'; // if (store.state.common.token) { // config.headers['Login-Type'] = 'pc'; // config.headers.Authorization = `Bearer ${store.state.common.token}`; @@ -45,10 +42,10 @@ service.interceptors.request.use( service.interceptors.response.use( (response) => { if ( - response.status === 200 || - response.status === 201 || - response.status === 202 || - response.status === 204 + response.status === 200 + || response.status === 201 + || response.status === 202 + || response.status === 204 ) { if (response.config.method === 'put') { // message.success('保存中...'); diff --git a/src/views/Home/components/CreateSurvey/Hooks/useRequestHooks.ts b/src/views/Home/components/CreateSurvey/Hooks/useRequestHooks.ts index ea5d31c..908dcac 100644 --- a/src/views/Home/components/CreateSurvey/Hooks/useRequestHooks.ts +++ b/src/views/Home/components/CreateSurvey/Hooks/useRequestHooks.ts @@ -1,27 +1,39 @@ export const surveys = [ { title: '报名签到', - icon: 'https://files.axshare.com/gsc/DR6075/de/a0/49/dea049d6ad3e4c2c80af44258c6c76d6/images/%E9%A6%96%E9%A1%B5_1/u48.png?pageId=74b3e5b2-848e-4258-8a34-9e220127c8a6' + icon: 'https://files.axshare.com/gsc/DR6075/de/a0/49/dea049d6ad3e4c2c80af44258c6c76d6/images/%E9%A6%96%E9%A1%B5_1/u48.png?pageId=74b3e5b2-848e-4258-8a34-9e220127c8a6', + scene_code: 1, + scene_code_info: 11 }, { title: '满意度调研', - icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/%E9%A6%96%E9%A1%B5_1/u27.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64' + icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/%E9%A6%96%E9%A1%B5_1/u27.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64', + scene_code: 1, + scene_code_info: 16 }, { title: '快速投票', - icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u29.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64' + icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u29.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64', + scene_code: 1, + scene_code_info: 13 }, { title: '打分评估', - icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u31.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64' + icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u31.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64', + scene_code: 1, + scene_code_info: 14 }, { title: 'NPS调研', - icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u22.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64' + icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u22.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64', + scene_code: 1, + scene_code_info: 17 }, { title: '考评测试', - icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u24.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64' + icon: 'https://files.axshare.com/gsc/DR6075/63/4d/77/634d77293a4d41d1b3d145974a8fb6a7/images/首页_1/u24.png?pageId=5cc10b9f-56eb-48dc-943a-bfe7afb18a64', + scene_code: 1, + scene_code_info: 15 }, { title: '表单收集', diff --git a/src/views/Home/components/CreateSurvey/Index.vue b/src/views/Home/components/CreateSurvey/Index.vue index a31b9c1..cd8adb2 100644 --- a/src/views/Home/components/CreateSurvey/Index.vue +++ b/src/views/Home/components/CreateSurvey/Index.vue @@ -1,17 +1,70 @@