Browse Source

优化框架验证&完善登录逻辑

master
zmt 3 years ago
parent
commit
bca9d166e8
  1. 71
      nxTemp/apis/userAPI.js
  2. 77
      nxTemp/config/requestConfig.js
  3. 4
      nxTemp/utils/tools.js
  4. 20
      pages.json
  5. 13
      pages/index/index.vue
  6. 29
      pages/login/login.vue

71
nxTemp/apis/userAPI.js

@ -4,13 +4,15 @@ import config from "@/nxTemp/config/index.config.js";
// 用户登录
export function postLogin(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/login`, data ,{
needLogin:false
needLogin:false //未登录前操作取消登录验证
});
}
//发送验证码
export function postSendSMS(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/captchaSms/send`, data);
return http.post(`${config.baseUrl}/gaMatchAssistant/captchaSms/send`, data,{
// needLogin:false //未登录前操作取消登录验证
});
}
/**
@ -27,4 +29,69 @@ export function wechatGetPhoneNumber(data) {
return http.post(`${config.baseUrl}/user/wechatGetPhoneNumber`, data);
}
/**
* @description: 赛事列表
* @param {*}
* token
page
page_size
*/
export function matchList(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/match/list`, data);
}
/**
* @description: 赛程列表(赛程打分)
* @param {*}
* token
match_id
page
page_size
*/
export function matchScheduleList(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/matchSchedule/list`, data);
}
/**
* @description: 赛程打分
* @param
* schedule_id 赛程id
order_no 赛事订单号
score 要设置的分数
schedule_son_id 赛程子id
*/
export function scoreSave(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/matchSchedule/scoreSave`, data);
}
/**
* @description: 参赛成员(赛程打分)
* @param {*}
* brand_id
match_id
page
page_size
*/
export function matchScoreMemberList(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/matchScore/memberList`, data);
}
/**
* @description: 赛程打分
* @param {*}
* brand_id
* order_no
* scode
*/
export function matchScoreSave(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/match/scoreSave`, data);
}
/**
* @description: 录入数据-数据名称列表
* @param {*}
* brand_id, order_no
*/
export function randOcondList(data) {
return http.post(`${config.baseUrl}/gaMatchAssistant/rankConf/list`, data);
}

77
nxTemp/config/requestConfig.js

@ -16,46 +16,13 @@ let $http = new request({
// 'project_token': config.projectToken, //项目token(可删除)
}
});
// 添加获取七牛云token的方法
$http.getQnToken = function(callback) {
//该地址需要开发者自行配置(每个后台的接口风格都不一样)
$http.get("api/common/v1/qn_upload").then(data => {
/*
*接口返回参数
*visitPrefix:访问文件的域名
*token:七牛云上传token
*folderPath:上传的文件夹
*region: 地区 默认为SCN
*/
callback({
visitPrefix: data.visitPrefix,
token: data.token,
folderPath: data.folderPath
});
});
}
//请求开始拦截器
$http.requestStart = function(options) {
// console.log("请求开始", options);
if (options.load) {
//打开加载动画
store.commit("setLoadingShow", true);
}
// 图片上传大小限制
if (options.method == "FILE" && options.maxSize) {
// 文件最大字节: options.maxSize 可以在调用方法的时候加入参数
let maxSize = options.maxSize;
for (let item of options.files) {
if (item.size > maxSize) {
setTimeout(() => {
uni.showToast({
title: "图片过大,请重新上传",
icon: "none"
});
}, 500);
return false;
}
}
}
//请求前加入token & token验证
@ -70,7 +37,24 @@ $http.requestStart = function(options) {
options.data['token'] = token; //请求data中带上token
}
}
}
}
// 图片上传大小限制
if (options.method == "FILE" && options.maxSize) {
// 文件最大字节: options.maxSize 可以在调用方法的时候加入参数
let maxSize = options.maxSize;
for (let item of options.files) {
if (item.size > maxSize) {
setTimeout(() => {
uni.showToast({
title: "图片过大,请重新上传",
icon: "none"
});
}, 500);
return false;
}
}
}
// if (options.url) {
// //请求前加入token
// let url = options.url.substring(options.url.lastIndexOf('/') + 1);
@ -108,7 +92,7 @@ $http.dataFactory = async function(res) {
// data: res.data,
// method: res.method,
// });
console.log("requestConfig:",res);
// console.log("requestConfig:",res);
showLog(res.data,res.url,res.response)
}
@ -257,6 +241,25 @@ $http.requestError = function(e) {
});
}
}
// 添加获取七牛云token的方法
$http.getQnToken = function(callback) {
//该地址需要开发者自行配置(每个后台的接口风格都不一样)
$http.get("api/common/v1/qn_upload").then(data => {
/*
*接口返回参数
*visitPrefix:访问文件的域名
*token:七牛云上传token
*folderPath:上传的文件夹
*region: 地区 默认为SCN
*/
callback({
visitPrefix: data.visitPrefix,
token: data.token,
folderPath: data.folderPath
});
});
}
//log日志函数
function showLog(data,url,response){
let weburl = getWebURL(data,url)
let temp = url.split("?")[0].split("/")
@ -267,7 +270,7 @@ function showLog(data,url,response){
+"\n 服务端返回:\n"+JSON.stringify(response.data)
+"\n <<-------------------- ["+postName+"][log] ↑↑↑\n")
}
//获取拼接url
function getWebURL(data,url){
let result = ""
for(var i in data){

4
nxTemp/utils/tools.js

@ -161,5 +161,9 @@ export default {
}
},
route(url,type){
// 无再次封装必要,参考
// https://hhyang.cn/v2/api/routerInsatll.html#router-aftereach
},
}

20
pages.json

@ -119,26 +119,6 @@
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#fe519f",
"borderStyle": "black",
"backgroundColor": "#F8F8F8",
"list": [{
"pagePath": "pages/index/index",
"iconPath": "static/images/tabbar/tab_home_01.png",
"selectedIconPath": "static/images/tabbar/tab_home_02.png",
"text": "首页"
},
{
"pagePath": "pages/me/index",
"iconPath": "static/images/tabbar/tab_user_01.png",
"selectedIconPath": "static/images/tabbar/tab_user_02.png",
"text": "我的"
}
]
},
"condition": { //
"current": 0, //(list )
"list": [

13
pages/index/index.vue

@ -5,7 +5,7 @@
<image class="bg" src="../../static/images/index/index_bg.png" mode="aspectFit"></image>
<view class="login-info flex_col" v-if="login">
<text>1888888888</text>
<text>{{userInfo.mobile||"-"}}</text>
<text>您好!</text>
</view>
<view class="button-login " v-else @click="jumpPage('login')">前往登录</view>
@ -30,14 +30,21 @@
<image src="../../static/images/index/arrow_right.png" mode=""></image>
</view>
</view>
</template>
<script>
</template>
<script>
import { mapState } from 'vuex'
export default {
data() {
return {
address:"",
login:true
};
},
computed:{
...mapState(['userInfo']),
getUserInfo(){
return this.$store.state.userInfo.mobile
}
},
onLoad(parms) {

29
pages/login/login.vue

@ -16,9 +16,10 @@
password="true" />
</view>
<view class="list-call l-small flex_col" @click="sendSMS">
<view v-if="!sended" class="list-call l-small flex_col" @click="sendSMS">
获取验证码
</view>
<view v-else class="list-call l-small flex_col">{{count}}s</view>
</view>
<view class="tips">验证码错误请重新填写</view>
</view>
@ -53,7 +54,9 @@
export default {
data() {
return {
agreed:false,
sended:false,//
count:5,
agreed:false,//
login: {//
mobile: '13500071371',//
ticket: 'test',//
@ -70,18 +73,14 @@
},
methods: {
bindLogin() {
// let that = this;
if (this.login.mobile.length != 11) {
return this.$tools.showNone("请输入正确的手机号");}
if (this.login.verify_code.length < 6) {
return this.$tools.showNone("请输入正确的验证码");}
postLogin(this.login).then(res => {
this.$tools.showNone("登录成功");
this.$store.dispatch('setUserData', res);
this.$Router.pushTab({//
path: '/pages/index/index',
});
// console.log(this.$store);
this.$store.dispatch('setUserData', res);
this.$Router.replace({name:"index"})
});
},
jumpAgreement(){
@ -92,9 +91,21 @@
postSendSMS({mobile}).then(res => {
this.$tools.showNone("发送成功");
this.login.ticket = res.data||""
setButtonCount(this)
});
function setButtonCount(that){//
that.sended = true
let _count = that.count
let timer = setInterval(()=>{
if(that.count>0)that.count--
else {
clearInterval(timer)
that.sended = false
that.count = _count
}
},1000)
}
},
async decryptPhoneNumber(e){
if(e.detail.errMsg!=="getPhoneNumber:ok")return this.$tools.showNone(e.detail.errMsg)
this.$tools.showNone("解析数据...")

Loading…
Cancel
Save