feat(api): 添加电话接通率API接口
refactor(cache): 将缓存系统重构为独立模块并添加测试页面 fix: 修复客户详情中电话接通率显示格式问题 refactor: 移除各页面中的缓存逻辑,统一使用缓存store feat: 在客户详情中添加通话分析API调用 fix: 修正导出客户API的URL路径 chore: 更新开发环境配置注释
This commit is contained in:
@@ -83,51 +83,6 @@ import { useRouter } from "vue-router";
|
||||
import {getGroupAbnormalResponse, getWeekTotalCall, getWeekAddCustomerTotal, getWeekAddDealTotal,
|
||||
getWeekAddFeeTotal, getGroupFunnel,getPayDepositToMoneyRate,getGroupRanking, getGroupCallDuration} from "@/api/manager.js";
|
||||
|
||||
// 缓存系统
|
||||
const cache = new Map()
|
||||
const CACHE_DURATION = 30 * 60 * 1000 // 30分钟缓存
|
||||
|
||||
// 缓存工具函数
|
||||
function getCacheKey(apiName, params = {}) {
|
||||
return `${apiName}_${JSON.stringify(params)}`
|
||||
}
|
||||
|
||||
function isValidCache(cacheData) {
|
||||
return cacheData && (Date.now() - cacheData.timestamp) < CACHE_DURATION
|
||||
}
|
||||
|
||||
function setCache(key, data) {
|
||||
cache.set(key, {
|
||||
data,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
}
|
||||
|
||||
function getCache(key) {
|
||||
const cacheData = cache.get(key)
|
||||
if (isValidCache(cacheData)) {
|
||||
return cacheData.data
|
||||
}
|
||||
cache.delete(key)
|
||||
return null
|
||||
}
|
||||
|
||||
// 通用缓存包装函数
|
||||
async function withCache(apiName, apiCall, params = {}) {
|
||||
const key = getCacheKey(apiName, params)
|
||||
const cachedData = getCache(key)
|
||||
|
||||
if (cachedData) {
|
||||
console.log(`使用缓存数据: ${key}`)
|
||||
return cachedData
|
||||
}
|
||||
|
||||
console.log(`调用API: ${key}`)
|
||||
const result = await apiCall()
|
||||
setCache(key, result)
|
||||
return result
|
||||
}
|
||||
|
||||
// 团队成员数据
|
||||
const teamMembers = [
|
||||
{
|
||||
@@ -198,7 +153,7 @@ async function TeamGetGroupAbnormalResponse() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
try {
|
||||
const response = await withCache('getGroupAbnormalResponse', () => getGroupAbnormalResponse(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const response = await getGroupAbnormalResponse(hasParams ? params : undefined)
|
||||
const rawData = response.data
|
||||
|
||||
// 转换数据格式,生成预警消息
|
||||
@@ -243,7 +198,7 @@ async function TeamGetGroupAbnormalResponse() {
|
||||
async function TeamGetWeekTotalCall() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getWeekTotalCall', () => getWeekTotalCall(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getWeekTotalCall(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
weekTotalData.value.week_total_call = res.data
|
||||
@@ -253,7 +208,7 @@ async function TeamGetWeekTotalCall() {
|
||||
async function TeamGetGroupCallDuration() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getGroupCallDuration', () => getGroupCallDuration(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getGroupCallDuration(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
weekTotalData.value.group_call_duration = res.data
|
||||
@@ -263,7 +218,7 @@ async function TeamGetGroupCallDuration() {
|
||||
async function TeamGetWeekAddCustomerTotal() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getWeekAddCustomerTotal', () => getWeekAddCustomerTotal(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getWeekAddCustomerTotal(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
weekTotalData.value.week_add_customer_total = res.data
|
||||
@@ -273,7 +228,7 @@ async function TeamGetWeekAddCustomerTotal() {
|
||||
async function TeamGetWeekAddDealTotal() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getWeekAddDealTotal', () => getWeekAddDealTotal(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getWeekAddDealTotal(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
weekTotalData.value.week_add_deal_total = res.data
|
||||
@@ -286,7 +241,7 @@ async function TeamGetWeekAddDealTotal() {
|
||||
async function TeamGetWeekAddFeeTotal() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getPayDepositToMoneyRate', () => getPayDepositToMoneyRate(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getPayDepositToMoneyRate(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
weekTotalData.value.pay_deposit_to_money_rate = res.data
|
||||
@@ -296,7 +251,7 @@ async function TeamGetWeekAddFeeTotal() {
|
||||
async function TeamGetGroupFunnel() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getGroupFunnel', () => getGroupFunnel(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getGroupFunnel(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
weekTotalData.value.group_funnel = res.data
|
||||
@@ -321,7 +276,7 @@ const groupRanking = ref({})
|
||||
async function TeamGetGroupRanking() {
|
||||
const params = getRequestParams()
|
||||
const hasParams = params.user_name
|
||||
const res = await withCache('getGroupRanking', () => getGroupRanking(hasParams ? params : undefined), hasParams ? params : {})
|
||||
const res = await getGroupRanking(hasParams ? params : undefined)
|
||||
console.log(res)
|
||||
if (res.code === 200) {
|
||||
groupRanking.value = res.data
|
||||
@@ -339,76 +294,11 @@ const selectMember = (member) => {
|
||||
selectedMember.value = member;
|
||||
};
|
||||
|
||||
// 缓存管理功能
|
||||
// 清除所有缓存
|
||||
function clearCache() {
|
||||
cache.clear()
|
||||
console.log('所有缓存已清除')
|
||||
}
|
||||
|
||||
// 清除特定缓存
|
||||
function clearSpecificCache(apiName, params = {}) {
|
||||
const key = getCacheKey(apiName, params)
|
||||
cache.delete(key)
|
||||
console.log(`已清除缓存: ${key}`)
|
||||
}
|
||||
|
||||
// 获取缓存信息并清理过期缓存
|
||||
function getCacheInfo() {
|
||||
const now = Date.now()
|
||||
const validCaches = []
|
||||
const expiredCaches = []
|
||||
|
||||
for (const [key, data] of cache.entries()) {
|
||||
if (isValidCache(data)) {
|
||||
validCaches.push({
|
||||
key,
|
||||
timestamp: data.timestamp,
|
||||
age: Math.round((now - data.timestamp) / 1000) + 's'
|
||||
})
|
||||
} else {
|
||||
expiredCaches.push(key)
|
||||
cache.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('有效缓存:', validCaches)
|
||||
console.log('已清理过期缓存:', expiredCaches)
|
||||
|
||||
return {
|
||||
validCount: validCaches.length,
|
||||
expiredCount: expiredCaches.length,
|
||||
validCaches,
|
||||
expiredCaches
|
||||
}
|
||||
}
|
||||
|
||||
// 强制刷新所有数据(清除缓存并重新调用所有API)
|
||||
async function forceRefreshAllData() {
|
||||
console.log('开始强制刷新所有数据...')
|
||||
clearCache()
|
||||
|
||||
// 重新调用所有API
|
||||
await Promise.all([
|
||||
TeamGetGroupAbnormalResponse(),
|
||||
TeamGetWeekTotalCall(),
|
||||
TeamGetGroupCallDuration(),
|
||||
TeamGetWeekAddCustomerTotal(),
|
||||
TeamGetWeekAddDealTotal(),
|
||||
TeamGetWeekAddFeeTotal(),
|
||||
TeamGetGroupFunnel(),
|
||||
TeamGetGroupRanking()
|
||||
])
|
||||
|
||||
console.log('所有数据刷新完成')
|
||||
}
|
||||
|
||||
// 团队异常预警
|
||||
|
||||
onMounted(async () => {
|
||||
// 输出缓存状态信息
|
||||
console.log('Manager页面缓存系统已初始化,缓存时长:', CACHE_DURATION / (1000 * 60), '分钟')
|
||||
|
||||
await TeamGetGroupAbnormalResponse()
|
||||
await TeamGetWeekTotalCall()
|
||||
await TeamGetGroupCallDuration()
|
||||
@@ -417,21 +307,6 @@ onMounted(async () => {
|
||||
await TeamGetWeekAddFeeTotal()
|
||||
await TeamGetGroupFunnel()
|
||||
await TeamGetGroupRanking()
|
||||
|
||||
// 输出初始缓存信息
|
||||
getCacheInfo()
|
||||
|
||||
// 开发环境下暴露缓存管理函数到全局对象,方便调试
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
window.managerCache = {
|
||||
clearCache,
|
||||
clearSpecificCache,
|
||||
getCacheInfo,
|
||||
forceRefreshAllData,
|
||||
cache
|
||||
}
|
||||
console.log('开发模式:缓存管理函数已暴露到 window.managerCache')
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user