smartswrtch-app/pages/login/login.vue

418 lines
9.2 KiB
Vue
Raw Normal View History

2024-03-13 10:54:22 +08:00
<template>
<view class="page">
2024-06-11 18:03:16 +08:00
<u-navbar :is-back="false" :title="tittxt" :border-bottom="false" :background="bgc" title-color='#fff'
title-size='36' height='36'>
2024-03-13 10:54:22 +08:00
</u-navbar>
<view class="imgbox">
2024-05-10 17:37:36 +08:00
<image src="https://api.ccttiot.com/smartmeter/img/static/uCqHftk2W2zEPX03DLcb" mode=""></image>
2024-03-13 10:54:22 +08:00
</view>
<view class="tip">
2024-05-10 17:37:36 +08:00
欢迎来到共享开关
2024-03-13 10:54:22 +08:00
</view>
<view class="inputbox">
2024-09-25 18:30:46 +08:00
<view class="box1" v-if="syflag">
2024-03-13 10:54:22 +08:00
<view class="input_txt" style="width: 536rpx;font-size: 24rpx;line-height: 32rpx;">
2024-05-10 17:37:36 +08:00
您暂未授权共享开关小程序获取你的信息将无法正常使用小程序的功能如需要正常使用请点击授权按钮打开头像昵称等信息的授权
2024-03-13 10:54:22 +08:00
</view>
2024-10-08 17:58:03 +08:00
<!-- <button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
style="margin-left: -10rpx;">
授权登录
</button> -->
<button class="button" @click="getPhoneNumber"
style="margin-left: -10rpx;">
2024-03-13 10:54:22 +08:00
授权登录
</button>
<view class="">
<view class="buttons" style="margin-top: 50rpx;margin-left: -10rpx;" @click="btnshoudong">
账号密码登录
</view>
2024-09-26 17:39:42 +08:00
<!-- <view class="buttons" style="margin-top: 50rpx;margin-left: -10rpx;" @click="btnyzm">
2024-09-25 18:30:46 +08:00
验证码登录
</view> -->
<view class="buttons" style="margin-top: 50rpx;margin-left: -10rpx;" @click="btnbudl">
暂不授权登录
</view>
</view>
2024-09-26 17:39:42 +08:00
</view>
<!-- 账号密码登录 -->
<view class="zhangh" v-if="dlflag">
<view class="tit">
账号密码登录
</view>
2024-09-26 17:39:42 +08:00
<!-- <input type="text" v-model="zh" placeholder="请输入你的账号" /> -->
<view class="" style="margin-top: 30rpx;">
<u-input v-model="zh" :border="border" placeholder="请输入你的账号" />
</view>
<view class="" style="margin-top: 30rpx;">
<u-input v-model="mm" :type="onetype" :border="border" placeholder="请输入你的密码"
:password-icon="passwordIcon" />
</view>
<view class="mmdl" @click="btndl">
登录
</view>
2024-09-26 17:39:42 +08:00
<view class="mmdl" @click="btnqx(1)"
style="background-color: #fff;border: 1px solid #efefef;color: #000;margin-top: 20rpx;">
2024-09-25 18:30:46 +08:00
取消
</view>
</view>
2024-09-26 17:39:42 +08:00
2024-09-25 18:30:46 +08:00
<!-- 验证码登录 -->
<view class="zhangh" v-if="yzmflag">
<view class="tit">
验证码登录
</view>
2024-09-26 17:39:42 +08:00
<view class="" style="margin-top: 30rpx;">
<u-input v-model="zh" :border="border" placeholder="请输入你的账号" />
2024-09-25 18:30:46 +08:00
</view>
2024-09-26 17:39:42 +08:00
<view class="" style="margin-top: 30rpx;display: flex;align-items: center;justify-content: space-between;">
<u-input v-model="yzm" :border="border" placeholder="请输入验证码" />
<u-toast ref="uToast"></u-toast>
<u-verification-code :seconds="seconds" @start="start" ref="uCode"
@change="codeChange"></u-verification-code>
<u-button @click="getCode">{{tips}}</u-button>
</view>
2024-09-25 18:30:46 +08:00
<view class="mmdl" @click="btndl">
登录
</view>
2024-09-26 17:39:42 +08:00
<view class="mmdl" @click="btnqx(2)"
style="background-color: #fff;border: 1px solid #efefef;color: #000;margin-top: 20rpx;">
取消
</view>
</view>
2024-09-26 17:39:42 +08:00
2024-03-13 10:54:22 +08:00
</view>
</view>
</template>
<script>
export default {
data() {
return {
2024-09-26 17:39:42 +08:00
tips: '',
seconds: 60,
onetype: 'password',
passwordIcon: true,
border: true,
twopwd: 'password',
2024-03-13 10:54:22 +08:00
bgc: {
backgroundColor: "#7D86EF",
},
2024-06-11 18:03:16 +08:00
tittxt: "授权登录",
chooseType: true,
usertype: '',
2024-06-14 18:51:43 +08:00
login: false,
2024-09-26 17:39:42 +08:00
id: '',
dlflag: false,
zh: '',
mm: '',
yzm: '',
yzmflag: false,
syflag: true
2024-06-14 18:51:43 +08:00
}
},
onLoad(option) {
2024-09-26 17:39:42 +08:00
if (option.id) {
2024-06-14 18:51:43 +08:00
this.id = option.id
2024-03-13 10:54:22 +08:00
}
},
2024-07-17 17:59:51 +08:00
// 分享到好友(会话)
2024-09-26 17:39:42 +08:00
onShareAppMessage: function() {
return {
title: '创想物联',
path: '/pages/shouye/index'
}
},
// 分享到朋友圈
onShareTimeline: function() {
return {
title: '创想物联',
query: '',
path: '/pages/shouye/index'
}
},
2024-03-13 10:54:22 +08:00
methods: {
2024-09-26 17:39:42 +08:00
codeChange(text) {
this.tips = text;
},
getCode() {
if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: '正在获取验证码'
})
setTimeout(() => {
uni.hideLoading();
// 这里此提示会被this.start()方法中的提示覆盖
this.$u.toast('验证码已发送');
// 通知验证码组件内部开始倒计时
this.$refs.uCode.start();
}, 1000);
} else {
this.$u.toast('验证码已发送');
}
},
start() {
this.$u.toast('验证码已发送');
},
// 账号密码登录
2024-09-26 17:39:42 +08:00
btndl() {
let data = {
2024-09-26 17:39:42 +08:00
username: this.zh,
password: this.mm
}
this.$u.post("/app/auth/login", data).then(res => {
2024-09-26 17:39:42 +08:00
if (res.code == 200) {
wx.setStorageSync('token', res.token);
this.ceshi()
2024-09-26 17:39:42 +08:00
} else {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000,
})
}
})
},
2024-09-26 17:39:42 +08:00
btnqx(num) {
if (num == 1) {
2024-09-25 18:30:46 +08:00
this.dlflag = false
this.syflag = true
2024-09-26 17:39:42 +08:00
} else {
2024-09-25 18:30:46 +08:00
this.yzmflag = false
this.syflag = true
}
},
2024-09-26 17:39:42 +08:00
btnyzm() {
2024-09-25 18:30:46 +08:00
this.yzmflag = true
this.syflag = false
},
2024-09-26 17:39:42 +08:00
btnshoudong() {
this.dlflag = true
2024-09-25 18:30:46 +08:00
this.syflag = false
},
2024-06-11 18:03:16 +08:00
userType(num) {
this.chooseType = false
this.login = true
if (num == 1) {
this.usertype = '01'
} else {
this.usertype = '00'
2024-03-13 10:54:22 +08:00
}
},
2024-10-08 17:58:03 +08:00
getPhoneNumber(){
2024-10-29 16:05:02 +08:00
uni.showLoading({
title: '登录中...',
mask: true
})
2024-10-08 17:58:03 +08:00
let taht = this
wx.login({
success(res) {
if (res.code) {
let data = {
loginCode: res.code,
2024-06-11 18:03:16 +08:00
}
2024-10-08 17:58:03 +08:00
taht.$u.post('/app/auth/wxLogin', data).then(res => {
if (res.code == 10003) {
2024-10-29 16:05:02 +08:00
uni.hideLoading()
2024-10-08 17:58:03 +08:00
uni.navigateTo({
url: '/pages/login/login'
})
} else if (res.code == 200) {
uni.setStorageSync('token', res.token)
taht.ceshi()
}
})
2024-09-26 17:39:42 +08:00
}
2024-10-08 17:58:03 +08:00
},
2024-09-26 17:39:42 +08:00
})
2024-03-13 10:54:22 +08:00
},
2024-10-08 17:58:03 +08:00
// getPhoneNumber(e) {
// let that = this;
// console.log("eeeeeeee", e);
// const wxLoginAsync = () => {
// return new Promise((resolve, reject) => {
// wx.login({
// success(res) {
// if (res.code) {
// let data = {
// loginCode: res.code,
// mobileCode: e.detail.code,
// }
// resolve(data);
// } else {
// reject(res.errMsg)
// }
// },
// fail(err) {
// reject(err)
// }
// })
// })
// }
// wxLoginAsync().then(async (data) => {
// this.$u.post("/app/auth/wxLogin", data).then((res) => {
// if (res.code == 200) {
// wx.setStorageSync('token', res.token);
// that.ceshi()
// }
// })
// }).catch((err) => {
// console.error(err)
// })
// },
2024-03-13 10:54:22 +08:00
async ceshi() {
2024-10-29 16:05:02 +08:00
uni.hideLoading()
2024-03-13 10:54:22 +08:00
this.$u.get("/app/user/userInfo").then((res) => {
2024-09-26 17:39:42 +08:00
if (this.id == 1) {
2024-06-14 18:51:43 +08:00
uni.navigateBack()
2024-09-26 17:39:42 +08:00
} else {
2024-07-16 15:00:10 +08:00
uni.reLaunch({
2024-06-14 18:51:43 +08:00
url: '/pages/shouye/index'
})
}
2024-06-11 18:03:16 +08:00
})
2024-03-13 10:54:22 +08:00
},
2024-09-26 17:39:42 +08:00
btnbudl() {
2024-07-16 15:00:10 +08:00
uni.reLaunch({
2024-06-14 18:51:43 +08:00
url: '/pages/shouye/index'
})
}
2024-03-13 10:54:22 +08:00
}
}
</script>
2024-06-11 18:03:16 +08:00
<style lang="scss">
2024-09-26 17:39:42 +08:00
/deep/ .u-size-default{
height: 37px !important;
line-height: 35px !important;
margin-left: 10rpx;
}
/deep/ .u-btn{
padding: 0 20rpx !important;
}
2024-06-11 18:03:16 +08:00
page {
2024-03-13 10:54:22 +08:00
background: #FFFFFF;
}
2024-09-26 17:39:42 +08:00
.zhangh {
width: 562rpx;
text-align: center;
2024-09-26 17:39:42 +08:00
.tit {
font-size: 40rpx;
color: #000;
margin-bottom: 30rpx;
}
2024-09-26 17:39:42 +08:00
// input{
// width: 562rpx;
// height: 90rpx;
// margin-top: 20rpx;
// border-radius: 20rpx;
// background-color: #eeefee;
// text-align: center;
// padding-left: 30rpx;
// box-sizing: border-box;
// text-align: left;
// }
.mmdl {
width: 562rpx;
2024-09-26 17:39:42 +08:00
height: 80rpx;
background: #8883F0;
border-radius: 52rpx 52rpx 52rpx 52rpx;
font-weight: 500;
font-size: 36rpx;
color: #FFFFFF;
2024-09-26 17:39:42 +08:00
line-height: 80rpx;
margin-top: 50rpx;
}
}
2024-09-26 17:39:42 +08:00
.buttons {
width: 562rpx;
text-align: center;
padding-bottom: 5rpx;
box-sizing: border-box;
color: #ccc;
}
2024-09-26 17:39:42 +08:00
2024-03-13 10:54:22 +08:00
.page {
2024-06-11 18:03:16 +08:00
position: relative;
/* 添加相对定位 */
2024-03-13 10:54:22 +08:00
}
.imgbox {
width: 750rpx;
height: 576rpx;
z-index: 0;
image {
width: 750rpx;
height: 576rpx;
}
}
.tip {
width: 204rpx;
position: absolute;
top: 400rpx;
left: 30rpx;
font-weight: 500;
font-size: 48rpx;
color: #FFFFFF;
line-height: 66rpx;
}
.inputbox {
2024-06-11 18:03:16 +08:00
position: absolute;
/* 或者 fixed根据你的需求 */
top: 700rpx;
/* 调整这里来控制距离顶部的距离 */
width: 750rpx;
/* 调整输入框的宽度 */
2024-03-13 10:54:22 +08:00
padding: 100rpx 0;
2024-06-11 18:03:16 +08:00
background: #fff;
/* 设置背景颜色,这里是红色的半透明 */
border-radius: 50rpx;
/* 设置圆角 */
z-index: 999;
/* 设置 z-index确保在其他内容上方显示 */
2024-03-13 10:54:22 +08:00
padding-left: 104rpx;
2024-06-11 18:03:16 +08:00
.input_txt {
2024-03-13 10:54:22 +08:00
font-weight: 400;
font-size: 32rpx;
color: #3D3D3D;
line-height: 44rpx;
}
2024-06-11 18:03:16 +08:00
.button {
2024-03-13 10:54:22 +08:00
margin-top: 64rpx;
display: flex;
justify-content: center;
align-items: center;
width: 562rpx;
height: 96rpx;
background: #8883F0;
border-radius: 52rpx 52rpx 52rpx 52rpx;
2024-06-11 18:03:16 +08:00
2024-03-13 10:54:22 +08:00
font-weight: 500;
font-size: 36rpx;
color: #FFFFFF;
}
}
2024-06-11 18:03:16 +08:00
</style>