| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <template>
- <view class="loginPage">
- <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/riyuexia/login_bg.png" mode="aspectFill" class="image">
- </image>
- <view class="titleflex" style="margin: 60rpx 0 140rpx 0; ">
- <text class="iconfont icon-back pdas" @click="$back"></text>
- <text class="pdas">日月峡康养旅行</text>
- <text class="pdas"></text>
- </view>
- <view class="logo">
- <image src="../static/login/LOGO@2x.png" mode="aspectFill"></image>
- </view>
- <!-- 选择登陆方式 -->
- <view class="btn">
- <button class="phoneNumber" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
- withCredentials="true">手机号一键登录</button>
- <!-- <view @click="gologin">
- 手机号一键登录
- </view> -->
- <view class="otherNumber" @click="gootherNuber">
- <view class="icon">
- <image src="../static/login/iconS@2x.png" mode="widthFix"></image>
- </view>
- <view class="">
- 其他手机号登陆
- </view>
- </view>
- </view>
- <view class="aggre">
- 登录即代表您同意我们的
- <text class="underline" @click="terms">用户协议</text>和
- <text class="underline" @click="Policy">隐私政策</text>
- </view>
- </view>
- </template>
- <script>
- import WXBizDataCrypt from "@/static/js/WXBizDataCrypt.js"
- export default {
- data() {
- return {
- tips: "获取验证码",
- value: '',
- // 输入的验证码
- code: '',
- // 获取微信登录的code
- wxCode: '',
- // 解密密钥
- session_key: '',
- // 手机号
- phone: '',
- encryptedData: "",
- iv: '',
- openid: "",
- unionid: '',
- nickName: ''
- }
- },
- onLoad() {
- this.initLogin()
- // this.checkTime()
- },
- methods: {
- // 获取微信登录的code以及发送请求
- initLogin() {
- this.getLoginTime()
- uni.login({
- success: (res) => {
- // console.log(res)
- if (res.code) { //微信登录成功 已拿到code
- this.wxCode = res.code //保存获取到的code
- uni.setStorageSync("code", this.wxCode)
- } else {
- this.$toast(res.errMsg)
- console.log('登录失败!' + res.errMsg)
- }
- }
- })
- },
- getPhoneNumber(e) {
- if (e.detail.errMsg == "getPhoneNumber:ok") {
- /*uni.login({
- success: (res) => {
- // console.log(res)
- if (res.code) { //微信登录成功 已拿到code
- this.wxCode = res.code //保存获取到的code */
- uni.$u.http.post('/api/login/phone', {
- code: this.wxCode,
- iv: e.detail.iv,
- enc: e.detail.encryptedData
- }).then(res => {
- console.log(res)
- uni.setStorageSync('token', res.token)
- uni.setStorageSync('phone', res.user.phone)
- this.$store.commit('setToken', res.token)
- this.$store.commit('loginState', res.token)
- this.$store.commit('getUserInfo', {
- //code:this.wxCode,
- phone: res.user.phone,
- })
- uni.showToast({
- title: '登录成功',
- icon: "success",
- duration: 1000
- })
- setTimeout(() => {
- this.$back()
- }, 500)
- }).catch(err => {
- console.log(err)
- uni.showToast({
- icon: "error",
- title: err.message,
- })
- })
- } else {
- console.log('用户点击了拒绝');
- }
- },
- getLoginTime() {
- const date = new Date();
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let nowDate = year + '-' + month
- uni.setStorageSync('loginTime', nowDate)
- },
- checkTime() {
- const date = new Date();
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let oldTime=uni.getStorageSync('loginTime')
- let arr=oldTime.split('-')
- console.log(arr,778)
- if(year-arr[0]==0||year-arr[0]==1){
- if(month-arr[1]==7){
- this.$toast("登录已过期,请重新登陆")
- setTimeout(()=>{
- uni.reLaunch({
- url:'/pages/login'
- })
- })
- }
- }
- },
- // getUserInfo(e){
- // uni.getUserInfo({
- // success:(res)=>{
- // console.log(res)
- // // var userInfo = res.userInfo;
- // }
- // })
- // },
- // 其他电话号码登录
- gootherNuber() {
- uni.navigateTo({
- url: "otherNumlogin"
- })
- },
- // 政策
- Policy() {
- uni.navigateTo({
- url: "/pages/userCenter/Policy"
- })
- },
- // 政策
- terms() {
- uni.navigateTo({
- url: "/pages/userCenter/Terms"
- })
- },
- }
- }
- </script>
- <style lang="less">
- page {
- color: #ffffff;
- }
- .titleflex {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .pdas {
- padding: 0 20rpx;
- }
- .image {
- position: fixed;
- width: 100%;
- height: 100%;
- top: 0;
- left: 0;
- z-index: -1;
- }
- .logo {
- text-align: center;
- margin-top: 197rpx;
- image {
- width: 114rpx;
- height: 114rpx;
- }
- }
- .btn {
- text-align: center;
- margin-top: 117rpx;
- .phoneNumber {
- margin: 0 auto;
- width: 654rpx;
- height: 92rpx;
- line-height: 92rpx;
- background: #1E9F6A;
- color: #FFFFFF;
- border-radius: 8rpx 32rpx 8rpx 32rpx;
- }
- .otherNumber {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 32rpx auto 0;
- width: 654rpx;
- height: 92rpx;
- line-height: 92rpx;
- background: rgba(255, 255, 255, 0.16);
- border-radius: 8rpx 32rpx 8rpx 32rpx;
- border: 1px solid #E2E2E3;
- .icon {
- image {
- width: 38rpx;
- margin: 40rpx 30rpx 0 0;
- }
- }
- }
- }
- .aggre {
- margin-top: 400rpx;
- text-align: center;
- font-family: PingFang-SC-Medium, PingFang-SC;
- font-weight: 500;
- color: #E2E2E2;
- font-size: 26rpx;
- .underline {
- text-decoration: underline;
- padding: 0 6rpx;
- }
- }
- </style>
|