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