app和验证码登录

This commit is contained in:
曹前明 2022-08-05 16:57:58 +08:00
parent 8281eff236
commit d4c786a126
9 changed files with 156 additions and 58 deletions

View File

@ -2,6 +2,10 @@
// launchtypelocalremote, localremote // launchtypelocalremote, localremote
"version": "0.0", "version": "0.0",
"configurations": [{ "configurations": [{
"app-plus" :
{
"launchtype" : "remote"
},
"default" : "default" :
{ {
"launchtype" : "remote" "launchtype" : "remote"

28
App.vue
View File

@ -5,6 +5,7 @@
appid: 'wxf7d6140f507466be' appid: 'wxf7d6140f507466be'
}, },
onLaunch() { onLaunch() {
var that = this
// 1.1.0http/common/http.interceptor.js // 1.1.0http/common/http.interceptor.js
// /main.jsVue() // /main.jsVue()
// import httpInterceptor from '@/common/http.interceptor.js' // import httpInterceptor from '@/common/http.interceptor.js'
@ -56,6 +57,33 @@
} }
}); });
// #endif // #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
}, },
} }
</script> </script>

View File

@ -18,6 +18,7 @@ const install = (Vue, vm) => {
let login = (data = {}) => vm.$u.post('auth/token/', data); //账户密码登录 let login = (data = {}) => vm.$u.post('auth/token/', data); //账户密码登录
let loginOut = () => vm.$u.post('/auth/logout/'); //账户密码退出 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)下 // 将各个定义的接口名称统一放进对象挂载到vm.$u.api(因为vm就是this也即this.$u.api)下
let wxmplogin = (data = {}) => vm.$u.post('auth/login_wxmp/', data); //微信登录 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 bindmp = (data = {}) => vm.$u.post('/system/user/bind_wxmp/', data); //微信小程序绑定
let unbindmp = (data = {}) => vm.$u.post('/system/user/unbind_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 getDickey = (params = {}) => vm.$u.get('/system/dict/', params); //查询字典
let userList = (params = {}) => vm.$u.get('/system/user/', params); // let userList = (params = {}) => vm.$u.get('/system/user/', params); //
let deptList = (params = {}) => vm.$u.get('/system/dept/', params); // let deptList = (params = {}) => vm.$u.get('/system/dept/', params); //
@ -75,6 +79,9 @@ const install = (Vue, vm) => {
wxmplogin, wxmplogin,
bindmp, bindmp,
unbindmp, unbindmp,
bindSecret,
loginSecret,
userList, userList,
deptList, deptList,
ticketCreate, ticketCreate,

View File

@ -50,7 +50,7 @@ const install = (Vue, vm) => {
}) })
}else{ }else{
uni.reLaunch({ uni.reLaunch({
url:'/pages/login/login' url:'/pages/login/login_'
}) })
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"name" : "共享平台", "name" : "曲阳金隅EHS",
"appid" : "__UNI__B00D419", "appid" : "__UNI__B00D419",
"description" : "共享平台", "description" : "曲阳金隅EHS",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",
"transformPx" : false, "transformPx" : false,
@ -70,7 +70,13 @@
"speech" : { "speech" : {
"ifly" : {} "ifly" : {}
}, },
"ad" : {} "ad" : {},
"push" : {
"unipush" : {
"version" : "2",
"offline" : false
}
}
}, },
"orientation" : [ "portrait-primary" ] "orientation" : [ "portrait-primary" ]
} }

View File

@ -13,49 +13,49 @@
"pages": [{ "pages": [{
"path": "pages/login/login_", "path": "pages/login/login_",
"style": { "style": {
"navigationBarTitleText": "密码登录", "navigationBarTitleText": "曲阳金隅EHS-密码登录",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},{ },{
"path": "pages/login/userRegister", "path": "pages/login/userRegister",
"style": { "style": {
"navigationBarTitleText": "新用户注册", "navigationBarTitleText": "曲阳金隅EHS-新用户注册",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/login/login",
"style" :
{
"navigationBarTitleText": "验证码登录",
"enablePullDownRefresh": false
}
},
{
"path": "pages/login/login_password",
"style": {
"navigationBarTitleText": "密码登录",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
// {
// "path" : "pages/login/login",
// "style" :
// {
// "navigationBarTitleText": "验证码登录",
// "enablePullDownRefresh": false
// }
// },
// {
// "path": "pages/login/login_password",
// "style": {
// "navigationBarTitleText": "密码登录",
// "enablePullDownRefresh": false
// }
// },
{ {
"path": "pages/home/home_", "path": "pages/home/home_",
"style": { "style": {
"navigationBarTitleText": "主页", // "navigationBarTitleText": "曲阳金隅EHS主页",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/home/list/ticket", "path": "pages/home/list/ticket",
"style": { "style": {
"navigationBarTitleText": "代办事件", "navigationBarTitleText": "曲阳金隅EHS-待办工单",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
{ {
"path": "pages/home/list/warning", "path": "pages/home/list/warning",
"style": { "style": {
"navigationBarTitleText": "实时报警", "navigationBarTitleText": "曲阳金隅EHS-实时报警",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@ -63,7 +63,7 @@
{ {
"path": "pages/home/detail/ticketHandle", "path": "pages/home/detail/ticketHandle",
"style": { "style": {
"navigationBarTitleText": "工作流审批", "navigationBarTitleText": "曲阳金隅EHS-工单处理",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@ -79,7 +79,7 @@
{ {
"path": "pages/home/detail/warningHandle", "path": "pages/home/detail/warningHandle",
"style": { "style": {
"navigationBarTitleText": "报警处理", "navigationBarTitleText": "曲阳金隅EHS-报警处理",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@ -87,14 +87,14 @@
{ {
"path": "pages/workSpace/workSpace", "path": "pages/workSpace/workSpace",
"style": { "style": {
"navigationBarTitleText": "工作台", "navigationBarTitleText": "曲阳金隅EHS-工作台",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/workSpace/rpj/rpjLisst", "path": "pages/workSpace/rpj/rpjLisst",
"style": { "style": {
"navigationBarTitleText": "入厂项目", "navigationBarTitleText": "曲阳金隅EHS-入厂项目",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@ -127,7 +127,7 @@
{ {
"path": "pages/workSpace/operation/operationList", "path": "pages/workSpace/operation/operationList",
"style": { "style": {
"navigationBarTitleText": "作业列表", "navigationBarTitleText": "曲阳金隅EHS-作业列表",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@ -151,7 +151,7 @@
{ {
"path": "pages/workSpace/visit/visitList", "path": "pages/workSpace/visit/visitList",
"style": { "style": {
"navigationBarTitleText": "来访项目", "navigationBarTitleText": "曲阳金隅EHS-来访项目",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@ -183,7 +183,7 @@
{ {
"path": "pages/my/my", "path": "pages/my/my",
"style": { "style": {
"navigationBarTitleText": "个人中心", "navigationBarTitleText": "曲阳金隅EHS-个人中心",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
@ -198,7 +198,7 @@
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "曲阳金隅智慧安全", "navigationBarTitleText": "曲阳金隅EHS",
"navigationBarBackgroundColor": "#F8F8F8", "navigationBarBackgroundColor": "#F8F8F8",
// "navigationStyle": "custom", // "navigationStyle": "custom",
"backgroundColor": "#F8F8F8" "backgroundColor": "#F8F8F8"

View File

@ -37,18 +37,19 @@
</form> </form>
</view> </view>
<view class="login-area" v-if="isMessage"> <view class="login-area" v-if="isMessage">
<form style="display: block;" @submit="formSubmit"> <form style="display: block;" @submit="formSubmit2">
<view class="login-item"> <view class="login-item">
<image class="login-icon" src="../../static/login/avatar.png" mode=""></image> <image class="login-icon" src="../../static/login/avatar.png" mode=""></image>
<input placeholder-style="color: #2c6fd9;" style="color: #2c6fd9;" class="loginItemInput" <input placeholder-style="color: #2c6fd9;" style="color: #2c6fd9;" class="loginItemInput"
type="text" name="phoneNumber" v-model="phoneNumber" placeholder="请输入手机号" /> type="text" name="phone" v-model="phoneNumber" placeholder="请输入手机号" />
</view> </view>
<view class="login-item"> <view class="login-item">
<image class="login-icon" src="../../static/login/password.png" mode=""></image> <image class="login-icon" src="../../static/login/password.png" mode=""></image>
<input placeholder-style="color: #2c6fd9;" style="color: #2c6fd9;" class="loginItemInput" <input placeholder-style="color: #2c6fd9;" style="color: #2c6fd9;" class="loginItemInput"
type="text" name="message" password placeholder="请输入验证码" /> type="text" name="code" placeholder="请输入验证码" />
<button class="getMessageCode" @click="getCode">{{codeTips}}</button> <button class="getMessageCode" @click="getCode">{{codeTips}}</button>
</view> </view>
<u-verification-code seconds="30" ref="uCode" @change="codeChange"></u-verification-code>
<view class="privacy"> <view class="privacy">
<view class="privacyIn"> <view class="privacyIn">
<u-checkbox-group> <u-checkbox-group>
@ -67,7 +68,7 @@
</view> </view>
<view class="wxBig"> <view class="wxBig">
<view class="Wxtitle"> <view class="Wxtitle">
<view class="WxtitleIn">新用户注册</view> <view class="WxtitleIn">访客注册</view>
</view> </view>
<view class="wx" @click="userRegister"> <view class="wx" @click="userRegister">
<image src="/static/login/userRegister.png" mode=""></image> <image src="/static/login/userRegister.png" mode=""></image>
@ -296,6 +297,21 @@
url: '/pages/login/userRegister' 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) { formSubmit(e) {
var that = this; var that = this;
const obj = e.target.value; const obj = e.target.value;
@ -311,18 +327,48 @@
that.$u.vuex('vuex_user', 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({ uni.reLaunch({
url: '/pages/home/home_' url: '/pages/home/home_'
}) })
}).catch(e => { }).catch(e => {
console.log(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) { codeChange(text) {
this.codeTips = text; this.codeTips = text;
}, },
@ -331,21 +377,23 @@
debugger; debugger;
console.log(this.phoneNumber) console.log(this.phoneNumber)
if (this.phoneNumber !== '') { if (this.phoneNumber !== '') {
uni.showLoading({ if (this.$refs.uCode.canGetCode){
title: '正在获取验证码', uni.showLoading({
mask: true title: '正在获取验证码',
}) mask: true
this.$u.api.getCode({ })
phone: this.phoneNumber this.$u.api.getCode({
}).then(res => { phone: this.phoneNumber
setTimeout(() => { }).then(res => {
uni.hideLoading(); setTimeout(() => {
// this.start() uni.hideLoading();
this.$u.toast('验证码已发送'); // this.start()
// this.$u.toast('验证码已发送');
this.$refs.uCode.start(); //
}, 2000); this.$refs.uCode.start();
}) }, 2000);
})
}
} else { } else {
// this.$u.toast(''); // this.$u.toast('');
this.$u.toast('请输入手机号'); this.$u.toast('请输入手机号');

View File

@ -13,7 +13,7 @@
</view> </view>
<!-- #endif --> <!-- #endif -->
<!-- #ifndef MP-WEIXIN --> <!-- #ifndef MP-WEIXIN -->
<u-avatar :src="vuex_user.avatar" size="124"></u-avatar> <u-avatar :src="vuex_user.avatar" size="100"></u-avatar>
<!-- #endif --> <!-- #endif -->
</view> </view>
<view> <view>
@ -257,6 +257,11 @@
var that = this; var that = this;
this.$u.api.loginOut().then(()=>{ this.$u.api.loginOut().then(()=>{
that.$u.vuex('vuex_token', null); that.$u.vuex('vuex_token', null);
try {
uni.removeStorageSync('mySecret');
} catch (e) {
// error
}
uni.reLaunch({ uni.reLaunch({
url:'/pages/login/login_' url:'/pages/login/login_'
}) })

View File

@ -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%;"> 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%;">
</view> </view>
<view class="top-title" style="display: flex;"> <view class="top-title" style="display: flex;">
<block v-for="(item,index) in routerList" :key="item.index"> <block v-for="(item,index) in routerList" :key="index">
<view class="title-item" @click="goInto(index)"> <view class="title-item" @click="goInto(index)">
<view class="title-icon"> <view class="title-icon">
<image :src="require('@/static/workSpace/'+item.icon+'')" mode="widthFix"></image> <image :src="require('@/static/workSpace/'+item.icon+'')" mode="widthFix"></image>