张延森 3 年前
父节点
当前提交
d52d8f991d
共有 2 个文件被更改,包括 14 次插入49 次删除
  1. 9
    1
      src/main.js
  2. 5
    48
      src/util/initial.js

+ 9
- 1
src/main.js 查看文件

@@ -16,7 +16,7 @@ import {
16 16
   Image, SwipeItem, Tag, Swipe, Divider, Picker, Popup, Dialog, List,ImagePreview 
17 17
 } from 'vant';
18 18
 import App from './App.vue'
19
-import { Login, redirect } from './util/initial'
19
+import { Login, redirect, getQueryPath } from './util/initial'
20 20
 
21 21
 // import Questionnaire from './views/components/Questionnaire'
22 22
 // import Loading from './views/components/Questionnaire/Loading.vue';
@@ -25,6 +25,14 @@ import store from './store';//状态管理
25 25
 
26 26
 import './global_style.less'
27 27
 
28
+// 如果有 query 分享路径
29
+const queryPath = getQueryPath()
30
+if (queryPath) {
31
+  window.location.href = queryPath
32
+  return
33
+}
34
+
35
+
28 36
 Vue.config.productionTip = false
29 37
 
30 38
 Vue.use(Popup);

+ 5
- 48
src/util/initial.js 查看文件

@@ -13,7 +13,7 @@ const jsApiList = [
13 13
 ]
14 14
 
15 15
 function initSDK (url) {
16
-  request(`https://api.h5.njyunzhi.com/mp/jssdk?url=${encodeURIComponent(url)}`).then((res) => {
16
+  request(`http://api.h5.njyunzhi.com/mp/jssdk?url=${encodeURIComponent(url)}`).then((res) => {
17 17
     window.wx.config({
18 18
       debug: process.env.NODE_ENV === 'development', // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
19 19
       appId: res.appId, // 必填,公众号的唯一标识
@@ -73,14 +73,16 @@ export function encodeHashLocation() {
73 73
  * @returns 
74 74
  */
75 75
 export function getQueryPath() {
76
-  const { search } = window.location
76
+  const { origin, pathname, search, hash } = window.location
77 77
   if (!search) return undefined
78 78
 
79 79
   const queryStr = search.substring(1) // 去掉 ?
80 80
   const pathParam = queryStr.split('&').filter(q => /^p=/.test(q))[0]
81 81
   if (!pathParam) return undefined
82 82
 
83
-  return atob(pathParam.substring(2))
83
+  const path = atob(pathParam.substring(2))
84
+
85
+  return origin + pathname + search + '#' + path
84 86
 }
85 87
 
86 88
 
@@ -129,51 +131,6 @@ export function hideLoading () {
129 131
   document.getElementsByClassName('page-loading-wrapper')[0].style = "display: none"
130 132
 }
131 133
 
132
-// export function GetCode () {
133
-
134
-//   // 从 window.location.href 中截取 code 并且赋值
135
-//   if (window.location.href.indexOf('Code_state') !== -1) {
136
-//     this.code = window.location.href.split('?')[1].split('=')[1].split('&')[0]
137
-//     store.commit('SET_USER_INFO', { code: this.code })
138
-//   }
139
-
140
-//   if (this.$store.state.user.code) {
141
-//     // 存在 code 直接调用接口
142
-//     this.handGetUserInfo(this.code)
143
-//   }
144
-
145
-
146
-//   // 重定向地址重定到当前页面,在路径获取 code
147
-//   if (process.env.NODE_ENV === 'development') {
148
-//     console.log(222)
149
-//     return
150
-//   }
151
-//   /**
152
-//    * 获取 code
153
-//    * @returns
154
-//    */
155
-//   function getCode () {
156
-//     const matched = /[?&]*code=([^&]+)/.exec(location.search)
157
-//     if (matched) {
158
-//       return decodeURIComponent(matched[1])
159
-//     }
160
-//   }
161
-
162
-//   const hrefUrl = window.location.href
163
-
164
-
165
-//   if (this.code === '') {
166
-//     window.location.href = `
167
-// 						https://open.weixin.qq.com/connect/oauth2/authorize
168
-// 						?appid=${this.$store.state.user.appid}
169
-// 						&redirect_uri=${encodeURIComponent(hrefUrl)}
170
-// 						&response_type=code
171
-// 						&scope=snsapi_userinfo
172
-// 						&state=Code_state#wechat_redirect
173
-// 					`
174
-//   }
175
-// }
176
-
177 134
 /**
178 135
  * 获取 code
179 136
  * @returns