From d4c786a12679204956dc8fd497d1bfa2898ed34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Fri, 5 Aug 2022 16:57:58 +0800 Subject: [PATCH] =?UTF-8?q?app=E5=92=8C=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .hbuilderx/launch.json | 4 ++ App.vue | 28 ++++++++++ common/http.api.js | 7 +++ common/http.interceptor.js | 2 +- manifest.json | 12 +++-- pages.json | 56 ++++++++++---------- pages/login/login_.vue | 96 ++++++++++++++++++++++++++--------- pages/my/my.vue | 7 ++- pages/workSpace/workSpace.vue | 2 +- 9 files changed, 156 insertions(+), 58 deletions(-) diff --git a/.hbuilderx/launch.json b/.hbuilderx/launch.json index 9cba30d..34b613b 100644 --- a/.hbuilderx/launch.json +++ b/.hbuilderx/launch.json @@ -2,6 +2,10 @@ // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数 "version": "0.0", "configurations": [{ + "app-plus" : + { + "launchtype" : "remote" + }, "default" : { "launchtype" : "remote" diff --git a/App.vue b/App.vue index 8d12b31..50a39ac 100644 --- a/App.vue +++ b/App.vue @@ -5,6 +5,7 @@ appid: 'wxf7d6140f507466be' }, onLaunch() { + var that = this // 1.1.0版本之前关于http拦截器代码,已平滑移动到/common/http.interceptor.js中 // 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明): // import httpInterceptor from '@/common/http.interceptor.js' @@ -56,6 +57,33 @@ } }); // #endif + // #ifdef APP-PLUS + uni.showLoading({ + title: '自动登录中...', + mask: true + }) + uni.getStorage({ + key: 'mySecret', + success: function (res) { + let secret = res.data + if(secret){ + that.$u.api.loginSecret(JSON.parse(secret)).then(res=>{ + that.$u.api.getUserInfo().then(res => { + that.$u.vuex('vuex_user', res) + // 修改资源请求地址 + }) + uni.reLaunch({ + url: '/pages/home/home_' + }) + }) + } + + }, + complete() { + uni.hideLoading() + } + }); + // #endif }, } diff --git a/common/http.api.js b/common/http.api.js index 911e5ba..59711f5 100644 --- a/common/http.api.js +++ b/common/http.api.js @@ -18,6 +18,7 @@ const install = (Vue, vm) => { let login = (data = {}) => vm.$u.post('auth/token/', data); //账户密码登录 let loginOut = () => vm.$u.post('/auth/logout/'); //账户密码退出 + let loginSecret = (data = {}) => vm.$u.post('/auth/login_secret/', data); //App密钥登录 // 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下 let wxmplogin = (data = {}) => vm.$u.post('auth/login_wxmp/', data); //微信登录 @@ -25,6 +26,9 @@ const install = (Vue, vm) => { let bindmp = (data = {}) => vm.$u.post('/system/user/bind_wxmp/', data); //微信小程序绑定 let unbindmp = (data = {}) => vm.$u.post('/system/user/unbind_wxmp/', data); //微信小程序解绑 + let bindSecret = (data = {}) => vm.$u.post('/system/user/bind_secret/', data); //App密钥绑定 + + let getDickey = (params = {}) => vm.$u.get('/system/dict/', params); //查询字典 let userList = (params = {}) => vm.$u.get('/system/user/', params); // let deptList = (params = {}) => vm.$u.get('/system/dept/', params); // @@ -75,6 +79,9 @@ const install = (Vue, vm) => { wxmplogin, bindmp, unbindmp, + bindSecret, + loginSecret, + userList, deptList, ticketCreate, diff --git a/common/http.interceptor.js b/common/http.interceptor.js index 5521dca..f1b5761 100644 --- a/common/http.interceptor.js +++ b/common/http.interceptor.js @@ -50,7 +50,7 @@ const install = (Vue, vm) => { }) }else{ uni.reLaunch({ - url:'/pages/login/login' + url:'/pages/login/login_' }) } } diff --git a/manifest.json b/manifest.json index 29b1ae7..f3d149d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { - "name" : "共享平台", + "name" : "曲阳金隅EHS", "appid" : "__UNI__B00D419", - "description" : "共享平台", + "description" : "曲阳金隅EHS", "versionName" : "1.0.0", "versionCode" : "100", "transformPx" : false, @@ -70,7 +70,13 @@ "speech" : { "ifly" : {} }, - "ad" : {} + "ad" : {}, + "push" : { + "unipush" : { + "version" : "2", + "offline" : false + } + } }, "orientation" : [ "portrait-primary" ] } diff --git a/pages.json b/pages.json index d162ed1..00973e9 100644 --- a/pages.json +++ b/pages.json @@ -13,49 +13,49 @@ "pages": [{ "path": "pages/login/login_", "style": { - "navigationBarTitleText": "密码登录", + "navigationBarTitleText": "曲阳金隅EHS-密码登录", "enablePullDownRefresh": false } },{ "path": "pages/login/userRegister", "style": { - "navigationBarTitleText": "新用户注册", - "enablePullDownRefresh": false - } - }, - { - "path" : "pages/login/login", - "style" : - { - "navigationBarTitleText": "验证码登录", - "enablePullDownRefresh": false - } - }, - { - "path": "pages/login/login_password", - "style": { - "navigationBarTitleText": "密码登录", + "navigationBarTitleText": "曲阳金隅EHS-新用户注册", "enablePullDownRefresh": false } }, + // { + // "path" : "pages/login/login", + // "style" : + // { + // "navigationBarTitleText": "验证码登录", + // "enablePullDownRefresh": false + // } + // }, + // { + // "path": "pages/login/login_password", + // "style": { + // "navigationBarTitleText": "密码登录", + // "enablePullDownRefresh": false + // } + // }, { "path": "pages/home/home_", "style": { - "navigationBarTitleText": "主页", + // "navigationBarTitleText": "曲阳金隅EHS主页", "enablePullDownRefresh": false } }, { "path": "pages/home/list/ticket", "style": { - "navigationBarTitleText": "代办事件", + "navigationBarTitleText": "曲阳金隅EHS-待办工单", "navigationStyle": "custom" } }, { "path": "pages/home/list/warning", "style": { - "navigationBarTitleText": "实时报警", + "navigationBarTitleText": "曲阳金隅EHS-实时报警", "navigationStyle": "custom", "enablePullDownRefresh": false } @@ -63,7 +63,7 @@ { "path": "pages/home/detail/ticketHandle", "style": { - "navigationBarTitleText": "工作流审批", + "navigationBarTitleText": "曲阳金隅EHS-工单处理", "navigationStyle": "custom", "enablePullDownRefresh": false } @@ -79,7 +79,7 @@ { "path": "pages/home/detail/warningHandle", "style": { - "navigationBarTitleText": "报警处理", + "navigationBarTitleText": "曲阳金隅EHS-报警处理", "navigationStyle": "custom", "enablePullDownRefresh": false } @@ -87,14 +87,14 @@ { "path": "pages/workSpace/workSpace", "style": { - "navigationBarTitleText": "工作台", + "navigationBarTitleText": "曲阳金隅EHS-工作台", "enablePullDownRefresh": false } }, { "path": "pages/workSpace/rpj/rpjLisst", "style": { - "navigationBarTitleText": "入厂项目", + "navigationBarTitleText": "曲阳金隅EHS-入厂项目", "navigationStyle": "custom", "enablePullDownRefresh": false } @@ -127,7 +127,7 @@ { "path": "pages/workSpace/operation/operationList", "style": { - "navigationBarTitleText": "作业列表", + "navigationBarTitleText": "曲阳金隅EHS-作业列表", "navigationStyle": "custom", "enablePullDownRefresh": false } @@ -151,7 +151,7 @@ { "path": "pages/workSpace/visit/visitList", "style": { - "navigationBarTitleText": "来访项目", + "navigationBarTitleText": "曲阳金隅EHS-来访项目", "navigationStyle": "custom", "enablePullDownRefresh": false } @@ -183,7 +183,7 @@ { "path": "pages/my/my", "style": { - "navigationBarTitleText": "个人中心", + "navigationBarTitleText": "曲阳金隅EHS-个人中心", "enablePullDownRefresh": false } }, @@ -198,7 +198,7 @@ ], "globalStyle": { "navigationBarTextStyle": "black", - "navigationBarTitleText": "曲阳金隅智慧安全", + "navigationBarTitleText": "曲阳金隅EHS", "navigationBarBackgroundColor": "#F8F8F8", // "navigationStyle": "custom", "backgroundColor": "#F8F8F8" diff --git a/pages/login/login_.vue b/pages/login/login_.vue index 2f03382..6abb5e5 100644 --- a/pages/login/login_.vue +++ b/pages/login/login_.vue @@ -37,18 +37,19 @@ -
+ + @@ -67,7 +68,7 @@ - 新用户注册 + 访客注册 @@ -296,6 +297,21 @@ url: '/pages/login/userRegister' }) }, + ranStr(e) { + //形参e,需要产生随机字符串的长度 + //如果没有传参,默认生成32位长度随机字符串 + e = e || 32; + //模拟随机字符串库 + var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789", + a = t.length,//字符串t的长度,随机数生成最大值 + n = ""; + for (let i = 0; i < e; i++) { + //随机生成长度为e的随机字符串拼接 + n += t.charAt(Math.floor(Math.random() * a)); + } + //返回随机组合字符串 + return n + }, formSubmit(e) { var that = this; const obj = e.target.value; @@ -311,18 +327,48 @@ that.$u.vuex('vuex_user', res) // 修改资源请求地址 }) + // #ifdef APP-PLUS + let secret = that.ranStr(12) + let mySecret = {'username': obj.username, 'secret': secret} + that.$u.api.bindSecret({secret: secret}).then(res=>{ + uni.setStorageSync('mySecret', JSON.stringify(mySecret)) + }).catch(e=>{}) + // #endif + uni.reLaunch({ url: '/pages/home/home_' }) }).catch(e => { console.log(e) - uni.showToast({ - title: '账户密码错误', - icon: 'none' - }) }) }, - + formSubmit2(e) { + var that = this; + const obj = e.target.value; + console.log(obj) + that.$u.api.codeLogin(obj).then(res => { + that.$u.vuex('vuex_token', res.access) + that.$u.vuex('vuex_refresh', res.refresh) + // let data = {openid: uni.getStorageSync('wxmp_openid')} + // that.$u.api.bindmp(data).then(res=>{}) + that.$u.api.getUserInfo().then(res => { + that.$u.vuex('vuex_user', res) + // 修改资源请求地址 + }) + // #ifdef APP-PLUS + let secret = that.ranStr(12) + let mySecret = {'username': obj.username, 'secret': secret} + that.$u.api.bindSecret({secret: secret}).then(res=>{ + uni.setStorageSync('mySecret', JSON.stringify(mySecret)) + }).catch(e=>{}) + // #endif + + uni.reLaunch({ + url: '/pages/home/home_' + }) + }).catch(e => { + }) + }, codeChange(text) { this.codeTips = text; }, @@ -331,21 +377,23 @@ debugger; console.log(this.phoneNumber) if (this.phoneNumber !== '') { - uni.showLoading({ - title: '正在获取验证码', - mask: true - }) - this.$u.api.getCode({ - phone: this.phoneNumber - }).then(res => { - setTimeout(() => { - uni.hideLoading(); - // 这里此提示会被this.start()方法中的提示覆盖 - this.$u.toast('验证码已发送'); - // 通知验证码组件内部开始倒计时 - this.$refs.uCode.start(); - }, 2000); - }) + if (this.$refs.uCode.canGetCode){ + uni.showLoading({ + title: '正在获取验证码', + mask: true + }) + this.$u.api.getCode({ + phone: this.phoneNumber + }).then(res => { + setTimeout(() => { + uni.hideLoading(); + // 这里此提示会被this.start()方法中的提示覆盖 + this.$u.toast('验证码已发送'); + // 通知验证码组件内部开始倒计时 + this.$refs.uCode.start(); + }, 2000); + }) + } } else { // this.$u.toast('倒计时结束后再发送'); this.$u.toast('请输入手机号'); diff --git a/pages/my/my.vue b/pages/my/my.vue index 5f9c5ec..0bb8a7b 100644 --- a/pages/my/my.vue +++ b/pages/my/my.vue @@ -13,7 +13,7 @@ - + @@ -257,6 +257,11 @@ var that = this; this.$u.api.loginOut().then(()=>{ that.$u.vuex('vuex_token', null); + try { + uni.removeStorageSync('mySecret'); + } catch (e) { + // error + } uni.reLaunch({ url:'/pages/login/login_' }) diff --git a/pages/workSpace/workSpace.vue b/pages/workSpace/workSpace.vue index 16debca..71d7a3c 100644 --- a/pages/workSpace/workSpace.vue +++ b/pages/workSpace/workSpace.vue @@ -5,7 +5,7 @@ style="position: absolute;top:0;left:0;bottom:0;right:0;height: 290rpx;background-image: url(../../static/workSpace/bgimg.png);background-position: center bottom;background-size: 100%;"> - +