|
@@ -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, // 必填,公众号的唯一标识
|
|
@@ -31,11 +31,11 @@ function initSDK (url) {
|
31
|
31
|
* @param {*} opt
|
32
|
32
|
*/
|
33
|
33
|
export function share (opt) {
|
34
|
|
- const { origin, pathname, search } = window.location
|
35
|
|
- // const defaultLink = origin + pathname
|
36
|
|
- const defaultImg = `${origin}${pathname}images/share.png`
|
|
34
|
+ const { origin, pathname, search, hash } = window.location
|
|
35
|
+ const defaultImg = `${origin}${pathname}images/share.jpg`
|
37
|
36
|
|
38
|
|
- const link = origin + pathname + search // opt.link || defaultLink
|
|
37
|
+ // const link = origin + pathname + search
|
|
38
|
+ const link = encodeHashLocation()
|
39
|
39
|
const imgUrl = opt.imgUrl || defaultImg
|
40
|
40
|
|
41
|
41
|
initSDK(link)
|
|
@@ -54,7 +54,36 @@ export function share (opt) {
|
54
|
54
|
})
|
55
|
55
|
}
|
56
|
56
|
|
|
57
|
+/**
|
|
58
|
+ * hash 路由处理为可分享路由
|
|
59
|
+ */
|
|
60
|
+export function encodeHashLocation () {
|
|
61
|
+ const { origin, pathname, search, hash } = window.location
|
|
62
|
+
|
|
63
|
+ const hashRoute = hash.substring(1)
|
|
64
|
+ const routeParam = btoa(hashRoute)
|
|
65
|
+
|
|
66
|
+ const query = search ? `${search}&p=${routeParam}` : `?p=${routeParam}`
|
|
67
|
+
|
|
68
|
+ return origin + pathname + query
|
|
69
|
+}
|
|
70
|
+
|
|
71
|
+/**
|
|
72
|
+ * getQueryPath 获取 query 中的 path 参数
|
|
73
|
+ * @returns
|
|
74
|
+ */
|
|
75
|
+export function getQueryPath () {
|
|
76
|
+ const { origin, pathname, search, hash } = window.location
|
|
77
|
+ if (!search) return undefined
|
57
|
78
|
|
|
79
|
+ const queryStr = search.substring(1) // 去掉 ?
|
|
80
|
+ const pathParam = queryStr.split('&').filter(q => /^p=/.test(q))[0]
|
|
81
|
+ if (!pathParam) return undefined
|
|
82
|
+
|
|
83
|
+ const path = atob(pathParam.substring(2))
|
|
84
|
+
|
|
85
|
+ return origin + pathname + search + '#' + path
|
|
86
|
+}
|
58
|
87
|
|
59
|
88
|
|
60
|
89
|
// Vue.use(Vuex)
|
|
@@ -102,7 +131,6 @@ export function hideLoading () {
|
102
|
131
|
document.getElementsByClassName('page-loading-wrapper')[0].style = "display: none"
|
103
|
132
|
}
|
104
|
133
|
|
105
|
|
-
|
106
|
134
|
/**
|
107
|
135
|
* 获取 code
|
108
|
136
|
* @returns
|