题目批量删除以及搜索限制

This commit is contained in:
caoqianming 2021-12-12 23:16:01 +08:00
parent 301d2ce174
commit 9d625e76ac
3 changed files with 45 additions and 3 deletions

View File

@ -108,6 +108,13 @@ export function deleteQuestion(id) {
method: 'delete',
})
}
export function deleteQuestions(data) {
return request({
url: `/question/question/deletes/`,
method: 'post',
data
})
}
export function importQuestion(data) {
return request({
url: `/question/question/import/`,

View File

@ -70,6 +70,12 @@
<el-button slot="reference">Excel导入</el-button>
</el-popover>
<el-button type="primary" icon="el-icon-download" @click="exportQuestion">导出Excel</el-button>
<el-button
type="danger"
@click="handleDeletes(scope)"
icon="el-icon-delete"
v-if="checkPermission(['question_delete'])"
>批量删除</el-button>
</div>
</div>
<el-table
@ -168,7 +174,8 @@ import {
deleteQuestion,
importQuestion,
exportQuestion,
enableQuestions
enableQuestions,
deleteQuestions
} from "@/api/question";
import { genTree, deepClone } from "@/utils";
import checkPermission from "@/utils/permission";
@ -307,6 +314,16 @@ export default {
// console.error(err);
});
},
handleDeletes(){
if (this.selects.length) {
deleteQuestions({ids:this.selects}).then(res=>{
this.$message.success("成功");
this.getList();
})
} else {
this.$message.warning("请先选择题目");
}
},
exportQuestion() {
const loading = this.$loading({
text:'正在准备..'

View File

@ -6,13 +6,13 @@ from rest_framework import status
from rest_framework.decorators import action, permission_classes
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework.generics import GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from crm.models import PaySubject
from crm.models import Consumer, PaySubject
from examtest.models import WorkScope
from server import settings
from utils.custom import CommonPagination
@ -116,6 +116,13 @@ class QuestionViewSet(ModelViewSet):
ret['panduan'] = queryset.filter(type='判断').count()
return Response(ret)
def get_queryset(self):
user = self.request.user
if isinstance(user, Consumer):
questioncats = user.workscope.questioncat.all()
self.queryset = self.queryset.filter(questioncat__in = questioncats)
return super().get_queryset()
@action(methods=['get'], detail=False,
url_path='export', url_name='export_question', perms_map=[{'*':'export_question'}])
def export(self, request):
@ -143,6 +150,17 @@ class QuestionViewSet(ModelViewSet):
i.save()
return Response()
@action(methods=['post'], detail=False, perms_map=[{'*':'question_delete'}])
def deletes(self, request):
"""
批量删除
"""
ids = request.data.get('ids', [])
if request.user.is_superuser:
Question.objects.filter(id__in=ids).update(is_delete=True)
return Response()
return Response({'error':'权限不足'})
@action(methods=['post'], detail=False, url_name='enable_question', permission_classes=[IsAuthenticated])
def enable(self, request):
ids = request.data.get('ids',None)