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
"version": "0.0",
"configurations": [{
"app-plus" :
{
"launchtype" : "remote"
},
"default" :
{
"launchtype" : "remote"

28
App.vue
View File

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

View File

@ -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,

View File

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

View File

@ -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" ]
}

View File

@ -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"

View File

@ -37,18 +37,19 @@
</form>
</view>
<view class="login-area" v-if="isMessage">
<form style="display: block;" @submit="formSubmit">
<form style="display: block;" @submit="formSubmit2">
<view class="login-item">
<image class="login-icon" src="../../static/login/avatar.png" mode=""></image>
<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 class="login-item">
<image class="login-icon" src="../../static/login/password.png" mode=""></image>
<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>
</view>
<u-verification-code seconds="30" ref="uCode" @change="codeChange"></u-verification-code>
<view class="privacy">
<view class="privacyIn">
<u-checkbox-group>
@ -67,7 +68,7 @@
</view>
<view class="wxBig">
<view class="Wxtitle">
<view class="WxtitleIn">新用户注册</view>
<view class="WxtitleIn">访客注册</view>
</view>
<view class="wx" @click="userRegister">
<image src="/static/login/userRegister.png" mode=""></image>
@ -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('请输入手机号');

View File

@ -13,7 +13,7 @@
</view>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<u-avatar :src="vuex_user.avatar" size="124"></u-avatar>
<u-avatar :src="vuex_user.avatar" size="100"></u-avatar>
<!-- #endif -->
</view>
<view>
@ -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_'
})

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%;">
</view>
<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-icon">
<image :src="require('@/static/workSpace/'+item.icon+'')" mode="widthFix"></image>