From fb636ec86cd817553bfc321f3db8eae0298dcaa2 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 7 Jun 2021 22:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=81=E4=B9=A6=E6=A0=B8=E5=BF=83=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_mini/app.js | 7 ++- test_mini/app.json | 5 +- test_mini/pages/candidate/detail.js | 41 +++++++++--- test_mini/pages/candidate/detail.wxml | 2 +- test_mini/pages/candidate/my.js | 89 +++++++++++++++++++++++++++ test_mini/pages/candidate/my.json | 4 ++ test_mini/pages/candidate/my.wxml | 30 +++++++++ test_mini/pages/candidate/my.wxss | 1 + test_mini/pages/exam/index.js | 9 +++ test_mini/pages/main/main.wxml | 8 +++ test_server/crm/views.py | 21 +++++-- test_server/examtest/views.py | 5 ++ 12 files changed, 203 insertions(+), 19 deletions(-) create mode 100644 test_mini/pages/candidate/my.js create mode 100644 test_mini/pages/candidate/my.json create mode 100644 test_mini/pages/candidate/my.wxml create mode 100644 test_mini/pages/candidate/my.wxss diff --git a/test_mini/app.js b/test_mini/app.js index 05eae33..877e559 100644 --- a/test_mini/app.js +++ b/test_mini/app.js @@ -25,7 +25,7 @@ App({ // var currentPage = pages[pages.length - 1] //获取当前页面的对象 // currentPage.showExp() - if(res.data.userinfo.role_name == '游客'){ + if(res.data.userinfo.role_name == '游客' && this.globalData.rlogin){ //匿名用户 wx.reLaunch({ url: '/pages/login/login', @@ -70,10 +70,11 @@ 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 : '', + rlogin:true } }) \ No newline at end of file diff --git a/test_mini/app.json b/test_mini/app.json index cc2cd7f..ed34f71 100644 --- a/test_mini/app.json +++ b/test_mini/app.json @@ -38,7 +38,8 @@ "pages/admin/exam/detail", "pages/admin/exam/index", "pages/candidate/show", - "pages/admin/candidate/index" + "pages/admin/candidate/index", + "pages/candidate/my" ], "window": { "backgroundTextStyle": "light", @@ -95,7 +96,7 @@ }, "plugins": { "tencentvideo": { - "version": "1.3.31", + "version": "1.4.0", "provider": "wxa75efa648b60994b" } }, diff --git a/test_mini/pages/candidate/detail.js b/test_mini/pages/candidate/detail.js index 2e35dc8..072bc00 100644 --- a/test_mini/pages/candidate/detail.js +++ b/test_mini/pages/candidate/detail.js @@ -16,10 +16,10 @@ Page({ let id = options.id this.getDetail(id) }, - getDetail: function(id){ - api.request(`/crm/candidate/${id}/`, 'GET').then(res=>{ + getDetail: function (id) { + api.request(`/crm/candidate/${id}/`, 'GET').then(res => { this.setData({ - candidate:res.data + candidate: res.data }) }) }, @@ -71,17 +71,40 @@ Page({ onShareAppMessage: function () { }, - godetail: function(e){ + godetail: function (e) { wx.navigateTo({ - url: '/pages/test/detail?id='+this.data.candidate.examtest, + url: '/pages/test/detail?id=' + this.data.candidate.examtest, }) }, - goCandidate:function(e){ + goCandidate: function (e) { wx.navigateTo({ - url: '/pages/candidate/show?number='+this.data.candidate.number, + url: '/pages/candidate/show?number=' + this.data.candidate.number, }) }, - downDoc: function(e){ - + downDoc: function (e) { + let id = this.data.candidate.id + wx.showLoading({ + title: '正在生成...', + }) + api.request(`/crm/candidate/${id}/down/`, 'GET').then(res => { + wx.showLoading({ + title: '正在下载...', + }) + wx.downloadFile({ + url: getApp().globalData.host + res.data.path, + success(res) { + const filePath = res.tempFilePath + wx.openDocument({ + filePath, + fileType: 'docx', + success: function (res) { + wx.hideLoading({ + success: (res) => {}, + }) + } + }) + } + }) + }) } }) \ No newline at end of file diff --git a/test_mini/pages/candidate/detail.wxml b/test_mini/pages/candidate/detail.wxml index eb9d0ec..4301e77 100644 --- a/test_mini/pages/candidate/detail.wxml +++ b/test_mini/pages/candidate/detail.wxml @@ -1,5 +1,5 @@ - + diff --git a/test_mini/pages/candidate/my.js b/test_mini/pages/candidate/my.js new file mode 100644 index 0000000..8b61488 --- /dev/null +++ b/test_mini/pages/candidate/my.js @@ -0,0 +1,89 @@ +const api = require("../../utils/request.js"); +Page({ + + /** + * 页面的初始数据 + */ + data: { + results:[] + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.getList() + }, + getList: function() { + wx.showLoading({ + title: '正在加载...', + }) + api.request('/crm/candidate/my/', 'GET').then(res=>{ + wx.hideLoading() + this.setData({ + results:res.data, + }) + }).catch( + wx.hideLoading() + ) + }, + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + }, + scanC: function() { + wx.scanCode({ + onlyFromCamera: true, + success(res) { + console.log(res) + let number = res.result.split('/')[6] + let id = number.substring(number.length-4).replace("0","") + wx.navigateTo({ + url: 'detail?id=' + id, + }) + } + }) + } +}) \ No newline at end of file diff --git a/test_mini/pages/candidate/my.json b/test_mini/pages/candidate/my.json new file mode 100644 index 0000000..adaff6c --- /dev/null +++ b/test_mini/pages/candidate/my.json @@ -0,0 +1,4 @@ +{ + "usingComponents": {}, + "navigationBarTitleText": "Ⅲ类证书" +} \ No newline at end of file diff --git a/test_mini/pages/candidate/my.wxml b/test_mini/pages/candidate/my.wxml new file mode 100644 index 0000000..1b31571 --- /dev/null +++ b/test_mini/pages/candidate/my.wxml @@ -0,0 +1,30 @@ + + 扫一扫证书二维码 + + 我的Ⅲ类证书 + + +

+ {{item.consumer_name}} + {{item.number}} +

+ + 身份证号:{{item.ID_number}} + + + 工作类别:{{item.workscope_name}} + + + 期限:{{item.start_date}}至{{item.end_date}} + +
+
+ 暂无证书信息 + +
+
\ No newline at end of file diff --git a/test_mini/pages/candidate/my.wxss b/test_mini/pages/candidate/my.wxss new file mode 100644 index 0000000..313142f --- /dev/null +++ b/test_mini/pages/candidate/my.wxss @@ -0,0 +1 @@ +/* pages/candidate/my.wxss */ \ No newline at end of file diff --git a/test_mini/pages/exam/index.js b/test_mini/pages/exam/index.js index 3339059..da45676 100644 --- a/test_mini/pages/exam/index.js +++ b/test_mini/pages/exam/index.js @@ -32,6 +32,15 @@ Page({ }, submit: function(){ var that = this + var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; + if(!reg.test(this.data.form.ID_number)) + { + wx.showToast({ + title: '身份证号有误', + icon:'none' + }) + return false; + } if(this.data.form.deptname&&this.data.form.code&&this.data.form.name&&this.data.form.company_name&&this.data.form.ID_number){ wx.showLoading({ title: '加入考试...', diff --git a/test_mini/pages/main/main.wxml b/test_mini/pages/main/main.wxml index a3f58f8..b80716f 100644 --- a/test_mini/pages/main/main.wxml +++ b/test_mini/pages/main/main.wxml @@ -88,6 +88,14 @@
Ⅲ类自测入口 + + + + + + + Ⅲ类报告单 +
diff --git a/test_server/crm/views.py b/test_server/crm/views.py index 9310559..cabad24 100644 --- a/test_server/crm/views.py +++ b/test_server/crm/views.py @@ -651,6 +651,7 @@ def candidate(request, number): candidate = Candidate.objects.get(number=number) return render(request, 'index.html', {"candidate":candidate}) +from examtest.exports import exportw_test class CandidateViewSet(RetrieveModelMixin, ListModelMixin, GenericViewSet): """ 出征记录:列表 @@ -662,12 +663,13 @@ class CandidateViewSet(RetrieveModelMixin, ListModelMixin, GenericViewSet): serializer_class = CandidateSerializer pagination_class = CommonPagination filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter] + filterset_fields = ['consumer'] search_fields = ('number', 'consumer_name', 'workscope_name', 'company_name') ordering_fields = ('-id', 'update_time') ordering = ['-update_time'] - def get_authenticators(self, request): - if self.request.action == 'retrieve': + def get_authenticators(self): + if self.detail: return [] return super().get_authenticators() @@ -695,5 +697,16 @@ class CandidateViewSet(RetrieveModelMixin, ListModelMixin, GenericViewSet): return Candidate.objects.none() else: return queryset.none() - print(queryset) - return queryset \ No newline at end of file + return queryset + + @action(methods=['get'], detail = True, authentication_classes=[], permission_classes=[]) + def down(self, request, *args, **kwargs): + instance = self.queryset.get(*args, **kwargs) + path = exportw_test(instance.examtest, False) + return Response({'path': path}) + + @action(methods=['get'], detail = False, permission_classes=[]) + def my(self, request, *args, **kwargs): + queryset = self.queryset.filter(consumer=request.user) + serializer = self.get_serializer(queryset, many=True) + return Response(serializer.data) \ No newline at end of file diff --git a/test_server/examtest/views.py b/test_server/examtest/views.py index 61f1322..b3bdcc6 100644 --- a/test_server/examtest/views.py +++ b/test_server/examtest/views.py @@ -391,6 +391,11 @@ class ExamTestViewSet(PageOrNot, ModelViewSet): filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter] filterset_fields = ['type','is_pass', 'exam'] + def get_serializer_class(self): + if self.request.query_params.get('exam', None) or self.request.query_params.get('type') == '正式考试': + return ExamTestExamListSerializer + return ExamTestListSerializer + def filter_queryset(self, queryset): for backend in list(self.filter_backends): queryset = backend().filter_queryset(self.request, queryset, self)