From 1c3cb8ab7f2945156a683a8bb7ca53a1a9644445 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 May 2021 17:39:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=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", "") From c7451fdc087562daa132a7d8c7514a7292d1019f Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 25 May 2021 17:07:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fabu=E8=80=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_mini/app.json | 4 +- .../components/timePicker/timePicker.js | 566 ++++++++++++++++++ .../components/timePicker/timePicker.json | 4 + .../components/timePicker/timePicker.wxml | 68 +++ .../components/timePicker/timePicker.wxss | 96 +++ test_mini/components/dynamicForm/index.js | 291 +++++++++ test_mini/components/dynamicForm/index.json | 8 + test_mini/components/dynamicForm/index.wxml | 72 +++ test_mini/components/dynamicForm/index.wxss | 119 ++++ .../dynamicForm/utils/formatTime.js | 29 + .../dynamicForm/vant/common/color.d.ts | 7 + .../dynamicForm/vant/common/color.js | 7 + .../dynamicForm/vant/common/component.d.ts | 3 + .../dynamicForm/vant/common/component.js | 48 ++ .../dynamicForm/vant/common/index.wxss | 1 + .../vant/common/style/clearfix.wxss | 1 + .../vant/common/style/ellipsis.wxss | 1 + .../vant/common/style/hairline.wxss | 1 + .../vant/common/style/mixins/clearfix.wxss | 0 .../vant/common/style/mixins/ellipsis.wxss | 0 .../vant/common/style/mixins/hairline.wxss | 0 .../dynamicForm/vant/common/style/theme.wxss | 0 .../dynamicForm/vant/common/style/var.wxss | 0 .../dynamicForm/vant/common/utils.d.ts | 8 + .../dynamicForm/vant/common/utils.js | 32 + .../dynamicForm/vant/icon/index.d.ts | 1 + .../components/dynamicForm/vant/icon/index.js | 27 + .../dynamicForm/vant/icon/index.json | 6 + .../dynamicForm/vant/icon/index.wxml | 20 + .../dynamicForm/vant/icon/index.wxss | 1 + .../dynamicForm/vant/info/index.d.ts | 1 + .../components/dynamicForm/vant/info/index.js | 12 + .../dynamicForm/vant/info/index.json | 3 + .../dynamicForm/vant/info/index.wxml | 8 + .../dynamicForm/vant/info/index.wxss | 1 + .../dynamicForm/vant/mixins/basic.js | 22 + .../dynamicForm/vant/mixins/button.js | 15 + .../dynamicForm/vant/mixins/iphonex.js | 39 ++ .../dynamicForm/vant/mixins/link.js | 24 + .../vant/mixins/observer/behavior.js | 43 ++ .../dynamicForm/vant/mixins/observer/index.js | 38 ++ .../dynamicForm/vant/mixins/observer/props.js | 32 + .../dynamicForm/vant/mixins/open-type.js | 22 + .../dynamicForm/vant/mixins/touch.js | 21 + .../dynamicForm/vant/mixins/transition.js | 73 +++ .../dynamicForm/vant/uploader/index.d.ts | 1 + .../dynamicForm/vant/uploader/index.js | 180 ++++++ .../dynamicForm/vant/uploader/index.json | 6 + .../dynamicForm/vant/uploader/index.wxml | 65 ++ .../dynamicForm/vant/uploader/index.wxss | 3 + .../dynamicForm/vant/uploader/utils.d.ts | 12 + .../dynamicForm/vant/uploader/utils.js | 16 + .../dynamicForm/vant/wxs/add-unit.wxs | 14 + .../components/dynamicForm/vant/wxs/array.wxs | 5 + .../components/dynamicForm/vant/wxs/bem.wxs | 38 ++ .../dynamicForm/vant/wxs/memoize.wxs | 54 ++ .../dynamicForm/vant/wxs/object.wxs | 13 + .../components/dynamicForm/vant/wxs/utils.wxs | 10 + test_mini/images/examtest.svg | 1 + test_mini/images/资格证书.svg | 1 + test_mini/pages/admin/exam/add.js | 68 +++ test_mini/pages/admin/exam/add.json | 3 + test_mini/pages/admin/exam/add.wxml | 81 +++ test_mini/pages/admin/exam/add.wxss | 1 + test_mini/pages/admin/exam/add2.js | 146 +++++ test_mini/pages/admin/exam/add2.json | 5 + test_mini/pages/admin/exam/add2.wxml | 4 + test_mini/pages/admin/exam/add2.wxss | 1 + test_mini/pages/admin/index.js | 22 +- test_mini/pages/admin/index.wxml | 43 +- test_mini/pages/admin/index.wxss | 10 +- test_mini/pages/admin/login.js | 38 +- test_mini/pages/login/login.js | 5 + test_mini/pages/login/login.wxml | 1 + test_server/crm/views.py | 15 +- .../migrations/0006_userprofile_mpopenid.py | 18 + test_server/rbac/models.py | 1 + test_server/rbac/views/user.py | 70 ++- test_server/server/config.py | 5 + 79 files changed, 2691 insertions(+), 40 deletions(-) create mode 100644 test_mini/components/dynamicForm/components/timePicker/timePicker.js create mode 100644 test_mini/components/dynamicForm/components/timePicker/timePicker.json create mode 100644 test_mini/components/dynamicForm/components/timePicker/timePicker.wxml create mode 100644 test_mini/components/dynamicForm/components/timePicker/timePicker.wxss create mode 100644 test_mini/components/dynamicForm/index.js create mode 100644 test_mini/components/dynamicForm/index.json create mode 100644 test_mini/components/dynamicForm/index.wxml create mode 100644 test_mini/components/dynamicForm/index.wxss create mode 100644 test_mini/components/dynamicForm/utils/formatTime.js create mode 100644 test_mini/components/dynamicForm/vant/common/color.d.ts create mode 100644 test_mini/components/dynamicForm/vant/common/color.js create mode 100644 test_mini/components/dynamicForm/vant/common/component.d.ts create mode 100644 test_mini/components/dynamicForm/vant/common/component.js create mode 100644 test_mini/components/dynamicForm/vant/common/index.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/clearfix.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/ellipsis.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/hairline.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/mixins/clearfix.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/mixins/ellipsis.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/mixins/hairline.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/theme.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/style/var.wxss create mode 100644 test_mini/components/dynamicForm/vant/common/utils.d.ts create mode 100644 test_mini/components/dynamicForm/vant/common/utils.js create mode 100644 test_mini/components/dynamicForm/vant/icon/index.d.ts create mode 100644 test_mini/components/dynamicForm/vant/icon/index.js create mode 100644 test_mini/components/dynamicForm/vant/icon/index.json create mode 100644 test_mini/components/dynamicForm/vant/icon/index.wxml create mode 100644 test_mini/components/dynamicForm/vant/icon/index.wxss create mode 100644 test_mini/components/dynamicForm/vant/info/index.d.ts create mode 100644 test_mini/components/dynamicForm/vant/info/index.js create mode 100644 test_mini/components/dynamicForm/vant/info/index.json create mode 100644 test_mini/components/dynamicForm/vant/info/index.wxml create mode 100644 test_mini/components/dynamicForm/vant/info/index.wxss create mode 100644 test_mini/components/dynamicForm/vant/mixins/basic.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/button.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/iphonex.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/link.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/observer/behavior.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/observer/index.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/observer/props.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/open-type.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/touch.js create mode 100644 test_mini/components/dynamicForm/vant/mixins/transition.js create mode 100644 test_mini/components/dynamicForm/vant/uploader/index.d.ts create mode 100644 test_mini/components/dynamicForm/vant/uploader/index.js create mode 100644 test_mini/components/dynamicForm/vant/uploader/index.json create mode 100644 test_mini/components/dynamicForm/vant/uploader/index.wxml create mode 100644 test_mini/components/dynamicForm/vant/uploader/index.wxss create mode 100644 test_mini/components/dynamicForm/vant/uploader/utils.d.ts create mode 100644 test_mini/components/dynamicForm/vant/uploader/utils.js create mode 100644 test_mini/components/dynamicForm/vant/wxs/add-unit.wxs create mode 100644 test_mini/components/dynamicForm/vant/wxs/array.wxs create mode 100644 test_mini/components/dynamicForm/vant/wxs/bem.wxs create mode 100644 test_mini/components/dynamicForm/vant/wxs/memoize.wxs create mode 100644 test_mini/components/dynamicForm/vant/wxs/object.wxs create mode 100644 test_mini/components/dynamicForm/vant/wxs/utils.wxs create mode 100644 test_mini/images/examtest.svg create mode 100644 test_mini/images/资格证书.svg create mode 100644 test_mini/pages/admin/exam/add.js create mode 100644 test_mini/pages/admin/exam/add.json create mode 100644 test_mini/pages/admin/exam/add.wxml create mode 100644 test_mini/pages/admin/exam/add.wxss create mode 100644 test_mini/pages/admin/exam/add2.js create mode 100644 test_mini/pages/admin/exam/add2.json create mode 100644 test_mini/pages/admin/exam/add2.wxml create mode 100644 test_mini/pages/admin/exam/add2.wxss create mode 100644 test_server/rbac/migrations/0006_userprofile_mpopenid.py create mode 100644 test_server/server/config.py diff --git a/test_mini/app.json b/test_mini/app.json index b9c6374..cc7cb9c 100644 --- a/test_mini/app.json +++ b/test_mini/app.json @@ -33,7 +33,9 @@ "pages/exam/index", "pages/exam/note", "pages/admin/index", - "pages/admin/login" + "pages/admin/login", + "pages/admin/exam/add", + "pages/admin/exam/add2" ], "window": { "backgroundTextStyle": "light", diff --git a/test_mini/components/dynamicForm/components/timePicker/timePicker.js b/test_mini/components/dynamicForm/components/timePicker/timePicker.js new file mode 100644 index 0000000..0eb7587 --- /dev/null +++ b/test_mini/components/dynamicForm/components/timePicker/timePicker.js @@ -0,0 +1,566 @@ + +Component({ + /** + * 组件的属性列表 + */ + properties: { + pickerShow: { + type: Boolean, + observer:function(val){ //弹出动画 + // console.log(this.data); + if(val){ + let animation = wx.createAnimation({ + duration: 500, + timingFunction: "ease" + }); + let animationOpacity = wx.createAnimation({ + duration: 500, + timingFunction: "ease" + }); + setTimeout(() => { + animation.bottom(0).step(); + animationOpacity.opacity(0.7).step(); + this.setData({ + animationOpacity: animationOpacity.export(), + animationData: animation.export() + }) + }, 0); + }else{ + let animation = wx.createAnimation({ + duration: 100, + timingFunction: "ease" + }); + let animationOpacity = wx.createAnimation({ + duration: 500, + timingFunction: "ease" + }); + animation.bottom(-320).step(); + animationOpacity.opacity(0).step(); + this.setData({ + animationOpacity: animationOpacity.export(), + animationData: animation.export() + }); + } + + // 在picker滚动未停止前点确定,会使startValue数组各项归零,发生错误,这里判断并重新初始化 + // 微信新增了picker滚动的回调函数,已进行兼容 + if(this.data.startValue&&this.data.endValue){ + let s = 0, e = 0; + let conf = this.data.config; + + this.data.startValue.map(val => { + if (val == 0) { + s++ + } + }) + this.data.endValue.map(val => { + if (val == 0) { + e++; + } + }); + let tmp={ + hour:4, + minute:5, + second:6 + } + let n = tmp[conf.column]; + if (s>=n || e>=n) { + this.initPick(this.data.config); + this.setData({ + startValue: this.data.startValue, + endValue: this.data.endValue, + }); + } + } + + + } + }, + config: Object + }, + + /** + * 组件的初始数据 + */ + data: { + // pickerShow:true + // limitStartTime: new Date().getTime()-1000*60*60*24*30, + // limitEndTime: new Date().getTime(), + // yearStart:2000, + // yearEnd:2100 + }, + detached: function() { + console.log("dele"); + }, + attached: function() {}, + ready: function() { + this.readConfig(); + this.initPick(this.data.config || null); + this.setData({ + startValue: this.data.startValue, + endValue: this.data.endValue, + }); + + + + + }, + /** + * 组件的方法列表 + */ + methods: { + //阻止滑动事件 + onCatchTouchMove(e) { + + }, + //读取配置项 + readConfig() { + let limitEndTime = new Date().getTime(); + let limitStartTime = new Date().getTime() - 1000 * 60 * 60 * 24 * 30; + if (this.data.config) { + let conf = this.data.config; + + if (typeof conf.dateLimit == "number") { + limitStartTime = + new Date().getTime() - 1000 * 60 * 60 * 24 * conf.dateLimit; + } + if(conf.limitStartTime){ + + limitStartTime = new Date(conf.limitStartTime.replace(/-/g,'/')).getTime(); + } + + if (conf.limitEndTime) { + limitEndTime = new Date(conf.limitEndTime.replace(/-/g, '/')).getTime(); + } + + this.setData({ + yearStart: conf.yearStart || 2000, + yearEnd: conf.yearEnd || 2100, + endDate: conf.endDate || false, + dateLimit: conf.dateLimit || false, + hourColumn: + conf.column == "hour" || + conf.column == "minute" || + conf.column == "second", + minColumn: conf.column == "minute" || conf.column == "second", + secColumn: conf.column == "second" + }); + } + + let limitStartTimeArr = formatTime(limitStartTime); + let limitEndTimeArr = formatTime(limitEndTime); + + this.setData({ + limitStartTime, + limitStartTimeArr, + limitEndTime, + limitEndTimeArr + }); + }, + //滚动开始 + handlePickStart:function(e){ + this.setData({ + isPicking:true + }) + }, + //滚动结束 + handlePickEnd:function(e){ + this.setData({ + isPicking:false + }) + }, + onConfirm: function() { + //滚动未结束时不能确认 + if(this.data.isPicking){return} + let startTime = new Date(this.data.startPickTime.replace(/-/g, "/")); + let endTime = new Date(this.data.endPickTime.replace(/-/g, "/")); + if (startTime <= endTime || !this.data.endDate) { + this.setData({ + startTime, + endTime + }); + let startArr = formatTime(startTime).arr; + let endArr = formatTime(endTime).arr; + let format0 = function(num){ + return num<10?'0'+num:num + } + + let startTimeBack = + startArr[0] + + "-" + + format0(startArr[1]) + + "-" + + format0(startArr[2]) + + " " + + (this.data.hourColumn ? format0(startArr[3]) : "00") + + ":" + + (this.data.minColumn ? format0(startArr[4]) : "00") + + ":" + + (this.data.secColumn ? format0(startArr[5]) : "00"); + + let endTimeBack = + endArr[0] + + "-" + + format0(endArr[1]) + + "-" + + format0(endArr[2]) + + " " + + (this.data.hourColumn ? format0(endArr[3]) : "00") + + ":" + + (this.data.minColumn ? format0(endArr[4]) : "00") + + ":" + + (this.data.secColumn ? format0(endArr[5]) : "00"); + + let time = { + startTime: startTimeBack, + endTime: endTimeBack + }; + + //触发自定义事件 + this.triggerEvent("setPickerTime", time); + this.triggerEvent("hidePicker", {}); + } else { + wx.showToast({ + icon: "none", + title: "时间不合理" + }); + } + }, + hideModal: function() { + + this.triggerEvent("hidePicker", {}); + }, + changeStartDateTime: function(e) { + let val = e.detail.value; + + this.compareTime(val, "start"); + }, + + changeEndDateTime: function(e) { + let val = e.detail.value; + this.compareTime(val, "end"); + }, + //比较时间是否在范围内 + compareTime(val, type) { + let h = val[3] ? this.data.HourList[val[3]] : "00"; + let m = val[4] ? this.data.MinuteList[val[4]] : "00"; + let s = val[5] ? this.data.SecondList[val[5]] : "00"; + let time = + this.data.YearList[val[0]] + + "-" + + this.data.MonthList[val[1]] + + "-" + + this.data.DayList[val[2]] + + " " + + h + + ":" + + m + + ":" + + s; + + let start = this.data.limitStartTime; + let end = this.data.limitEndTime; + let timeNum = new Date(time.replace(/-/g, '/')).getTime(); + let year, month, day, hour, min, sec, limitDate; + let tempArr = [] + + if (!this.data.dateLimit){ + limitDate = [ + this.data.YearList[val[0]], + this.data.MonthList[val[1]], + this.data.DayList[val[2]], + this.data.HourList[val[3]], + this.data.MinuteList[val[4]], + this.data.SecondList[val[5]]] + } else if (type == "start" && timeNum > new Date(this.data.endPickTime.replace(/-/g, '/')) && this.data.config.endDate) { + limitDate = formatTime(this.data.endPickTime).arr; + + } else if (type == "end" && timeNum < new Date(this.data.startPickTime.replace(/-/g, '/'))) { + limitDate = formatTime(this.data.startPickTime).arr; + + } else if (timeNum < start) { + limitDate = this.data.limitStartTimeArr.arr; + + } else if (timeNum > end) { + limitDate = this.data.limitEndTimeArr.arr; + + } else { + limitDate = [ + this.data.YearList[val[0]], + this.data.MonthList[val[1]], + this.data.DayList[val[2]], + this.data.HourList[val[3]], + this.data.MinuteList[val[4]], + this.data.SecondList[val[5]] + ] + + } + + year = limitDate[0]; + month = limitDate[1]; + day = limitDate[2]; + hour = limitDate[3]; + min = limitDate[4]; + sec = limitDate[5]; + + if (type == "start") { + this.setStartDate(year, month, day, hour, min, sec); + } else if (type == "end") { + this.setEndDate(year, month, day, hour, min, sec); + } + }, + getDays: function(year, month) { + let daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + if (month === 2) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 + ? 29 + : 28; + } else { + return daysInMonth[month - 1]; + } + }, + initPick: function(initData) { + const date = initData.initStartTime ? new Date(initData.initStartTime.replace(/-/g, '/')): new Date(); + const endDate = initData.initEndTime ? new Date(initData.initEndTime.replace(/-/g, '/')) : new Date(); + // const startDate = new Date(date.getTime() - 1000 * 60 * 60 * 24); + const startDate = date; + const startYear = date.getFullYear(); + const startMonth = date.getMonth() + 1; + const startDay = date.getDate(); + const startHour = date.getHours(); + const startMinute = date.getMinutes(); + const startSecond = date.getSeconds(); + + const endYear = endDate.getFullYear(); + const endMonth = endDate.getMonth() + 1; + const endDay = endDate.getDate(); + const endHour = endDate.getHours(); + const endMinute = endDate.getMinutes(); + const endSecond = endDate.getSeconds(); + + let YearList = []; + let MonthList = []; + let DayList = []; + let HourList = []; + let MinuteList = []; + let SecondList = []; + + //设置年份列表 + for (let i = this.data.yearStart; i <= this.data.yearEnd; i++) { + YearList.push(i); + } + + // 设置月份列表 + for (let i = 1; i <= 12; i++) { + MonthList.push(i); + } + // 设置日期列表 + for (let i = 1; i <= 31; i++) { + DayList.push(i); + } + // 设置时列表 + for (let i = 0; i <= 23; i++) { + if (0 <= i && i < 10) { + i = "0" + i; + } + HourList.push(i); + } + // 分|秒 + for (let i = 0; i <= 59; i++) { + if (0 <= i && i < 10) { + i = "0" + i; + } + MinuteList.push(i); + SecondList.push(i); + } + + this.setData({ + YearList, + MonthList, + DayList, + HourList, + MinuteList, + SecondList + }); + + this.setStartDate(startYear, startMonth, startDay, startHour, startMinute, startSecond); + this.setEndDate(endYear, endMonth, endDay, endHour, endMinute, endSecond); + + //!!! + // setTimeout(() => { + // this.setStartDate(nowYear, nowMonth, nowDay, nowHour, nowMinute) + // this.setEndDate(nowYear, nowMonth, nowDay, nowHour, nowMinute) + // }, 0); + }, + setPickerDateArr(type, year, month, day, hour, minute, second) { + let yearIdx = 0; + let monthIdx = 0; + let dayIdx = 0; + let hourIdx = 0; + let minuteIdx = 0; + let secondIdx = 0; + + this.data.YearList.map((v, idx) => { + if (parseInt(v) === year) { + yearIdx = idx; + } + }); + + this.data.MonthList.map((v, idx) => { + if (parseInt(v) === month) { + monthIdx = idx; + } + }); + + // 重新设置日期列表 + let DayList = []; + for (let i = 1; i <= this.getDays(year, month); i++) { + DayList.push(i); + } + + DayList.map((v, idx) => { + if (parseInt(v) === day) { + dayIdx = idx; + } + }); + if (type == "start") { + this.setData({ startDayList: DayList }); + } else if (type == "end") { + this.setData({ endDayList: DayList }); + } + + this.data.HourList.map((v, idx) => { + if (parseInt(v) === parseInt(hour)) { + hourIdx = idx; + } + }); + + this.data.MinuteList.map((v, idx) => { + if (parseInt(v) === parseInt(minute)) { + minuteIdx = idx; + } + }); + this.data.SecondList.map((v, idx) => { + if (parseInt(v) === parseInt(second)) { + secondIdx = idx; + } + }); + + return { + yearIdx, + monthIdx, + dayIdx, + hourIdx, + minuteIdx, + secondIdx + }; + }, + setStartDate: function(year, month, day, hour, minute, second) { + let pickerDateArr = this.setPickerDateArr( + "start", + year, + month, + day, + hour, + minute, + second + ); + this.setData({ + startYearList: this.data.YearList, + startMonthList: this.data.MonthList, + // startDayList: this.data.DayList, + startHourList: this.data.HourList, + startMinuteList: this.data.MinuteList, + startSecondList: this.data.SecondList, + startValue: [ + pickerDateArr.yearIdx, + pickerDateArr.monthIdx, + pickerDateArr.dayIdx, + pickerDateArr.hourIdx, + pickerDateArr.minuteIdx, + pickerDateArr.secondIdx + ], + startPickTime: + this.data.YearList[pickerDateArr.yearIdx] + + "-" + + this.data.MonthList[pickerDateArr.monthIdx] + + "-" + + this.data.DayList[pickerDateArr.dayIdx] + + " " + + this.data.HourList[pickerDateArr.hourIdx] + + ":" + + this.data.MinuteList[pickerDateArr.minuteIdx] + + ":" + + this.data.SecondList[pickerDateArr.secondIdx] + }); + }, + setEndDate: function(year, month, day, hour, minute, second) { + let pickerDateArr = this.setPickerDateArr( + "end", + year, + month, + day, + hour, + minute, + second + ); + + this.setData({ + endYearList: this.data.YearList, + endMonthList: this.data.MonthList, + // endDayList: this.data.DayList, + endHourList: this.data.HourList, + endMinuteList: this.data.MinuteList, + endSecondList: this.data.SecondList, + endValue: [ + pickerDateArr.yearIdx, + pickerDateArr.monthIdx, + pickerDateArr.dayIdx, + pickerDateArr.hourIdx, + pickerDateArr.minuteIdx, + pickerDateArr.secondIdx + ], + endPickTime: + this.data.YearList[pickerDateArr.yearIdx] + + "-" + + this.data.MonthList[pickerDateArr.monthIdx] + + "-" + + this.data.DayList[pickerDateArr.dayIdx] + + " " + + this.data.HourList[pickerDateArr.hourIdx] + + ":" + + this.data.MinuteList[pickerDateArr.minuteIdx] + + ":" + + this.data.SecondList[pickerDateArr.secondIdx] + }); + }, + } +}); + + +function formatTime(date) { + + if (typeof date == 'string' || 'number') { + try { + date = date.replace(/-/g, '/')//兼容ios + } catch (error) { + } + date = new Date(date) + } + + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return { + str: [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':'), + arr: [year, month, day, hour, minute, second] + } +} +function formatNumber(n) { + n = n.toString() + return n[1] ? n : '0' + n +} diff --git a/test_mini/components/dynamicForm/components/timePicker/timePicker.json b/test_mini/components/dynamicForm/components/timePicker/timePicker.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/test_mini/components/dynamicForm/components/timePicker/timePicker.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/test_mini/components/dynamicForm/components/timePicker/timePicker.wxml b/test_mini/components/dynamicForm/components/timePicker/timePicker.wxml new file mode 100644 index 0000000..963e0dd --- /dev/null +++ b/test_mini/components/dynamicForm/components/timePicker/timePicker.wxml @@ -0,0 +1,68 @@ + + +