feat: 列表页新增复制功能 (#42)

This commit is contained in:
dayou 2024-01-11 14:06:12 +08:00 committed by sudoooooo
parent 908537ea0b
commit 31ddefba16
5 changed files with 75 additions and 16 deletions

View File

@ -49,3 +49,7 @@ export const deleteSurvey = (surveyId) => {
export const updateSurvey = (data) => { export const updateSurvey = (data) => {
return axios.post('/surveyManage/update', data); return axios.post('/surveyManage/update', data);
}; };
export const copySurvey = (data) => {
return axios.post('/surveyManage/create', data);
};

View File

@ -40,7 +40,7 @@
:data="scope.row" :data="scope.row"
type="list" type="list"
:tools="getToolConfig(scope.row)" :tools="getToolConfig(scope.row)"
:tool-width="65" :tool-width="50"
@on-delete="onDelete" @on-delete="onDelete"
@on-modify="onModify" @on-modify="onModify"
/> />
@ -63,6 +63,7 @@
</div> </div>
<modify-dialog <modify-dialog
:type="modifyType"
:visible="showModify" :visible="showModify"
:question-info="questionInfo" :question-info="questionInfo"
@on-close-codify="onCloseModify" @on-close-codify="onCloseModify"
@ -84,7 +85,7 @@ import State from './state';
import ToolBar from './toolBar'; import ToolBar from './toolBar';
import { fieldConfig, thead, noListDataConfig } from '../config'; import { fieldConfig, thead, noListDataConfig } from '../config';
import { CODE_MAP } from '@/management/api/base'; import { CODE_MAP } from '@/management/api/base';
import { QOP_MAP } from '@/management/utils/constant';
import { getSurveyList, deleteSurvey } from '@/management/api/survey'; import { getSurveyList, deleteSurvey } from '@/management/api/survey';
export default { export default {
@ -92,6 +93,7 @@ export default {
data() { data() {
return { return {
fields: ['type', 'title', 'remark', 'creator', 'state', 'updateDate', 'createDate'], fields: ['type', 'title', 'remark', 'creator', 'state', 'updateDate', 'createDate'],
modifyType: QOP_MAP.EDIT,
showModify: false, showModify: false,
loading: false, loading: false,
theadDict: thead, theadDict: thead,
@ -152,7 +154,7 @@ export default {
getToolConfig() { getToolConfig() {
const funcList = [ const funcList = [
{ {
key: 'edit', key: QOP_MAP.EDIT,
label: '修改', label: '修改',
}, },
{ {
@ -168,6 +170,11 @@ export default {
label: '删除', label: '删除',
icon: 'icon-shanchu', icon: 'icon-shanchu',
}, },
{
key: QOP_MAP.COPY,
label: '复制',
icon: 'icon-shanchu',
}
]; ];
return funcList; return funcList;
}, },
@ -192,8 +199,9 @@ export default {
this.currentPage = current; this.currentPage = current;
this.init(); this.init();
}, },
onModify(data) { onModify(data, type = QOP_MAP.EDIT) {
this.showModify = true; this.showModify = true;
this.modifyType = type
this.questionInfo = data; this.questionInfo = data;
}, },
onCloseModify(type) { onCloseModify(type) {

View File

@ -25,7 +25,7 @@
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" class="save-btn" @click="onSave" <el-button type="primary" class="save-btn" @click="onSave"
>保存</el-button >{{ type === QOP_MAP.EDIT ? '保存' : '确定' }}</el-button
> >
</div> </div>
</el-dialog> </el-dialog>
@ -33,18 +33,21 @@
<script> <script>
import { CODE_MAP } from '@/management/api/base'; import { CODE_MAP } from '@/management/api/base';
import { updateSurvey } from '@/management/api/survey'; import { updateSurvey, copySurvey } from '@/management/api/survey';
import { pick as _pick } from 'lodash'; import { pick as _pick } from 'lodash';
import { QOP_MAP } from '@/management/utils/constant'
export default { export default {
name: 'modifyDialog', name: 'modifyDialog',
props: { props: {
type: String,
questionInfo: Object, questionInfo: Object,
width: String, width: String,
visible: Boolean, visible: Boolean,
}, },
data() { data() {
return { return {
QOP_MAP,
loadingInstance: null, loadingInstance: null,
rules: { rules: {
title: [{ required: true, message: '请输入问卷标题', trigger: 'blur' }], title: [{ required: true, message: '请输入问卷标题', trigger: 'blur' }],
@ -70,6 +73,17 @@ export default {
this.$emit('on-close-codify'); this.$emit('on-close-codify');
}, },
async onSave() { async onSave() {
if(this.type === QOP_MAP.COPY) {
await this.handleCopy()
} else {
await this.handleUpdate()
}
this.$emit('on-close-codify', 'update');
},
async handleUpdate() {
try {
const res = await updateSurvey({ const res = await updateSurvey({
surveyId: this.questionInfo._id, surveyId: this.questionInfo._id,
...this.current, ...this.current,
@ -80,9 +94,33 @@ export default {
} else { } else {
this.$message.error(res.errmsg); this.$message.error(res.errmsg);
} }
} catch (err) {
this.$emit('on-close-codify', 'update'); this.$message.error(err);
}
}, },
async handleCopy() {
try {
const res = await copySurvey({
createFrom: this.questionInfo._id,
createMethod: QOP_MAP.COPY,
...this.current,
});
if (res.code === CODE_MAP.SUCCESS) {
const { data } = res
this.$router.push({
name: 'QuestionEditIndex',
params: {
id: data.id,
},
});
} else {
this.$message.error(res.errmsg);
}
} catch(err) {
this.$message.error(err);
}
}
}, },
}; };
</script> </script>

View File

@ -15,6 +15,7 @@
</template> </template>
<script> <script>
import { QOP_MAP } from '@/management/utils/constant';
import Tool from './tool'; import Tool from './tool';
export default { export default {
@ -31,8 +32,11 @@ export default {
methods: { methods: {
onCall(val) { onCall(val) {
switch (val.key) { switch (val.key) {
case 'edit': case QOP_MAP.EDIT:
this.$emit('on-modify', this.data); this.$emit('on-modify', this.data, QOP_MAP.EDIT);
return;
case QOP_MAP.COPY:
this.$emit('on-modify', this.data, QOP_MAP.COPY);
return; return;
case 'analysis': case 'analysis':
this.$router.push({ this.$router.push({

View File

@ -0,0 +1,5 @@
// 问卷操作枚举
export const QOP_MAP = {
COPY: 'copy',
EDIT: 'edit',
};