Skip to content

Commit

Permalink
Merge branch 'develop' into fix/surveditV2
Browse files Browse the repository at this point in the history
  • Loading branch information
skique authored Dec 30, 2024
2 parents 19dc921 + 2aefaff commit 0d6eef4
Show file tree
Hide file tree
Showing 40 changed files with 1,851 additions and 26 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

**3、能力增强**

  在线平台:建设中、智能化问卷:规划中
  智能化问卷:规划中

# 项目优势

Expand Down Expand Up @@ -128,17 +128,35 @@

# 快速使用

_(在线平台建设中)_
快速试用:https://xiaojuwenjuan.com/render/LWpBOxRx

在线平台:https://xiaojuwenjuan.com

# 本地开发

请查看 [本地安装手册](https://xiaojusurvey.didi.cn/docs/next/document/%E6%A6%82%E8%BF%B0/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B) 来启动项目。

```
// 服务启动
cd server
npm install
npm run local
// 页面启动
cd web
npm install
npm run serve
// B端 http://localhost:8080/management
// C端 http://localhost:8080/render/:surveyPath
```

# 快速部署

### 服务部署

请查看 [快速部署指导](https://xiaojusurvey.didi.cn/docs/next/document/%E5%B7%A5%E7%A8%8B%E9%83%A8%E7%BD%B2/Docker%E9%83%A8%E7%BD%B2)
请查看 [部署指导](https://xiaojusurvey.didi.cn/docs/next/document/%E5%B7%A5%E7%A8%8B%E9%83%A8%E7%BD%B2/Docker%E9%83%A8%E7%BD%B2)

### 一键部署

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- xiaoju-survey

xiaoju-survey:
image: "xiaojusurvey/xiaoju-survey:1.3.0-slim" # 最新版本:https://hub.docker.com/r/xiaojusurvey/xiaoju-survey/tags
image: "xiaojusurvey/xiaoju-survey:1.3.1-slim" # 最新版本:https://hub.docker.com/r/xiaojusurvey/xiaoju-survey/tags
container_name: xiaoju-survey
restart: always
ports:
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xiaoju-survey-server",
"version": "1.3.0",
"version": "1.3.1",
"description": "XIAOJUSURVEY的server端",
"author": "",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions server/src/enums/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export enum QUESTION_TYPE {
* 投票
*/
VOTE = 'vote',
/**
* 多级联动
*/
CASCADER = 'cascader',
}
15 changes: 15 additions & 0 deletions server/src/interfaces/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export interface NPS {
rightText: string;
}

export interface CascaderItem {
hash: string;
text: string;
children?: CascaderItem[];
}

export interface CascaderDate {
placeholder: Array<{
hash: string;
text: string;
}>;
children: Array<CascaderItem>;
}

export interface TextRange {
min: {
placeholder: string;
Expand Down Expand Up @@ -60,6 +74,7 @@ export interface DataItem {
rangeConfig?: any;
starStyle?: string;
innerType?: string;
cascaderData: CascaderDate;
}

export interface Option {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class DataStatisticController {
QUESTION_TYPE.RADIO_STAR,
QUESTION_TYPE.RADIO_NPS,
QUESTION_TYPE.VOTE,
QUESTION_TYPE.CASCADER,
];
const fieldList = responseSchema.code.dataConf.dataList
.filter((item) => allowQuestionType.includes(item.type as QUESTION_TYPE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class SurveyGroupController {
const surveyTotalList = await Promise.all(
groupIdList.map((item) => {
return this.surveyMetaService.countSurveyMetaByGroupId({
userId,
groupId: item,
});
}),
Expand All @@ -95,6 +96,7 @@ export class SurveyGroupController {
return pre;
}, {});
const notTotal = await this.surveyMetaService.countSurveyMetaByGroupId({
userId,
groupId: null,
});
return {
Expand Down
15 changes: 15 additions & 0 deletions server/src/modules/survey/services/dataStatistic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ export class DataStatisticService {
.join(',')
: optionTextMap[data[itemKey]]?.text || data[itemKey];
}
// 将多级联动id还原成选项文案
if (
itemConfig.cascaderData &&
itemConfig.type === QUESTION_TYPE.CASCADER
) {
let optionTextMap = keyBy(itemConfig.cascaderData.children, 'hash');
data[itemKey] = data[itemKey]
?.split(',')
.map((v) => {
const text = optionTextMap[v]?.text || v;
optionTextMap = keyBy(optionTextMap[v].children, 'hash');
return text;
})
.join('-');
}
}
return {
...data,
Expand Down
5 changes: 3 additions & 2 deletions server/src/modules/survey/services/surveyMeta.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class SurveyMetaService {
}
if (groupId && groupId !== 'all') {
query.groupId =
groupId === 'nogrouped'
groupId === 'unclassified'
? {
$exists: true,
$eq: null,
Expand Down Expand Up @@ -248,8 +248,9 @@ export class SurveyMetaService {
});
return total;
}
async countSurveyMetaByGroupId({ groupId }) {
async countSurveyMetaByGroupId({ groupId, userId = undefined }) {
const total = await this.surveyRepository.count({
ownerId: userId,
groupId,
$or: [
{ workspaceId: { $exists: false } },
Expand Down
43 changes: 43 additions & 0 deletions server/src/modules/survey/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function handleAggretionData({ dataMap, item }) {
title: dataMap[item.field].title,
type: dataMap[item.field].type,
data: {
...item.data,
aggregation: arr.map((item) => {
const num = item.toString();
return {
Expand All @@ -173,6 +174,27 @@ export function handleAggretionData({ dataMap, item }) {
summary,
},
};
} else if (type == QUESTION_TYPE.CASCADER) {
const aggregation = getTextPaths(
dataMap[item.field].cascaderData.children,
);
return {
...item,
title: dataMap[item.field].title,
type: dataMap[item.field].type,
data: {
...item.data,
aggregation: aggregation
.map((item) => {
return {
id: item.id,
text: item.text,
count: aggregationMap[item.id]?.count || 0,
};
})
.filter((v) => v.count > 0),
},
};
} else {
return {
...item,
Expand All @@ -182,6 +204,27 @@ export function handleAggretionData({ dataMap, item }) {
}
}

const getTextPaths = (arr, textPrefix = '', idPrefix = '') => {
let paths = [];

arr.forEach((item) => {
const currentTextPath = textPrefix
? `${textPrefix}-${item.text}`
: item.text;
const currentIdPath = idPrefix ? `${idPrefix},${item.hash}` : item.hash;

if (item.children && item.children.length > 0) {
paths = paths.concat(
getTextPaths(item.children, currentTextPath, currentIdPath),
);
} else {
paths.push({ id: currentIdPath, text: currentTextPath });
}
});

return paths;
};

function getAverage({ aggregation }) {
const { sum, count } = aggregation.reduce(
(pre, cur) => {
Expand Down
5 changes: 3 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xiaoju-survey-web",
"version": "1.3.0",
"version": "1.3.1",
"description": "XIAOJUSURVEY的web端,包含B端和C端应用",
"type": "module",
"scripts": {
Expand All @@ -22,13 +22,14 @@
"axios": "^1.4.0",
"clipboard": "^2.0.11",
"crypto-js": "^4.2.0",
"default-passive-events": "^2.0.0",
"echarts": "^5.5.0",
"element-plus": "^2.8.5",
"lodash-es": "^4.17.21",
"moment": "^2.29.4",
"nanoid": "^5.0.7",
"node-forge": "^1.3.1",
"pinia": "^2.1.7",
"pinia": "2.2.7",
"qrcode": "^1.5.3",
"uuid": "^10.0.0",
"vue": "^3.4.15",
Expand Down
Binary file not shown.
Binary file not shown.
9 changes: 7 additions & 2 deletions web/src/common/typeEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export enum QUESTION_TYPE {
BINARY_CHOICE = 'binary-choice',
RADIO_STAR = 'radio-star',
RADIO_NPS = 'radio-nps',
VOTE = 'vote'
VOTE = 'vote',
CASCADER = 'cascader',
}

// 题目类型标签映射对象
Expand All @@ -19,7 +20,8 @@ export const typeTagLabels: Record<QUESTION_TYPE, string> = {
[QUESTION_TYPE.BINARY_CHOICE]: '判断',
[QUESTION_TYPE.RADIO_STAR]: '评分',
[QUESTION_TYPE.RADIO_NPS]: 'NPS评分',
[QUESTION_TYPE.VOTE]: '投票'
[QUESTION_TYPE.VOTE]: '投票',
[QUESTION_TYPE.CASCADER]: '多级联动'
}

// 输入类题型
Expand All @@ -38,3 +40,6 @@ export const CHOICES = [

// 评分题题型分类
export const RATES = [QUESTION_TYPE.RADIO_STAR, QUESTION_TYPE.RADIO_NPS]

// 高级题型分类
export const ADVANCED = [QUESTION_TYPE.CASCADER]
10 changes: 10 additions & 0 deletions web/src/management/config/questionMenuConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export const menuItems = {
snapshot: '/imgs/question-type-snapshot/nGTscsZlwn1657702222857.webp',
icon: 'tixing-toupiao',
title: '投票'
},
cascader: {
type: 'cascader',
path: 'CascaderModule',
snapshot: '/imgs/question-type-snapshot/cascader.webp',
icon: 'cascader-select',
title: '多级联动'
}
}

Expand All @@ -65,6 +72,9 @@ const menuGroup = [
{
title: '选择类题型',
questionList: ['radio', 'checkbox', 'binary-choice', 'radio-star', 'radio-nps', 'vote']
}, {
title: '高级题型',
questionList: ['cascader']
}
]

Expand Down
Loading

0 comments on commit 0d6eef4

Please sign in to comment.