提交 | 用户 | age
|
3ac5f2
|
1 |
/** |
J |
2 |
* ismock 0不用mock 1用mock |
|
3 |
* istest 0线上 1本地 |
|
4 |
* |
|
5 |
* 发布时请设置3个变量为0 |
|
6 |
*/ |
|
7 |
|
|
8 |
import appId from './appid.js' |
|
9 |
|
aeb317
|
10 |
var ismock = 0// 虚拟数据 0不使用 1使用 |
J |
11 |
var istest = 2// 0线上 1本地 2测试环境 |
3ac5f2
|
12 |
var isConsole = 1// 是否屏蔽console 0屏蔽 1开放 |
J |
13 |
var debug = isConsole |
|
14 |
var isWxLoginType = 0 // 微信登录 0无 1静默微信登录snsapi_base 2手动微信登录snsapi_userinfo |
aeb317
|
15 |
var isTestView = 1 |
d2d830
|
16 |
var is_use_test_server = 0 // 是否部署在测试服务器 |
aeb317
|
17 |
var localOnline = istest ? 0 : 1 // 本地连线上 |
3ac5f2
|
18 |
|
J |
19 |
// 打包后的环境 |
|
20 |
if (process.env && process.env.NODE_ENV !== 'development') { |
|
21 |
istest = 0 |
|
22 |
ismock = 0 |
aeb317
|
23 |
isTestView = 0 |
J |
24 |
localOnline = 0 |
878885
|
25 |
if (is_use_test_server) { |
J |
26 |
isTestView = 1 |
|
27 |
} |
|
28 |
|
3ac5f2
|
29 |
} |
J |
30 |
|
|
31 |
const pdomain = '/' // 线上 |
|
32 |
|
|
33 |
const mock_domain = '' |
|
34 |
// api_local 本地 http://192.168.1.106:8080 |
|
35 |
// api_test 测试环境 |
|
36 |
const tdomain = '/api_local/' // 本地 |
|
37 |
const pdomain_test = '/api_test/' // 测试环境 |
|
38 |
|
|
39 |
// 微信长链 |
|
40 |
const appid = appId |
|
41 |
let scope = '' |
|
42 |
if (isWxLoginType === 1) scope = 'snsapi_base' // snsapi_base 静默授权【只有openid】 |
|
43 |
if (isWxLoginType === 2) scope = 'snsapi_userinfo' // snsapi_userinfo 手动授权【有用户信息】 |
|
44 |
const long = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid={{appid}}&redirect_uri={{url}}&response_type=code&scope={{scope}}&state=1&connect_redirect=1#wechat_redirect' |
|
45 |
|
|
46 |
// 生成微信重定向链接 |
|
47 |
function createCodeUrl() { |
|
48 |
// 首页链接 |
|
49 |
let indexUrl = location.origin + location.pathname |
|
50 |
const search = location.search |
|
51 |
// 参数数组 |
|
52 |
let querys = [] |
|
53 |
if (search && search.indexOf('?')>-1) { |
|
54 |
querys = search.split('?')[1].split('&').filter((str)=>{ |
|
55 |
const key = str.split('=')[0] |
|
56 |
const value = str.split('=')[1] |
|
57 |
return (key != 'code' && key != 'state') |
|
58 |
}) |
|
59 |
} |
|
60 |
|
|
61 |
console.log(querys) |
|
62 |
|
|
63 |
// 补充参数 |
|
64 |
if (querys.length) { |
|
65 |
indexUrl += '?'+querys.join('&') |
|
66 |
} |
|
67 |
|
|
68 |
return long.replace('{{appid}}', appid).replace('{{scope}}', scope).replace('{{url}}', encodeURIComponent(indexUrl)) |
|
69 |
} |
|
70 |
|
|
71 |
// 屏蔽console.log |
|
72 |
if (!isConsole) { |
|
73 |
console.log = () => {} |
|
74 |
} |
|
75 |
|
|
76 |
var domain; |
|
77 |
|
|
78 |
if (istest == 0) domain = pdomain // 线上 |
|
79 |
if (istest == 1) domain = tdomain // 本地 |
|
80 |
if (istest == 2) domain = pdomain_test // 测试环境 |
|
81 |
if (ismock == 1) domain = mock_domain // 本地模拟 |
|
82 |
|
|
83 |
export default { |
|
84 |
ismock, |
|
85 |
istest, |
aeb317
|
86 |
isTestView, |
J |
87 |
localOnline, |
3ac5f2
|
88 |
isWxLoginType, |
J |
89 |
isConsole, |
|
90 |
debug, |
|
91 |
domain, |
|
92 |
devtools: !!debug, |
|
93 |
|
|
94 |
createCodeUrl |
|
95 |
} |