Files
LSM_OIL_SITE/pages/login/posLogin/posLogin.vue

511 lines
13 KiB
Vue
Raw Normal View History

2020-09-04 09:20:45 +08:00
<!-- pos机账号登录入口 -->
<template>
<view class="page-content my-bg">
<cu-custom class="main-topbar bg-main-oil" bgColor="bg-main-oil" :isBack="true">
<block slot="content">星油云站</block>
</cu-custom>
<view class="bg-img margin flex padding-lg radius align-center text-center" :style="'background-image: url('+mainURL+'login-bg.png)'">
<view class="padding-lg margin text-center text-lg text-white w100">
<text class>油站工作人员绑定油站</text>
2020-09-04 09:20:45 +08:00
</view>
</view>
<view class="pannel">
<view class="bg-white margin padding radius shadow-warp">
2020-09-04 09:20:45 +08:00
<view class="cu-form-group">
2020-10-14 11:40:08 +08:00
<view class="title mini-label text-black">手机号</view>
<input type="number" v-model="auth.phone" placeholder="请输入手机号" name="input" />
2020-09-04 09:20:45 +08:00
</view>
2020-10-14 11:40:08 +08:00
<view class="cu-form-group padding-top-sm" v-if="showRandom">
<view class="title text-black mini-label">验证码</view>
<input type="number" :maxlength="6" v-model="auth.captcha" placeholder="六位数字验证码" name="input" />
<text :class="frozen?'text-gray':'oil-main-color'" @tap="sendMsg">{{tips}}</text>
2020-09-04 09:20:45 +08:00
</view>
2020-10-14 11:40:08 +08:00
<view class=" cu-form-group padding-top-sm" v-else>
<view class="title mini-label text-black">密码</view>
2020-09-09 17:07:57 +08:00
<input type="password" v-model="auth.password" placeholder="请输入登入密码" name="input" />
2020-09-04 09:20:45 +08:00
</view>
</view>
<view class="margin-right padding-right-lg text-right" @tap="showRandom=true" v-if="!showRandom">
<text class="text-sm text-red padding-right">短信验证码登录</text>
2020-09-04 09:20:45 +08:00
</view>
<view class="margin-right padding-right-lg text-right" @tap="showRandom=false" v-else>
<text class="text-sm text-red padding-right">密码登录</text>
2020-09-04 09:20:45 +08:00
</view>
</view>
2020-10-14 11:40:08 +08:00
<view class="margin-lg padding-lg bottom-bg">
<button class="bg-main-oil round" v-if="showRandom" @tap="loginRandom">登录</button>
<button class="bg-main-oil round" v-else @tap="loginPwd">登录</button>
2020-11-11 14:02:28 +08:00
<view class="text-center margin-top text-gray text-sm padding-right" @tap="showTips">
<text class="cuIcon-question padding-right-xs"></text>突然登不上了
</view>
2020-09-04 09:20:45 +08:00
</view>
2020-11-11 14:02:28 +08:00
2020-09-04 09:20:45 +08:00
<view class="bottom-part">
<service-hotline />
</view>
2020-11-11 14:02:28 +08:00
<view class="cu-modal" :class="modalName">
<view class="cu-dialog">
<view class="cu-bar bg-red light justify-end">
<view class="content ">
{{'温馨提示'}}
</view>
<view class="action" @tap="hideModal">
<text class="cuIcon-close text-red"></text>
</view>
</view>
<view class="text-left padding-xl padding-bottom padding-top bg-white">
<view class="padding-bottom-sm">
由于微信平台规则变更现用户要关注 星油云站 公众号才能登陆
</view>
<view class="padding-bottom-sm ">
之前已经关注过的小部分用户可能需要重新关注才能登陆即取消关注再关注
</view>
<official-account @binderror="bindload" @bindload="binderror"></official-account>
<view class="text-center" @longpress="navToQr" @tap="toQr">
<view class=" img-view">
<image height="200" src="https://xingka51.oss-cn-hangzhou.aliyuncs.com/applets/cloudSite/yunzhan.jpg" mode="widthFix"></image>
星油云站公众号
</view>
</view>
<view class="text-center padding-top padding-bottom">
<button class="cu-btn bg-red light round" open-type='contact' @tap="hideModal">未解决联系在线客服</button>
</view>
</view>
</view>
</view>
2020-09-04 09:20:45 +08:00
</view>
</template>
<script>
import cloudSiteApi from '@/api/cloud-site.js'
import loginApi from '@/api/login.js'
import md5 from 'js-md5'
2020-09-04 09:20:45 +08:00
export default {
data() {
return {
2020-11-11 14:02:28 +08:00
modalName: '',
2020-09-04 09:20:45 +08:00
baseURL: this.global.baseURL,
mainURL: this.global.mainURL,
forcedLogin: true,
oilSiteNo: '',
showRandom: true,
auth: {},
tips: '发送验证码',
frozen: false // 二维码冷却时间
2020-09-04 09:20:45 +08:00
}
},
created() {
uni.showShareMenu()
},
methods: {
2020-11-11 14:02:28 +08:00
toQr() {
uni.navigateTo({
url: '/pages/test/test'
})
},
navToQr() {
uni.setClipboardData({
data: 'https://xingka51.oss-cn-hangzhou.aliyuncs.com/applets/cloudSite/yunzhan.jpg',
success: () => {
uni.showToast({
title: '二维码链接已复制',
icon: 'none'
})
}
})
},
hideModal() {
this.modalName = ''
},
showTips() {
this.modalName = 'show'
},
bindload() {
2020-10-28 10:47:16 +08:00
console.log('组件夹杂')
},
2020-11-11 14:02:28 +08:00
binderror() {
2020-10-28 10:47:16 +08:00
console.log('组件夹杂失败')
2020-11-11 14:02:28 +08:00
},
// loginWeixin() {
// uni.login({
// provider: 'weixin',
// success: loginRes => {
// const code = loginRes.code
// console.log('启动页code', code)
// loginApi.loginWeixin(code).then(res => {
// if (res.code === 20000) {
// uni.reLaunch({
// url: '/pages/index/index',
// fail: (err) => {
// console.log(err)
// }
// })
// uni.showToast({
// title: res.msg,
// icon: 'success',
// duration: 3000
// })
// uni.setStorage({
// key: 'Authorization',
// data: res.data.accessToken,
// success: () => {
// console.log('Authorization成功', res.data.accessToken)
// }
// })
// uni.setStorage({
// key: 'device',
// data: res.data.openid,
// success: () => {
// console.log('deviceopenid', res.data.openid)
// }
// })
// uni.setStorageSync('userMenu', res.data.loginUser.procedureAuthList)
// uni.setStorageSync('loginUser', {
// id: res.data.loginUser.id,
// name: res.data.loginUser.name,
// userPhone: res.data.loginUser.userPhone
// })
// } else {
// uni.reLaunch({
// url: '/pages/login/boforeLogin/boforeLogin',
// fail: (err) => {
// console.log(err)
// }
// })
// console.log('res', res.code)
// }
2020-10-14 11:40:08 +08:00
2020-11-11 14:02:28 +08:00
// }).catch(err => {
// uni.reLaunch({
// url: '/pages/login/boforeLogin/boforeLogin',
// fail: (err) => {
// console.log(err)
// }
// })
// })
// },
// fail: err => {
// console.log(err)
// }
// });
// },
2020-10-14 11:40:08 +08:00
2020-09-04 09:20:45 +08:00
loginPwd() {
uni.login({
provider: 'weixin',
success: loginRes => {
const code = loginRes.code
console.log(code)
console.log('加密', this.auth.password)
const data3 = {
username: this.auth.phone,
password: md5(this.auth.password),
code: code
}
loginApi.loginWeiXinByPassword(data3).then(res => {
console.log('res', res)
uni.showToast({
title: res.msg,
icon: 'none'
})
console.log('oilSiteCode', this.oilSiteNo)
if (res.code === 20000) {
uni.reLaunch({
url: '/pages/index/index',
fail: (err) => {
console.log(err)
}
})
uni.showToast({
title: res.msg,
icon: 'success',
duration: 3000
})
uni.setStorage({
key: 'Authorization',
data: res.data.accessToken,
success: () => {
console.log('Authorization成功', res.data.accessToken)
}
})
uni.setStorage({
key: 'device',
data: res.data.openid,
success: () => {
console.log('deviceopenid', res.data.openid)
}
})
uni.setStorageSync('userMenu', res.data.loginUser.procedureAuthList)
uni.setStorageSync('loginUser', {
id: res.data.loginUser.id,
2020-10-14 11:40:08 +08:00
name: res.data.loginUser.name,
userPhone: res.data.loginUser.userPhone
})
}
})
},
fail: err => {
console.log(err)
}
});
2020-09-04 09:20:45 +08:00
},
loginWeixin() {
uni.login({
provider: 'weixin',
success: loginRes => {
const code = loginRes.code
console.log(code)
loginApi.loginWeixin(code).then(res => {
if (res.code === 20000) {
uni.reLaunch({
url: '/pages/index/index',
fail: (err) => {
console.log(err)
}
})
uni.showToast({
title: res.msg,
icon: 'success',
duration: 3000
})
uni.setStorage({
key: 'Authorization',
data: res.data.accessToken,
success: () => {
console.log('Authorization成功', res.data.accessToken)
}
})
uni.setStorage({
key: 'device',
data: res.data.openid,
success: () => {
console.log('deviceopenid', res.data.openid)
}
})
uni.setStorageSync('userMenu', res.data.loginUser.procedureAuthList)
uni.setStorageSync('loginUser', {
id: res.data.loginUser.id,
2020-10-14 11:40:08 +08:00
name: res.data.loginUser.name,
userPhone: res.data.loginUser.userPhone
2020-09-04 09:20:45 +08:00
})
} else {
console.log('res', res.code)
2020-10-14 11:40:08 +08:00
uni.showToast({
title: '未绑定微信',
icon: 'none',
duration: 1500
})
2020-09-04 09:20:45 +08:00
}
})
},
fail: err => {
console.log(err)
}
});
},
sendMsg() {
if (!this.frozen) {
if (this.auth.phone) {
const data2 = {
phone: this.auth.phone
}
loginApi.loginAppSendSms(data2).then(res => {
console.log('res', res)
uni.showToast({
title: res.msg,
icon: 'none'
})
if (res.code === 20000) {
2020-09-09 17:07:57 +08:00
this.frozen = true
setTimeout(() => {
2020-09-09 17:07:57 +08:00
this.frozen = false
clearInterval(timer)
2020-09-09 17:07:57 +08:00
this.tips = `发送验证码`
}, 1000 * 60);
let second = 60
const timer = setInterval(() => {
2020-09-09 17:07:57 +08:00
second--
if (second) {
this.tips = `${second}秒后重发`
} else {
this.tips = `发送验证码`
this.disabled = false
this.btnColor = '#FE0505'
}
}, 1000)
2020-09-09 17:07:57 +08:00
}
2020-09-09 17:07:57 +08:00
})
2020-09-09 17:07:57 +08:00
} else {
uni.showToast({
title: '请输入您的账号',
icon: 'none'
})
}
2020-09-04 09:20:45 +08:00
}
},
2020-09-09 17:07:57 +08:00
2020-09-04 09:20:45 +08:00
loginRandom() {
uni.login({
provider: 'weixin',
success: loginRes => {
const code = loginRes.code
console.log(code)
const data2 = {
phone: this.auth.phone,
username: this.auth.phone, //类型String 必有字段 备注:手机号
verifyCode: this.auth.captcha, //类型String 必有字段 备注:验证码
code: code //类型String 必有字段 备注微信code
2020-09-04 09:20:45 +08:00
}
loginApi.loginWeiXinSMS(data2).then(res => {
console.log('res', res)
uni.showToast({
title: res.msg,
icon: 'none'
})
2020-09-04 09:20:45 +08:00
console.log('oilSiteCode', this.oilSiteNo)
if (res.code === 20000) {
uni.reLaunch({
url: '/pages/index/index',
fail: (err) => {
console.log(err)
}
})
uni.showToast({
title: res.msg,
icon: 'success',
duration: 3000
})
2020-09-04 09:20:45 +08:00
uni.setStorage({
key: 'Authorization',
data: res.data.accessToken,
2020-09-04 09:20:45 +08:00
success: () => {
console.log('Authorization成功', res.data.accessToken)
2020-09-04 09:20:45 +08:00
}
})
uni.setStorage({
key: 'device',
data: res.data.openid,
2020-09-04 09:20:45 +08:00
success: () => {
console.log('deviceopenid', res.data.openid)
2020-09-04 09:20:45 +08:00
}
})
uni.setStorageSync('userMenu', res.data.loginUser.procedureAuthList)
uni.setStorageSync('loginUser', {
id: res.data.loginUser.id,
2020-10-14 11:40:08 +08:00
name: res.data.loginUser.name,
userPhone: res.data.loginUser.userPhone
2020-09-04 09:20:45 +08:00
})
}
})
},
fail: err => {
console.log(err)
}
});
},
getMsg() {
uni.requestSubscribeMessage({
tmplIds: ['W5XD3NQVa6knC5jXHeWT8GS7q5CHrDUMY_sF79kLkKk'],
success: (res) => {
console.log(res)
}
})
},
getUserInfo({
detail
}) {
console.log('三方登录只演示登录api能力暂未关联云端数据');
console.log('detail', detail)
if (detail.userInfo) {
this.loginLocal(detail.userInfo.nickName);
} else {
uni.showToast({
icon: 'none',
title: '登陆失败'
});
}
},
loginLocal(nickName) {
uni.setStorageSync('login_type', 'local')
uni.setStorageSync('username', nickName)
this.toMain(nickName);
},
toMain(userName) {
// this.login(userName)
console.log(userName)
/**
* 强制登录时使用reLaunch方式跳转过来
* 返回首页也使用reLaunch方式
*/
if (this.forcedLogin) {
uni.reLaunch({
url: '/pages/index/index',
success: () => {
console.log('success')
},
fail: err => {
console.log(err)
}
});
} else {
uni.navigateBack();
}
}
}
};
</script>
<style scoped>
.page-content {
min-height: 100%;
position: relative;
}
.logo {
min-width: 100%;
text-align: center;
}
.logo img {
width: 200upx;
height: 200rpx;
background-size: contain;
margin: auto;
}
.bottom-bg {
position: sticky;
bottom: 50upx;
}
2020-11-11 14:02:28 +08:00
.img-view {
max-width: 300upx;
width: 100%;
display: inline-block;
}
.qrimg-yunzhan {
width: 200upx;
height: 200rpx;
}
2020-09-04 09:20:45 +08:00
</style>