consumer perm

This commit is contained in:
caoqianming 2020-06-28 15:33:55 +08:00
parent 96b218f535
commit 49948f0a4b
9 changed files with 253 additions and 20 deletions

View File

@ -20,9 +20,9 @@ App({
this.globalData.token = res.data.token
this.globalData.userinfo = res.data.userinfo
wx.hideLoading()
var pages = getCurrentPages() //获取加载的页面
var currentPage = pages[pages.length - 1] //获取当前页面的对象
currentPage.showExp()
// var pages = getCurrentPages() //获取加载的页面
// var currentPage = pages[pages.length - 1] //获取当前页面的对象
// currentPage.showExp()
if(res.data.userinfo.username == null){
//匿名用户
@ -57,9 +57,9 @@ App({
globalData: {
userInfo: {},
userinfo: {}, // 服务器传回的消费者信息
//host: 'https://apitest.ahctc.cn',
host: 'https://apitest.ahctc.cn',
mediahost: 'https://apitest.ahctc.cn',
host: 'http://127.0.0.1:8000',
//host: 'http://127.0.0.1:8000',
//mediahost: 'http://127.0.0.1:8000',
token : '',
}

View File

@ -23,7 +23,8 @@
"pages/article/index",
"pages/article/detail",
"pages/quota/quota",
"pages/material/index"
"pages/material/index",
"pages/question/detail"
],
"window": {
"backgroundTextStyle": "light",

View File

@ -43,7 +43,7 @@
<view class="weui-article__h2">正确答案是{{tm_current.right}},你的答案是{{tm_current.user_answer}}</view>
<view class="weui-article__title">
<span style="color:blue">解析: </span>
<span wx:if="{{tm_current.resolution != null}}">{{tm_current.resolution}}</span>
<span wx:if="{{tm_current.resolution}}">{{tm_current.resolution}}</span>
<span wx:else>无</span>
</view>
</view>

View File

@ -241,20 +241,25 @@ Page({
})
},
search: function (value) {
api.request('/question/question/', 'GET', {search:value}).then(res => {
if(res.data && res.data.results){
for(var i=0; i<res.data.results.length;i++){
res.data.results
}
}
})
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([{text: '搜索结果', value: 1}, {text: '搜索结果2', value: 2}])
}, 200)
api.request('/question/question/', 'GET', {search:value}).then(res => {
if(res.data && res.data.results){
for(var i=0; i<res.data.results.length;i++){
res.data.results[i].text = res.data.results[i].name
res.data.results[i].value = res.data.results[i].id
}
resolve(res.data.results)
}else{
resolve([{text: '无搜索结果', value: 0}])
}
})
})
},
selectResult: function (e) {
console.log(e.detail)
wx.navigateTo({
url: `/pages/question/detail?id=${e.detail.item.id}`,
})
},
})

View File

@ -0,0 +1,155 @@
const api = require("../../utils/request.js");
var util = require('../../utils/util.js')
Page({
/**
* 页面的初始数据
*/
data: {
is_right: false,
answerP: false,
},
radioChange: function (e) {
var that = this
that.data.tm_current['user_answer'] = e.detail.value
that.showAnswer()
},
checkboxChange: function (e) {
var that = this
that.data.tm_current['user_answer'] = e.detail.value
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this
wx.showLoading({
title: '加载中',
mask:true
})
api.request(`/question/question/${options.id}/`, 'GET').then(res => {
if(res.data.img){
res.data.img = getApp().globalData.mediahost + res.data.img
}
that.data.tm_current = res.data
that.showTm()
wx.hideLoading({
complete: (res) => {},
})
})
try {
const res = wx.getSystemInfoSync()
that.setData({
scrollHeight: res.windowHeight - 90
})
} catch (e) {
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
showTm: function (index) {
var that = this
var tm_current = that.data.tm_current
that.setData({
tm_current: tm_current,
answerP: false
})
that.showOptions()
if (tm_current.user_answer) {
that.showAnswer()
}
},
panTi: function () {
var that = this
let tm_current = that.data.tm_current
let is_right = false
if (tm_current.type == '多选') {
if (tm_current.user_answer) {
if (tm_current.user_answer.sort().toString() == tm_current.right.sort().toString()) {
is_right = true
}
}
} else {
is_right = tm_current.right == tm_current.user_answer
}
return is_right
},
showAnswer: function () {
let is_right = this.panTi()
this.setData({
is_right: is_right,
answerP: true,
tm_current: this.data.tm_current
})
},
showOptions: function () {
let tm_current = this.data.tm_current
let options = []
for (let key in tm_current.options) {
let option = {}
option.key = key
option.value = key + ':' + tm_current.options[key]
if (tm_current.user_answer) {
if (key == tm_current.user_answer || tm_current.user_answer.indexOf(key) != -1) {
option.checked = true
}
} else {
option.checked = false
}
options.push(option)
}
this.setData({
options: options
})
},
})

View File

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@ -0,0 +1,53 @@
<view class="head">
题目详情
</view>
<scroll-view scroll-y="true" style="height: {{scrollHeight}}px;">
<view class="weui-article">
<view class="weui-article__h2">
<span class="txlabel">{{tm_current.type}}</span>
<span style="color:gray"> {{tm_current.questioncat_name}}</span>
</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>
<view class="weui-cells weui-cells_radio">
<radio-group class="radio-group" bindchange="radioChange" wx:if="{{(tm_current.type=='单选' ||tm_current.type=='判断')}}">
<label class="weui-cell weui-cell_active weui-check__label" wx:for="{{options}}" wx:key="key">
<view class="weui-cell__bd">
<view>{{item.value}}</view>
</view>
<view class="weui-cell__ft">
<radio class="weui-check" value="{{item.key}}" checked="{{item.checked}}" />
<i class="weui-icon-checked"></i>
</view>
</label>
</radio-group>
</view>
<view class="weui-cells weui-cells_checkbox">
<checkbox-group bindchange="checkboxChange" wx:if="{{tm_current.type=='多选'}}">
<label class="weui-cell weui-cell_active weui-check__label" wx:for="{{options}}" wx:key="key">
<view class="weui-cell__bd">
<view>{{item.value}}</view>
</view>
<view class="weui-cell__hd">
<checkbox class="weui-check" value="{{item.key}}" checked="{{item.checked}}"/>
<i class="weui-icon-checked"></i>
</view>
</label>
</checkbox-group>
</view>
<view class="weui-article" wx:if="{{answerP}}">
<view class="weui-article__h2" wx:if="{{is_right}}" style="color:green;font-weight:bold">回答正确!</view>
<view class="weui-article__h2" wx:else style="color:red;font-weight:bold">回答有误!</view>
<view class="weui-article__h2">正确答案是{{tm_current.right}},你的答案是{{tm_current.user_answer}}</view>
<view class="weui-article__title">
<span style="color:blue">解析: </span>
<span wx:if="{{tm_current.resolution}}">{{tm_current.resolution}}</span>
<span wx:else>无</span>
</view>
</view>
</scroll-view>
<view class="btns">
<a class="weui-btn weui-btn_primary" bindtap="showAnswer">查看答案</a>
</view>

View File

@ -0,0 +1,16 @@
.head{
width:100%;
height:30px;
color:#fff;
background-color: cornflowerblue;
text-align: center;
}
.btns{
height:60px;
}
.txlabel{
color:#fff;
background-color: rgb(216, 140, 0);
padding: 2px
}

View File

@ -23,7 +23,7 @@ VistorPerms = [
]
def get_consumerperm_list(consumer):
perms = consumer.role.perms.values_list('code', flat=True)
cache.get_or_set(consumer.username + '__perms', perms)
cache.get_or_set('cperms_'+str(consumer.id), perms)
return perms
class MyPermission(RbacPermission):
@ -43,7 +43,7 @@ class MyPermission(RbacPermission):
return True
elif isinstance(request.user,Consumer):
if cache.get(request.user.username + '__perms'):
perms = cache.get(request.user.username + '__perms')
perms = cache.get('cperms_'+str(request.user.id))
else:
perms = get_consumerperm_list(request.user)
if perms: