Commit 28ee8c5b authored by 冷冷's avatar 冷冷

👽 Updating code due to external API changes.

parent 27de1d55
......@@ -29,10 +29,23 @@ export const loginByUsername = (username, password, code, randomStr) => {
})
}
export const loginByMobile = (mobile, code) => {
var grant_type = 'mobile'
return request({
url: '/auth/mobile/token/sms',
headers: {
'TENANT_ID': '1',
'Authorization': 'Basic cGlnOnBpZw=='
},
method: 'post',
params: { mobile: 'SMS@' + mobile,code: code, grant_type }
})
}
export const loginBySocial = (state, code) => {
var grant_type = 'mobile'
return request({
url: '/auth/mobile/token',
url: '/auth/mobile/token/social',
headers: {
'TENANT_ID': '1',
'Authorization': 'Basic cGlnOnBpZw=='
......
......@@ -8,7 +8,7 @@
<el-form-item prop="phone">
<el-input size="small"
@keyup.enter.native="handleLogin"
v-model="loginForm.phone"
v-model="loginForm.mobile"
auto-complete="off"
placeholder="请输入手机号码">
<i slot="prefix"
......@@ -42,11 +42,11 @@
<script>
const MSGINIT = "发送验证码",
// MSGERROR = "验证码发送失败",
MSGSCUCCESS = "${time}秒后重发",
MSGTIME = 60;
import { isvalidatemobile } from "@/util/validate";
import { mapGetters } from "vuex";
import request from '@/router/axios'
export default {
name: "codelogin",
data () {
......@@ -69,12 +69,12 @@ export default {
msgTime: MSGTIME,
msgKey: false,
loginForm: {
phone: "17547400800",
code: ""
mobile: '',
code: ''
},
loginRules: {
phone: [{ required: true, trigger: "blur", validator: validatePhone }],
code: [{ required: true, trigger: "blur", validator: validateCode }]
mobile: [{ required: true, trigger: 'blur', validator: validatePhone }],
code: [{ required: true, trigger: 'blur', validator: validateCode }]
}
};
},
......@@ -85,21 +85,34 @@ export default {
},
props: [],
methods: {
handleSend () {
if (this.msgKey) return;
this.msgText = MSGSCUCCESS.replace("${time}", this.msgTime);
this.msgKey = true;
const time = setInterval(() => {
this.msgTime--;
this.msgText = MSGSCUCCESS.replace("${time}", this.msgTime);
if (this.msgTime == 0) {
this.msgTime = MSGTIME;
this.msgText = MSGINIT;
this.msgKey = false;
clearInterval(time);
}
}, 1000);
},
handleSend() {
if (this.msgKey) return
request({
url: '/admin/mobile/' + this.loginForm.mobile,
method: 'get'
}).then(response => {
console.log(response.data.data)
if (response.data.data) {
this.$message.success('验证码发送成功')
} else {
this.$message.error(response.data.msg)
}
})
this.msgText = MSGSCUCCESS.replace('${time}', this.msgTime)
this.msgKey = true
const time = setInterval(() => {
this.msgTime--
this.msgText = MSGSCUCCESS.replace('${time}', this.msgTime)
if (this.msgTime == 0) {
this.msgTime = MSGTIME
this.msgText = MSGINIT
this.msgKey = false
clearInterval(time)
}
}, 1000)
},
handleLogin () {
this.$refs.loginForm.validate(valid => {
if (valid) {
......
......@@ -32,7 +32,7 @@ export default {
redirect_uri = encodeURIComponent(window.location.origin + '/#/authredirect')
if (thirdpart === 'wechat') {
appid = 'wxd1678d3f83b1d83a'
url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=' + appid + '&response_type=code&scope=snsapi_login#wechat_redirect'
url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=WX&response_type=code&scope=snsapi_login#wechat_redirect'
} else if (thirdpart === 'tencent') {
client_id = '101322838'
url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=' + appid + '&client_id=' + client_id + '&redirect_uri=' + redirect_uri
......
......@@ -75,6 +75,10 @@ export default {
data () {
return {
socialForm: {
code: '',
state: ''
},
loginForm: {
username: "admin",
password: "123456",
......@@ -104,6 +108,24 @@ export default {
passwordType: "password"
};
},
watch: {
$route() {
const params = this.$route.query
this.socialForm.state = params.state
this.socialForm.code = params.code
if (!validatenull(this.socialForm.state)) {
const loading = this.$loading({
lock: true,
text: `登录中,请稍后。。。`,
spinner: 'el-icon-loading'
})
setTimeout(() => {
loading.close()
}, 2000)
this.handleSocialLogin()
}
}
},
created () {
this.refreshCode();
},
......
......@@ -47,7 +47,7 @@ axios.interceptors.request.use(config => {
axios.interceptors.response.use(res => {
NProgress.done();
const status = Number(res.status);
const message = res.data.message || errorCode[status] || errorCode['default'];
const message = res.data.data || errorCode[status] || errorCode['default'];
if (status === 401){
store.dispatch('FedLogOut').then(() => {
......
import { setToken, removeToken } from '@/util/auth'
import { setStore, getStore } from '@/util/store'
import { logout, loginByUsername, loginBySocial, getUserInfo } from '@/api/login'
import { logout, loginByUsername,loginByMobile, loginBySocial, getUserInfo } from '@/api/login'
import { encryption } from '@/util/util'
import webiste from '@/const/website';
import { GetMenu } from '@/api/menu'
......@@ -61,14 +61,16 @@ const user = {
},
//根据手机号登录
LoginByPhone({ commit }, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.phone, userInfo.code).then(res => {
const data = res.data;
commit('SET_TOKEN', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
setToken(data);
resolve();
return new Promise((resolve, reject) => {
loginByMobile(userInfo.mobile, userInfo.code).then(response => {
const data = response.data
setToken(data.access_token)
commit('SET_ACCESS_TOKEN', data.access_token)
commit('SET_REFRESH_TOKEN', data.refresh_token)
commit('CLEAR_LOCK')
resolve()
}).catch(error => {
reject(error)
})
})
},
......
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