Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
walk_daka_h5
Overview
Overview
Details
Activity
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
穆启卓
walk_daka_h5
Commits
3365f1a1
Commit
3365f1a1
authored
Apr 03, 2019
by
穆启卓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build制动切换生产环境
parent
1b16d0f6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
52 deletions
+40
-52
fetch.js
src/components/axios/fetch.js
+23
-24
url.js
src/components/axios/url.js
+9
-22
vue.config.js
vue.config.js
+8
-6
No files found.
src/components/axios/fetch.js
View file @
3365f1a1
import
axios
from
'axios'
;
//引入axios
export
function
fetch
(
options
)
{
// if (!window['userData']) {
// let user_data_str = localStorage.getItem('walk_userData');
// if (user_data_str) {
// window['userData'] = JSON.parse(user_data_str);
// }
// }
// if (!window['userData']) {
// localStorage.setItem('last_url', location.hash.slice(1));
// location.replace('#/Author');
// // this.$router.push({name:"Author"})
// }
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
if
(
!
window
[
'userData'
])
{
let
user_data_str
=
localStorage
.
getItem
(
'walk_userData'
);
if
(
user_data_str
)
{
window
[
'userData'
]
=
JSON
.
parse
(
user_data_str
);
}
}
if
(
!
window
[
'userData'
])
{
localStorage
.
setItem
(
'last_url'
,
location
.
hash
.
slice
(
1
));
location
.
replace
(
'#/Author'
);
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
const
instance
=
axios
.
create
({
//instance创建一个axios实例,可以自定义配置,可在 axios文档中查看详情
//所有的请求都会带上这些配置,比如全局都要用的身份信息等。
headers
:
{
'Content-Type'
:
'application/json'
,
// 'Authorization': window['userData']?window['userData'].token:''
'Authorization'
:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJvcGVuX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsInVuaW9uX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsImV4cCI6MTU1NDQ1NzU3Mn0.ehCAENl8zjdMyF4y44Z2-XEascaDhEbUF3BaNsWbfY8"
'Authorization'
:
process
.
env
.
NODE_ENV
===
'production'
?
(
window
[
'userData'
]?
window
[
'userData'
].
token
:
''
)
:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJvcGVuX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsInVuaW9uX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsImV4cCI6MTU1NDQ1NzU3Mn0.ehCAENl8zjdMyF4y44Z2-XEascaDhEbUF3BaNsWbfY8"
// 'token_in_header': global_.token,//token从全局变量那里传过来
},
timeout
:
30
*
1000
// 30秒超时
...
...
@@ -30,17 +30,16 @@ export function fetch(options) {
resolve
(
response
.
data
);
//把请求到的数据发到引用请求的地方
})
.
catch
(
error
=>
{
// console.log('请求异常信息:', error);
// console.log(error);
// if (error.response.status == 401) {
// localStorage.setItem('last_url', location.hash.slice(1));
// localStorage.setItem('walk_userData', '');
// location.replace('#/Author');
// // this.$router.push({name:"Author"})
// } else {
// reject(error);
// }
console
.
log
(
'请求异常信息:'
,
error
);
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
if
(
error
.
response
.
status
==
401
)
{
localStorage
.
setItem
(
'last_url'
,
location
.
hash
.
slice
(
1
));
localStorage
.
setItem
(
'walk_userData'
,
''
);
location
.
replace
(
'#/Author'
);
}
else
{
reject
(
error
);
}
}
});
});
}
src/components/axios/url.js
View file @
3365f1a1
//也可以像下面这样,区分环境或者区分服务器等等
let
service
=
'dev'
// let service = 'prod';
let
api
=
''
if
(
service
===
'dev'
)
{
/**dev开发**/
api
=
''
}
else
if
(
service
===
'prod'
)
{
/**prod部署**/
api
=
'https://miniapp-api.wxatech.com/game-bsdk'
// 开发环境
let
api
=
''
;
let
trackApi
=
'https://test-api.wxagame.com/game-track'
;
// 生产环境
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
api
=
'https://miniapp-api.wxatech.com/game-bsdk'
;
trackApi
=
'https://minigame.api.wxagame.com/game-track'
;
}
let
trackApi
=
''
if
(
service
===
'dev'
)
{
/**dev开发**/
trackApi
=
'https://test-api.wxagame.com/game-track'
}
else
if
(
service
===
'prod'
)
{
/**prod部署**/
trackApi
=
'https://minigame.api.wxagame.com/game-track'
}
export
default
{
/**个人中心start**/
//1 打卡查询 GET /api/v1/daka_status
...
...
@@ -91,4 +77,4 @@ export default {
pop_up_windows
:
`
${
api
}
/api/v1/pop_up_windows`
,
//首页第一项立即报名
daka_info
:
`
${
api
}
/api/v1/daka_info`
,
}
}
\ No newline at end of file
vue.config.js
View file @
3365f1a1
//vue.config.js
module
.
exports
=
{
// 选项...
// publicPath: 'https://miniapp-api.wxatech.com/app_pages',
// indexPath: "walk_daka.html",
// assetsDir: "walk_static",
let
config
=
{
devServer
:
{
proxy
:
{
'/api'
:
{
...
...
@@ -15,4 +10,10 @@ module.exports = {
}
}
}
};
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
config
.
publicPath
=
'https://miniapp-api.wxatech.com/app_pages'
;
config
.
indexPath
=
'walk_daka.html'
;
config
.
assetsDir
=
'walk_static'
;
}
module
.
exports
=
config
;
\ No newline at end of file
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