123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <!-- 对应页面: 受访页 -->
- <view class="fix-top-window">
- <view class="uni-header">
- <uni-stat-breadcrumb class="uni-stat-breadcrumb-on-phone" />
- <view class="uni-group">
- <!-- <view class="uni-title">受访页</view> -->
- <view class="uni-sub-title hide-on-phone">受访页数据分析</view>
- </view>
- </view>
- <view class="uni-container">
- <view class="uni-stat--x flex">
- <uni-data-select collection="opendb-app-list" field="appid as value, name as text" orderby="text asc"
- :defItem="1" label="应用选择" v-model="query.appid" :clear="false" />
- <uni-data-select collection="opendb-app-versions" :where="versionQuery"
- field="_id as value, version as text" orderby="text asc" label="版本选择" v-model="query.version_id" />
- <view class="flex">
- <uni-stat-tabs label="日期选择" :current="currentDateTab" mode="date" @change="changeTimeRange" />
- <uni-datetime-picker type="daterange" :end="new Date().getTime()" v-model="query.start_time"
- returnType="timestamp" :clearIcon="false" class="uni-stat-datetime-picker"
- :class="{'uni-stat__actived': currentDateTab < 0 && !!query.start_time.length}"
- @change="useDatetimePicker" />
- </view>
- </view>
- <view class="uni-stat--x">
- <uni-stat-tabs label="平台选择" type="boldLine" mode="platform" v-model="query.platform_id"
- @change="changePlatform" />
- <uni-data-select v-if="query.platform_id && query.platform_id.indexOf('==') === -1"
- :localdata="channelData" label="渠道选择" v-model="query.channel_id"></uni-data-select>
- </view>
- <uni-stat-panel :items="panelData" />
- <view class="uni-stat--x p-m">
- <uni-table :loading="loading" border stripe :emptyText="$t('common.empty')">
- <uni-tr>
- <template v-for="(mapper, index) in fieldsMap">
- <uni-th v-if="mapper.title" :key="index" align="center">
- <!-- #ifdef MP -->
- {{mapper.title}}
- <!-- #endif -->
- <!-- #ifndef MP -->
- <uni-tooltip>
- {{mapper.title}}
- <uni-icons v-if="index === 0 && mapper.tooltip" type="help" color="#666" />
- <template v-if="index === 0 && mapper.tooltip" v-slot:content>
- <view class="uni-stat-tooltip-s">
- {{mapper.tooltip}}
- </view>
- </template>
- </uni-tooltip>
- <!-- #endif -->
- </uni-th>
- </template>
- </uni-tr>
- <uni-tr v-for="(item ,i) in tableData" :key="i">
- <template v-for="(mapper, index) in fieldsMap">
- <uni-td v-if="index === 1" :key="mapper.field" class="uni-stat-edit--x">
- {{item[mapper.field] !== undefined ? item[mapper.field] : '-'}}
- <uni-icons type="compose" color="#2979ff" size="25" class="uni-stat-edit--btn"
- @click="inputDialogToggle(item.path, item.title)" />
- </uni-td>
- <uni-td v-else :key="mapper.field" :align="index === 0 ? 'left' : 'center'">
- {{item[mapper.field] !== undefined ? item[mapper.field] : '-'}}
- </uni-td>
- </template>
- </uni-tr>
- </uni-table>
- <view class="uni-pagination-box">
- <uni-pagination show-icon show-page-size :page-size="options.pageSize"
- :current="options.pageCurrent" :total="options.total" @change="changePageCurrent"
- @pageSizeChange="changePageSize" />
- </view>
- </view>
- </view>
- <uni-popup ref="inputDialog" type="dialog" :maskClick="true">
- <uni-popup-dialog ref="inputClose" mode="input" title="请编辑名称" v-model="updateValue" placeholder="请输入内容"
- @confirm="editName"></uni-popup-dialog>
- </uni-popup>
- <!-- #ifndef H5 -->
- <fix-window />
- <!-- #endif -->
- </view>
- </template>
- <script>
- import {
- mapfields,
- stringifyQuery,
- stringifyField,
- stringifyGroupField,
- getTimeOfSomeDayAgo,
- division,
- format,
- debounce
- } from '@/js_sdk/uni-stat/util.js'
- import fieldsMap from './fieldsMap.js'
- export default {
- data() {
- return {
- fieldsMap,
- query: {
- dimension: "day",
- appid: '',
- platform_id: '',
- uni_platform: '',
- version_id: '',
- channel_id: '',
- start_time: [],
- },
- options: {
- pageSize: 20,
- pageCurrent: 1, // 当前页
- total: 0, // 数据总量
- },
- loading: false,
- currentDateTab: 1,
- tableData: [],
- panelData: fieldsMap.filter(f => f.hasOwnProperty('value')),
- queryId: '',
- updateValue: '',
- channelData: []
- }
- },
- computed: {
- channelQuery() {
- const platform_id = this.query.platform_id
- return stringifyQuery({
- platform_id
- })
- },
- versionQuery() {
- const {
- appid,
- uni_platform
- } = this.query
- const query = stringifyQuery({
- appid,
- uni_platform
- })
- return query
- }
- },
- created() {
- this.debounceGet = debounce(() => this.getAllData())
- this.getChannelData()
- },
- watch: {
- query: {
- deep: true,
- handler(val) {
- this.options.pageCurrent = 1 // 重置分页
- this.debounceGet()
- }
- }
- },
- methods: {
- useDatetimePicker() {
- this.currentDateTab = -1
- },
- changeAppid(id) {
- this.getChannelData(id, false)
- },
- changePlatform(id, index, name, item) {
- this.getChannelData(null, id)
- this.query.version_id = 0
- this.query.uni_platform = item.code
- },
- changeTimeRange(id, index) {
- this.currentDateTab = index
- const start = getTimeOfSomeDayAgo(id),
- end = getTimeOfSomeDayAgo(0) - 1
- this.query.start_time = [start, end]
- },
- changePageCurrent(e) {
- this.options.pageCurrent = e.current
- this.getTableData(this.query)
- },
- changePageSize(pageSize) {
- this.options.pageSize = pageSize
- this.options.pageCurrent = 1 // 重置分页
- this.getTableData()
- },
- getAllData() {
- this.getPanelData()
- this.getTableData()
- },
- getTableData(query) {
- query = stringifyQuery(this.query, null, ['uni_platform'])
- const {
- pageCurrent
- } = this.options
- this.loading = true
- const db = uniCloud.database()
- const filterAppid = stringifyQuery({
- appid: this.query.appid
- })
- const mainTableTemp = db.collection('uni-stat-pages')
- .where(filterAppid)
- .field('_id, title, path')
- .getTemp()
- const subTableTemp = db.collection('uni-stat-page-result')
- .where(query)
- .getTemp()
- db.collection(subTableTemp, mainTableTemp)
- .field(
- `${stringifyField(fieldsMap)}, stat_date, page_id`
- )
- .groupBy("page_id")
- .groupField(stringifyGroupField(fieldsMap))
- .orderBy('visit_times', 'desc')
- .skip((pageCurrent - 1) * this.options.pageSize)
- .limit(this.options.pageSize)
- .get({
- getCount: true
- })
- .then(res => {
- const {
- count,
- data
- } = res.result
- this.options.total = count
- this.tableData = []
- for (const item of data) {
- const lines = item.page_id
- if (Array.isArray(lines)) {
- delete(item.page_id)
- const line = lines[0]
- if (line && Object.keys(line).length) {
- for (const key in line) {
- if (key !== '_id') {
- item[key] = line[key]
- }
- }
- }
- }
- mapfields(fieldsMap, item, item)
- this.tableData.push(item)
- }
- }).catch((err) => {
- console.error(err)
- // err.message 错误信息
- // err.code 错误码
- }).finally(() => {
- this.loading = false
- })
- },
- getPanelData(query = stringifyQuery(this.query, null, ['uni_platform'])) {
- const db = uniCloud.database()
- const subTable = db.collection('uni-stat-page-result')
- .where(query)
- .field(stringifyField(fieldsMap))
- .groupBy('appid')
- .groupField(stringifyGroupField(fieldsMap))
- .orderBy('start_time', 'desc ')
- .get()
- .then(res => {
- const items = res.result.data[0]
- this.panelData = []
- this.panelData = mapfields(fieldsMap, items)
- })
- },
- inputDialogToggle(url, title) {
- this.queryId = url
- this.updateValue = title
- this.$refs.inputDialog.open()
- },
- editName(value) {
- // 使用 clientDB 提交数据
- const db = uniCloud.database()
- db.collection('uni-stat-pages')
- .where({
- url: this.queryId
- })
- .update({
- title: value
- })
- .then((res) => {
- uni.showToast({
- title: '修改成功'
- })
- this.getTableData()
- }).catch((err) => {
- uni.showModal({
- content: err.message || '请求服务失败',
- showCancel: false
- })
- }).finally(() => {
- uni.hideLoading()
- })
- },
- getChannelData(appid, platform_id) {
- this.query.channel_id = ''
- const db = uniCloud.database()
- const condition = {}
- //对应应用
- appid = appid ? appid : this.query.appid
- if (appid) {
- condition.appid = appid
- }
- //对应平台
- platform_id = platform_id ? platform_id : this.query.platform_id
- if (platform_id) {
- condition.platform_id = platform_id
- }
- let platformTemp = db.collection('uni-stat-app-platforms')
- .field('_id, name')
- .getTemp()
- let channelTemp = db.collection('uni-stat-app-channels')
- .where(condition)
- .field('_id, channel_name, create_time, platform_id')
- .getTemp()
- db.collection(channelTemp, platformTemp)
- .orderBy('platform_id', 'asc')
- .get()
- .then(res => {
- let data = res.result.data
- let channels = []
- if (data.length > 0) {
- let channelName
- for (let i in data) {
- channelName = data[i].channel_name ? data[i].channel_name : '默认'
- if (data[i].platform_id.length > 0) {
- channelName = data[i].platform_id[0].name + '-' + channelName
- }
- channels.push({
- value: data[i]._id,
- text: channelName
- })
- }
- }
- this.channelData = channels
- })
- .catch((err) => {
- console.error(err)
- // err.message 错误信息
- // err.code 错误码
- }).finally(() => {})
- }
- }
- }
- </script>
- <style>
- .uni-stat-edit--x {
- display: flex;
- justify-content: space-between;
- }
- .uni-stat-edit--btn {
- cursor: pointer;
- }
- </style>
|