Browse Source

获取浏览器返回的功能操作

master
453530270@qq.com 2 years ago
parent
commit
ebb4d26e4d
  1. 8
      pages.json
  2. 441
      pages/login/index.vue
  3. 111
      pages/login/indexBk.vue

8
pages.json

@ -275,6 +275,14 @@
"navigationBarTitleText" : "",
"enablePullDownRefresh" : false
}
},
{
"path" : "pages/login/index",
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : false
}
}
],
"globalStyle": {

441
pages/login/index.vue

@ -1,111 +1,396 @@
<template>
<view class="login">
<!-- 常规方式登录 -->
<Main :isParty="isParty" :partyData="partyData" />
</view>
<view>
</view>
</template>
<script>
import Main from './components/main'
import MpWeixin from './components/mp-weixin'
import SettingKeyEnum from '@/common/enum/setting/Key'
import SettingModel from '@/common/model/Setting'
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
<template>
<view class="container">
<!-- 页面头部 -->
<view class="header">
<view class="title">
<text>登录</text>
</view>
</view>
<!-- 表单 -->
<view class="login-form">
<!-- 手机号 -->
<view class="form-item">
<input class="form-item--input" type="number" v-model="mobile" maxlength="11" autocomplete="off" placeholder="请输入手机号码" />
</view>
<!-- 密码 -->
<view class="form-item">
<input class="form-item--input" type="password" v-model="vpass" autocomplete="off" placeholder="请输入密码" />
</view>
<!-- 选择机构个人 -->
<radio-group @change="radioChange">
<view class="form-item">
<radio class="radio" color="#4399ff" value="企业" :checked="utchk1"/> 机构
</view>
<view class="form-item">
<radio class="radio" color="#4399ff" value="个人" :checked="utchk2"/> 个人
</view>
</radio-group>
<!-- 登录按钮 -->
<view class="login-button" @click="handleLogin">
<text>登录</text>
</view>
</view>
<!-- 找回密码 注册 -->
<view class="fdreg">
<text class="findpass" @click="fdpass">找回密码</text>
<text class="regnow" @click="register">立即注册</text>
</view>
<!-- 隐私政策等 -->
<view class="privacy">
<checkbox :checked="isTick" color="#4399ff" class="ckbox" @click="readpri"></checkbox>
<view class="">
我已阅读并同意网站的 <text class="atxt" @click="gotopage('private')">隐私政策</text>
<text class="atxt" @click="gotopage('prototal')">用户注册协议</text>
</view>
</view>
<!-- 协议弹框 -->
<whpop v-model="showPopup" :maskCloseAble="true" :mkey="murl"></whpop>
</view>
</template>
<script>
import store from '@/store'
import * as LoginApi from '@/api/login'
import * as Verify from '@/utils/verify'
//
import { checkLogin, showError } from '@/core/app'
import whpop from './components/WhPopup'
export default {
components: {
Main,
MpWeixin
// nothing
whpop
},
data() {
return {
// [onLoadview]
isLoad: false,
//
isMpWeixinAuth: false,
//
isParty: false,
//
partyData: {}
//
isLoading: false,
//
mobile: '',
//
vpass:"",
//
isTick:false,
// user type
userType:"",
//
utchk1:true,
utchk2:false,
//
murl:"",
// /
showPopup: false,
}
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
console.log('login onLoad')
//
// await this.setShowUserInfo()
//
this.isLoad = true
console.log('isLoad', true)
created() {
// console.log('main created')
},
mounted() {
// ,
if(window.history && window.history.pushState){
console.log(window.history)
window.addEventListener('popstate',this.goback,false)
}
},
methods: {
/**
* 设置当前是否显示微信小程序授权登录
* - 条件1: 只有微信小程序才显示获取用户信息按钮
* - 条件2: 后台设置是否已开启该选项 [后台-客户端-注册设置]
*/
async setShowUserInfo() {
console.log('setShowUserInfo start')
goback(){
console.log("6666666666666666666")
// let path = this.$route.path
// this.$toast(path)
this.onNavigateBack(1)
},
//
radioChange(evt) {
this.userType = evt.detail.value
if(this.userType=="企业"){
this.utchk2=false
this.utchk1=true;
}else{
this.utchk2=true
this.utchk1=false;
}
},
//
readpri(e){
this.isTick=!this.isTick
},
//
formValidation() {
const app = this
// , getUserProfile
const isMpWeixin = app.platform === 'MP-WEIXIN' && wx.canIUse('getUserProfile')
//
// await SettingModel.item(SettingKeyEnum.REGISTER.value, false)
// .then(setting => {
// app.isMpWeixinAuth = isMpWeixin && setting.isOauthMpweixin
// console.log('setShowUserInfo complete')
// })
//
if (!app.validteMobile(app.mobile) ||!app.validtePass(app.vpass)) {
return false
}
//
if(app.utchk1){
this.userType="企业"
}
if(app.utchk2){
this.userType ="个人"
}
//
if(!app.isTick){
this.$toast("请勾选《隐私保护政策》和《用户注册协议》")
return false
}
return true
},
//
goBack(){
// url
let history = store.state.urlHistory;
console.log(history,"history");
//
// if(history.length > 1) {
// // 1url
// router.push(history[history.length - 3]);
// } else {
// //
// router.push('/');
// }
// // 退popstate
// window.history.pushState('forward', null, '');
// window.history.forward(1);
// this.$router.replace({path: '/'});
//
validtePass(str){
if (Verify.isEmpty(str)) {
this.$toast('请先输入登录密码')
return false
}
return true;
},
//
onGetUserInfoSuccess({ oauth, code, userInfo }) {
//
this.partyData = { oauth, code, userInfo }
//
this.onShowRegister()
//
validteMobile(str) {
if (Verify.isEmpty(str)) {
this.$toast('请先输入手机号')
return false
}
if (!Verify.isMobile(str)) {
this.$toast('请输入正确格式的手机号')
return false
}
return true
},
//
onShowRegister() {
//
this.isMpWeixinAuth = false
//
// this.isParty = true
}
}
//
handleLogin() {
const app = this
if (!app.isLoading && app.formValidation()) {
app.submitLogin()
}
},
//
submitLogin() {
const app = this
app.isLoading = true
store.dispatch('Login', {
loginName: app.mobile,
loginType: "0",
password: this.$md5(app.vpass).toUpperCase(), //
userType: app.userType
})
.then(result => {
//
app.$toast("登录成功")
//app.$toast(result.message)
// :
uni.$emit('syncRefresh', true)
//
setTimeout(() => app.onNavigateBack(1), 2000)
})
.catch(err => {
console.log("err",err)
//
if (err.result.data.isBack) {
setTimeout(() => app.onNavigateBack(1), 2000)
}
})
.finally(() => app.isLoading = false)
},
/**
* 登录成功-跳转回原页面
*/
onNavigateBack(delta = 1) {
const pages = getCurrentPages()
if (pages.length > 1) {
uni.navigateBack({
delta: Number(delta || 1)
})
} else {
//this.$navTo('pages/user/index')
this.$navTo('pages/index/index')
}
},
/**
* 阅读注册协议和隐私
*/
gotopage(str){
//this.$toast(str)
this.murl = str
this.showPopup = ! this.showPopup
},
/**
* 跳转到注册
*/
register(){
this.$navTo("pages/reg/reg")
},
/**
*
*/
fdpass(){
this.$navTo("pages/findpass/findpass")
},
},
//退
destroyed(){
//
window.removeEventListener('popstate',this.goback,false)
}
}
</script>
<style lang="scss" scoped>
.container {
padding: 100rpx 60rpx;
min-height: 100vh;
background-color: #fff;
}
//
.header {
margin-bottom: 60rpx;
.title {
color: #191919;
font-size: 54rpx;
}
}
//
.form-item {
display: flex;
padding: 18rpx;
border-bottom: 1rpx solid #f3f1f2;
margin-bottom: 30rpx;
height: 96rpx;
&--input {
font-size: 28rpx;
letter-spacing: 1rpx;
flex: 1;
height: 100%;
}
&--parts {
min-width: 100rpx;
height: 100%;
}
&--radgrp{
display: flex;
flex:1;
height: 100%;
}
//
.captcha-sms {
font-size: 28rpx;
line-height: 50rpx;
padding-right: 20rpx;
.activate {
color: #cea26a;
}
.un-activate {
color: #9e9e9e;
}
}
}
//
.login-button {
width: 100%;
height: 86rpx;
margin-top: 80rpx;
background: linear-gradient(to right, #242e4b, #242e4b);
color: #fff;
// border-radius: 80rpx;
box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.1);
letter-spacing: 5rpx;
display: flex;
justify-content: center;
align-items: center;
}
//
.fdreg{
display: flex;
margin-top: 26rpx;
line-height: 1.4;
min-height: 26rpx;
color:#ff0000;
padding-left: 32rpx;
padding-right: 32rpx;
text{
display: block;
// display: flex;
float: left;
width: 46%;
line-height: 1.4;
}
.findpass{
text-align: left;
}
.regnow{
text-align: right;
}
}
.privacy{
display: flex;
margin-top: 10rpx;
.ckbox{
border-radius: 50%;
}
.atxt{
color: #4399ff;
}
}
</style>

111
pages/login/indexBk.vue

@ -0,0 +1,111 @@
<template>
<view class="login">
<!-- 常规方式登录 -->
<Main :isParty="isParty" :partyData="partyData" />
</view>
</template>
<script>
import Main from './components/main'
import MpWeixin from './components/mp-weixin'
import SettingKeyEnum from '@/common/enum/setting/Key'
import SettingModel from '@/common/model/Setting'
export default {
components: {
Main,
MpWeixin
},
data() {
return {
// [onLoadview]
isLoad: false,
//
isMpWeixinAuth: false,
//
isParty: false,
//
partyData: {}
}
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
console.log('login onLoad')
//
// await this.setShowUserInfo()
//
this.isLoad = true
console.log('isLoad', true)
},
methods: {
/**
* 设置当前是否显示微信小程序授权登录
* - 条件1: 只有微信小程序才显示获取用户信息按钮
* - 条件2: 后台设置是否已开启该选项 [后台-客户端-注册设置]
*/
async setShowUserInfo() {
console.log('setShowUserInfo start')
const app = this
// , getUserProfile
const isMpWeixin = app.platform === 'MP-WEIXIN' && wx.canIUse('getUserProfile')
//
// await SettingModel.item(SettingKeyEnum.REGISTER.value, false)
// .then(setting => {
// app.isMpWeixinAuth = isMpWeixin && setting.isOauthMpweixin
// console.log('setShowUserInfo complete')
// })
},
//
goBack(){
// url
let history = store.state.urlHistory;
console.log(history,"history");
//
// if(history.length > 1) {
// // 1url
// router.push(history[history.length - 3]);
// } else {
// //
// router.push('/');
// }
// // 退popstate
// window.history.pushState('forward', null, '');
// window.history.forward(1);
// this.$router.replace({path: '/'});
},
//
onGetUserInfoSuccess({ oauth, code, userInfo }) {
//
this.partyData = { oauth, code, userInfo }
//
this.onShowRegister()
},
//
onShowRegister() {
//
this.isMpWeixinAuth = false
//
// this.isParty = true
}
}
}
</script>
<style lang="scss" scoped>
</style>
Loading…
Cancel
Save