question search

This commit is contained in:
caoqianming 2020-06-28 14:18:59 +08:00
parent 1837f67df5
commit 8c1f912bc6
11 changed files with 117 additions and 87 deletions

View File

@ -63,6 +63,10 @@
} }
] ]
}, },
"useExtendedLib": {
"kbone": true,
"weui": true
},
"style": "v2", "style": "v2",
"sitemapLocation": "sitemap.json" "sitemapLocation": "sitemap.json"
} }

View File

@ -5,9 +5,7 @@
<view class="weui-article"> <view class="weui-article">
<view class="weui-article__h2">{{tm_index+1}}. <view class="weui-article__h2">{{tm_index+1}}.
<span class="txlabel">{{tm_current.type}}</span> <span class="txlabel">{{tm_current.type}}</span>
</view> <span style="color:gray"> {{tm_current.questioncat_name}}</span>
<view style="text-align:center">
<span style="color:drakblue;font-weight:bold;font-size:14px">{{tm_current.questioncat_name}}</span>
</view> </view>
<view class="weui-article__title">{{tm_current.name}}</view> <view class="weui-article__title">{{tm_current.name}}</view>
<view wx:if="{{tm_current.img}}" style="text-align:center"><image src="{{tm_current.img}}" mode="aspectFit"></image></view> <view wx:if="{{tm_current.img}}" style="text-align:center"><image src="{{tm_current.img}}" mode="aspectFit"></image></view>

View File

@ -11,12 +11,10 @@
<view class="weui-article"> <view class="weui-article">
<view class="weui-article__h2">{{tm_index+1}}. <view class="weui-article__h2">{{tm_index+1}}.
<span class="txlabel">{{currentTm.type}}</span> <span class="txlabel">{{currentTm.type}}</span>
<span style="color:gray"> {{currentTm.questioncat_name}}</span>
</view> </view>
<view style="text-align:center"> <view style="text-align:center">
<span style="color:drakblue;font-weight:bold;font-size:14px">{{currentTm.questioncat_name}}</span>
(
<span style="color:orange;font-weight:bold;font-size:14px">{{currentTm.dtime}}</span> <span style="color:orange;font-weight:bold;font-size:14px">{{currentTm.dtime}}</span>
)
</view> </view>
<view class="weui-article__title">{{currentTm.name}}</view> <view class="weui-article__title">{{currentTm.name}}</view>
<view wx:if="{{currentTm.img}}" style="text-align:center"><image src="{{currentTm.img}}" mode="aspectFit"></image></view> <view wx:if="{{currentTm.img}}" style="text-align:center"><image src="{{currentTm.img}}" mode="aspectFit"></image></view>

View File

@ -42,6 +42,9 @@ Page({
background: images background: images
}) })
}) })
that.setData({
search: this.search.bind(this)
})
}, },
/** /**
@ -236,5 +239,18 @@ Page({
// }) // })
} }
}) })
} },
search: function (value) {
api.request('/question/question/', 'GET', {search:value}).then(res => {
})
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([{text: '搜索结果', value: 1}, {text: '搜索结果2', value: 2}])
}, 200)
})
},
selectResult: function (e) {
},
}) })

View File

@ -1,3 +1,5 @@
{ {
"usingComponents": {} "usingComponents": {
"mp-searchbar": "weui-miniprogram/searchbar/searchbar"
}
} }

View File

@ -1,76 +1,78 @@
<view class="page"> <view class="page">
<view class="page-section page-section-spacing swiper"> <view>
<swiper indicator-dots="{{indicatorDots}}" <mp-searchbar bindselectresult="selectResult" search="{{search}}" placeholder="搜题"></mp-searchbar>
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" style='height:{{Hei}}'>
<block wx:for="{{background}}" wx:key="*this">
<swiper-item>
<image style="width: 100%;" src="{{item}}" bindload='imgH'></image>
</swiper-item>
</block>
</swiper>
</view>
<swiper class="swiper_container" vertical="true" autoplay="true" circular="true" interval="3000">
<block wx:for="{{msgList}}" wx:key="title">
<swiper-item>
<view class="swiper_item">{{item.title}}</view>
</swiper-item>
</block>
</swiper>
<view class="weui-cells weui-cells_after-title">
<navigator url="/pages/quota/quota" class="weui-cell weui-cell_access" hover-class="weui-cell_active">
<view class="weui-cell__hd">
<image src="/images/quota.svg" style="margin-right: 16px;vertical-align: middle;width:20px; height: 20px;"></image>
</view>
<view class="weui-cell__bd">考试名额监控</view>
<view class="weui-cell__ft weui-cell__ft_in-access" style="color:red" >
<!-- <span wx:if="{{to_read}}">{{to_read}}条未读</span> -->
</view>
</navigator>
</view> </view>
<view class="weui-cells weui-cells_after-title"> <view class="page-section page-section-spacing swiper">
<view class="weui-grids"> <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" style='height:{{Hei}}'>
<a class="weui-grid" bindtap="goLianxi"> <block wx:for="{{background}}" wx:key="*this">
<view class="weui-grid__icon"> <swiper-item>
<image src="/images/suiji.svg" alt></image> <image style="width: 100%;" src="{{item}}" bindload='imgH'></image>
</view> </swiper-item>
<view class="weui-grid__label">练习</view> </block>
</a> </swiper>
<navigator class="weui-grid" url="/pages/cuoti/index"> </view>
<view class="weui-grid__icon"> <swiper class="swiper_container1" vertical="true" autoplay="true" circular="true" interval="3000">
<image src="/images/cuoti.svg" alt></image> <block wx:for="{{msgList}}" wx:key="title">
</view> <swiper-item>
<view class="weui-grid__label">错题集</view> <view class="swiper_item1">{{item.title}}</view>
</navigator> </swiper-item>
<navigator class="weui-grid" url="/pages/collect/main"> </block>
<view class="weui-grid__icon"> </swiper>
<image src="/images/shoucang.svg" alt></image> <view class="weui-cells weui-cells_after-title">
</view> <navigator url="/pages/quota/quota" class="weui-cell weui-cell_access" hover-class="weui-cell_active">
<view class="weui-grid__label">收藏集</view> <view class="weui-cell__hd">
</navigator> <image src="/images/quota.svg" style="margin-right: 16px;vertical-align: middle;width:20px; height: 20px;"></image>
</view>
<view class="weui-cell__bd">考试名额监控</view>
<view class="weui-cell__ft weui-cell__ft_in-access" style="color:red">
<!-- <span wx:if="{{to_read}}">{{to_read}}条未读</span> -->
</view>
</navigator>
</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-grids">
<a class="weui-grid" bindtap="goLianxi">
<view class="weui-grid__icon">
<image src="/images/suiji.svg" alt></image>
</view>
<view class="weui-grid__label">练习</view>
</a>
<navigator class="weui-grid" url="/pages/cuoti/index">
<view class="weui-grid__icon">
<image src="/images/cuoti.svg" alt></image>
</view>
<view class="weui-grid__label">错题集</view>
</navigator>
<navigator class="weui-grid" url="/pages/collect/main">
<view class="weui-grid__icon">
<image src="/images/shoucang.svg" alt></image>
</view>
<view class="weui-grid__label">收藏集</view>
</navigator>
<a class="weui-grid" bindtap="goMoni"> <a class="weui-grid" bindtap="goMoni">
<view class="weui-grid__icon"> <view class="weui-grid__icon">
<image src="/images/moni.svg" alt></image> <image src="/images/moni.svg" alt></image>
</view> </view>
<view class="weui-grid__label">自助模考</view> <view class="weui-grid__label">自助模考</view>
</a> </a>
<a class="weui-grid" bindtap="goYati"> <a class="weui-grid" bindtap="goYati">
<view class="weui-grid__icon" > <view class="weui-grid__icon">
<image src="/images/yati.svg" alt></image> <image src="/images/yati.svg" alt></image>
</view> </view>
<view class="weui-grid__label">押卷模考</view> <view class="weui-grid__label">押卷模考</view>
</a> </a>
<a class="weui-grid" bindtap="testList"> <a class="weui-grid" bindtap="testList">
<view class="weui-grid__icon" > <view class="weui-grid__icon">
<image src="/images/ksjl.svg" alt></image> <image src="/images/ksjl.svg" alt></image>
</view> </view>
<view class="weui-grid__label">考试记录</view> <view class="weui-grid__label">考试记录</view>
</a> </a>
</view> </view>
</view> </view>
<view style="margin-top:6px"> <view style="margin-top:6px">
<!-- <a class="weui-btn weui-btn_primary" bindtap="Baoming" >前往正式报名</a> --> <!-- <a class="weui-btn weui-btn_primary" bindtap="Baoming" >前往正式报名</a> -->
</view> </view>
</view> </view>

View File

@ -1,10 +1,10 @@
.swiper_container { .swiper_container1 {
margin-top:12rpx; margin-top:12rpx;
height: 50rpx; height: 50rpx;
width: 100%; width: 100%;
text-align: center text-align: center
} }
.swiper_item { .swiper_item1 {
font-size: 30rpx; font-size: 30rpx;
font-weight: bold; font-weight: bold;
color:darkblue; color:darkblue;

View File

@ -2,6 +2,7 @@ from rbac.permission import RbacPermission
from rbac.models import UserProfile from rbac.models import UserProfile
from crm.models import Consumer from crm.models import Consumer
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from django.core.cache import cache
# 学员接口列表 # 学员接口列表
ConsumerPerms = [ ConsumerPerms = [
@ -20,6 +21,10 @@ VistorPerms = [
'questioncat_view', 'questioncat_view',
'my_examtest', 'my_examtest',
] ]
def get_consumerperm_list(consumer):
perms = consumer.role.perms.values_list('code', flat=True)
cache.get_or_set(consumer.username + '__perms', perms)
return perms
class MyPermission(RbacPermission): class MyPermission(RbacPermission):
@ -37,10 +42,10 @@ class MyPermission(RbacPermission):
# perms = get_permission_list(request.user) # perms = get_permission_list(request.user)
return True return True
elif isinstance(request.user,Consumer): elif isinstance(request.user,Consumer):
if request.user.workscope: if cache.get(request.user.username + '__perms'):
perms = ConsumerPerms perms = cache.get(request.user.username + '__perms')
else: else:
perms = VistorPerms perms = get_consumerperm_list(request.user)
if perms: if perms:
if not hasattr(view, 'perms_map'): if not hasattr(view, 'perms_map'):
return True return True

View File

@ -1,7 +1,7 @@
from rest_framework import serializers from rest_framework import serializers
from .models import Company, Consumer, PaySubject, ConsumerPerm, ConsumerRole from .models import Company, Consumer, PaySubject, ConsumerPerm, ConsumerRole
from question.models import Question, Questioncat from question.models import Question, Questioncat
from .permission import get_consumerperm_list
class ConsumerPermSerializer(serializers.ModelSerializer): class ConsumerPermSerializer(serializers.ModelSerializer):
@ -35,7 +35,7 @@ class ConsumerSerializer(serializers.ModelSerializer):
subjects_name = serializers.StringRelatedField(source='subjects', many=True, read_only=True) subjects_name = serializers.StringRelatedField(source='subjects', many=True, read_only=True)
workscope_name = serializers.StringRelatedField(source='workscope', read_only=True) workscope_name = serializers.StringRelatedField(source='workscope', read_only=True)
role_name = serializers.StringRelatedField(source='role', read_only=True) role_name = serializers.StringRelatedField(source='role', read_only=True)
perms = serializers.SerializerMethodField(read_only=True)
class Meta: class Meta:
model = Consumer model = Consumer
exclude = ('avatar','collects') exclude = ('avatar','collects')
@ -46,3 +46,6 @@ class ConsumerSerializer(serializers.ModelSerializer):
queryset = queryset.select_related('company','workscope') queryset = queryset.select_related('company','workscope')
queryset = queryset.prefetch_related('subjects',) queryset = queryset.prefetch_related('subjects',)
return queryset return queryset
def get_perms(self,obj):
return get_consumerperm_list(obj)

View File

@ -293,9 +293,11 @@ class ConsumerViewSet(ModelViewSet):
@action(methods=['get'], detail=False, @action(methods=['get'], detail=False,
url_path='correctrole', url_name='correct_role', perms_map=[{'*':'correct_role'}]) url_path='correctrole', url_name='correct_role', perms_map=[{'*':'correct_role'}])
def correctrole(self, request): def correctrole(self, request):
role0 = ConsumerRole.objects.get(name='游客')
role1 = ConsumerRole.objects.get(name='付费学员') role1 = ConsumerRole.objects.get(name='付费学员')
role2 = ConsumerRole.objects.get(name='注册用户') role2 = ConsumerRole.objects.get(name='注册用户')
for i in Consumer.objects.all(): for i in Consumer.objects.filter(role__isnull = True):
i.role = role0
if i.workscope and i.username: if i.workscope and i.username:
i.role = role1 i.role = role1
elif i.username and i.openid: elif i.username and i.openid:

View File

@ -101,7 +101,7 @@ class QuestionViewSet(ModelViewSet):
ordering = ['-create_time'] ordering = ['-create_time']
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter] filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
filterset_fields = ['questioncat','level', 'type'] filterset_fields = ['questioncat','level', 'type']
search_fields = ['^name'] search_fields = ['name', 'options', 'resolution']
@action(methods=['post'], detail=False, @action(methods=['post'], detail=False,
url_path='count', url_name='question_count') url_path='count', url_name='question_count')