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

This commit is contained in:
dayou 2024-01-11 14:06:12 +08:00 committed by GitHub
parent d01d50a9d5
commit 67d373bf88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 16 deletions

View File

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

View File

@ -25,7 +25,7 @@
<div slot="footer" class="dialog-footer">
<el-button type="primary" class="save-btn" @click="onSave"
>保存</el-button
>{{ type === QOP_MAP.EDIT ? '保存' : '确定' }}</el-button
>
</div>
</el-dialog>
@ -33,18 +33,21 @@
<script>
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 { QOP_MAP } from '@/management/utils/constant'
export default {
name: 'modifyDialog',
props: {
type: String,
questionInfo: Object,
width: String,
visible: Boolean,
},
data() {
return {
QOP_MAP,
loadingInstance: null,
rules: {
title: [{ required: true, message: '请输入问卷标题', trigger: 'blur' }],
@ -70,19 +73,54 @@ export default {
this.$emit('on-close-codify');
},
async onSave() {
const res = await updateSurvey({
surveyId: this.questionInfo._id,
...this.current,
});
if (res.code === CODE_MAP.SUCCESS) {
this.$message.success('修改成功');
if(this.type === QOP_MAP.COPY) {
await this.handleCopy()
} else {
this.$message.error(res.errmsg);
await this.handleUpdate()
}
this.$emit('on-close-codify', 'update');
},
async handleUpdate() {
try {
const res = await updateSurvey({
surveyId: this.questionInfo._id,
...this.current,
});
if (res.code === CODE_MAP.SUCCESS) {
this.$message.success('修改成功');
} else {
this.$message.error(res.errmsg);
}
} catch (err) {
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>

View File

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

View File

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