From 49948f0a4b976d6e2f5b74ef0c665b133c7f4f0e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 28 Jun 2020 15:33:55 +0800 Subject: [PATCH] consumer perm --- test_mini/app.js | 10 +- test_mini/app.json | 3 +- test_mini/pages/collect/main.wxml | 2 +- test_mini/pages/main/main.js | 27 +++-- test_mini/pages/question/detail.js | 155 +++++++++++++++++++++++++++ test_mini/pages/question/detail.json | 3 + test_mini/pages/question/detail.wxml | 53 +++++++++ test_mini/pages/question/detail.wxss | 16 +++ test_server/crm/permission.py | 4 +- 9 files changed, 253 insertions(+), 20 deletions(-) create mode 100644 test_mini/pages/question/detail.js create mode 100644 test_mini/pages/question/detail.json create mode 100644 test_mini/pages/question/detail.wxml create mode 100644 test_mini/pages/question/detail.wxss diff --git a/test_mini/app.js b/test_mini/app.js index 6821c8f..2f65e82 100644 --- a/test_mini/app.js +++ b/test_mini/app.js @@ -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 : '', } diff --git a/test_mini/app.json b/test_mini/app.json index 5f1bf4d..5c8af78 100644 --- a/test_mini/app.json +++ b/test_mini/app.json @@ -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", diff --git a/test_mini/pages/collect/main.wxml b/test_mini/pages/collect/main.wxml index e638cf8..2ecbde4 100644 --- a/test_mini/pages/collect/main.wxml +++ b/test_mini/pages/collect/main.wxml @@ -43,7 +43,7 @@ 正确答案是{{tm_current.right}},你的答案是{{tm_current.user_answer}} 解析: - {{tm_current.resolution}} + {{tm_current.resolution}} diff --git a/test_mini/pages/main/main.js b/test_mini/pages/main/main.js index 415276f..3e01878 100644 --- a/test_mini/pages/main/main.js +++ b/test_mini/pages/main/main.js @@ -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 { - 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 { + 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 + }) + }, +}) \ No newline at end of file diff --git a/test_mini/pages/question/detail.json b/test_mini/pages/question/detail.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/test_mini/pages/question/detail.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/test_mini/pages/question/detail.wxml b/test_mini/pages/question/detail.wxml new file mode 100644 index 0000000..acc90e7 --- /dev/null +++ b/test_mini/pages/question/detail.wxml @@ -0,0 +1,53 @@ + + 题目详情 + + + + + {{tm_current.type}} + {{tm_current.questioncat_name}} + + {{tm_current.name}} + + + + + + + + + + + + + + 回答正确! + 回答有误! + 正确答案是{{tm_current.right}},你的答案是{{tm_current.user_answer}} + + 解析: + {{tm_current.resolution}} + + + + + + 查看答案 + \ No newline at end of file diff --git a/test_mini/pages/question/detail.wxss b/test_mini/pages/question/detail.wxss new file mode 100644 index 0000000..231fbbd --- /dev/null +++ b/test_mini/pages/question/detail.wxss @@ -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 +} + diff --git a/test_server/crm/permission.py b/test_server/crm/permission.py index f96b9fe..35280c1 100644 --- a/test_server/crm/permission.py +++ b/test_server/crm/permission.py @@ -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: