Browse Source

feat(login): 实现销售端和学员端的登录功能

- 新增 api.js 文件,定义了 personnelLogin 和 memberEdit 方法
- 修改 config.js,更新了 API 地址
- 重构了 login 页面的登录逻辑,支持不同用户类型的登录
master
liutong 11 months ago
parent
commit
19f72099bf
  1. 23
      api/api.js
  2. 10
      common/config.js
  3. 90
      pages/student/login/login.vue

23
api/api.js

@ -0,0 +1,23 @@
import http from '../common/axios.js'
//全部api接口
export default {
//教师端登陆
personnelLogin(data = {}) {
let url = '/personnelLogin'
return http.post(url, data).then(res => {
return res;
})
},
//修改销售人员详情
memberEdit(data = {}) {
let url = '/member/member_edit'
return http.post(url, data).then(res => {
return res;
})
},
}

10
common/config.js

@ -1,10 +1,10 @@
// 线上地址 // 线上测试地址
const Api_url='http://146.56.228.75:20021/api' // const Api_url='http://aaaaaaaa.hksywl.cn/api'
const img_domian = 'http://146.56.228.75:20021/' // const img_domian = 'http://aaaaaaaa.hksywl.cn/'
//本地测试地址 //本地测试地址
// const Api_url='http://zhjw.cc/api' const Api_url='http://zhjw.cc/api'
// const img_domian = 'http://zhjw.cc/' const img_domian = 'http://zhjw.cc/'
const IsDemo = false const IsDemo = false

90
pages/student/login/login.vue

@ -37,16 +37,19 @@
<script> <script>
import memberApi from '@/api/member.js'; import memberApi from '@/api/member.js';
import Api from '@/api/api.js';
export default { export default {
data() { data() {
return { return {
password: true, password: true,
user: '18888888888', // user: '15148228108', //
password1: '123456' // password1: '123123', //
loginType:'',//|1=,2=,3=
} }
}, },
onLoad() { onLoad(options) {
this.loginType = options.loginType ?? '2'//|1=,2=,3=
// uni.hideHomeButton() // uni.hideHomeButton()
// console.log(uni.getStorageSync('um_id')) // console.log(uni.getStorageSync('um_id'))
}, },
@ -63,51 +66,62 @@ export default {
}) })
}, },
// //
login() { async login() {
let item = {}; let item = {};
item['username'] = this.user item['username'] = this.user
item['password'] = this.password1 item['password'] = this.password1
//
memberApi.login(item).then(res => {
if (res.code == 1) {
uni.setStorageSync('token', res.data.token);
let userType = res.data.userType
// userType = 3// let res
console.log('用户类型', userType) //|1=,2=,3=
if(this.loginType == 1){
}else if(this.loginType == 2){
//
let params = {
'phone': this.user,
'password': this.password1,
'login_type': 2,
}
res = await Api.personnelLogin(params)
console.log(123123,res)
uni.setStorageSync('userType', userType); }else if (this.loginType == 3){
uni.setStorageSync('tabBerIndex', 0); }
let url_path = '' if(!res.code){
switch (String(userType)) { uni.showToast({
case '1': // title: res.msg,
url_path = '/pages/coach/home/index' icon: 'none'
break; })
case '2': // return
url_path = '/pages/market/index/index' }
break; uni.setStorageSync('expires_time', res.data.expires_time);//token
case '3': // uni.setStorageSync('token', res.data.token);
url_path = '/pages/student/index/index' let userType = res.data.user_type
break; console.log('用户类型', userType)
default: uni.setStorageSync('userType', userType);
uni.showToast({ uni.setStorageSync('tabBerIndex', 0);
title: '用户类型错误',
icon: 'none'
})
return;
}
uni.navigateTo({ let url_path = ''
url: url_path switch (String(userType)) {
}) case '1': //
} else { url_path = '/pages/coach/home/index'
break;
case '2': //
url_path = '/pages/market/index/index'
break;
case '3': //
url_path = '/pages/student/index/index'
break;
default:
uni.showToast({ uni.showToast({
title: res.msg, title: '用户类型错误',
icon: 'none' icon: 'none'
}) })
} return;
}); }
uni.navigateTo({
url: url_path
})
}, },
loginWx() { loginWx() {
uni.login({ uni.login({

Loading…
Cancel
Save