Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
8ba66e31
U
uni-app
项目概览
lzb_79
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8ba66e31
编写于
8月 26, 2021
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(stat): wx 统计兼容 vue3
上级
4b0b64c1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
192 addition
and
228 deletion
+192
-228
packages/vue-cli-plugin-uni/packages/uni-stat/dist/uni-stat.cjs.js
...vue-cli-plugin-uni/packages/uni-stat/dist/uni-stat.cjs.js
+96
-114
packages/vue-cli-plugin-uni/packages/uni-stat/dist/uni-stat.es.js
.../vue-cli-plugin-uni/packages/uni-stat/dist/uni-stat.es.js
+96
-114
未找到文件。
packages/vue-cli-plugin-uni/packages/uni-stat/dist/uni-stat.cjs.js
浏览文件 @
8ba66e31
...
...
@@ -246,18 +246,14 @@ const getRoute = () => {
if
(
getPlatformName
()
===
'
bd
'
)
{
return
_self
.
$mp
&&
_self
.
$mp
.
page
.
is
}
else
{
return
_self
.
route
||
(
_self
.
$
mp
&&
_self
.
$mp
.
pag
e
.
route
)
return
_self
.
route
||
(
_self
.
$
scope
&&
_self
.
$scop
e
.
route
)
}
};
const
getPageRoute
=
(
self
)
=>
{
let
route
=
getRoute
();
let
query
=
self
.
_query
;
let
str
=
query
&&
JSON
.
stringify
(
query
)
!==
'
{}
'
?
'
?
'
+
JSON
.
stringify
(
query
)
:
''
;
// clear
self
.
_query
=
''
;
return
route
+
str
const
getPageRoute
=
(
_this
)
=>
{
let
pageVm
=
_this
.
self
;
let
page
=
pageVm
.
$page
||
pageVm
.
$scope
.
$page
;
return
page
.
fullPath
===
'
/
'
?
page
.
route
:
page
.
fullPath
};
const
getPageTypes
=
(
self
)
=>
{
...
...
@@ -389,7 +385,18 @@ const requestData = (done) => {
});
};
const
titleJsons
=
process
.
env
.
UNI_STAT_TITLE_JSON
;
let
titleJsons
=
{};
// #ifdef MP
let
pagesTitle
=
require
(
'
uni-pages?{"type":"style"}
'
).
default
;
pagesTitle
=
pagesTitle
.
pages
;
for
(
let
i
in
pagesTitle
)
{
titleJsons
[
i
]
=
pagesTitle
[
i
].
navigationBarTitleText
||
''
;
}
// #endif
// #ifndef MP
titleJsons
=
process
.
env
.
UNI_STAT_TITLE_JSON
;
// #endif
const
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
};
...
...
@@ -443,6 +450,62 @@ class Util {
sw
:
resultOptions
.
screenWidth
,
sh
:
resultOptions
.
screenHeight
,
};
// 注册拦截器
let
registerInterceptor
=
typeof
uni
.
addInterceptor
===
'
function
'
&&
process
.
env
.
NODE_ENV
!==
'
development
'
;
if
(
registerInterceptor
)
{
this
.
addInterceptorInit
();
this
.
interceptLogin
();
this
.
interceptShare
(
true
);
this
.
interceptRequestPayment
();
}
}
addInterceptorInit
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
setNavigationBarTitle
'
,
{
invoke
(
args
)
{
self
.
_navigationBarTitle
.
page
=
args
.
title
;
},
});
}
interceptLogin
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
login
'
,
{
complete
()
{
self
.
_login
();
},
});
}
interceptShare
(
type
)
{
let
self
=
this
;
if
(
!
type
)
{
self
.
_share
();
return
}
uni
.
addInterceptor
(
'
share
'
,
{
success
()
{
self
.
_share
();
},
fail
()
{
self
.
_share
();
},
});
}
interceptRequestPayment
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
requestPayment
'
,
{
success
()
{
self
.
_payment
(
'
pay_success
'
);
},
fail
()
{
self
.
_payment
(
'
pay_fail
'
);
},
});
}
getIsReportData
()
{
...
...
@@ -482,12 +545,11 @@ class Util {
_pageShow
()
{
const
route
=
getPageRoute
(
this
);
const
routepath
=
getRoute
();
this
.
_navigationBarTitle
.
config
=
titleJsons
[
routepath
]
||
''
;
this
.
_navigationBarTitle
.
config
=
(
titleJsons
&&
titleJsons
[
routepath
])
||
''
;
if
(
this
.
__licationShow
)
{
getFirstTime
();
this
.
__licationShow
=
false
;
// console.log('这是 onLauch 之后执行的第一次 pageShow ,为下次记录时间做准备');
this
.
_lastPageRoute
=
route
;
return
}
...
...
@@ -509,7 +571,10 @@ class Util {
if
(
!
this
.
__licationHide
)
{
getLastTime
();
const
time
=
getResidenceTime
(
'
page
'
);
const
route
=
getPageRoute
(
this
);
let
route
=
getPageRoute
(
this
);
if
(
!
this
.
_lastPageRoute
)
{
this
.
_lastPageRoute
=
route
;
}
this
.
_sendPageRequest
({
url
:
route
,
urlref
:
this
.
_lastPageRoute
,
...
...
@@ -553,6 +618,8 @@ class Util {
}
_sendReportRequest
(
options
)
{
this
.
_navigationBarTitle
.
lt
=
'
1
'
;
this
.
_navigationBarTitle
.
config
=
(
titleJsons
&&
titleJsons
[
options
.
path
])
||
''
;
let
query
=
options
.
query
&&
JSON
.
stringify
(
options
.
query
)
!==
'
{}
'
?
'
?
'
+
JSON
.
stringify
(
options
.
query
)
...
...
@@ -663,7 +730,6 @@ class Util {
requestData
[
data
.
lt
]
=
[];
}
requestData
[
data
.
lt
].
push
(
data
);
if
(
getPlatformName
()
===
'
n
'
)
{
uni
.
setStorageSync
(
'
__UNI__STAT__DATA
'
,
requestData
);
}
...
...
@@ -725,11 +791,7 @@ class Util {
url
:
STAT_URL
,
method
:
'
POST
'
,
data
:
optionsData
,
success
:
()
=>
{
// if (process.env.NODE_ENV === 'development') {
// console.log('stat request success');
// }
},
success
:
()
=>
{},
fail
:
(
e
)
=>
{
if
(
++
this
.
_retry
<
3
)
{
setTimeout
(()
=>
{
...
...
@@ -779,77 +841,16 @@ class Stat extends Util {
constructor
()
{
super
();
this
.
instance
=
null
;
// 注册拦截器
if
(
typeof
uni
.
addInterceptor
===
'
function
'
&&
process
.
env
.
NODE_ENV
!==
'
development
'
)
{
this
.
addInterceptorInit
();
this
.
interceptLogin
();
this
.
interceptShare
(
true
);
this
.
interceptRequestPayment
();
}
}
addInterceptorInit
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
setNavigationBarTitle
'
,
{
invoke
(
args
)
{
self
.
_navigationBarTitle
.
page
=
args
.
title
;
},
});
}
interceptLogin
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
login
'
,
{
complete
()
{
self
.
_login
();
},
});
}
interceptShare
(
type
)
{
let
self
=
this
;
if
(
!
type
)
{
self
.
_share
();
return
}
uni
.
addInterceptor
(
'
share
'
,
{
success
()
{
self
.
_share
();
},
fail
()
{
self
.
_share
();
},
});
}
interceptRequestPayment
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
requestPayment
'
,
{
success
()
{
self
.
_payment
(
'
pay_success
'
);
},
fail
()
{
self
.
_payment
(
'
pay_fail
'
);
},
});
}
report
(
options
,
self
)
{
this
.
self
=
self
;
// TODO 需要确认如果不用 $vm ,其他平台会不会出错
setPageResidenceTime
();
this
.
__licationShow
=
true
;
this
.
_sendReportRequest
(
options
,
true
);
}
load
(
options
,
self
)
{
// if (!self.$scope && !self.$mp) {
// const page = getCurrentPages()
// console.log();
// self.$scope = page[page.length - 1]
// }
this
.
self
=
self
;
this
.
_query
=
options
;
}
...
...
@@ -862,13 +863,7 @@ class Stat extends Util {
this
.
_applicationShow
(
self
);
}
}
ready
(
self
)
{
// this.self = self;
// if (getPageTypes(self)) {
// this._pageShow(self);
// }
}
ready
(
self
)
{}
hide
(
self
)
{
this
.
self
=
self
;
if
(
getPageTypes
(
self
))
{
...
...
@@ -882,7 +877,6 @@ class Stat extends Util {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
);
}
// return;
}
let
emVal
=
''
;
if
(
!
em
.
message
)
{
...
...
@@ -913,15 +907,12 @@ const stat = Stat$1.getInstance();
let
isHide
=
false
;
const
lifecycle
=
{
onLaunch
(
options
)
{
console
.
log
(
'
report onLaunch init
'
);
stat
.
report
(
options
,
this
);
},
onReady
()
{
console
.
log
(
'
report onReady init
'
);
stat
.
ready
(
this
);
},
onLoad
(
options
)
{
console
.
log
(
'
report onLoad init
'
);
stat
.
load
(
options
,
this
);
// 重写分享,获取分享上报事件
if
(
this
.
$scope
&&
this
.
$scope
.
onShareAppMessage
)
{
...
...
@@ -933,17 +924,14 @@ const lifecycle = {
}
},
onShow
()
{
console
.
log
(
'
report onShow init
'
);
isHide
=
false
;
stat
.
show
(
this
);
},
onHide
()
{
console
.
log
(
'
report onHide init
'
);
isHide
=
true
;
stat
.
hide
(
this
);
},
onUnload
()
{
console
.
log
(
'
report onUnload init
'
);
if
(
isHide
)
{
isHide
=
false
;
return
...
...
@@ -951,29 +939,23 @@ const lifecycle = {
stat
.
hide
(
this
);
},
onError
(
e
)
{
console
.
log
(
'
report onError init
'
);
stat
.
error
(
e
);
},
};
function
main
()
{
console
.
log
(
'
stat onload ----
'
);
uni
.
onAppLaunch
((
options
)
=>
{
// 小程序平台此时也无法获取getApp,统一在options中传递一个app对象
options
.
app
.
$vm
.
$
.
appContext
.
app
.
mixin
(
lifecycle
);
uni
.
report
=
function
(
type
,
options
)
{
stat
.
sendEvent
(
type
,
options
);
};
});
// if (process.env.NODE_ENV === 'development') {
// uni.report = function (type, options) {}
// } else {
// const Vue = require('vue')
// ;(Vue.default || Vue).mixin(lifecycle)
// uni.report = function (type, options) {
// stat.sendEvent(type, options)
// }
// }
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
uni
.
report
=
function
(
type
,
options
)
{};
}
else
{
uni
.
onAppLaunch
((
options
)
=>
{
stat
.
report
(
options
);
// 小程序平台此时也无法获取getApp,统一在options中传递一个app对象
options
.
app
.
$vm
.
$
.
appContext
.
app
.
mixin
(
lifecycle
);
uni
.
report
=
function
(
type
,
options
)
{
stat
.
sendEvent
(
type
,
options
);
};
});
}
}
main
();
packages/vue-cli-plugin-uni/packages/uni-stat/dist/uni-stat.es.js
浏览文件 @
8ba66e31
...
...
@@ -244,18 +244,14 @@ const getRoute = () => {
if
(
getPlatformName
()
===
'
bd
'
)
{
return
_self
.
$mp
&&
_self
.
$mp
.
page
.
is
}
else
{
return
_self
.
route
||
(
_self
.
$
mp
&&
_self
.
$mp
.
pag
e
.
route
)
return
_self
.
route
||
(
_self
.
$
scope
&&
_self
.
$scop
e
.
route
)
}
};
const
getPageRoute
=
(
self
)
=>
{
let
route
=
getRoute
();
let
query
=
self
.
_query
;
let
str
=
query
&&
JSON
.
stringify
(
query
)
!==
'
{}
'
?
'
?
'
+
JSON
.
stringify
(
query
)
:
''
;
// clear
self
.
_query
=
''
;
return
route
+
str
const
getPageRoute
=
(
_this
)
=>
{
let
pageVm
=
_this
.
self
;
let
page
=
pageVm
.
$page
||
pageVm
.
$scope
.
$page
;
return
page
.
fullPath
===
'
/
'
?
page
.
route
:
page
.
fullPath
};
const
getPageTypes
=
(
self
)
=>
{
...
...
@@ -387,7 +383,18 @@ const requestData = (done) => {
});
};
const
titleJsons
=
process
.
env
.
UNI_STAT_TITLE_JSON
;
let
titleJsons
=
{};
// #ifdef MP
let
pagesTitle
=
require
(
'
uni-pages?{"type":"style"}
'
).
default
;
pagesTitle
=
pagesTitle
.
pages
;
for
(
let
i
in
pagesTitle
)
{
titleJsons
[
i
]
=
pagesTitle
[
i
].
navigationBarTitleText
||
''
;
}
// #endif
// #ifndef MP
titleJsons
=
process
.
env
.
UNI_STAT_TITLE_JSON
;
// #endif
const
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
};
...
...
@@ -441,6 +448,62 @@ class Util {
sw
:
resultOptions
.
screenWidth
,
sh
:
resultOptions
.
screenHeight
,
};
// 注册拦截器
let
registerInterceptor
=
typeof
uni
.
addInterceptor
===
'
function
'
&&
process
.
env
.
NODE_ENV
!==
'
development
'
;
if
(
registerInterceptor
)
{
this
.
addInterceptorInit
();
this
.
interceptLogin
();
this
.
interceptShare
(
true
);
this
.
interceptRequestPayment
();
}
}
addInterceptorInit
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
setNavigationBarTitle
'
,
{
invoke
(
args
)
{
self
.
_navigationBarTitle
.
page
=
args
.
title
;
},
});
}
interceptLogin
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
login
'
,
{
complete
()
{
self
.
_login
();
},
});
}
interceptShare
(
type
)
{
let
self
=
this
;
if
(
!
type
)
{
self
.
_share
();
return
}
uni
.
addInterceptor
(
'
share
'
,
{
success
()
{
self
.
_share
();
},
fail
()
{
self
.
_share
();
},
});
}
interceptRequestPayment
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
requestPayment
'
,
{
success
()
{
self
.
_payment
(
'
pay_success
'
);
},
fail
()
{
self
.
_payment
(
'
pay_fail
'
);
},
});
}
getIsReportData
()
{
...
...
@@ -480,12 +543,11 @@ class Util {
_pageShow
()
{
const
route
=
getPageRoute
(
this
);
const
routepath
=
getRoute
();
this
.
_navigationBarTitle
.
config
=
titleJsons
[
routepath
]
||
''
;
this
.
_navigationBarTitle
.
config
=
(
titleJsons
&&
titleJsons
[
routepath
])
||
''
;
if
(
this
.
__licationShow
)
{
getFirstTime
();
this
.
__licationShow
=
false
;
// console.log('这是 onLauch 之后执行的第一次 pageShow ,为下次记录时间做准备');
this
.
_lastPageRoute
=
route
;
return
}
...
...
@@ -507,7 +569,10 @@ class Util {
if
(
!
this
.
__licationHide
)
{
getLastTime
();
const
time
=
getResidenceTime
(
'
page
'
);
const
route
=
getPageRoute
(
this
);
let
route
=
getPageRoute
(
this
);
if
(
!
this
.
_lastPageRoute
)
{
this
.
_lastPageRoute
=
route
;
}
this
.
_sendPageRequest
({
url
:
route
,
urlref
:
this
.
_lastPageRoute
,
...
...
@@ -551,6 +616,8 @@ class Util {
}
_sendReportRequest
(
options
)
{
this
.
_navigationBarTitle
.
lt
=
'
1
'
;
this
.
_navigationBarTitle
.
config
=
(
titleJsons
&&
titleJsons
[
options
.
path
])
||
''
;
let
query
=
options
.
query
&&
JSON
.
stringify
(
options
.
query
)
!==
'
{}
'
?
'
?
'
+
JSON
.
stringify
(
options
.
query
)
...
...
@@ -661,7 +728,6 @@ class Util {
requestData
[
data
.
lt
]
=
[];
}
requestData
[
data
.
lt
].
push
(
data
);
if
(
getPlatformName
()
===
'
n
'
)
{
uni
.
setStorageSync
(
'
__UNI__STAT__DATA
'
,
requestData
);
}
...
...
@@ -723,11 +789,7 @@ class Util {
url
:
STAT_URL
,
method
:
'
POST
'
,
data
:
optionsData
,
success
:
()
=>
{
// if (process.env.NODE_ENV === 'development') {
// console.log('stat request success');
// }
},
success
:
()
=>
{},
fail
:
(
e
)
=>
{
if
(
++
this
.
_retry
<
3
)
{
setTimeout
(()
=>
{
...
...
@@ -777,77 +839,16 @@ class Stat extends Util {
constructor
()
{
super
();
this
.
instance
=
null
;
// 注册拦截器
if
(
typeof
uni
.
addInterceptor
===
'
function
'
&&
process
.
env
.
NODE_ENV
!==
'
development
'
)
{
this
.
addInterceptorInit
();
this
.
interceptLogin
();
this
.
interceptShare
(
true
);
this
.
interceptRequestPayment
();
}
}
addInterceptorInit
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
setNavigationBarTitle
'
,
{
invoke
(
args
)
{
self
.
_navigationBarTitle
.
page
=
args
.
title
;
},
});
}
interceptLogin
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
login
'
,
{
complete
()
{
self
.
_login
();
},
});
}
interceptShare
(
type
)
{
let
self
=
this
;
if
(
!
type
)
{
self
.
_share
();
return
}
uni
.
addInterceptor
(
'
share
'
,
{
success
()
{
self
.
_share
();
},
fail
()
{
self
.
_share
();
},
});
}
interceptRequestPayment
()
{
let
self
=
this
;
uni
.
addInterceptor
(
'
requestPayment
'
,
{
success
()
{
self
.
_payment
(
'
pay_success
'
);
},
fail
()
{
self
.
_payment
(
'
pay_fail
'
);
},
});
}
report
(
options
,
self
)
{
this
.
self
=
self
;
// TODO 需要确认如果不用 $vm ,其他平台会不会出错
setPageResidenceTime
();
this
.
__licationShow
=
true
;
this
.
_sendReportRequest
(
options
,
true
);
}
load
(
options
,
self
)
{
// if (!self.$scope && !self.$mp) {
// const page = getCurrentPages()
// console.log();
// self.$scope = page[page.length - 1]
// }
this
.
self
=
self
;
this
.
_query
=
options
;
}
...
...
@@ -860,13 +861,7 @@ class Stat extends Util {
this
.
_applicationShow
(
self
);
}
}
ready
(
self
)
{
// this.self = self;
// if (getPageTypes(self)) {
// this._pageShow(self);
// }
}
ready
(
self
)
{}
hide
(
self
)
{
this
.
self
=
self
;
if
(
getPageTypes
(
self
))
{
...
...
@@ -880,7 +875,6 @@ class Stat extends Util {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
);
}
// return;
}
let
emVal
=
''
;
if
(
!
em
.
message
)
{
...
...
@@ -911,15 +905,12 @@ const stat = Stat$1.getInstance();
let
isHide
=
false
;
const
lifecycle
=
{
onLaunch
(
options
)
{
console
.
log
(
'
report onLaunch init
'
);
stat
.
report
(
options
,
this
);
},
onReady
()
{
console
.
log
(
'
report onReady init
'
);
stat
.
ready
(
this
);
},
onLoad
(
options
)
{
console
.
log
(
'
report onLoad init
'
);
stat
.
load
(
options
,
this
);
// 重写分享,获取分享上报事件
if
(
this
.
$scope
&&
this
.
$scope
.
onShareAppMessage
)
{
...
...
@@ -931,17 +922,14 @@ const lifecycle = {
}
},
onShow
()
{
console
.
log
(
'
report onShow init
'
);
isHide
=
false
;
stat
.
show
(
this
);
},
onHide
()
{
console
.
log
(
'
report onHide init
'
);
isHide
=
true
;
stat
.
hide
(
this
);
},
onUnload
()
{
console
.
log
(
'
report onUnload init
'
);
if
(
isHide
)
{
isHide
=
false
;
return
...
...
@@ -949,29 +937,23 @@ const lifecycle = {
stat
.
hide
(
this
);
},
onError
(
e
)
{
console
.
log
(
'
report onError init
'
);
stat
.
error
(
e
);
},
};
function
main
()
{
console
.
log
(
'
stat onload ----
'
);
uni
.
onAppLaunch
((
options
)
=>
{
// 小程序平台此时也无法获取getApp,统一在options中传递一个app对象
options
.
app
.
$vm
.
$
.
appContext
.
app
.
mixin
(
lifecycle
);
uni
.
report
=
function
(
type
,
options
)
{
stat
.
sendEvent
(
type
,
options
);
};
});
// if (process.env.NODE_ENV === 'development') {
// uni.report = function (type, options) {}
// } else {
// const Vue = require('vue')
// ;(Vue.default || Vue).mixin(lifecycle)
// uni.report = function (type, options) {
// stat.sendEvent(type, options)
// }
// }
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
uni
.
report
=
function
(
type
,
options
)
{};
}
else
{
uni
.
onAppLaunch
((
options
)
=>
{
stat
.
report
(
options
);
// 小程序平台此时也无法获取getApp,统一在options中传递一个app对象
options
.
app
.
$vm
.
$
.
appContext
.
app
.
mixin
(
lifecycle
);
uni
.
report
=
function
(
type
,
options
)
{
stat
.
sendEvent
(
type
,
options
);
};
});
}
}
main
();
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录