Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
op-web-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
op-web-service
Commits
93092b65
Commit
93092b65
authored
May 29, 2021
by
lvweichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: login redirct pandora
parent
f0407c55
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
92 additions
and
84 deletions
+92
-84
config.js
server/config.js
+8
-1
system.js
server/controllers/system.js
+23
-9
user.js
server/controllers/user.js
+4
-2
router.js
server/router.js
+3
-0
App.vue
src/App.vue
+18
-17
user.js
src/service/user.js
+6
-2
request.js
src/utils/request.js
+27
-52
vue.config.js
vue.config.js
+3
-1
No files found.
server/config.js
View file @
93092b65
...
@@ -7,6 +7,12 @@ const LOGIN_URI = {
...
@@ -7,6 +7,12 @@ const LOGIN_URI = {
'production'
:
"http://web-rest.int.yidian-inc.com"
'production'
:
"http://web-rest.int.yidian-inc.com"
}
}
const
PANDORA_URI
=
{
'development'
:
"http://pandora.yidian-inc.com"
,
'test'
:
"http://pandora.yidian-inc.com"
,
'production'
:
"http://pandora.yidian-inc.com"
}
const
API_INTERNAL_URI
=
{
const
API_INTERNAL_URI
=
{
'development'
:
"bp-test.ini.yidian-inc.com "
,
'development'
:
"bp-test.ini.yidian-inc.com "
,
'test'
:
"bp-test.ini.yidian-inc.com "
,
'test'
:
"bp-test.ini.yidian-inc.com "
,
...
@@ -17,5 +23,6 @@ module.exports = {
...
@@ -17,5 +23,6 @@ module.exports = {
env
:
env
,
env
:
env
,
port
:
port
,
port
:
port
,
LOGIN_URI
:
LOGIN_URI
[
env
],
LOGIN_URI
:
LOGIN_URI
[
env
],
API_INTERNAL_URI
:
API_INTERNAL_URI
[
env
]
API_INTERNAL_URI
:
API_INTERNAL_URI
[
env
],
PANDORA_URI
:
PANDORA_URI
[
env
]
};
};
server/controllers/system.js
View file @
93092b65
const
LOGIN_URI
=
require
(
'../config.js'
).
LOGIN_URI
const
LOGIN_URI
=
require
(
'../config.js'
).
LOGIN_URI
const
PANDORA_URI
=
require
(
'../config.js'
).
PANDORA_URI
const
req
=
require
(
'../utils/request'
).
httpReq
const
req
=
require
(
'../utils/request'
).
httpReq
exports
.
login
=
async
(
ctx
,
next
)
=>
{
// exports.login = async (ctx, next) => {
var
url
=
`
${
LOGIN_URI
}
/api/v1/pandora/auth`
;
// const url = `${LOGIN_URI}/api/v1/pandora/auth`;
var
opts
=
{
// const opts = {
// url: url,
// method: 'POST',
// json: true,
// body : ctx.request.body
// }
// console.log("koa login:::::", ctx.request)
// ctx.body = await req(ctx, opts)
// }
exports
.
fetch_user
=
async
(
ctx
,
next
)
=>
{
const
url
=
`
${
PANDORA_URI
}
/api/user/getuser`
;
const
cookie
=
ctx
.
request
.
header
.
cookie
;
const
opts
=
{
url
:
url
,
url
:
url
,
method
:
'
POS
T'
,
method
:
'
GE
T'
,
json
:
true
,
headers
:
{
timeout
:
8000
,
'Cookie'
:
ctx
.
request
.
header
.
cookie
body
:
ctx
.
request
.
body
}
}
}
console
.
log
(
"fetch_user:::::"
,
ctx
.
request
)
ctx
.
body
=
await
req
(
ctx
,
opts
)
ctx
.
body
=
await
req
(
ctx
,
opts
)
}
}
\ No newline at end of file
server/controllers/user.js
View file @
93092b65
const
{
API_INTERNAL_URI
}
=
require
(
'../config.js'
)
const
API_INTERNAL_URI
=
require
(
'../config.js'
).
API_INTERNAL_URI
const
req
=
require
(
'../utils/request'
).
httpReq
var
query
=
{
var
query
=
{
async
get_permissions
(
ctx
,
next
)
{
async
get_permissions
(
ctx
,
next
)
{
...
@@ -18,12 +19,13 @@ var query = {
...
@@ -18,12 +19,13 @@ var query = {
exports
.
query
=
async
(
ctx
,
next
)
=>
{
exports
.
query
=
async
(
ctx
,
next
)
=>
{
var
type
=
ctx
.
params
.
type
var
type
=
ctx
.
params
.
type
console
.
log
(
"koa user::::::"
,
type
)
if
(
query
[
type
])
{
if
(
query
[
type
])
{
try
{
try
{
ctx
.
set
(
'Content-Type'
,
'application/json; charset=utf-8'
)
ctx
.
set
(
'Content-Type'
,
'application/json; charset=utf-8'
)
await
query
[
type
](
ctx
,
next
)
await
query
[
type
](
ctx
,
next
)
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
'/
home/q
error'
,
e
,
ctx
.
url
,
ctx
.
headers
[
'cookie'
])
console
.
error
(
'/
api/v1
error'
,
e
,
ctx
.
url
,
ctx
.
headers
[
'cookie'
])
ctx
.
body
=
{
status
:
'failed'
,
reason
:
'Internal Server Error'
}
ctx
.
body
=
{
status
:
'failed'
,
reason
:
'Internal Server Error'
}
}
}
}
else
{
}
else
{
...
...
server/router.js
View file @
93092b65
...
@@ -6,6 +6,9 @@ const router = Router();
...
@@ -6,6 +6,9 @@ const router = Router();
const
API_VERSION
=
"/api/v1"
;
const
API_VERSION
=
"/api/v1"
;
router
.
post
(
`
${
API_VERSION
}
/login`
,
system
.
login
);
router
.
post
(
`
${
API_VERSION
}
/login`
,
system
.
login
);
router
.
get
(
`
${
API_VERSION
}
/fetch_user`
,
system
.
fetch_user
);
router
.
get
(
`
${
API_VERSION
}
/user/:type`
,
user
.
query
)
router
.
get
(
`
${
API_VERSION
}
/user/:type`
,
user
.
query
)
module
.
exports
=
router
;
module
.
exports
=
router
;
src/App.vue
View file @
93092b65
...
@@ -9,27 +9,28 @@
...
@@ -9,27 +9,28 @@
<
script
>
<
script
>
// Layout 为布局组件,控制页面基础布局,通过 slot 实现
// Layout 为布局组件,控制页面基础布局,通过 slot 实现
// import Layout from '@/layouts';
// import Layout from '@/layouts';
// import { fetchCurrentUser } from './services
/user';
import
{
fetchCurrentUser
}
from
'./service
/user'
;
// async function isUserLogged() {
async
function
isUserLogged
()
{
// return (await fetchCurrentUser()).status === 'success';
const
res
=
await
fetchCurrentUser
()
// }
return
res
.
status
===
'success'
;
}
//
function redirectToLogin() {
function
redirectToLogin
()
{
//
const loginUrl = '//pandora.yidian-inc.com/tools/admin/login';
const
loginUrl
=
'//pandora.yidian-inc.com/tools/admin/login'
;
//
const cbUrl = location.href;
const
cbUrl
=
location
.
href
;
//
location.href = `${loginUrl}?callback=${cbUrl}`;
location
.
href
=
`
${
loginUrl
}
?callback=
${
cbUrl
}
`
;
//
}
}
export
default
{
export
default
{
// components:
{
async
mounted
()
{
// Layout,
// http://dev.yidian-inc.com:8081/home
// },
if
(
!
(
await
isUserLogged
()))
{
// async mounted() {
redirectToLogin
();
// if (!(await isUserLogged()))
{
}
else
{
// redirectToLogin();
//
}
}
//
},
},
};
};
</
script
>
</
script
>
...
...
src/service/user.js
View file @
93092b65
...
@@ -7,6 +7,10 @@ export async function login(email, password) {
...
@@ -7,6 +7,10 @@ export async function login(email, password) {
return
res
.
data
;
return
res
.
data
;
}
}
export
async
function
getPermissions
()
{
export
async
function
fetchCurrentUser
()
{
return
await
axios
.
post
(
"api/home/user/get_permissions"
)
return
await
axios
.
get
(
"api/v1/fetch_user"
);
}
export
async
function
getPermissions
(
email
)
{
return
await
axios
.
get
(
"api/v1/user/get_permissions"
,
{
email
});
}
}
\ No newline at end of file
src/utils/request.js
View file @
93092b65
...
@@ -2,25 +2,26 @@
...
@@ -2,25 +2,26 @@
* axios封装
* axios封装
*/
*/
import
axios
from
"axios"
;
import
axios
from
"axios"
;
import
{
ElMessage
}
from
"element-plus"
;
//
import { ElMessage } from "element-plus";
// import { APP_URI } from "../config/app.config";
// import { APP_URI } from "../config/app.config";
/**
/**
* show error tip
* show error tip
* @param mgs
* @param mgs
*/
*/
const
showErrorMessage
=
mgs
=>
{
//
const showErrorMessage = mgs => {
ElMessage
({
//
ElMessage({
message
:
mgs
,
//
message: mgs,
type
:
"error"
,
//
type: "error",
showClose
:
true
//
showClose: true
});
//
});
};
//
};
/**
/**
* default axios config
* default axios config
*/
*/
export
const
defaultConfig
=
{
export
const
defaultConfig
=
{
// baseURL: APP_URI,
// baseURL: APP_URI,
withCredentials
:
true
,
timeout
:
10000
timeout
:
10000
};
};
...
@@ -71,52 +72,26 @@ instance.interceptors.request.use(
...
@@ -71,52 +72,26 @@ instance.interceptors.request.use(
instance
.
interceptors
.
response
.
use
(
instance
.
interceptors
.
response
.
use
(
function
(
response
)
{
function
(
response
)
{
const
{
data
=
{}
}
=
response
;
const
{
data
=
{}
}
=
response
;
const
code
=
data
.
code
??
-
1
;
//
const code = data.code ?? -1;
if
(
code
!==
0
)
{
//
if (code !== 0) {
const
msg
=
data
.
reason
||
"未定义错误"
;
//
const msg = data.reason || "未定义错误";
showErrorMessage
(
data
.
reason
);
//
showErrorMessage(data.reason);
return
Promise
.
reject
({
code
,
msg
});
//
return Promise.reject({ code, msg });
}
//
}
if
(
data
.
message
)
{
//
if (data.message) {
ElMessage
({
//
ElMessage({
message
:
data
.
reason
,
//
message: data.reason,
type
:
"info"
,
//
type: "info",
showClose
:
true
//
showClose: true
});
//
});
}
//
}
return
data
;
return
data
;
},
},
function
(
error
)
{
//
function (error) {
if
(
!
(
error
.
code
&&
error
.
code
===
-
1
))
error
.
message
=
"接口请求错误"
;
//
if (!(error.code && error.code === -1)) error.message = "接口请求错误";
showErrorMessage
(
error
.
message
);
//
showErrorMessage(error.message);
return
Promise
.
reject
(
error
);
//
return Promise.reject(error);
}
//
}
);
);
// /**
// * Get
// * @param {*} url
// * @param {*} params
// */
// export const get = ({url, params, headers}) => {
// return instance.request({
// url,
// method: "get",
// params
// });
// };
// /**
// * Post
// * @param {*} url
// * @param {*} params
// */
// export const post = ({url, data, headers}) => {
// return instance.request({
// url,
// method: "post",
// data
// });
// };
export
default
instance
;
export
default
instance
;
vue.config.js
View file @
93092b65
...
@@ -16,7 +16,9 @@ module.exports = {
...
@@ -16,7 +16,9 @@ module.exports = {
// changeOrigin: true,
// changeOrigin: true,
// },
// },
// },
// },
proxy
:
'http://localhost:8055'
proxy
:
'http://localhost:8055'
,
hot
:
true
,
disableHostCheck
:
true
,
},
},
},
},
chainWebpack
:
config
=>
{
chainWebpack
:
config
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment