jazz
2024-01-03 12a2f18a968c29b3502a50c4f0a9f49c27c9f3f6
提交 | 用户 | 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
12a2f1 10 var ismock = 0// 虚拟数据 0不使用 1使用
aeb317 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
878885 16 var is_use_test_server = 1 // 是否部署在测试服务器
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   }
3ac5f2 28 }
J 29
30 const pdomain = '/' // 线上
31
32 const mock_domain = ''
33 // api_local 本地 http://192.168.1.106:8080
34 // api_test 测试环境
35 const tdomain = '/api_local/' // 本地
36 const pdomain_test = '/api_test/' // 测试环境
37
38 // 微信长链
39 const appid = appId
40 let scope = ''
41 if (isWxLoginType === 1) scope = 'snsapi_base' // snsapi_base 静默授权【只有openid】
42 if (isWxLoginType === 2) scope = 'snsapi_userinfo' // snsapi_userinfo 手动授权【有用户信息】
43 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'
44
45 // 生成微信重定向链接
46 function createCodeUrl() {
47   // 首页链接
48   let indexUrl = location.origin + location.pathname
49   const search = location.search
50   // 参数数组
51   let querys = []
459990 52   if (search && search.indexOf('?') > -1) {
J 53     querys = search.split('?')[1].split('&').filter((str) => {
3ac5f2 54       const key = str.split('=')[0]
J 55       const value = str.split('=')[1]
56       return (key != 'code' && key != 'state')
57     })
58   }
59
60   console.log(querys)
61
62   // 补充参数
63   if (querys.length) {
459990 64     indexUrl += '?' + querys.join('&')
3ac5f2 65   }
J 66
67   return long.replace('{{appid}}', appid).replace('{{scope}}', scope).replace('{{url}}', encodeURIComponent(indexUrl))
68 }
69
70 // 屏蔽console.log
71 if (!isConsole) {
72   console.log = () => {}
73 }
74
459990 75 var domain
3ac5f2 76
J 77 if (istest == 0) domain = pdomain // 线上
78 if (istest == 1) domain = tdomain // 本地
79 if (istest == 2) domain = pdomain_test // 测试环境
80 if (ismock == 1) domain = mock_domain // 本地模拟
81
82 export default {
83   ismock,
84   istest,
aeb317 85   isTestView,
J 86   localOnline,
3ac5f2 87   isWxLoginType,
J 88   isConsole,
89   debug,
90   domain,
91   devtools: !!debug,
92
93   createCodeUrl
94 }