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