event.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <!-- 对应页面:事件分析 -->
  3. <view class="fix-top-window">
  4. <view class="uni-header">
  5. <uni-stat-breadcrumb class="uni-stat-breadcrumb-on-phone" />
  6. <view class="uni-group">
  7. <!-- <view class="uni-title">事件分析管理</view> -->
  8. <view class="uni-sub-title hide-on-phone">分析用户自定义事件
  9. <uni-link href="https://ask.dcloud.net.cn/article/36304" text="自定义事件说明>>"></uni-link>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="uni-container">
  14. <view class="uni-stat--x flex">
  15. <uni-data-select collection="opendb-app-list" field="appid as value, name as text" orderby="text asc"
  16. :defItem="1" label="应用选择" v-model="query.appid" :clear="false" />
  17. <uni-data-select collection="opendb-app-versions" :where="versionQuery"
  18. field="_id as value, version as text" orderby="text asc" label="版本选择" v-model="query.version_id" />
  19. <view class="flex">
  20. <uni-stat-tabs label="日期选择" :current="currentDateTab" mode="date" @change="changeTimeRange" />
  21. <uni-datetime-picker type="daterange" :end="new Date().getTime()" v-model="query.create_time"
  22. returnType="timestamp" :clearIcon="false" class="uni-stat-datetime-picker"
  23. :class="{'uni-stat__actived': currentDateTab < 0 && !!query.create_time.length}"
  24. @change="useDatetimePicker" />
  25. </view>
  26. </view>
  27. <view class="uni-stat--x">
  28. <uni-stat-tabs label="平台选择" type="boldLine" mode="platform" v-model="query.platform_id"
  29. @change="changePlatform" />
  30. <uni-data-select v-if="query.platform_id && query.platform_id.indexOf('==') === -1"
  31. :localdata="channelData" label="渠道选择" v-model="query.channel_id"></uni-data-select>
  32. </view>
  33. <view class="uni-stat--x p-m">
  34. <uni-table :loading="loading" border stripe :emptyText="$t('common.empty')">
  35. <uni-tr>
  36. <template v-for="(mapper, index) in fieldsMap">
  37. <uni-th v-if="mapper.title" :key="index" align="center">
  38. {{mapper.title}}
  39. </uni-th>
  40. </template>
  41. </uni-tr>
  42. <uni-tr v-for="(item ,i) in tableData" :key="i">
  43. <template v-for="(mapper, index) in fieldsMap">
  44. <uni-td align="center">
  45. {{item[mapper.field] !== undefined ? item[mapper.field] : '-'}}
  46. </uni-td>
  47. </template>
  48. </uni-tr>
  49. </uni-table>
  50. <view class="uni-pagination-box">
  51. <uni-pagination show-icon show-page-size :page-size="options.pageSize"
  52. :current="options.pageCurrent" :total="options.total" @change="changePageCurrent"
  53. @pageSizeChange="changePageSize" />
  54. </view>
  55. </view>
  56. </view>
  57. <uni-popup ref="inputDialog" type="dialog" :maskClick="true">
  58. <uni-popup-dialog ref="inputClose" mode="input" title="请编辑名称" v-model="updateValue" placeholder="请输入内容"
  59. @confirm="editName"></uni-popup-dialog>
  60. </uni-popup>
  61. <!-- #ifndef H5 -->
  62. <fix-window />
  63. <!-- #endif -->
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. mapfields,
  69. stringifyQuery,
  70. stringifyField,
  71. stringifyGroupField,
  72. getTimeOfSomeDayAgo,
  73. division,
  74. format,
  75. parseDateTime,
  76. debounce
  77. } from '@/js_sdk/uni-stat/util.js'
  78. import fieldsMap from './fieldsMap.js'
  79. export default {
  80. data() {
  81. return {
  82. fieldsMap,
  83. query: {
  84. appid: '',
  85. platform_id: '',
  86. uni_platform: '',
  87. channel_id: '',
  88. version_id: '',
  89. create_time: [],
  90. },
  91. options: {
  92. pageSize: 20,
  93. pageCurrent: 1, // 当前页
  94. total: 0, // 数据总量
  95. },
  96. loading: false,
  97. currentDateTab: 1,
  98. tableData: [],
  99. panelData: [],
  100. queryId: '',
  101. updateValue: '',
  102. channelData: []
  103. }
  104. },
  105. computed: {
  106. channelQuery() {
  107. const platform_id = this.query.platform_id
  108. return stringifyQuery({
  109. platform_id
  110. })
  111. },
  112. versionQuery() {
  113. const {
  114. appid,
  115. uni_platform
  116. } = this.query
  117. const query = stringifyQuery({
  118. appid,
  119. uni_platform
  120. })
  121. return query
  122. }
  123. },
  124. created() {
  125. this.debounceGet = debounce(() => this.getAllData())
  126. this.getChannelData()
  127. },
  128. watch: {
  129. query: {
  130. deep: true,
  131. handler(val) {
  132. this.options.pageCurrent = 1 // 重置分页
  133. this.debounceGet()
  134. }
  135. }
  136. },
  137. methods: {
  138. useDatetimePicker() {
  139. this.currentDateTab = -1
  140. },
  141. changeAppid(id) {
  142. this.getChannelData(id, false)
  143. },
  144. changePlatform(id, index, name, item) {
  145. this.getChannelData(null, id)
  146. this.query.version_id = 0
  147. this.query.uni_platform = item.code
  148. },
  149. changeTimeRange(id, index) {
  150. this.currentDateTab = index
  151. const start = getTimeOfSomeDayAgo(id),
  152. end = getTimeOfSomeDayAgo(0) - 1
  153. this.query.create_time = [start, end]
  154. },
  155. changePageCurrent(e) {
  156. this.options.pageCurrent = e.current
  157. this.getTableData()
  158. },
  159. changePageSize(pageSize) {
  160. this.options.pageSize = pageSize
  161. this.options.pageCurrent = 1 // 重置分页
  162. this.getTableData()
  163. },
  164. getAllData(query) {
  165. this.getTableData(query)
  166. },
  167. getTableData(query = stringifyQuery(this.query, null, ['uni_platform'])) {
  168. const {
  169. pageCurrent
  170. } = this.options
  171. this.loading = true
  172. const db = uniCloud.database()
  173. db.collection('uni-stat-event-logs', 'uni-stat-app-platforms')
  174. .where(query)
  175. .orderBy('create_time', 'desc')
  176. .skip((pageCurrent - 1) * this.options.pageSize)
  177. .limit(this.options.pageSize)
  178. .get({
  179. getCount: true
  180. })
  181. .then(res => {
  182. const {
  183. count,
  184. data
  185. } = res.result
  186. this.tableData = []
  187. this.options.total = count
  188. for (const item of data) {
  189. item.create_time = parseDateTime(item.create_time, 'dateTime')
  190. item.platform = item.platform && item.platform[0].name
  191. mapfields(fieldsMap, item, item)
  192. this.tableData.push(item)
  193. }
  194. }).catch((err) => {
  195. console.error(err)
  196. // err.message 错误信息
  197. // err.code 错误码
  198. }).finally(() => {
  199. this.loading = false
  200. })
  201. },
  202. getChannelData(appid, platform_id) {
  203. this.query.channel_id = ''
  204. const db = uniCloud.database()
  205. const condition = {}
  206. //对应应用
  207. appid = appid ? appid : this.query.appid
  208. if (appid) {
  209. condition.appid = appid
  210. }
  211. //对应平台
  212. platform_id = platform_id ? platform_id : this.query.platform_id
  213. if (platform_id) {
  214. condition.platform_id = platform_id
  215. }
  216. let platformTemp = db.collection('uni-stat-app-platforms')
  217. .field('_id, name')
  218. .getTemp()
  219. let channelTemp = db.collection('uni-stat-app-channels')
  220. .where(condition)
  221. .field('_id, channel_name, create_time, platform_id')
  222. .getTemp()
  223. db.collection(channelTemp, platformTemp)
  224. .orderBy('platform_id', 'asc')
  225. .get()
  226. .then(res => {
  227. let data = res.result.data
  228. let channels = []
  229. if (data.length > 0) {
  230. let channelName
  231. for (let i in data) {
  232. channelName = data[i].channel_name ? data[i].channel_name : '默认'
  233. if (data[i].platform_id.length > 0) {
  234. channelName = data[i].platform_id[0].name + '-' + channelName
  235. }
  236. channels.push({
  237. value: data[i]._id,
  238. text: channelName
  239. })
  240. }
  241. }
  242. this.channelData = channels
  243. })
  244. .catch((err) => {
  245. console.error(err)
  246. // err.message 错误信息
  247. // err.code 错误码
  248. }).finally(() => {})
  249. }
  250. }
  251. }
  252. </script>
  253. <style>
  254. .uni-stat-edit--x {
  255. display: flex;
  256. justify-content: space-between;
  257. }
  258. .uni-stat-edit--btn {
  259. cursor: pointer;
  260. }
  261. </style>