report.uvue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex:1">
  4. <!-- #endif -->
  5. <page-head title="report"></page-head>
  6. <view class="tips">
  7. <view class="tips-title">调用信息:</view>
  8. <view class="tips-content">{{msg}}</view>
  9. </view>
  10. <view class="page">
  11. <button class="normal-button" type="default" @click="handleAppLaunch">
  12. 模拟应用启动
  13. </button>
  14. <button class="normal-button" type="default" @click="handleAppHide">
  15. 模拟应用切入后台
  16. </button>
  17. <button class="normal-button" type="default" @click="handleAppShow">
  18. 模拟应用切入前台
  19. </button>
  20. <button class="normal-button" type="default" @click="handleAppError">
  21. 模拟应用错误
  22. </button>
  23. <button class="normal-button" type="default" @click="handleTitle">
  24. 模拟自定义title
  25. </button>
  26. <button class="normal-button" type="default" @click="handleEvent">
  27. 模拟自定义事件
  28. </button>
  29. <text class="instructions">
  30. 当前页面调用API均为模拟,请查看文档,在特定场景下使用以上 API。请在main.uts中设置统计debug配置为true,并点击按钮查控制台输出。
  31. </text>
  32. </view>
  33. <!-- #ifdef APP -->
  34. </scroll-view>
  35. <!-- #endif -->
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. msg: '点击按钮,测试上报'
  42. }
  43. },
  44. onLoad() {
  45. uni.report({
  46. name: '自定义上报-report页面打开',
  47. options: '1'
  48. })
  49. },
  50. onUnload() {
  51. uni.report({
  52. name: '自定义上报-report页面关闭',
  53. options: '1'
  54. })
  55. },
  56. methods: {
  57. handleAppLaunch() {
  58. const options = uni.getLaunchOptionsSync()
  59. uni.report({
  60. name: 'uni-app-launch',
  61. options: options,
  62. success: (res) => {
  63. this.msg = 'onLaunch --> ' + res.errMsg
  64. console.log(res);
  65. }, fail: (err) => {
  66. this.msg = 'onLaunch --> ' + err.errMsg
  67. console.log(err);
  68. }
  69. })
  70. },
  71. handleAppHide() {
  72. uni.report({
  73. name: 'uni-app-hide',
  74. success: (res) => {
  75. this.msg = 'onAppHide --> ' + res.errMsg
  76. console.log(res);
  77. }, fail: (err) => {
  78. this.msg = 'onAppHide --> ' + err.errMsg
  79. console.log(err);
  80. }
  81. })
  82. },
  83. handleAppShow() {
  84. // const options = uni.getLaunchOptionsSync()
  85. uni.report({
  86. name: 'uni-app-show',
  87. success: (res) => {
  88. this.msg = 'onAppShow --> ' + res.errMsg
  89. console.log(res);
  90. }, fail: (err) => {
  91. this.msg = 'onAppShow --> ' + err.errMsg
  92. console.log(err);
  93. }
  94. })
  95. },
  96. handleAppError() {
  97. const errmsg = '测试错误'
  98. uni.report({
  99. name: 'uni-app-error',
  100. options: errmsg,
  101. success: (res) => {
  102. this.msg = 'onAppError --> ' + res.errMsg
  103. console.log(res);
  104. }, fail: (err) => {
  105. this.msg = 'onAppError --> ' + err.errMsg
  106. console.log(err);
  107. }
  108. })
  109. },
  110. handleEvent() {
  111. // 此处name为用户自定义
  112. uni.report({
  113. name: 'custom-event',
  114. options: {
  115. title: '自定义事件',
  116. total: 1
  117. },
  118. success: (res) => {
  119. this.msg = '自定义事件 --> ' + res.errMsg
  120. console.log(res);
  121. }, fail: (err) => {
  122. this.msg = '自定义事件 --> ' + err.errMsg
  123. console.log(err);
  124. }
  125. })
  126. },
  127. handleTitle() {
  128. // 此处name为用户自定义
  129. uni.report({
  130. name: 'title',
  131. options: '自定义title测试上报',
  132. success: (res) => {
  133. this.msg = '自定义title --> ' + res.errMsg
  134. console.log(res);
  135. }, fail: (err) => {
  136. this.msg = '自定义title --> ' + err.errMsg
  137. console.log(err);
  138. }
  139. })
  140. },
  141. }
  142. }
  143. </script>
  144. <style>
  145. .page {
  146. padding: 15px;
  147. }
  148. .tips {
  149. margin: 15px;
  150. padding: 15px;
  151. background-color: #f5f5f5;
  152. font-size: 14px;
  153. text-align: center;
  154. }
  155. .tips-title {
  156. font-size: 16px;
  157. color: #333;
  158. margin-bottom: 10px;
  159. }
  160. .tips-content {
  161. font-size: 14px;
  162. color: #999;
  163. }
  164. .normal-button {
  165. width: 100%;
  166. margin-bottom: 10px;
  167. }
  168. .instructions {
  169. margin-top: 10px;
  170. margin-left: 10px;
  171. margin-right: 10px;
  172. background-color: #eee;
  173. font-size: 12px;
  174. color: #999;
  175. }
  176. </style>