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