123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <template>
- <div class="p-4">
- <!-- <GrowCard :loading="loading" class="enter-y" /> -->
- <BasicTable @register="registerTable">
- <template #headerTop>
- <div class="md:flex enter-y">
- <div class="md:w-1/2 enter-y">
- <Card class="w-full">
- <VisitAnalysisBar
- :loading="loading"
- :viewStatics="viewStaticsData"
- :shareStatics="shareStaticsData"
- />
- </Card>
- </div>
- <div class="!md:mx-2"></div>
- <Card class="md:w-1/2 enter-y">
- <!-- <VisitAnalysis :loading="loading" /> -->
- <VisitAnalysis
- :loading="loading"
- :bulletChatAmounts="bulletChatAmountsData"
- :userAmount="userAmountData"
- />
- </Card>
- </div>
- </template>
- <template #toolbar>
- <a-button type="primary" @click="handleExport">导出数据</a-button>
- </template>
- <template #Time="{ record }">
- <Time :value="record.createTime" mode="datetime" />
- </template>
- <template #Time1="{ record }">
- <Time v-if="record.firstEnterRoomTime" :value="record.firstEnterRoomTime" mode="datetime" />
- </template>
- <template #Time2="{ record }">
- <Time v-if="record.lastExistRoomTime" :value="record.lastExistRoomTime" mode="datetime" />
- </template>
- </BasicTable>
- <!-- <div class="md:flex enter-y">
- <div class="md:w-1/2 enter-y">
- <Card class="w-full">
- <VisitAnalysisBar :loading="loading" />
- </Card>
- </div>
- <div class="!md:mx-2"></div>
- <Card class="md:w-1/2 enter-y">
- <VisitAnalysis :loading="loading" />
- </Card>
- </div>
- <div class="md:flex enter-y mt-4">
- <Card class="md:w-1/2 md:w-full"> </Card>
- </div> -->
- </div>
- </template>
- <script lang="ts" setup>
- import { onMounted, ref } from 'vue';
- import { BasicTable, useTable, BasicColumn, FormProps } from '/@/components/Table';
- // import { useI18n } from '/@/hooks/web/useI18n';
- // import GrowCard from './components/GrowCard.vue';
- import { Card } from 'ant-design-vue';
- import VisitAnalysis from './components/VisitAnalysis.vue';
- import VisitAnalysisBar from './components/VisitAnalysisBar.vue';
- import { Time } from '/@/components/Time';
- import {
- bulletChatApi,
- userStaticsApi,
- bulletChatStaticsApi,
- bulletChatExportApi,
- } from '/@/api/dashboard/analysis';
- import { listRoomsApi } from '/@/api/scene/list';
- import { dateUtil, formatToDate } from '/@/utils/dateUtil';
- import { StaticItemType } from '/@/api/dashboard/model';
- const today = formatToDate(dateUtil(new Date()));
- const priorDate = formatToDate(dateUtil(new Date().setDate(new Date().getDate() - 30)));
- const loading = ref(true);
- // UserStaticsModel
- const viewStaticsData = ref<StaticItemType[]>([]);
- const shareStaticsData = ref<StaticItemType[]>([]);
- const bulletChatAmountsData = ref<StaticItemType[]>([]);
- const userAmountData = ref<StaticItemType[]>([]);
- // const { t } = useI18n();
- const columns: BasicColumn[] = [
- {
- title: '微信昵称',
- dataIndex: 'nickName',
- width: 120,
- ellipsis: true,
- customRender: ({ record }) => {
- const { nickName } = record;
- return nickName?.length ? nickName : ' -- ';
- },
- },
- {
- title: '手机号',
- dataIndex: 'userName',
- width: 120,
- customRender: ({ record }) => {
- const { userName } = record;
- let reg = /(\d{3})\d{4}(\d{4})/;
- const macthUserName = userName && userName.replace(reg, '$1****$2');
- return macthUserName;
- },
- },
- {
- title: '房间名称',
- dataIndex: 'liveRoomName',
- width: 120,
- },
- {
- title: '在线时长(min)',
- dataIndex: 'duration',
- width: 120,
- },
- {
- title: '初次进入房间',
- dataIndex: 'firstEnterRoomTime',
- slots: { customRender: 'Time1' },
- width: 150,
- },
- {
- title: '最后离开房间',
- dataIndex: 'lastExistRoomTime',
- slots: { customRender: 'Time2' },
- width: 150,
- },
- {
- title: '邀请者',
- dataIndex: 'inviterUserName',
- width: 120,
- },
- {
- title: '留言条数',
- dataIndex: 'bulletChatAmount',
- width: 120,
- },
- {
- title: '留言内容',
- dataIndex: 'bulletChatContents',
- width: 320,
- },
- ];
- const searchForm: Partial<FormProps> = {
- labelWidth: 100,
- schemas: [
- {
- field: 'liveRoomId',
- label: '全部房间',
- component: 'ApiSelect',
- // required: true,
- colProps: {
- xl: 5,
- xxl: 5,
- },
- componentProps: {
- api: listRoomsApi,
- labelField: 'name',
- resultField: 'list',
- valueField: 'id',
- immediate: false,
- showSearch: true,
- optionFilterProp: 'label',
- params: {
- page: 1,
- limit: 1000,
- state: 103,
- },
- },
- },
- {
- field: 'time',
- label: '时间段',
- component: 'RangePicker',
- defaultValue: [priorDate, today],
- colProps: {
- xl: 6,
- xxl: 6,
- },
- componentProps: {
- format: 'YYYY-MM-DD',
- showTime: false,
- disabledDate(current) {
- // console.log('current', current, date);
- return current && current > dateUtil().endOf('day');
- },
- // onChange: (value) => {
- // console.log('onchange', value);
- // },
- },
- rules: [
- {
- required: true,
- // @ts-ignore
- validator: async (rule, value) => {
- if (!value) {
- return Promise.reject('请选择时间段');
- }
- const days = Math.abs(value[1].diff(value[0], 'days'));
- console.log('days', days);
- if (days > 30) {
- return Promise.reject('选择时间段应小于30天');
- }
- if (days < 1) {
- return Promise.reject('至少选择2天以上');
- }
- return Promise.resolve();
- },
- trigger: 'change',
- },
- ],
- },
- {
- field: 'inviterUserName',
- label: '邀请者',
- component: 'Input',
- componentProps: {
- maxLength: 100,
- },
- colProps: {
- xl: 5,
- xxl: 5,
- },
- },
- ],
- resetFunc: handleReset,
- };
- const searchInfo = ref({
- liveRoomId: '',
- // limit: 20,
- // page: 1,
- time: [priorDate, today],
- });
- const [registerTable] = useTable({
- title: '房间留言状态',
- columns: columns,
- useSearchForm: true,
- formConfig: searchForm,
- immediate: true,
- api: bulletChatApi,
- beforeFetch: (data) => {
- console.log('beforeFetch', data);
- data.time = data.time.map((item) => formatToDate(item));
- handleStatic(data);
- searchInfo.value = {
- liveRoomId: data.liveRoomId,
- time: data.time,
- };
- return data;
- },
- afterFetch: function (data) {
- console.log('afterFetch', arguments);
- return data;
- },
- searchInfo: searchInfo,
- handleSearchInfoFn(data) {
- searchInfo.value = Object.assign(searchInfo.value, data);
- console.log(searchInfo.value);
- return;
- },
- });
- onMounted(() => {
- handleStatic();
- });
- async function handleStatic(search?: any) {
- try {
- loading.value = true;
- const searchInfoParams = search || searchInfo.value;
- const sData = await userStaticsApi(searchInfoParams);
- const bData = await bulletChatStaticsApi(searchInfoParams);
- console.log('sData', sData);
- console.log('bData', sData);
- viewStaticsData.value = sData.viewStatics;
- shareStaticsData.value = sData.shareStatics;
- userAmountData.value = bData.userAmount;
- bulletChatAmountsData.value = bData.bulletChatAmounts;
- loading.value = false;
- } catch (error) {
- loading.value = false;
- }
- }
- async function handleExport() {
- const data = await bulletChatExportApi(searchInfo.value);
- const downloadBlob = new Blob([data], {
- type: 'application/msexcel',
- });
- const url = URL.createObjectURL(downloadBlob);
- const a: HTMLAnchorElement = document.createElement('a');
- document.body.appendChild(a);
- a.style.display = 'none';
- a.href = url;
- const name = new Date().getTime();
- a.download = `${name}.csv`;
- a.click();
- window.URL.revokeObjectURL(url);
- }
- async function handleReset() {
- searchInfo.value = {
- liveRoomId: '',
- // limit: 20,
- // page: 1,
- time: [priorDate, today],
- };
- }
- // setTimeout(() => {
- // loading.value = false;
- // }, 1500);
- </script>
|