From 1c3cb8ab7f2945156a683a8bb7ca53a1a9644445 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 May 2021 17:39:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=AB=AF=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_mini/app.json | 6 ++- test_mini/pages/admin/index.js | 72 +++++++++++++++++++++++++++ test_mini/pages/admin/index.json | 4 ++ test_mini/pages/admin/index.wxml | 26 ++++++++++ test_mini/pages/admin/index.wxss | 1 + test_mini/pages/admin/login.js | 84 ++++++++++++++++++++++++++++++++ test_mini/pages/admin/login.json | 4 ++ test_mini/pages/admin/login.wxml | 33 +++++++++++++ test_mini/pages/admin/login.wxss | 1 + test_mini/pages/login/login.wxml | 2 +- test_mini/pages/my/index.wxml | 7 +++ test_mini/project.config.json | 6 ++- test_mini/utils/request.js | 53 +++++++++++++++++++- test_server/rbac/views/user.py | 1 + test_server/utils/response.py | 6 ++- 15 files changed, 299 insertions(+), 7 deletions(-) create mode 100644 test_mini/pages/admin/index.js create mode 100644 test_mini/pages/admin/index.json create mode 100644 test_mini/pages/admin/index.wxml create mode 100644 test_mini/pages/admin/index.wxss create mode 100644 test_mini/pages/admin/login.js create mode 100644 test_mini/pages/admin/login.json create mode 100644 test_mini/pages/admin/login.wxml create mode 100644 test_mini/pages/admin/login.wxss diff --git a/test_mini/app.json b/test_mini/app.json index 8bc0cf8..b9c6374 100644 --- a/test_mini/app.json +++ b/test_mini/app.json @@ -31,7 +31,9 @@ "pages/qtest/form", "pages/main/start", "pages/exam/index", - "pages/exam/note" + "pages/exam/note", + "pages/admin/index", + "pages/admin/login" ], "window": { "backgroundTextStyle": "light", @@ -88,7 +90,7 @@ }, "plugins": { "tencentvideo": { - "version": "1.3.15", + "version": "1.3.31", "provider": "wxa75efa648b60994b" } }, diff --git a/test_mini/pages/admin/index.js b/test_mini/pages/admin/index.js new file mode 100644 index 0000000..c536490 --- /dev/null +++ b/test_mini/pages/admin/index.js @@ -0,0 +1,72 @@ +// pages/admin/index.js +const api = require("../../utils/request.js"); +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + api.requesta('/rbac/user/info/', 'GET').then(res => { + getApp().globalData.admininfo = res.data + this.setData({ + admininfo:res.data + }) + }) + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/test_mini/pages/admin/index.json b/test_mini/pages/admin/index.json new file mode 100644 index 0000000..63f2663 --- /dev/null +++ b/test_mini/pages/admin/index.json @@ -0,0 +1,4 @@ +{ + "usingComponents": {}, + "navigationBarTitleText": "管理员控制台" +} \ No newline at end of file diff --git a/test_mini/pages/admin/index.wxml b/test_mini/pages/admin/index.wxml new file mode 100644 index 0000000..bb0d926 --- /dev/null +++ b/test_mini/pages/admin/index.wxml @@ -0,0 +1,26 @@ + + + + + + + + + 账号: + {{admininfo.username}} + + 昵称: + {{ admininfo.name }} + + 角色: + {{ admininfo.roles }} + + + + + + + + + + diff --git a/test_mini/pages/admin/index.wxss b/test_mini/pages/admin/index.wxss new file mode 100644 index 0000000..3d6f7a5 --- /dev/null +++ b/test_mini/pages/admin/index.wxss @@ -0,0 +1 @@ +/* pages/admin/index.wxss */ \ No newline at end of file diff --git a/test_mini/pages/admin/login.js b/test_mini/pages/admin/login.js new file mode 100644 index 0000000..ad80364 --- /dev/null +++ b/test_mini/pages/admin/login.js @@ -0,0 +1,84 @@ +// pages/admin/login.js +const api = require("../../utils/request.js"); +Page({ + + /** + * 页面的初始数据 + */ + data: { + form:{ + username:'', + password:'' + } + }, + usernameChange: function (e) { + this.data.form.username = e.detail.value + }, + passwordChange: function (e) { + this.data.form.password = e.detail.value + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + }, + denglu: function ( ) { + var form = this.data.form + api.requesta('/token/', 'POST', form).then(res => { + getApp().globalData.admintoken = res.data.token + wx.redirectTo({ + url: '/pages/admin/index', + }) + }) + }, +}) \ No newline at end of file diff --git a/test_mini/pages/admin/login.json b/test_mini/pages/admin/login.json new file mode 100644 index 0000000..7035483 --- /dev/null +++ b/test_mini/pages/admin/login.json @@ -0,0 +1,4 @@ +{ + "usingComponents": {}, + "navigationBarTitleText": "管理员登录" +} \ No newline at end of file diff --git a/test_mini/pages/admin/login.wxml b/test_mini/pages/admin/login.wxml new file mode 100644 index 0000000..ee39079 --- /dev/null +++ b/test_mini/pages/admin/login.wxml @@ -0,0 +1,33 @@ + + + + 中科辐射学堂 + 管理员登录 + + + + + + 账号 + + + + + + + + 密码 + + + + + + + + + + + + Copyright © 2018-2021 国检集团 + 中存大数据提供技术支持 + \ No newline at end of file diff --git a/test_mini/pages/admin/login.wxss b/test_mini/pages/admin/login.wxss new file mode 100644 index 0000000..6c0a800 --- /dev/null +++ b/test_mini/pages/admin/login.wxss @@ -0,0 +1 @@ +/* pages/admin/login.wxss */ \ No newline at end of file diff --git a/test_mini/pages/login/login.wxml b/test_mini/pages/login/login.wxml index 83f347e..efd0a0b 100644 --- a/test_mini/pages/login/login.wxml +++ b/test_mini/pages/login/login.wxml @@ -33,6 +33,6 @@ - Copyright © 2018-2020 国检集团 + Copyright © 2018-2021 国检集团 中存大数据提供技术支持 \ No newline at end of file diff --git a/test_mini/pages/my/index.wxml b/test_mini/pages/my/index.wxml index 48c0083..1b415d7 100644 --- a/test_mini/pages/my/index.wxml +++ b/test_mini/pages/my/index.wxml @@ -72,6 +72,13 @@ + 管理员操作台 + + + 管理员入口 + + + 更多服务请联系课程顾问 diff --git a/test_mini/project.config.json b/test_mini/project.config.json index be350c3..028731e 100644 --- a/test_mini/project.config.json +++ b/test_mini/project.config.json @@ -21,13 +21,15 @@ "checkSiteMap": true, "uploadWithSourceMap": true, "compileHotReLoad": false, - "useMultiFrameRuntime": false, + "useMultiFrameRuntime": true, "useApiHook": true, + "useApiHostProcess": false, "babelSetting": { "ignore": [], "disablePlugins": [], "outputPath": "" }, + "enableEngineNative": false, "bundle": false, "useIsolateContext": true, "useCompilerModule": true, @@ -38,7 +40,7 @@ "minifyWXSS": true }, "compileType": "miniprogram", - "libVersion": "2.14.1", + "libVersion": "2.16.1", "appid": "wxf1e9471c93f05ad6", "projectname": "test_mini", "debugOptions": { diff --git a/test_mini/utils/request.js b/test_mini/utils/request.js index 3248084..8c498f2 100644 --- a/test_mini/utils/request.js +++ b/test_mini/utils/request.js @@ -51,6 +51,57 @@ function request(url, method, data) { return promise; } +function requesta(url, method, data) { + let promise = new Promise((resolve, reject) => { + wx.showNavigationBarLoading(); + wx.request({ + url: getApp().globalData.host + url, + method: method, + data: data, + header:{ + 'Authorization': 'JWT ' + getApp().globalData.admintoken + }, + success: (res => { + if (res.data.code >= 200 && res.data.code < 400) { + resolve(res.data); + }else if(res.data.code == 401){ + + } + else { + var msg = '请求错误' + if(res.data.msg){ + msg = res.data.msg + } + if (msg.indexOf('该操作的权限')!=-1){ + msg = '权限不足或账户过期,请联系课程顾问' + } + wx.showToast({ + title: msg, + icon: 'none', + duration: 1000 + }) + } + + }), + fail: (res => { + wx.showToast({ + title: '请求出错', + icon: 'none', + duration: 1500 + }) + console.log(res) + reject('网络出错'); + }), + complete: function () { + wx.hideNavigationBarLoading(); + } + + }) + }) + return promise; +} + module.exports = { - request: request + request: request, + requesta: requesta } \ No newline at end of file diff --git a/test_server/rbac/views/user.py b/test_server/rbac/views/user.py index 9ac1280..47755fe 100644 --- a/test_server/rbac/views/user.py +++ b/test_server/rbac/views/user.py @@ -47,6 +47,7 @@ class UserInfoView(APIView): # 'avatar': request._request._current_scheme_host + '/media/' + str(user.image), 'avatar': user.avatar, 'perms': perms, + 'roles':user.roles.values_list('name', flat=True) } return Response(data) diff --git a/test_server/utils/response.py b/test_server/utils/response.py index 13f8553..e97d94a 100644 --- a/test_server/utils/response.py +++ b/test_server/utils/response.py @@ -45,7 +45,11 @@ class FitJSONRenderer(JSONRenderer): response = renderer_context.get("response") response_body.code = response.status_code if response_body.code >= 400: # drf异常 - response_body.msg = data['detail'] if 'detail' in data else data + if isinstance(data, dict): + data = data[list(data.keys())[0]] + if isinstance(data, list): + data = data[0] + response_body.msg = data elif data and 'error' in data and data['error']:# 自传异常,key为error response_body.code = data.get("code",400) response_body.msg = data.get("error", "")