refactor(home): 重构首页组件和 API 接口
- 新增 consoleSurveys 和 useTemplate API 接口 - 优化 create-survey 组件,支持创建新页面和使用模板 - 更新 last-survey 和 market 组件,使用新的 API 接口 -重构 home 页面,统一处理用户信息获取和错误处理 - 更新类型声明,添加 Element Plus 和 Vant 组件
This commit is contained in:
11
components.d.ts
vendored
11
components.d.ts
vendored
@@ -8,9 +8,15 @@ export {}
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
Contenteditable: typeof import('./src/components/contenteditable.vue')['default']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElDropdown: typeof import('element-plus/es')['ElDropdown']
|
||||
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
|
||||
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
|
||||
ElInput: typeof import('element-plus/es')['ElInput']
|
||||
ElOption: typeof import('element-plus/es')['ElOption']
|
||||
ElSelect: typeof import('element-plus/es')['ElSelect']
|
||||
ElSpace: typeof import('element-plus/es')['ElSpace']
|
||||
ElText: typeof import('element-plus/es')['ElText']
|
||||
RichText: typeof import('./src/components/RichText.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
@@ -23,6 +29,8 @@ declare module 'vue' {
|
||||
VanCol: typeof import('vant/es')['Col']
|
||||
VanDivider: typeof import('vant/es')['Divider']
|
||||
VanField: typeof import('vant/es')['Field']
|
||||
VanGrid: typeof import('vant/es')['Grid']
|
||||
VanGridItem: typeof import('vant/es')['GridItem']
|
||||
VanIcon: typeof import('vant/es')['Icon']
|
||||
VanNavBar: typeof import('vant/es')['NavBar']
|
||||
VanPicker: typeof import('vant/es')['Picker']
|
||||
@@ -30,9 +38,12 @@ declare module 'vue' {
|
||||
VanRadio: typeof import('vant/es')['Radio']
|
||||
VanRadioGroup: typeof import('vant/es')['RadioGroup']
|
||||
VanRow: typeof import('vant/es')['Row']
|
||||
VanSearch: typeof import('vant/es')['Search']
|
||||
VanStepper: typeof import('vant/es')['Stepper']
|
||||
VanSwitch: typeof import('vant/es')['Switch']
|
||||
VanTab: typeof import('vant/es')['Tab']
|
||||
VanTabbar: typeof import('vant/es')['Tabbar']
|
||||
VanTabbarItem: typeof import('vant/es')['TabbarItem']
|
||||
VanTabs: typeof import('vant/es')['Tabs']
|
||||
YLCascader: typeof import('./src/components/YLCascader.vue')['default']
|
||||
YLInput: typeof import('./src/components/YLInput.vue')['default']
|
||||
|
||||
@@ -8,6 +8,14 @@ export function getQuestionList(params) {
|
||||
});
|
||||
}
|
||||
export function consoleSurveys(params) {
|
||||
return request({
|
||||
url: '/console/surveys',
|
||||
method: 'post',
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
export function getSurveysPage(params) {
|
||||
return request({
|
||||
url: '/console/surveys',
|
||||
method: 'get',
|
||||
@@ -29,3 +37,11 @@ export function getSurveyTemplates(params) {
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
export function useTemplate(sn, params) {
|
||||
return request({
|
||||
url: `console/templates/${sn}`,
|
||||
method: 'post',
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.van-nav-bar {
|
||||
padding-top: calc(var(--status-bar-height) + 15px) !important;
|
||||
z-index:999;
|
||||
padding-top: calc(var(--status-bar-height) + 15px) !important;
|
||||
}
|
||||
|
||||
.van-cell {
|
||||
|
||||
@@ -19,7 +19,7 @@ import appBridge from '@/assets/js/appBridge';
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
function goBack () {
|
||||
function goBack() {
|
||||
if (window.history.length > 1 && route.meta.title !== '伊调研') {
|
||||
router.go(-1);
|
||||
} else {
|
||||
|
||||
@@ -21,7 +21,7 @@ service.interceptors.request.use(
|
||||
config.headers.Accept = 'application/json';
|
||||
}
|
||||
config.headers.Authorization = `${localStorage.getItem('plantToken')}`;
|
||||
config.headers.Source = 1
|
||||
config.headers.Source = 1;
|
||||
// if (!config.headers.remoteIp) {
|
||||
// config.baseURL += '/api';
|
||||
// }
|
||||
|
||||
@@ -26,7 +26,7 @@ service.interceptors.request.use(
|
||||
config.headers.Accept = 'application/json';
|
||||
}
|
||||
config.headers.Authorization = `${localStorage.getItem('plantToken')}`;
|
||||
config.headers.Source = 1
|
||||
config.headers.Source = 1;
|
||||
// if (!config.headers.remoteIp) {
|
||||
// config.baseURL += '/api';
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<template>
|
||||
<van-field v-model="element.stem" :label="element.stem" :required="element.config.is_required === 1" label-align="top"
|
||||
class="contenteditable-question-title base-select">
|
||||
<van-field
|
||||
v-model="element.stem" :label="element.stem" :required="element.config.is_required === 1" label-align="top"
|
||||
class="contenteditable-question-title base-select"
|
||||
>
|
||||
<template #left-icon>
|
||||
{{ index + 1 }}
|
||||
</template>
|
||||
@@ -11,11 +13,15 @@
|
||||
<template #input>
|
||||
<template v-for="(item, optionIndex) in element.options" :key="item.id">
|
||||
<van-radio-group v-if="element.question_type === 1" v-model="choiceValue">
|
||||
<option-action :data="isPreview ? item.options : item" :active="active" :question="element"
|
||||
handle=".moverQues">
|
||||
<option-action
|
||||
:data="isPreview ? item.options : item" :active="active" :question="element"
|
||||
handle=".moverQues"
|
||||
>
|
||||
<template #item="{ element: it, index: itIndex }">
|
||||
<van-radio :key="itIndex" :name="it.option_index" :label="it.label" :disabled="it.disabled"
|
||||
icon-size="0.45rem">
|
||||
<van-radio
|
||||
:key="itIndex" :name="it.option_index" :label="it.label" :disabled="it.disabled"
|
||||
icon-size="0.45rem"
|
||||
>
|
||||
<!-- 自定义文本 -->
|
||||
<template #default>
|
||||
<div class="flex align-center van-cell">
|
||||
@@ -37,11 +43,15 @@
|
||||
</van-radio-group>
|
||||
|
||||
<van-checkbox-group v-if="element.question_type === 2" v-model="value" shape="square">
|
||||
<option-action v-model:data="element.options[optionIndex]" handle=".moverQues" :active="active"
|
||||
:question="element">
|
||||
<option-action
|
||||
v-model:data="element.options[optionIndex]" handle=".moverQues" :active="active"
|
||||
:question="element"
|
||||
>
|
||||
<template #item="{ element: it, index: itIndex }">
|
||||
<van-checkbox :key="itIndex" :name="it.option_index" :label="it.label" :disabled="it.disabled"
|
||||
icon-size="0.45rem">
|
||||
<van-checkbox
|
||||
:key="itIndex" :name="it.option_index" :label="it.label" :disabled="it.disabled"
|
||||
icon-size="0.45rem"
|
||||
>
|
||||
<template #default>
|
||||
<div class="flex align-center van-cell">
|
||||
<contenteditable v-model="it.option" className="contenteditable-input" :active="active">
|
||||
@@ -106,7 +116,6 @@ const emitValue = () => {
|
||||
}
|
||||
|
||||
.base-select {
|
||||
|
||||
& .van-checkbox-group,
|
||||
.van-radio-group {
|
||||
width: 100%;
|
||||
|
||||
@@ -12,20 +12,24 @@ const show = ref(false);
|
||||
onMounted(async() => {
|
||||
if (utils.getSessionStorage('xToken')) {
|
||||
const appToken = utils.getSessionStorage('xToken');
|
||||
getUserInfo(appToken).then((res) => {
|
||||
if (res.data) {
|
||||
contentShow.value = true;
|
||||
let token = res.data.data.token;
|
||||
localStorage.setItem('plantToken',token)
|
||||
utils.setSessionStorage('userInfo', res.data.data);
|
||||
} else {
|
||||
getUserInfo(appToken)
|
||||
.then((res) => {
|
||||
if (res.data) {
|
||||
contentShow.value = true;
|
||||
const token = res.data.data.token;
|
||||
localStorage.setItem('plantToken', token);
|
||||
utils.setSessionStorage('userInfo', res.data.data);
|
||||
} else {
|
||||
contentShow.value = false;
|
||||
showFailToast(
|
||||
error.response.data?.message || error.data?.message || error.message || '服务器错误'
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
contentShow.value = false;
|
||||
showFailToast(error.response.data?.message || error.data?.message || error.message || '服务器错误');
|
||||
}
|
||||
}).catch((error) => {
|
||||
contentShow.value = false;
|
||||
showFailToast(error?.response?.data?.message || error?.message || '服务器错误');
|
||||
});
|
||||
showFailToast(error?.response?.data?.message || error?.message || '服务器错误');
|
||||
});
|
||||
} else {
|
||||
contentShow.value = true;
|
||||
}
|
||||
@@ -37,7 +41,7 @@ function create() {
|
||||
|
||||
<template>
|
||||
<div v-if="contentShow" class="container">
|
||||
<create-survey />
|
||||
<create-survey :createdNewPage="false" />
|
||||
<!-- 最新问卷 -->
|
||||
<last-survey />
|
||||
<!-- 模板市场 -->
|
||||
@@ -49,7 +53,7 @@ function create() {
|
||||
</div>
|
||||
</div>
|
||||
<van-popup v-model:show="show" round closeable position="bottom">
|
||||
<CreateSurvey></CreateSurvey>
|
||||
<CreateSurvey :createdNewPage="true"></CreateSurvey>
|
||||
</van-popup>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { consoleSurveys, getQuestionList } from '@/api/home/index.js';
|
||||
import { consoleSurveys, getQuestionList, useTemplate } from '@/api/home/index.js';
|
||||
import { snQuestions, saveQuestions } from '@/api/design/index.js';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useCounterStore } from '@/stores/counter';
|
||||
@@ -12,35 +12,70 @@ const store = storeToRefs(counterStore);
|
||||
const router = useRouter();
|
||||
const surveys = ref([]);
|
||||
|
||||
const createdNewPage = defineModel('createdNewPage', {
|
||||
type: Boolean,
|
||||
default: false
|
||||
});
|
||||
const createdQuestion = (item) => {
|
||||
const query = {
|
||||
group_id: 0,
|
||||
project_name: `${item.title}问卷 `,
|
||||
remarks: '',
|
||||
scene_code: item.scene_code,
|
||||
scene_code_info: item.scene_code_info,
|
||||
scene_code: item.parentCode,
|
||||
scene_code_info: item.code,
|
||||
// 很迷茫 模板新增 tag 空数组 非模板 就是k
|
||||
tags: ''
|
||||
};
|
||||
consoleSurveys(query).then((res) => {
|
||||
if (res.data) {
|
||||
snQuestions({ sn: res.data.data.sn }).then((ques) => {
|
||||
if (ques.data) {
|
||||
ques.data.data.survey.introduction = `<p>为优化活动服务品质,烦请完成问卷,感谢配合!您的反馈至关重要!(此提示语为默认提示语,您可选择自行输入本问卷的提示语)</p>`;
|
||||
store.questionsInfo.value = ques.data.data;
|
||||
saveQuestions({
|
||||
sn: res.data.data.sn,
|
||||
introduction: ques.data.data.survey.introduction,
|
||||
title: ques.data.data.survey.title
|
||||
}).then(() => {
|
||||
router.push({
|
||||
path: '/create',
|
||||
query: {
|
||||
sn: res.data.data.sn
|
||||
}
|
||||
});
|
||||
});
|
||||
if (createdNewPage.value) {
|
||||
query.scene_code = item.parentCode;
|
||||
query.tags = '';
|
||||
} else {
|
||||
if (item.sn) {
|
||||
query.scene_code = null;
|
||||
query.tags = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 如果放在了底部 当作新增组件
|
||||
if (createdNewPage.value) {
|
||||
consoleSurveys(query).then((res) => {
|
||||
if (res.data) {
|
||||
createdApx(res);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (item.sn) {
|
||||
useTemplate(item.sn, query).then((temp) => {
|
||||
if (temp.data) {
|
||||
createdApx(temp);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
consoleSurveys(query).then((res) => {
|
||||
if (res.data) {
|
||||
createdApx(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
const createdApx = (res) => {
|
||||
snQuestions({ sn: res.data.data.sn }).then((ques) => {
|
||||
if (ques.data) {
|
||||
ques.data.data.survey.introduction = `<p>为优化活动服务品质,烦请完成问卷,感谢配合!您的反馈至关重要!(此提示语为默认提示语,您可选择自行输入本问卷的提示语)</p>`;
|
||||
store.questionsInfo.value = ques.data.data;
|
||||
saveQuestions({
|
||||
sn: res.data.data.sn,
|
||||
introduction: ques.data.data.survey.introduction,
|
||||
title: ques.data.data.survey.title
|
||||
}).then(() => {
|
||||
router.push({
|
||||
path: '/create',
|
||||
query: {
|
||||
sn: res.data.data.sn
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -41,18 +41,18 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { consoleSurveys } from '@/api/home/index.js';
|
||||
import { getSurveysPage } from '@/api/home/index.js';
|
||||
|
||||
const survey = ref({
|
||||
project_name: ''
|
||||
});
|
||||
const fetchSurveys = async() => {
|
||||
const fetchSurveys = async () => {
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 10,
|
||||
group_id: 0
|
||||
};
|
||||
const res = await consoleSurveys(params);
|
||||
const res = await getSurveysPage(params);
|
||||
if (res.data.code === 0) {
|
||||
survey.value = res.data.data[0];
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ const marketList = ref([]);
|
||||
const active = ref(null);
|
||||
const marketInfo = ref([]);
|
||||
|
||||
const getTableList = async() => {
|
||||
const getTableList = async () => {
|
||||
const res = await getListScene();
|
||||
if (res.data.code === 0) {
|
||||
res.data.data.forEach((item) => {
|
||||
@@ -28,23 +28,24 @@ const getTableList = async() => {
|
||||
marketList.value.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
getMarketInfo(marketList.value[0]);
|
||||
}
|
||||
};
|
||||
const getMarketInfo = async(item) => {
|
||||
const code = marketList.value.filter((market, index) => item === index)[0].code;
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 10,
|
||||
group_id: 0,
|
||||
is_public: 1,
|
||||
scene_code_info: code,
|
||||
sort: 'quote_nums, desc'
|
||||
};
|
||||
const res = await getSurveyTemplates(params);
|
||||
if (res.data.code === 0) {
|
||||
marketInfo.value = res.data.data;
|
||||
const getMarketInfo = async (item) => {
|
||||
const data = marketList.value.filter((market, index) => item === index)[0];
|
||||
if (data) {
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 10,
|
||||
group_id: 0,
|
||||
is_public: 1,
|
||||
scene_code_info: data.code,
|
||||
sort: 'quote_nums, desc'
|
||||
};
|
||||
const res = await getSurveyTemplates(params);
|
||||
if (res.data.code === 0) {
|
||||
marketInfo.value = res.data.data;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user