提交 | 用户 | 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 |
|
|
10 |
var ismock = 1// 虚拟数据 0不使用 1使用 |
|
11 |
var istest = 0// 0线上 1本地 2测试环境 |
|
12 |
var isConsole = 1// 是否屏蔽console 0屏蔽 1开放 |
|
13 |
var debug = isConsole |
|
14 |
var isWxLoginType = 0 // 微信登录 0无 1静默微信登录snsapi_base 2手动微信登录snsapi_userinfo |
|
15 |
|
|
16 |
// 打包后的环境 |
|
17 |
if (process.env && process.env.NODE_ENV !== 'development') { |
|
18 |
istest = 0 |
|
19 |
ismock = 0 |
|
20 |
} |
|
21 |
|
|
22 |
const pdomain = '/' // 线上 |
|
23 |
|
|
24 |
const mock_domain = '' |
|
25 |
// api_local 本地 http://192.168.1.106:8080 |
|
26 |
// api_test 测试环境 |
|
27 |
const tdomain = '/api_local/' // 本地 |
|
28 |
const pdomain_test = '/api_test/' // 测试环境 |
|
29 |
|
|
30 |
// 微信长链 |
|
31 |
const appid = appId |
|
32 |
let scope = '' |
|
33 |
if (isWxLoginType === 1) scope = 'snsapi_base' // snsapi_base 静默授权【只有openid】 |
|
34 |
if (isWxLoginType === 2) scope = 'snsapi_userinfo' // snsapi_userinfo 手动授权【有用户信息】 |
|
35 |
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' |
|
36 |
|
|
37 |
// 生成微信重定向链接 |
|
38 |
function createCodeUrl() { |
|
39 |
// 首页链接 |
|
40 |
let indexUrl = location.origin + location.pathname |
|
41 |
const search = location.search |
|
42 |
// 参数数组 |
|
43 |
let querys = [] |
|
44 |
if (search && search.indexOf('?')>-1) { |
|
45 |
querys = search.split('?')[1].split('&').filter((str)=>{ |
|
46 |
const key = str.split('=')[0] |
|
47 |
const value = str.split('=')[1] |
|
48 |
return (key != 'code' && key != 'state') |
|
49 |
}) |
|
50 |
} |
|
51 |
|
|
52 |
console.log(querys) |
|
53 |
|
|
54 |
// 补充参数 |
|
55 |
if (querys.length) { |
|
56 |
indexUrl += '?'+querys.join('&') |
|
57 |
} |
|
58 |
|
|
59 |
return long.replace('{{appid}}', appid).replace('{{scope}}', scope).replace('{{url}}', encodeURIComponent(indexUrl)) |
|
60 |
} |
|
61 |
|
|
62 |
// 屏蔽console.log |
|
63 |
if (!isConsole) { |
|
64 |
console.log = () => {} |
|
65 |
} |
|
66 |
|
|
67 |
var domain; |
|
68 |
|
|
69 |
if (istest == 0) domain = pdomain // 线上 |
|
70 |
if (istest == 1) domain = tdomain // 本地 |
|
71 |
if (istest == 2) domain = pdomain_test // 测试环境 |
|
72 |
if (ismock == 1) domain = mock_domain // 本地模拟 |
|
73 |
|
|
74 |
export default { |
|
75 |
ismock, |
|
76 |
istest, |
|
77 |
isWxLoginType, |
|
78 |
isConsole, |
|
79 |
debug, |
|
80 |
domain, |
|
81 |
devtools: !!debug, |
|
82 |
|
|
83 |
createCodeUrl |
|
84 |
} |