test-api.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <div class="c-sibling-item--v">
  9. <div
  10. class="l-flex--row inline u-color--blue u-font-size--sm u-bold has-active"
  11. @click="onChoose"
  12. >
  13. {{ tip }}
  14. </div>
  15. </div>
  16. <div class="l-flex__fill l-flex c-sibling-item--v">
  17. <div class="l-flex__fill l-flex--col c-sibling-item">
  18. <span class="c-sibling-item--v far u-font-size--sm u-bold">在线时长统计</span>
  19. <div class="c-sibling-item--v l-grid--info mini">
  20. <button
  21. class="o-button"
  22. @click="onTriggerOnlineDurationSnap"
  23. >
  24. 触发快照
  25. </button>
  26. <button
  27. class="o-button"
  28. @click="onGetOnlineDurationByDevice"
  29. >
  30. 设备总时长
  31. </button>
  32. <button
  33. class="o-button"
  34. @click="onGetOnlineDurationReport"
  35. >
  36. 设备日报
  37. </button>
  38. </div>
  39. <span class="c-sibling-item--v far u-font-size--sm u-bold">自助广告统计</span>
  40. <div class="c-sibling-item--v l-grid--info mini">
  41. <button
  42. class="o-button"
  43. @click="onTriggerAdSnap"
  44. >
  45. 触发快照
  46. </button>
  47. <button
  48. class="o-button"
  49. @click="onGetAdReportForPlatfrom"
  50. >
  51. 平台日报
  52. </button>
  53. <button
  54. class="o-button"
  55. @click="onGetAdReportForTenant"
  56. >
  57. 租户日报
  58. </button>
  59. <button
  60. class="o-button"
  61. @click="onGetAdReportForDevice"
  62. >
  63. 设备日报
  64. </button>
  65. <button
  66. class="o-button"
  67. @click="onGetAdCollectForPlatfrom"
  68. >
  69. 平台汇总
  70. </button>
  71. <button
  72. class="o-button"
  73. @click="onGetAdCollectForTenant"
  74. >
  75. 租户汇总
  76. </button>
  77. <button
  78. class="o-button"
  79. @click="onGetAdCollectForDevice"
  80. >
  81. 设备汇总
  82. </button>
  83. </div>
  84. <span class="c-sibling-item--v far u-font-size--sm u-bold">数据</span>
  85. <div class="c-sibling-item--v l-grid--info mini">
  86. <button
  87. class="o-button"
  88. @click="onGetDepartmentDeviceTree"
  89. >
  90. 部门设备树
  91. </button>
  92. </div>
  93. </div>
  94. <div class="l-flex__none c-sibling-item far u-width--lg u-font-size--sm u-overflow-y--auto">
  95. <pre
  96. class="l-flex__fill"
  97. style="white-space: break-spaces;"
  98. ><code>{{ responseData }}</code></pre>
  99. </div>
  100. </div>
  101. <single-device-dialog
  102. ref="deviceDialog"
  103. @confirm="onConfirm"
  104. />
  105. </wrapper>
  106. </template>
  107. <script>
  108. import { parseTime } from '@/utils'
  109. import {
  110. triggetOnlineDurationSnap,
  111. getOnlineDurationByDevice,
  112. getOnlineDurationReport,
  113. triggerAdSnap,
  114. getAdReport,
  115. getAdCollect
  116. } from '@/api/statistics'
  117. import { getDepartmentDeviceTree } from '@/api/device'
  118. export default {
  119. name: 'TestApi',
  120. data () {
  121. return {
  122. device: null,
  123. responseData: null
  124. }
  125. },
  126. computed: {
  127. tip () {
  128. return this.device?.name || '点击选择设备'
  129. },
  130. deviceId () {
  131. return this.device?.id
  132. }
  133. },
  134. methods: {
  135. onChoose () {
  136. this.$refs.deviceDialog.show(this.device)
  137. },
  138. onConfirm ({ value, done }) {
  139. this.device = value
  140. done()
  141. },
  142. onData (data) {
  143. this.responseData = data
  144. },
  145. checkDevice () {
  146. if (this.device) {
  147. return true
  148. }
  149. this.$message({
  150. type: 'warning',
  151. message: '请先选择设备'
  152. })
  153. return false
  154. },
  155. getMonth () {
  156. const endDate = new Date()
  157. endDate.setDate(endDate.getDate() - 1)
  158. const startDate = new Date(endDate.getTime())
  159. startDate.setMonth(startDate.getMonth() - 1)
  160. return {
  161. startDate: parseTime(startDate, '{y}-{m}-{d}'),
  162. endDate: parseTime(endDate, '{y}-{m}-{d}')
  163. }
  164. },
  165. onTriggerOnlineDurationSnap () {
  166. const endDate = new Date()
  167. endDate.setDate(endDate.getDate() - 1)
  168. triggetOnlineDurationSnap({ endDate: parseTime(endDate, '{y}-{m}-{d}') }).then(() => {
  169. this.$message({
  170. type: 'success',
  171. message: '触发完成'
  172. })
  173. })
  174. },
  175. onGetOnlineDurationByDevice () {
  176. this.checkDevice() && getOnlineDurationByDevice(this.deviceId).then(this.onData)
  177. },
  178. onGetOnlineDurationReport () {
  179. const { startDate, endDate } = this.getMonth()
  180. this.checkDevice() && getOnlineDurationReport({
  181. deviceId: this.deviceId,
  182. type: 1,
  183. sumDateFrom: startDate,
  184. sumDateTo: endDate
  185. }).then(this.onData)
  186. },
  187. async onTriggerAdSnap () {
  188. const endDate = new Date()
  189. endDate.setDate(endDate.getDate() - 1)
  190. let startDate = new Date(endDate.getTime())
  191. startDate.setMonth(startDate.getMonth() - 1)
  192. while (startDate <= endDate) {
  193. try {
  194. await triggerAdSnap(parseTime(startDate, '{y}-{m}-{d}'))
  195. } catch (e) {
  196. console.log('onTriggerAdSnap fail', parseTime(startDate, '{y}-{m}-{d}'))
  197. }
  198. startDate = new Date(startDate.setDate(startDate.getDate() + 1))
  199. }
  200. this.$message({
  201. type: 'success',
  202. message: '触发完成'
  203. })
  204. },
  205. onGetAdReportForPlatfrom () {
  206. getAdReport(this.getMonth()).then(this.onData)
  207. },
  208. onGetAdReportForTenant () {
  209. getAdReport({
  210. tenant: this.$store.getters.tenant,
  211. ...this.getMonth()
  212. }).then(this.onData)
  213. },
  214. onGetAdReportForDevice () {
  215. this.checkDevice() && getAdReport({
  216. deviceId: this.deviceId,
  217. ...this.getMonth()
  218. }).then(this.onData)
  219. },
  220. onGetAdCollectForPlatfrom () {
  221. getAdCollect().then(this.onData)
  222. },
  223. onGetAdCollectForTenant () {
  224. getAdCollect({ tenant: this.$store.getters.tenant }).then(this.onData)
  225. },
  226. onGetAdCollectForDevice () {
  227. this.checkDevice() && getAdCollect({ deviceId: this.deviceId }).then(this.onData)
  228. },
  229. onGetDepartmentDeviceTree () {
  230. getDepartmentDeviceTree().then(this.onData)
  231. }
  232. }
  233. }
  234. </script>