田间的稻草人
田间的稻草人
  • 发布:2023-05-22 13:51
  • 更新:2023-05-22 20:46
  • 阅读:219

【报Bug】uni-admin统计问题

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows11

HBuilderX类型: 正式

HBuilderX版本号: 3.8.2

浏览器平台: Chrome

浏览器版本: 所有

项目创建方式: HBuilderX

操作步骤:

uni-admin

预期结果:

筛选出结果

实际结果:

选择筛选条件显示为空

bug描述:

uni-admin自定义事件筛选条件没起作用,具体可看截图,第一张图正常,当我选择固定日期,数据为空,选择平台,数据也为空....

2023-05-22 13:51 负责人:无 分享
已邀请:
DCloud_uniCloud_VK

DCloud_uniCloud_VK

核实中

DCloud_uniCloud_VK

DCloud_uniCloud_VK

你试试手动选到5月22日, 具体原因是因为在手动选日期时, 截止日期是你选的日期的00:00:00秒,而不是23:59:59 导致的
因此看上去时间是一样的,但其实最近7天的截止日期是那天的23:59:59, 而手动选的截止日期是那天的00:00:00

DCloud_uniCloud_VK

DCloud_uniCloud_VK

下版本时间会显示到秒

  • 田间的稻草人 (作者)

    最后一张图单独选择平台类型筛选出来的结果也是显示空的哦

    2023-05-22 14:56

  • DCloud_uniCloud_VK

    第二张图时间选到 2023-05-15 到 2023-05-22 是否有数据

    2023-05-22 15:11

  • 田间的稻草人 (作者)

    回复 DCloud_uniCloud_VK: 没有,只有平台选择 -> 全部才有数据

    2023-05-22 15:20

  • DCloud_uniCloud_VK

    回复 1***@qq.com: 我的意思是第二张图你平台选了全部也没数据, 因为你时间选到了5月21日,你试试平台选择全部, 然后时间选到2023-05-15 到 2023-05-22 是否有数据

    2023-05-22 15:32

  • DCloud_uniCloud_VK

    回复 DCloud_uniCloud_VK: 你这应该是2个问题, 先确认下第一个问题,时间选择器的问题

    2023-05-22 15:40

  • 田间的稻草人 (作者)

    回复 DCloud_uniCloud_VK: 我时间选了15-21,平台选择 -> 微信小程序依然没有数据

    2023-05-22 15:43

  • 田间的稻草人 (作者)

    回复 DCloud_uniCloud_VK: 时间单独选择一天没有数据显示,选择两天就有数据

    2023-05-22 15:44

  • DCloud_uniCloud_VK

    回复 1***@qq.com: 我问你2个问题,

    问题1:你时间选择15-22 平台选择全部 是否有数据?

    问题2:你时间选择15-22 平台选择微信小程序 是否有数据?

    2023-05-22 16:08

  • 田间的稻草人 (作者)

    回复 DCloud_uniCloud_VK: 问题1有数据 问题2无数据

    2023-05-22 16:50

  • DCloud_uniCloud_VK

    回复 1***@qq.com: 好的,核实中

    2023-05-22 17:15

DCloud_uniCloud_VK

DCloud_uniCloud_VK

替换下这个文件 /pages/uni-stat/event/event.vue 的内容为下方代码后试试

<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">分析用户自定义事件  
                    <uni-link href="https://ask.dcloud.net.cn/article/36304" text="自定义事件说明>>"></uni-link>  
                </view>  
            </view>  
        </view>  
        <view class="uni-container">  
            <view class="uni-stat--x flex p-1015">  
                <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" class="ml-m" field="concat(version, '---',uni_platform) as value, version as text, uni_platform as label, create_date as date" format="{label} - {text}" orderby="date desc" label="版本选择" v-model="query.version_id" @change="changeVersion"/>  
            </view>  
            <view class="uni-stat--x flex">  
                <uni-stat-tabs label="日期选择" :current="currentDateTab" mode="date" @change="changeTimeRange" />  
                <uni-datetime-picker type="datetimerange" :end="new Date().getTime()" v-model="query.create_time"  
                    returnType="timestamp" :clearIcon="false" class="uni-stat-datetime-picker"  
                    :class="{'uni-stat__actived': currentDateTab < 0 && !!query.create_time.length}"  
                    @change="useDatetimePicker" />  
            </view>  
            <view class="uni-stat--x">  
                <uni-stat-tabs label="平台选择" type="boldLine" mode="platform" v-model="query.platform_id" @change="changePlatform" />  
                <uni-data-select ref="version-select" v-if="query.platform_id && query.platform_id.indexOf('==') === -1" collection="uni-stat-app-channels" :where="channelQuery" class="p-channel" field="concat(channel_code, '---',channel_name) as value,  channel_name as text" orderby="text asc" label="渠道/场景值选择" v-model="query.channel_id" @change="changeChannel"/>  
                <!-- <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>  
            <view class="uni-stat--x p-m">  
                <uni-table :loading="loading" border stripe :emptyText="$t('common.empty')">  
                    <uni-tr>  
                        <block v-for="(mapper, index) in fieldsMap" :key="index">  
                            <uni-th v-if="mapper.title" :key="index" align="center">  
                                {{mapper.title}}  
                            </uni-th>  
                        </block>  
                    </uni-tr>  
                    <uni-tr v-for="(item ,i) in tableData" :key="i">  
                        <uni-td align="center" v-for="(mapper, index) in fieldsMap" :key="index">  
                            {{item[mapper.field] !== undefined ? item[mapper.field] : '-'}}  
                        </uni-td>  
                    </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,  
        parseDateTime,  
        debounce  
    } from '@/js_sdk/uni-stat/util.js'  
    import fieldsMap from './fieldsMap.js'  
    export default {  
        data() {  
            return {  
                fieldsMap,  
                query: {  
                    appid: '',  
                    platform_id: '',  
                    uni_platform: '',  
                    platform: '',  
                    channel_id: '',  
                    channel: '',  
                    version_id: '',  
                    version:'',  
                    create_time: [],  
                },  
                options: {  
                    pageSize: 20,  
                    pageCurrent: 1, // 当前页  
                    total: 0, // 数据总量  
                },  
                loading: false,  
                currentDateTab: 1,  
                tableData: [],  
                panelData: [],  
                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)  
            },  
            changeTimeRange(id, index) {  
                this.currentDateTab = index  
                const start = getTimeOfSomeDayAgo(id),  
                    end = getTimeOfSomeDayAgo(0) - 1  
                this.query.create_time = [start, end]  
            },  
            changePageCurrent(e) {  
                this.options.pageCurrent = e.current  
                this.getTableData()  
            },  

            changePageSize(pageSize) {  
                this.options.pageSize = pageSize  
                this.options.pageCurrent = 1 // 重置分页  
                this.getTableData()  
            },  

            getAllData(query) {  
                this.getTableData(query)  
            },  
            changePlatform(id, index, name, item) {  
                this.getChannelData(null, id)  
                this.query.version_id = 0  
                this.query.uni_platform = item.code  
                this.query.platform = item.code  
            },  
            changeVersion(version){  
                if (!version) version = "";  
                let versionArr = version.split("---");  
                this.query.version = version.split("---")[0];  
                this.query.platform = version.split("---")[1];  
            },  
            changeChannel(channel){  
                if (!channel) channel = "";  
                let channelArr = channel.split("---");  
                this.query.channel = channel.split("---")[0];  
                //this.query.platform = channel.split("---")[1];  
            },  
            getTableData(query = stringifyQuery(this.query, null, ['uni_platform','platform_id','version_id', 'channel_id'])) {  
                const {  
                    pageCurrent  
                } = this.options  
                this.loading = true  
                const db = uniCloud.database()  

                let collectionList = [  
                    db.collection('uni-stat-event-logs').where(query).getTemp(),  
                    db.collection('uni-stat-app-platforms').getTemp()  
                ];  
                db.collection(...collectionList)  
                    //.where(query)  
                    .orderBy('create_time', 'desc')  
                    .skip((pageCurrent - 1) * this.options.pageSize)  
                    .limit(this.options.pageSize)  
                    .get({  
                        getCount: true  
                    })  
                    .then(res => {  
                        const {  
                            count,  
                            data  
                        } = res.result  
                        this.tableData = []  
                        this.options.total = count  
                        for (const item of data) {  
                            item.create_time = parseDateTime(item.create_time, 'dateTime')  
                            item.platform = item.platform && item.platform[0].name  
                            mapfields(fieldsMap, item, item)  
                            this.tableData.push(item)  
                        }  
                    }).catch((err) => {  
                        console.error(err)  
                        // err.message 错误信息  
                        // err.code 错误码  
                    }).finally(() => {  
                        this.loading = false  
                    })  
            },  

            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>  

该问题目前已经被锁定, 无法添加新回复