Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
micro-system
/
micro-portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ea0bf46e
authored
Oct 29, 2020
by
冒粤蓉
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix mock config
1 parent
f9b89176
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
59 deletions
src/App.vue
src/config/api.js
src/micro/app-store.js
src/micro/index.js
src/services/Base.js
src/utils/http/http.js
vue.config.js
src/App.vue
View file @
ea0bf46
...
...
@@ -17,7 +17,7 @@ import Dashboard from '@/views/Dashboard';
import
Login
from
'@/views/Login'
;
import
Loading
from
'components/Loading/Loading'
;
import
BaseService
from
'services/Base'
;
//
import BaseService from 'services/Base';
import
{
onCreated
,
onMounted
,
computed
,
reactive
,
toRefs
}
from
'vue'
;
import
{
useStore
}
from
'vuex'
;
...
...
@@ -32,14 +32,14 @@ export default {
},
setup
()
{
const
store
=
useStore
();
// const baseService = new BaseService();
// baseService.getBaseConfig().then((res) => {
// const baseURL = res.axios.baseURL;
// store.dispatch('app/updateBaseURL', baseURL);
// }, (err) => {
const
baseService
=
new
BaseService
();
baseService
.
getBaseConfig
().
then
((
res
)
=>
{
const
baseURL
=
res
.
axios
.
baseURL
;
store
.
dispatch
(
'app/updateBaseURL'
,
baseURL
);
},
(
err
)
=>
{
});
// });
let
hasToken
=
computed
(()
=>
{
return
!!
store
.
getters
.
token
;
...
...
src/config/api.js
View file @
ea0bf46
import
store
from
'@/store/index
'
// import store from '@/store
'
let
BASE_URL
=
store
.
state
.
baseURL
;
const
MOCK_CONFIG_URL
=
'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config'
;
const
env
=
process
.
env
.
NODE_ENV
;
if
(
!
BASE_URL
)
{
BASE_URL
=
env
===
'development'
?
'http://192.168.0.63:8880'
:
''
;
}
// const MOCK_CONFIG_URL = 'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config';
// const env = process.env.NODE_ENV;
const
API
=
{
getMockConfig
()
{
return
MOCK_CONFIG_URL
+
'/e_sheild_config'
;
return
'/e_sheild_config'
;
},
LOGIN_CAPTCHA
:
BASE_URL
+
'/usercenter/captcha'
,
// 非接口,直接url可展示验证码
LOGIN_ACTION
:
BASE_URL
+
'/usercenter/login'
,
// 登录接口
MENU_TREE_ACTION
:
BASE_URL
+
'/usercenter/menu/permtree'
,
// 用户登录成功后拉取权限菜单
LOGIN_CAPTCHA
:
'/usercenter/captcha'
,
// 非接口,直接url可展示验证码
LOGIN_ACTION
:
'/usercenter/login'
,
// 登录接口
MENU_TREE_ACTION
:
'/usercenter/menu/permtree'
,
// 用户登录成功后拉取权限菜单
}
export
{
...
...
src/micro/app-store.js
View file @
ea0bf46
...
...
@@ -30,7 +30,7 @@ actions.onGlobalStateChange((state, prev) => {
window
.
location
.
reload
();
},
300
)
}
// store.dispatch('app/showLoading', showLoading);
});
...
...
src/micro/index.js
View file @
ea0bf46
...
...
@@ -10,6 +10,10 @@ registerMicroApps(apps, {
// qiankun 生命周期钩子 - 加载前
beforeLoad
:
(
app
)
=>
{
showLoading
(
true
);
// 超时
setTimeout
(()
=>
{
showLoading
(
false
);
},
10000
)
return
Promise
.
resolve
();
},
// qiankun 生命周期钩子 - 挂载后
...
...
src/services/Base.js
deleted
100644 → 0
View file @
f9b8917
import
HTTP
from
'@/utils/http/http'
;
import
{
API
}
from
'@/config/api'
;
export
default
class
BaseService
extends
HTTP
{
getBaseConfig
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
axiosGet
({
url
:
API
.
getMockConfig
(),
data
:
{},
success
(
data
)
{
resolve
(
data
);
},
error
(
error
)
{
// 网络请求失败
console
.
log
(
'网络请求失败'
);
// window.location.reload();
}
})
});
}
}
src/utils/http/http.js
View file @
ea0bf46
...
...
@@ -82,27 +82,75 @@ instance.interceptors.response.use(response => {
});
})
// 从mock获取基础域名配置
const
MOCK_CONFIG_URL
=
'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/e_sheild_config'
;
let
baseFlag
=
true
;
const
getBaseUrl
=
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
BASE_URL
=
store
.
getters
.
baseURL
;
if
(
!
BASE_URL
&&
baseFlag
)
{
instance
({
url
:
MOCK_CONFIG_URL
,
method
:
'get'
}).
then
((
res
)
=>
{
const
resData
=
res
.
data
;
if
(
resData
)
{
const
resBaseURL
=
resData
.
axios
.
baseURL
;
store
.
dispatch
(
'app/updateBaseURL'
,
resBaseURL
);
baseFlag
=
!!
resBaseURL
;
resolve
(
resBaseURL
);
}
else
{
baseFlag
=
true
;
resolve
(
BASE_URL
)
}
}).
catch
((
err
)
=>
{
baseFlag
=
true
;
resolve
(
BASE_URL
)
})
}
else
{
resolve
(
BASE_URL
)
}
})
}
const
HTTP_POST
=
(
baseUrl
,
options
)
=>
{
instance
({
url
:
baseUrl
+
options
.
url
,
method
:
'post'
,
data
:
JSON
.
stringify
(
options
.
data
)
}).
then
((
res
)
=>
{
options
.
success
(
res
.
data
);
}).
catch
((
err
)
=>
{
options
.
error
(
err
);
})
}
const
HTTP_GET
=
(
baseUrl
,
options
)
=>
{
instance
({
url
:
baseUrl
+
options
.
url
,
method
:
'get'
}).
then
((
res
)
=>
{
options
.
success
(
res
.
data
);
}).
catch
((
err
)
=>
{
options
.
error
(
err
);
})
}
export
default
class
HTTP
{
axiosPost
(
options
)
{
instance
({
url
:
options
.
url
,
method
:
'post'
,
data
:
JSON
.
stringify
(
options
.
data
)
}).
then
((
res
)
=>
{
options
.
success
(
res
.
data
);
}).
catch
((
err
)
=>
{
options
.
error
(
err
);
getBaseUrl
().
then
((
baseUrl
)
=>
{
HTTP_POST
(
baseUrl
,
options
);
},
(
err
)
=>
{
HTTP_POST
(
''
);
})
}
axiosGet
(
options
)
{
instance
({
url
:
options
.
url
,
method
:
'get'
}).
then
((
res
)
=>
{
options
.
success
(
res
.
data
);
}).
catch
((
err
)
=>
{
options
.
error
(
err
);
getBaseUrl
().
then
((
baseUrl
)
=>
{
HTTP_GET
(
baseUrl
,
options
);
},
(
err
)
=>
{
HTTP_GET
(
''
)
})
}
}
\ No newline at end of file
vue.config.js
View file @
ea0bf46
...
...
@@ -38,6 +38,33 @@ module.exports = {
.
set
(
"config"
,
resolve
(
"src/config"
))
.
set
(
"utils"
,
resolve
(
"src/utils"
))
.
set
(
"services"
,
resolve
(
"src/services"
));
// config.module.rule('fonts')
// .use('url-loader')
// .loader('url-loader')
// .options({
// limit: 4096, // 小于4kb将会被打包成 base64
// fallback: {
// loader: 'file-loader',
// options: {
// name: 'fonts/[name].[hash:8].[ext]',
// publicPath
// }
// }
// })
// .end();
// config.module.rule('images')
// .use('url-loader')
// .loader('url-loader')
// .options({
// limit: 4096, // 小于4kb将会被打包成 base64
// fallback: {
// loader: 'file-loader',
// options: {
// name: 'img/[name].[hash:8].[ext]',
// publicPath
// }
// }
// })
},
css
:
{
loaderOptions
:
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment