Commit e6d1d1d5 by sunchao

登陆注册

parent d3eab360
<script>
import initApp from "@/util/router.js";
import {interceptor} from '@/util/interceptor.ts';
export default {
onLaunch: function() {
console.log('App Launch')
initApp()
},
onShow: function() {
console.log('App Show')
......
import request from "../util/request";
import {baseURL,apiURL,sfpURL} from "../environments/environment";
import {baseURL,apiURL,cffpURL} from "../environments/environment";
export default {
//查看token是否已经失效
......@@ -17,6 +17,17 @@ export default {
}
return request(`${baseURL}/api/authorize/obtainToken`, "POST", params)
},
//获取验证码
verificationCode(params){
return request(`${baseURL}/api/verificationCode`, "POST", params)
},
//登录接口
loginVerification(params){
return request(`${cffpURL}/user/loginVerification`, "POST", params)
},
//注册接口
register(params){
return request(`${cffpURL}/user/register`, "POST", params)
}
}
export default {
mobileNoValid(no) {
const MOBILE_REGEXP = /^(1)\d{10}$/;
return MOBILE_REGEXP.test(no);
},
// 封装报错弹窗
errorDialog(type,content){
// type 1 必填项校验 2 规则校验
uni.showModal({
title: type===1 ? '必填项校验' : '规则校验',
content:content,
showCancel:false,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
}
\ No newline at end of file
<template>
<view>
课程列表
</view>
</template>
<script>
export default{
data(){
return;
},
name:'courselist',
}
</script>
<style>
</style>
\ No newline at end of file
......@@ -10,14 +10,19 @@
</view>
<form>
<view class="inputItem" v-if="loginType==='register'">
<input class="uni-input" name="invitationCode" placeholder="输入邀请码(非必填)" />
<input class="uni-input" name="invitationCode" placeholder="输入邀请码(非必填)" v-model="invitation_code"/>
</view>
<view class="inputItem">
<input class="uni-input" name="mobileNo" placeholder="输入手机号" />
<view class="inputItem" v-if="loginType!=='agentlogin'">
<input class="uni-input" name="mobileNo" placeholder="输入手机号" v-model="form.mobile" maxlength="11"
/>
</view>
<view class="inputItem" v-if="loginType === 'codelogin' || loginType==='register'">
<input class="uni-input" name="code" placeholder="输入验证码" />
<text @click="sendMessage()">{{sedCode}}</text>
<view class="inputItem" v-if="loginType==='agentlogin'">
<input class="uni-input" name="mobileNo" placeholder="输入账号" v-model="account" maxlength="11"
/>
</view>
<view class="inputItem" v-if="loginType === 'codelogin' || loginType==='register' || loginType === 'resetpw'">
<input class="uni-input" name="code" placeholder="输入验证码" v-model="form.code" type="number"/>
<text @click="sendMessage()" :class="{'grey':disabledSendBtn}">{{sendCodeHtml}}</text>
</view>
<view class="inputItem" v-if="loginType === 'pwlogin' || loginType==='register'">
<input class="uni-input" type="text" name="password" placeholder="输入密码" v-if="!passwordFlag"/>
......@@ -25,26 +30,40 @@
<text v-if="passwordFlag" @click="passwordFlag=false">显示密码</text>
<text v-if="!passwordFlag" @click="passwordFlag=true">不显示密码</text>
</view>
<!--重置密码-->
<view v-if="loginType === 'resetpw'">
<view class="inputItem" >
<input class="uni-input" type="text" password name="password" placeholder="密码(6-20位字母数字组合)" />
</view>
<view class="inputItem" >
<input class="uni-input" type="text" password name="password" placeholder="再次确认密码" />
</view>
</view>
</form>
<view class="agree">
<view class="agree" v-if="loginType!='resetpw'">
<icon :type="radioUnselect" size="26"/><text>已阅读并同意</text><a href="#">银盾保险经纪服务协议</a><text></text><a href="">隐私政策</a>
</view>
<view class="login_btn">
<view class="login_btn" @click="loginInCheck()()" v-if="loginType!='resetpw'">
{{loginType=='register'?'注册':'登录'}}
{{loginType}}
</view>
<view class="login_btn" v-if="loginType=='resetpw'">
保存
</view>
<view class="login_type">
<text @click="getLogin()">{{(loginType=='pwlogin' || loginType=='register')?'验证码登录':'密码登录'}}</text>
<view class="login_type" v-if="loginType!='resetpw'">
<text @click="getLoginType()">{{(loginType=='pwlogin' || loginType=='register')?'验证码登录':'密码登录'}}</text>
<text @click="register()">{{loginType=='codelogin'?'立即注册':'忘记密码'}}</text>
</view>
<view>
<view v-if="loginType!='resetpw'">
<view class="other_login">
<text class="text_line"></text>
<text style="margin: 0 40rpx;position: relative;top: 10rpx;">其他登录</text>
<text class="text_line"></text>
</view>
<view class="login_type">
<text>游客</text>
<text>代理商</text>
<text @click="loginType='visitor';loginIn(1)">游客</text>
<text @click="loginType = 'agentlogin';loginTypeName = '管理账号登录';">代理商</text>
</view>
</view>
</view>
......@@ -53,6 +72,9 @@
</template>
<script>
import api from '../../api/api';
import common from '../../common/common';
export default {
data() {
return {
......@@ -60,39 +82,147 @@
loginType: 'codelogin',
passwordFlag:false,
loginTypeName:'验证码登录',
countdown:60,
sedCode:'获取验证码'
remainTimes:60,
sendCodeHtml:'获取验证码',
//用户输入信息
form:{
mobile:null,
code:null,
password:null,
},
disabledSendBtn:false,
invitation_code:null,
account:null
}
},
methods: {
formReset: function(e) {
console.log('清空数据')
},
getLogin(){
getLoginType(){
this.loginType==='codelogin'?this.loginType='pwlogin':this.loginType='codelogin';
this.loginTypeName = this.loginType =='codelogin'?'验证码登录':'密码登录';
this.loginType==='codelogin'?this.form.password=null:this.form.code=null;
},
register(){
this.loginType = 'register';
this.loginTypeName = '注册';
this.loginType==='register'?this.loginType='resetpw':this.loginType='register';
this.loginTypeName = this.loginType =='register'?'注册':'重置密码';
},
sendMessage(){
this.delayTime()
const params = {
mobileNo:this.form.mobile,
type:"1"
}
if(common.mobileNoValid(this.form.mobile) && !this.disabledSendBtn){
api.verificationCode(params).then((res)=>{
console.log(res)
if(res['success']){
this.delayTime()
}
})
}else{
common.errorDialog(2,'手机号校验错误')
}
},
delayTime() {
if (this.countdown == 0) {
this.isValid = false;
this.sedCode = "重新发送";
this.countdown = 60;
} else {
this.isValid = true;
this.sedCode = this.countdown + "s";
this.countdown--;
setTimeout(() => {
this.delayTime();
}, 1000);
}
}
this.disabledSendBtn = true;
this.timer = setInterval(() => {
this.remainTimes--;
this.sendCodeHtml = `${this.remainTimes}(S)`;
if (this.remainTimes <= 0) {
this.sendCodeHtml = '获取验证码';
this.remainTimes = 60;
this.disabledSendBtn = false;
clearInterval(this.timer);
}
}, 1000);
},
loginIn(loginType){
console.log(loginType)
const params = {
loginType:loginType,
...this.form
}
console.log(params)
api.loginVerification(params).then((res)=>{
if(res['success']){
uni.setStorageSync('isLogin',1)
uni.navigateTo({
url:'/pages/index/index'
})
}else{
uni.showToast({
title: res['message'],
duration: 2000,
icon: 'none'
})
}
})
},
registerIn(){
const params = {
invitation_code:this.invitation_code,
...this.form
}
console.log(params)
api.register(params).then((res)=>{
if(res['success']){
uni.setStorageSync('isLogin',1)
uni.navigateTo({
url:'/pages/index/index'
})
}else{
uni.showToast({
title: res['message'],
duration: 2000,
icon: 'none'
})
}
})
},
loginInCheck(){
//只有代理商登录不需要填写手机号
if(this.loginType !== 'agentlogin'){
if(!this.form.mobile){
common.errorDialog(1,'请输入手机号');
return false;
}
if(!common.mobileNoValid(this.form.mobile)){
common.errorDialog(2,'手机号格式填写错误');
return false;
}
if(this.loginType === 'codelogin'){
if(!this.form.code){
common.errorDialog(1,'请输入验证码');
return false;
}
this.loginIn(3)
}
if(this.loginType === 'password'){
if(!this.form.code){
common.errorDialog(1,'请输入密码');
return false;
}
this.loginIn(2)
}
if(this.loginType === 'register'){
}
}
if(this.loginType === 'agentlogin'){
if(!this.account){
if(!this.form.code){
common.errorDialog(1,'请输入密码');
return false;
}
}
this.loginIn(4)
}
}
},
mounted() {
}
}
</script>
......@@ -134,16 +264,16 @@
}
.uni-input:after{
content: " ";
position: absolute;
left: 0;
bottom: 0;
right: 0;
height: 1px;
border-bottom: 1px solid rgba(0,0,0,.1);
color: #CECECE;
transform-origin: 0 100%;
transform: scaleY(.5);
z-index: 2;
position: absolute;
left: 0;
bottom: 0;
right: 0;
height: 1px;
border-bottom: 1px solid rgba(0,0,0,.1);
color: #CECECE;
transform-origin: 0 100%;
transform: scaleY(.5);
z-index: 2;
}
text{
position: absolute;
......@@ -151,6 +281,9 @@
top: 20rpx;
color: #20279B;
}
.grey{
color: #CECECE;
}
}
}
.agree{
......
const dev = {
base_url:'https://mdev.zuihuibi.cn',
api_url:'https://mdev.zuihuibi.cn/api',
sfp_url:'https://mdev.zuihuibi.cn/api/sfp'
cffp_url:'https://mdev.zuihuibi.cn/api/cffp'
}
const stage = {
base_url:'https://mstage.zuihuibi.cn',
api_url:'https://mstage.zuihuibi.cn/api',
sfp_url:'https://mstage.zuihuibi.cn/api/sfp'
cffp_url:'https://mstage.zuihuibi.cn/api/cffp'
}
const prod = {
base_url:'https://m.zuihuibi.cn',
api_url:'https://m.zuihuibi.cn/api',
sfp_url:'https://m.zuihuibi.cn/api/sfp'
cffp_url:'https://m.zuihuibi.cn/api/cffp'
}
const config = {
......@@ -30,10 +30,10 @@ let env = 'dev';
let baseURL = config[env].base_url;
let apiURL = config[env].api_url;
let sfpURL = config[env].sfp_url;
let cffpURL = config[env].cffp_url;
export{
baseURL,
apiURL,
sfpURL
cffpURL
}
\ No newline at end of file
import App from './App'
import App from './App';
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
......
......@@ -76,5 +76,25 @@
"uniStatistics" : {
"enable" : false
},
"vueVersion" : "3"
"vueVersion" : "3",
"h5" : {
"router" : {
"base" : "/cffp/",
"mode" : "history"
},
"devServer" : {
"proxy" : {
"/api" : {
"port" : 3000, // 端口号
"target" : "https://mdev.zuihuibi.cn", //请求的目标域名
"changeOrigin" : true, //是否跨域
"secure" : false, //设置支持https协议的代理
"logLevel" : "debug",
"pathRewrite" : {
"^/api" : ""
}
}
}
}
}
}
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"topWindow": false,
"navigationBarTitleText": "CFFP"
}
},
{
"path": "components/login/login",
"style": {
"topWindow": false,
"navigationBarTitleText": "CFFP"
}
}
},
// {
// "path": "pages/index/index",
// "style": {
// "topWindow": false,
// "navigationBarTitleText": "CFFP"
// }
// },
],
// "tabBar": {
// "color": "#7A7E83", // tab 上的文字默认颜色
// "selectedColor": "#3cc51f", // tab 上的文字选中时的颜色
// "borderStyle": "black", // tabbar 上边框的颜色,可选值 black/white
// "backgroundColor": "#ffffff", // tab 的背景色
// "list": [{ // 最少2个、最多5 tab
// "pagePath": "pages/index/index", // 页面路径,必须在 pages 中先定义
// "iconPath": "static/tabbar/home.png", // 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px
// "selectedIconPath": "static/tabbar/home-active.png", // 选中时的图片路径
// "text": "首页" // tab 上按钮文字
// }, { // 最少2个、最多5 tab
// "pagePath": "pages/index/index", // 页面路径,必须在 pages 中先定义
// "iconPath": "static/tabbar/home.png", // 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px
// "selectedIconPath": "static/tabbar/home-active.png", // 选中时的图片路径
// "text": "SFP智能财策" // tab 上按钮文字
// },{ // 最少2个、最多5 tab
// "pagePath": "pages/index/index", // 页面路径,必须在 pages 中先定义
// "iconPath": "static/tabbar/home.png", // 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px
// "selectedIconPath": "static/tabbar/home-active.png", // 选中时的图片路径
// "text": "CFFP认证" // tab 上按钮文字
// },{
// "pagePath": "pages/my/my",
// "iconPath": "static/tabbar/my.png",
// "selectedIconPath": "static/tabbar/my-active.png",
// "text": "我的"
// }]
// },
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
......@@ -15,5 +56,15 @@
"backgroundColor": "#F8F8F8",
"navigationStyle": "custom"
},
"uniIdRouter": {}
"uniIdRouter": {},
"condition" : { //模式配置,仅开发期间生效
"current": 0, //当前激活的模式(list 的索引项)
"list": [
{
"name": "", //模式名称
"path": "", //启动页面,必选
"query": "" //启动参数,在页面的onLoad函数里面得到
}
]
}
}
......@@ -4,21 +4,34 @@
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<courselist></courselist>
</view>
</template>
<script>
import courselist from '../../components/courselist/courselist.vue'
export default {
data() {
return {
title: 'Hello'
title: '首页'
}
},
comments:{
courselist
},
onLoad() {
},
methods: {
},
onShow() {
if(!uni.getStorageSync('isLogin')){
uni.navigateTo({
url:'/components/login/login'
})
}
}
}
</script>
......
<template>
</template>
<script>
</script>
<style>
</style>
\ No newline at end of file
......@@ -78,6 +78,9 @@
top: 0.625rem;
color: #20279B;
}
.wrapper .content uni-form .inputItem .grey {
color: #CECECE;
}
.wrapper .content .agree {
font-size: 0.875rem;
color: #666;
......
......@@ -75,6 +75,7 @@
}
}
},
"arguments": "{\"path\":\"components/login/login\"}",
"uniStatistics": {
"enable": false
},
......
......@@ -10,7 +10,7 @@ export const interceptor = () => {
// 请求拦截器
invoke(args) {
// console.log('请求拦截器',args);
console.log('请求拦截器',args);
// 加载loading
uni.showLoading({
title: '加载中...'
......@@ -28,7 +28,7 @@ export const interceptor = () => {
uni.setStorageSync('uni-token',res.data['data']['token']);
window.location.href = window.location.href + '?' + 't_reload=' + new Date().getTime();
}
// console.log(res)
console.log(res)
},fail(err) {
reject(err);
},
......
//只要是未登录状态,想要跳转到名单内的路径时,直接跳到登录页
// 页面白名单,不受拦截
const whiteList = [
'/components/login/login',
'/pages/index/index'
]
export default function initApp(){
uni.addInterceptor('navigateTo', {
// 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转
invoke (e) {
if(!hasPermission(e.url)){
uni.reLaunch({
url: '/components/login/login'
})
return false
}
return true
},
success (e) {
}
})
uni.addInterceptor('switchTab', {
// tabbar页面跳转前进行拦截
invoke (e) {
if(!hasPermission(e.url)){
uni.reLaunch({
url: '/components/login/login'
})
return false
}
return true
},
success (e) {
}
})
}
function hasPermission (url) {
let islogin = uni.getStorageSync("isLogin");//在这可以使用token、vuex
islogin = Boolean(Number(islogin));//返回布尔值
// 在白名单中或有登录判断条件可以直接跳转
if(whiteList.indexOf(url) !== -1 || islogin) {
return true
}
return false
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment