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