|
@@ -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,34 @@ 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
|
+}
|
57
|
70
|
|
|
71
|
+/**
|
|
72
|
+ * getQueryPath 获取 query 中的 path 参数
|
|
73
|
+ * @returns
|
|
74
|
+ */
|
|
75
|
+export function getQueryPath() {
|
|
76
|
+ const { search } = window.location
|
|
77
|
+ if (!search) return undefined
|
|
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
|
+ return atob(pathParam.substring(2))
|
|
84
|
+}
|
58
|
85
|
|
59
|
86
|
|
60
|
87
|
// Vue.use(Vuex)
|