Files
tkNewAdmin/src/views/Home/Index.vue

776 lines
23 KiB
Vue
Raw Normal View History

2025-07-01 21:08:51 +08:00
<template>
<div>
<el-card shadow="never">
<el-skeleton :loading="loading" animated>
<el-row :gutter="16" justify="space-between">
<el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
<div class="flex items-center">
<el-avatar :src="avatar" :size="70" class="mr-16px">
<img src="@/assets/imgs/avatar.gif" alt="" />
</el-avatar>
<div>
<div class="text-20px">
{{ t('workplace.welcome') }} {{ username }} {{ t('workplace.happyDay') }}
</div>
<div class="mt-10px text-14px text-gray-500">
{{ t('workplace.toady') }}20 - 32
</div>
</div>
</div>
</el-col>
<!-- <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
<div class="h-70px flex items-center justify-end lt-sm:mt-10px">
<div class="px-8px text-right">
<div class="mb-16px text-14px text-gray-400">{{ t('workplace.project') }}</div>
<CountTo class="text-20px" :start-val="0" :end-val="totalSate.project" :duration="2600" />
</div>
<el-divider direction="vertical" />
<div class="px-8px text-right">
<div class="mb-16px text-14px text-gray-400">{{ t('workplace.toDo') }}</div>
<CountTo class="text-20px" :start-val="0" :end-val="totalSate.todo" :duration="2600" />
</div>
<el-divider direction="vertical" border-style="dashed" />
<div class="px-8px text-right">
<div class="mb-16px text-14px text-gray-400">{{ t('workplace.access') }}</div>
<CountTo class="text-20px" :start-val="0" :end-val="totalSate.access" :duration="2600" />
</div>
</div>
</el-col> -->
</el-row>
</el-skeleton>
</el-card>
</div>
<el-row class="mt-8px" :gutter="8" justify="space-between">
<el-col :xl="16" :lg="16" :md="24" :sm="24" :xs="24" class="mb-8px">
<el-card shadow="never">
<template #header>
<div class="h-3 flex justify-between">
<span>{{ t('workplace.project') }}</span>
<!-- <el-link type="primary" :underline="false" href="https://github.com/yudaocode" target="_blank">
{{ t('action.more') }}
</el-link> -->
</div>
</template>
<el-skeleton :loading="loading" animated>
<el-row>
<el-col v-for="(item, index) in projects" :key="`card-${index}`" :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
<el-card shadow="hover" class="mr-5px mt-5px cursor-pointer" @click="handleProjectClick(item.message)">
<div class="flex items-center">
<Icon :icon="item.icon" :size="25" class="mr-8px" :style="{ color: item.color }" />
<span class="text-16px">{{ item.name }}</span>
</div>
<div class="mt-12px text-12px text-gray-400">{{ t(item.message) }}</div>
<div class="mt-12px flex justify-between text-12px text-gray-400">
<span>{{ item.personal }}</span>
<span>{{ formatTime(item.time, 'yyyy-MM-dd') }}</span>
</div>
</el-card>
</el-col>
</el-row>
</el-skeleton>
</el-card>
2025-08-08 14:38:06 +08:00
<el-card shadow="never" class="mt-8px">
2025-09-09 20:33:33 +08:00
<!-- <div style="display: flex; width: 50%;"
2025-12-05 21:10:27 +08:00
v-if="wsCache.get('roleRouters').find(item => item.id === 5019)?.children.find(item => item.id === 5020)">
2025-08-08 14:38:06 +08:00
<el-select v-model="allocationUser" :placeholder="t('newHosts.placeAllocationUser')" clearable
@change="getUserAccessSource(allocationUser)">
<el-option v-for="(user, index) in allocationUserList" :key="index" :label="user.label"
:value="user.value" />
</el-select>
2025-09-09 20:33:33 +08:00
</div> -->
2025-08-08 14:38:06 +08:00
2025-07-01 21:08:51 +08:00
<el-skeleton :loading="loading" animated>
<el-row :gutter="20" justify="space-between">
2025-09-09 20:33:33 +08:00
<!-- <el-col :xl="10" :lg="10" :md="24" :sm="24" :xs="24">
2025-07-01 21:08:51 +08:00
<el-card shadow="hover" class="mb-8px">
<el-skeleton :loading="loading" animated>
<Echart :options="pieOptionsData" :height="280" />
</el-skeleton>
</el-card>
2025-09-09 20:33:33 +08:00
</el-col> -->
<el-col
2025-12-05 21:10:27 +08:00
v-if="wsCache.get('roleRouters').find(item => item.id === 5019)?.children.find(item => item.id === 5020)"
2025-10-17 15:37:42 +08:00
:xl="20" :lg="20" :md="24" :sm="24" :xs="24">
2025-07-01 21:08:51 +08:00
<el-card shadow="hover" class="mb-8px">
2025-10-17 15:37:42 +08:00
<el-select style="width: 200px;" v-model="days" @change="updataDays">
2025-10-17 15:53:12 +08:00
<el-option :value="1" label="当日">当日</el-option>
<el-option :value="7" label="近7日">近7日</el-option>
2025-10-17 15:37:42 +08:00
</el-select>
2025-07-01 21:08:51 +08:00
<el-skeleton :loading="loading" animated>
2025-10-17 15:37:42 +08:00
<Echart style="width: 100%;" :options="barOptionsData" :height="280" />
2025-07-01 21:08:51 +08:00
</el-skeleton>
</el-card>
2025-09-09 20:33:33 +08:00
</el-col>
2025-12-05 21:10:27 +08:00
<el-col v-if="tenantLevel != 1" :xl="14" :lg="14" :md="24" :sm="24" :xs="24">
2025-09-09 20:33:33 +08:00
<el-card shadow="hover" class="mb-8px">
2025-11-12 18:55:21 +08:00
<div>当日建联主播数量</div>
2025-09-09 20:33:33 +08:00
{{ HostsOperationNum }}
</el-card>
</el-col>
2025-07-01 21:08:51 +08:00
</el-row>
</el-skeleton>
2025-08-08 14:38:06 +08:00
</el-card>
2025-11-12 18:55:21 +08:00
<!-- 当日建联大哥数 -->
<el-card shadow="never" class="mt-8px">
<el-skeleton :loading="loading" animated>
<el-row :gutter="20" justify="space-between">
<el-col
2025-12-05 21:10:27 +08:00
v-if="wsCache.get('roleRouters').find(item => item.id === 5041)?.children.find(item => item.id === 5042)"
2025-11-12 18:55:21 +08:00
:xl="20" :lg="20" :md="24" :sm="24" :xs="24">
<el-card shadow="hover" class="mb-8px">
<el-select style="width: 200px;" v-model="daysDsec" @change="updataDaysDsec">
<el-option :value="1" label="当日">当日</el-option>
<el-option :value="7" label="近7日">近7日</el-option>
</el-select>
<el-skeleton :loading="loading" animated>
<Echart style="width: 100%;" :options="barOptionsDataDsec" :height="280" />
</el-skeleton>
</el-card>
</el-col>
2025-12-05 21:10:27 +08:00
<el-col v-if="tenantLevel != 1" :xl="14" :lg="14" :md="24" :sm="24" :xs="24">
2025-11-12 18:55:21 +08:00
<el-card shadow="hover" class="mb-8px">
<div>当日建联大哥数量</div>
{{ HostsOperationNumDsec }}
</el-card>
</el-col>
</el-row>
</el-skeleton>
</el-card>
2025-07-01 21:08:51 +08:00
</el-col>
<el-col :xl="8" :lg="8" :md="24" :sm="24" :xs="24" class="mb-8px">
<!-- 快捷入口 -->
<!-- <el-card shadow="never">
2025-09-09 20:33:33 +08:00
<template #header>
2025-07-01 21:08:51 +08:00
<div class="h-3 flex justify-between">
<span>{{ t('workplace.shortcutOperation') }}</span>
</div>
</template>
<el-skeleton :loading="loading" animated>
<el-row>
<el-col v-for="item in shortcut" :key="`team-${item.name}`" :span="8" class="mb-8px">
<div class="flex items-center">
<Icon :icon="item.icon" class="mr-8px" :style="{ color: item.color }" />
<el-link type="default" :underline="false" @click="handleShortcutClick(item.url)">
{{ item.name }}
</el-link>
</div>
</el-col>
</el-row>
</el-skeleton>
</el-card> -->
<el-card shadow="never">
<template #header>
<div class="h-3 flex justify-between">
<span>{{ t('workplace.notice') }}</span>
<!-- <el-button @click="test">test</el-button> -->
<!-- <el-link type="primary" :underline="false">{{ t('action.more') }}</el-link> -->
</div>
</template>
<el-skeleton :loading="loading" animated>
<div v-for="(item, index) in notice" :key="`dynamics-${index}`">
<div class="flex items-center">
<el-avatar :src="avatar" :size="35" class="mr-16px">
<img src="@/assets/imgs/avatar.gif" alt="" />
</el-avatar>
<div>
<div class="text-14px">
<Highlight :keys="item.keys.map((v) => t(v))">
{{ item.type }} : {{ item.title }}
</Highlight>
</div>
<div class="mt-16px text-12px text-gray-400">
{{ formatTime(item.date, 'yyyy-MM-dd') }}
</div>
</div>
</div>
<el-divider />
</div>
</el-skeleton>
</el-card>
</el-col>
</el-row>
</template>
<script lang="ts" setup>
import { set } from 'lodash-es'
import { EChartsOption } from 'echarts'
import { formatTime } from '@/utils'
import { useUserStore } from '@/store/modules/user'
// import { useWatermark } from '@/hooks/web/useWatermark'
import type { WorkplaceTotal, Project, Notice, Shortcut } from './types'
2025-11-12 18:55:21 +08:00
import { pieOptions, barOptions, bigbrotherbarOptions } from './echarts-data'
2025-07-01 21:08:51 +08:00
import { useRouter } from 'vue-router'
2025-08-08 14:38:06 +08:00
import { getComplete, getEmployeeComplete } from '@/api/system/user'
import { useCache } from '@/hooks/web/useCache'
import { getSimpleUserListPage, getSimpleUserList } from '@/api/system/user'
2025-09-09 20:33:33 +08:00
import { EmployeeHostsApi } from '@/api/server/employeehosts'
import { ref, reactive, onMounted, onActivated } from 'vue'
2025-10-17 15:37:42 +08:00
import WxMusic from '../mp/components/wx-music'
2025-12-05 21:10:27 +08:00
import * as TenantApi from '@/api/system/tenant'
2025-11-12 18:55:21 +08:00
let HostsOperationNum = ref(0)//当日建联主播数量
let HostsOperationNumDsec = ref(0)//当日建联大哥数量
let days = ref(1)//当日
let daysDsec = ref(1)//当日
2025-12-05 21:10:27 +08:00
let tenantLevel = ref()//租户等级
2025-11-12 18:55:21 +08:00
//初始
2025-09-09 20:33:33 +08:00
onMounted(async () => {
2025-12-05 21:10:27 +08:00
await TenantApi.getSelfTenantLevel().then(res => {
tenantLevel.value = res.tenantLevel
console.log(res.tenantLevel)
})
if (tenantLevel.value == 1) {
loading.value = false
return
}
console.log(1321231)
2025-09-09 20:33:33 +08:00
await getAllApi()
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
await getAllocationList()
2025-12-05 21:10:27 +08:00
//用户id == 1 且
if (wsCache.get('roleRouters').find(item => item.id === 5019)?.children.find(item => item.id === 5020)) {
2025-10-17 15:37:42 +08:00
await fetchAllHostsCount(1)
2025-11-12 18:55:21 +08:00
await fetchAllHostsCountDesc(1)
2025-09-09 20:33:33 +08:00
} else {
2025-12-05 21:10:27 +08:00
// await fetchDailyHostsCount()
2025-09-09 20:33:33 +08:00
2025-11-12 18:55:21 +08:00
await fetchDailyHostsCountDesc()
}
2025-09-09 20:33:33 +08:00
})
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
// 每次页面“再次显示”时都会触发(前提:该路由组件被 keep-alive 缓存)
onActivated(async () => {
2025-12-05 21:10:27 +08:00
console.log(wsCache.get('user'))
console.log(tenantLevel.value)
await TenantApi.getSelfTenantLevel().then(res => {
tenantLevel.value = res.tenantLevel
console.log(res.tenantLevel)
})
if (tenantLevel.value == 1) {
loading.value = false
return
}
await fetchDailyHostsCount() //爬主播建联率
2025-11-12 18:55:21 +08:00
2025-12-05 21:10:27 +08:00
await fetchDailyHostsCountDesc()//爬主播建联率 指定员工
2025-11-12 18:55:21 +08:00
2025-12-05 21:10:27 +08:00
await fetchAllHostsCount(1) //爬大哥建联率
2025-11-12 18:55:21 +08:00
2025-12-05 21:10:27 +08:00
await fetchAllHostsCountDesc(1) //爬大哥建联率 指定员工
2025-09-09 20:33:33 +08:00
})
2025-10-17 15:37:42 +08:00
2025-11-12 18:55:21 +08:00
// 天数切换
2025-10-17 15:37:42 +08:00
async function updataDays(val) {
await fetchAllHostsCount(val)
}
2025-11-12 18:55:21 +08:00
//大哥天数切换
async function updataDaysDsec(val: any) {
await fetchAllHostsCountDesc(val)
}
2025-07-01 21:08:51 +08:00
// import { useGlobalWebSocket } from '@/components/useGlobalWebSocket'
// let messageList = useGlobalWebSocket().messageList
// console.log(messageList.value)
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
const { wsCache } = useCache()
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
let allocationUser = ref('') //选中的分配用户
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
let allocationUserList = ref([
{
label: '分配用户1',
value: 1
}
]) //选中的分配用户
2025-07-01 21:08:51 +08:00
// function test() {
// console.log(messageList.value)
// }
defineOptions({ name: 'Index' })
2025-09-09 20:33:33 +08:00
// console.log(data)
2025-07-01 21:08:51 +08:00
// const { open } = useGlobalWebSocket()
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const { t } = useI18n()
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const router = useRouter()
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const userStore = useUserStore()
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
// const { setWatermark } = useWatermark()
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const loading = ref(true)
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const avatar = userStore.getUser.avatar
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const username = userStore.getUser.nickname
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
// 获取统计数
let totalSate = reactive<WorkplaceTotal>({
project: 0,
access: 0,
todo: 0
})
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const getCount = async () => {
const data = {
project: 40,
access: 2340,
todo: 10
}
totalSate = Object.assign(totalSate, data)
}
// 获取项目数
let projects = reactive<Project[]>([])
const getProject = async () => {
const data = [
{
name: 'YOLO助手',
icon: 'simple-icons:springboot',
message: 'www.yolozs.com/',
personal: '全球tiktok经纪人必备高效管理神器!',
time: new Date('2025-01-02'),
color: '#6DB33F'
},
// {
// name: '找大哥助手',
// icon: 'ep:element-plus',
// message: 'www.yolozs.com/',
// personal: '全球tiktok经纪人必备高效管理神器!',
// time: new Date('2025-02-03'),
// color: '#409EFF'
// },
// {
// name: 'yudao-ui-mall-uniapp',
// icon: 'icon-park-outline:mall-bag',
// message: 'github.com/yudaocode/yudao-ui-mall-uniapp',
// personal: 'Vue3 + uniapp 商城手机端',
// time: new Date('2025-03-04'),
// color: '#ff4d4f'
// },
// {
// name: 'yudao-cloud',
// icon: 'material-symbols:cloud-outline',
// message: 'github.com/YunaiV/yudao-cloud',
// personal: 'Spring Cloud 微服务架构',
// time: new Date('2025-04-05'),
// color: '#1890ff'
// },
// {
// name: 'yudao-ui-admin-vben',
// icon: 'devicon:antdesign',
// message: 'github.com/yudaocode/yudao-ui-admin-vben',
// personal: 'Vue3 + vben5(antd) 管理后台',
// time: new Date('2025-05-06'),
// color: '#e18525'
// },
// {
// name: 'yudao-ui-admin-uniapp',
// icon: 'ant-design:mobile',
// message: 'github.com/yudaocode/yudao-ui-admin-uniapp',
// personal: 'Vue3 + uniapp 管理手机端',
// time: new Date('2025-06-01'),
// color: '#2979ff'
// }
]
projects = Object.assign(projects, data)
}
// 获取通知公告
let notice = reactive<Notice[]>([])
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const getNotice = async () => {
const data = [
// {
// title: '系统支持 JDK 8/17/21Vue 2/3',
// type: '技术兼容性',
// keys: ['JDK', 'Vue'],
// date: new Date()
// },
// {
// title: '后端提供 Spring Boot 2.7/3.2 + Cloud 双架构',
// type: '架构灵活性',
// keys: ['Boot', 'Cloud'],
// date: new Date()
// },
// {
// title: '全部开源,个人与企业可 100% 直接使用,无需授权',
// type: '开源免授权',
// keys: ['无需授权'],
// date: new Date()
// },
// {
// title: '国内使用最广泛的快速开发平台,远超 10w+ 企业使用',
// type: '广泛企业认可',
// keys: ['最广泛', '10w+'],
// date: new Date()
// }
]
notice = Object.assign(notice, data)
}
// 获取快捷入口
let shortcut = reactive<Shortcut[]>([])
const getShortcut = async () => {
const data = [
{
name: '首页',
icon: 'ion:home-outline',
url: '/',
color: '#1fdaca'
},
{
name: '商城中心',
icon: 'ep:shop',
url: '/mall/home',
color: '#ff6b6b'
},
{
name: 'AI 大模型',
icon: 'tabler:ai',
url: '/ai/chat',
color: '#7c3aed'
},
{
name: 'ERP 系统',
icon: 'simple-icons:erpnext',
url: '/erp/home',
color: '#3fb27f'
},
{
name: 'CRM 系统',
icon: 'simple-icons:civicrm',
url: '/crm/backlog',
color: '#4daf1bc9'
},
{
name: 'IoT 物联网',
icon: 'fa-solid:hdd',
url: '/iot/home',
color: '#1a73e8'
}
]
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
shortcut = Object.assign(shortcut, data)
}
// 用户来源
2025-08-08 14:38:06 +08:00
const getUserAccessSource = async (id) => {
const res = id ? await getEmployeeComplete(id) : await getComplete()
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
const completeData = res ?? { unfinishedNum: 0, finishedNum: 0 }
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
console.log('completeData', completeData)
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const data = [
2025-08-08 14:38:06 +08:00
{ value: completeData.unfinishedNum, name: 'analysis.noAlliance' },
{ value: completeData.finishedNum, name: 'analysis.alreadyJianlian' },
// { value: 234, name: 'analysis.allianceAdvertising' },
// { value: 135, name: 'analysis.videoAdvertising' },
// { value: 1548, name: 'analysis.searchEngines' }
2025-07-01 21:08:51 +08:00
]
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
set(
pieOptionsData,
'legend.data',
data.map((v) => t(v.name))
)
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
pieOptionsData!.series![0].data = data.map((v) => {
return {
name: t(v.name),
value: v.value
}
})
}
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
2025-11-12 18:55:21 +08:00
const barOptionsDataDsec = reactive<EChartsOption>(bigbrotherbarOptions) as EChartsOption
2025-09-09 20:33:33 +08:00
type EmpBarItem = {
userId: number
finishedNum: number | null
totalNum: number | null
unfinishedNum: number | null
}
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
// 传入希望展示的用户 id 列表 + 后端原始返回,补齐未返回的用户为 0
function mergeZeroUsers(ids: number[], resList: EmpBarItem[]): EmpBarItem[] {
const map = new Map<number, EmpBarItem>(resList.map(it => [it.userId, it]))
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
return ids.map(id => {
const it = map.get(id)
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
const finished = it?.finishedNum ?? 0
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
// 未建联:优先用后端给的 unfinishedNum若没有且提供了 totalNum则用 totalNum - finished否则 0
const total = it?.totalNum ?? 0
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
const unfinished = it?.unfinishedNum ?? (it?.totalNum != null && it?.finishedNum != null
? Math.max(Number(total) - Number(finished), 0)
: 0)
return {
userId: id,
finishedNum: Number(finished),
totalNum: Number(total),
unfinishedNum: Number(unfinished)
}
})
}
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
// 把后端返回的数据渲染到柱状图
function updateEmployeeBarChart(list: EmpBarItem[]) {
// 建立 id -> 昵称 的映射
const id2label = new Map(allocationUserList.value.map(u => [u.value, u.label]))
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
const labels = list.map(it => id2label.get(it.userId) || String(it.userId))
const finished = list.map(it => it.finishedNum ?? 0)
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
const unfinished = list.map(it => it.unfinishedNum ?? 0)
2025-07-01 21:08:51 +08:00
2025-09-09 20:33:33 +08:00
// legend
const legendNames = []
set(barOptionsData, 'legend.data', legendNames)
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
set(barOptionsData, 'xAxis.data', labels)
2025-09-09 21:02:15 +08:00
// 1) 轴标签强制全部显示 + 不自动隐藏
set(barOptionsData, 'xAxis.axisLabel.interval', 0)
2025-11-12 18:55:21 +08:00
2025-09-09 21:02:15 +08:00
set(barOptionsData, 'xAxis.axisLabel.hideOverlap', false)
2025-09-09 20:33:33 +08:00
2025-09-09 21:02:15 +08:00
// 2) 适当旋转,避免重叠(不想旋转可设为 0
set(barOptionsData, 'xAxis.axisLabel.rotate', 30)
// 3) 防止被裁剪:让 grid 预留标签空间
set(barOptionsData, 'grid.containLabel', true)
2025-11-12 18:55:21 +08:00
2025-09-09 21:02:15 +08:00
set(barOptionsData, 'grid.bottom', 60) // 视情况调大/调小
2025-09-09 20:33:33 +08:00
2025-11-12 18:55:21 +08:00
set(barOptionsData, 'xAxis.axisTick.alignWithLabel', true)
2025-09-09 20:33:33 +08:00
set(barOptionsData, 'series', [
{
name: t('analysis.alreadyJianlian'),
type: 'bar',
data: finished
},
// {
// name: t('analysis.noAlliance'),
// type: 'bar',
// data: unfinished
// }
])
}
2025-11-12 18:55:21 +08:00
// 周活跃量 大哥图表数据
function updateEmployeeBarChartDesc(lists: EmpBarItem[]) {
// 建立 id -> 昵称 的映射
const id2label = new Map(allocationUserList.value.map(u => [u.value, u.label]))
const labels = lists.map(it => id2label.get(it.userId) || String(it.userId))
const finished = lists.map(it => it.finishedNum ?? 0)
const unfinished = lists.map(it => it.unfinishedNum ?? 0)
// legend
const legendNames = []
set(barOptionsDataDsec, 'legend.data', legendNames)
set(barOptionsDataDsec, 'xAxis.data', labels)
// 1) 轴标签强制全部显示 + 不自动隐藏
set(barOptionsDataDsec, 'xAxis.axisLabel.interval', 0)
set(barOptionsDataDsec, 'xAxis.axisLabel.hideOverlap', false)
// 2) 适当旋转,避免重叠(不想旋转可设为 0
set(barOptionsDataDsec, 'xAxis.axisLabel.rotate', 30)
// 3) 防止被裁剪:让 grid 预留标签空间
set(barOptionsDataDsec, 'grid.containLabel', true)
set(barOptionsDataDsec, 'grid.bottom', 60) // 视情况调大/调小
set(barOptionsDataDsec, 'xAxis.axisTick.alignWithLabel', true)
set(barOptionsDataDsec, 'series', [
{
name: t('analysis.alreadyJianlian'),
type: 'bar',
data: finished
},
// {
// name: t('analysis.noAlliance'),
// type: 'bar',
// data: unfinished
// }
])
}
2025-09-09 20:33:33 +08:00
// 周活跃量 图表数据
2025-07-01 21:08:51 +08:00
const getWeeklyUserActivity = async () => {
const data = [
2025-09-09 20:33:33 +08:00
{ value: HostsOperationNum.value, name: 'analysis.monday' },
2025-07-01 21:08:51 +08:00
]
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
set(
barOptionsData,
'xAxis.data',
data.map((v) => t(v.name))
)
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
set(barOptionsData, 'series', [
{
name: t('analysis.activeQuantity'),
data: data.map((v) => v.value),
type: 'bar'
}
])
}
const getAllApi = async () => {
await Promise.all([
getCount(),
getProject(),
getNotice(),
getShortcut(),
2025-12-05 21:10:27 +08:00
wsCache.get('roleRouters').find(item => item.id === 5019)?.children.find(item => item.id === 5020) ? getUserAccessSource(null) : null,
2025-07-01 21:08:51 +08:00
getWeeklyUserActivity()
])
2025-11-12 18:55:21 +08:00
2025-07-01 21:08:51 +08:00
loading.value = false
}
const handleProjectClick = (message: string) => {
window.open(`https://${message}`, '_blank')
}
const handleShortcutClick = (url: string) => {
router.push(url)
}
2025-08-08 14:38:06 +08:00
/** 查询员工 */
const getAllocationList = async () => {
loading.value = true
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
allocationUserList.value = []
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
try {
const data = await getSimpleUserList()
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
console.log('data', data)
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
data.forEach((item) => {
if (wsCache.get('user').user.id == item.id) {
} else {
allocationUserList.value.push({
label: item.nickname,
value: item.id
})
}
})
2025-11-12 18:55:21 +08:00
2025-08-08 14:38:06 +08:00
console.log(allocationUserList.value)
} finally {
loading.value = false
}
}
2025-09-09 20:33:33 +08:00
// 获取当前日期,格式为 YYYY-MM-DD
const getFormattedDate = () => {
const now = new Date()
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
return now.toISOString().split('T')[0] + ' 00:00:00'
}
// ✅ 抽成函数:每天数量
async function fetchDailyHostsCount() {
const res = await EmployeeHostsApi.getEmployeeHostsPage({
operationStatus: 1,
pageNo: 1,
pageSize: 10,
updateTime: getFormattedDate()
})
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
HostsOperationNum.value = res.total ?? 0
// 如果柱状图依赖这个值,顺便刷新一次图表数据
}
2025-11-12 18:55:21 +08:00
async function fetchDailyHostsCountDesc() {
const res = await EmployeeHostsApi.getEmployeeHostsPageDsec({
operationStatus: 1,
pageNo: 1,
pageSize: 10,
updateTime: getFormattedDate()
})
HostsOperationNumDsec.value = res.finishedNum ?? 0
// 如果柱状图依赖这个值,顺便刷新一次图表数据
}
2025-12-05 21:10:27 +08:00
// ✅ 爬大哥建联率
2025-10-17 15:37:42 +08:00
async function fetchAllHostsCount(val) {
2025-09-09 20:33:33 +08:00
// 以“传入的用户 id”为准展示顺序也按这里来
const ids = allocationUserList.value.map(item => item.value)
2025-10-17 15:37:42 +08:00
const res = await EmployeeHostsApi.employeeCompleteBarChart(ids, val)
2025-11-12 18:55:21 +08:00
2025-09-09 20:33:33 +08:00
const rawList: EmpBarItem[] = Array.isArray(res) ? res : (res?.data ?? [])
// 补齐后端未返回的用户为 0
const list = mergeZeroUsers(ids, rawList)
// 渲染
updateEmployeeBarChart(list)
}
2025-11-12 18:55:21 +08:00
async function fetchAllHostsCountDesc(val) {
// 以“传入的用户 id”为准展示顺序也按这里来
const idss = allocationUserList.value.map(item => item.value)
const ress = await EmployeeHostsApi.employeeCompleteBarChartDsec(idss, val)
console.log('fetchAllHostsCountDesc', ress);
const rawLists: EmpBarItem[] = Array.isArray(ress) ? ress : (ress?.data ?? [])
// 补齐后端未返回的用户为 0
const lists = mergeZeroUsers(idss, rawLists)
// 渲染
updateEmployeeBarChartDesc(lists)
}
2025-07-01 21:08:51 +08:00
</script>