first commit
This commit is contained in:
1
UniAppMobile/pages/.pydio
Normal file
1
UniAppMobile/pages/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
3e252970-c241-4b5f-a964-2b49c8802b47
|
||||
1
UniAppMobile/pages/authorization/.pydio
Normal file
1
UniAppMobile/pages/authorization/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
c9b89ada-5572-47b3-9ed2-1ae864de57d5
|
||||
59
UniAppMobile/pages/authorization/authorization.vue
Normal file
59
UniAppMobile/pages/authorization/authorization.vue
Normal file
@@ -0,0 +1,59 @@
|
||||
<template>
|
||||
<view class="authorization">
|
||||
<h2>授权登录</h2>
|
||||
<button type="primary" @click="AuthorizationLogin">授权Web登录</button>
|
||||
<p class="tips">{{tips}}</p>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
tips: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
AuthorizationLogin() {
|
||||
console.log("授权Web登录");
|
||||
uni.request({
|
||||
url: `${this.$config.baseUrl}/AuthorizedWeb`,
|
||||
method: 'GET',
|
||||
data: {
|
||||
uid: uni.getStorageSync('userinfo').id
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.status == 404) {
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
this.tips = res.data.msg
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.authorization {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20% 0;
|
||||
text-align: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
h2 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
1
UniAppMobile/pages/index/.pydio
Normal file
1
UniAppMobile/pages/index/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
f3d71557-f4a9-4a7c-b077-e36d352dbb4e
|
||||
106
UniAppMobile/pages/index/index.vue
Normal file
106
UniAppMobile/pages/index/index.vue
Normal file
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
|
||||
<div class="scanCode">
|
||||
<h3 class="title">扫码登录 案例</h3>
|
||||
<p>Nodejs + Redis + Mysql + Vue + Uni-app</p>
|
||||
<button class="scan" type="primary" @click="scanCode">扫码登录</button>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
uuid: null,
|
||||
StorageSync: null,
|
||||
timer: null
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
},
|
||||
created() {
|
||||
this.setTime();
|
||||
},
|
||||
methods: {
|
||||
setTime() {
|
||||
this.timer = setInterval(() => {
|
||||
this.CheckAuthorization();
|
||||
},1000);
|
||||
},
|
||||
// 定时器,每隔一秒检查web端是否在请求登录
|
||||
CheckAuthorization() {
|
||||
uni.request({
|
||||
url: `${this.$config.baseUrl}/InquiryWebIsLogining`,
|
||||
method: 'GET',
|
||||
data: {
|
||||
uid: uni.getStorageSync('userinfo').id
|
||||
},
|
||||
success: (res) => {
|
||||
switch (res.data.status){
|
||||
// 没有对应的web端请求登录
|
||||
case 404:
|
||||
console.log(res.data.msg)
|
||||
break;
|
||||
// web端正在请求授权
|
||||
case 200:
|
||||
clearInterval(this.timer)
|
||||
uni.navigateTo({
|
||||
url: `/pages/authorization/authorization`
|
||||
});
|
||||
break;
|
||||
// 授权成功,请勿重复授权
|
||||
case 500:
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
scanCode() {
|
||||
uni.scanCode({
|
||||
success: (res) => {
|
||||
// 保存扫码获得的uuid
|
||||
this.uuid = res.result;
|
||||
uni.request({
|
||||
url: `${this.$config.baseUrl}/SweepStatus`,
|
||||
method: 'GET',
|
||||
data: {
|
||||
uuid: this.uuid
|
||||
},
|
||||
success: (res) => {
|
||||
console.log("ddddddd ------: ", res)
|
||||
uni.navigateTo({
|
||||
url: `/pages/login/login?uuid=${this.uuid}`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.scanCode {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20% 0;
|
||||
}
|
||||
p {
|
||||
color: #8d8d8d;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.scan {
|
||||
margin-top: 30px;
|
||||
}
|
||||
</style>
|
||||
1
UniAppMobile/pages/login/.pydio
Normal file
1
UniAppMobile/pages/login/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
6e7a3a19-b3de-4452-9d21-1dee74cb05a3
|
||||
64
UniAppMobile/pages/login/login.vue
Normal file
64
UniAppMobile/pages/login/login.vue
Normal file
@@ -0,0 +1,64 @@
|
||||
<template>
|
||||
<div class="login">
|
||||
<h2>确认登录吗</h2>
|
||||
<h2 v-if="loginSuccess">登录成功</h2>
|
||||
<button type="primary" @click="submitLogin">确 认</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
uuid: "",
|
||||
loginSuccess: false
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
this.uuid = option.uuid;
|
||||
},
|
||||
methods: {
|
||||
submitLogin() {
|
||||
uni.request({
|
||||
url: `${this.$config.baseUrl}/login`,
|
||||
method: 'GET',
|
||||
data: {
|
||||
uuid: this.uuid,
|
||||
uid: uni.getStorageSync('userinfo').id
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.status == 404) {
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
this.loginSuccess = true
|
||||
}
|
||||
console.log("res ------: ", JSON.stringify(res));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.login {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20% 0;
|
||||
text-align: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
h2 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user