mall数据库文件
This commit is contained in:
@@ -94,10 +94,11 @@
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
import supa, { ensureSupabaseReady } from '@/components/supadb/aksupainstance.uts'
|
||||
import AnalyticsSidebarMenu from '@/components/analytics/AnalyticsSidebarMenu.uvue'
|
||||
import AnalyticsTopBar from '@/components/analytics/AnalyticsTopBar.uvue'
|
||||
import EChartsView from '@/uni_modules/charts/EChartsView.vue'
|
||||
import { fetchMarketTrends } from '@/services/analytics/marketTrendsService.uts'
|
||||
import { mapAnalyticsError } from '@/services/analytics/errorMapper.uts'
|
||||
|
||||
type TimePeriod = { value: string; label: string }
|
||||
|
||||
@@ -149,106 +150,21 @@ export default {
|
||||
methods: {
|
||||
async loadMarketData() {
|
||||
try {
|
||||
const now = new Date()
|
||||
const start = new Date(now.getTime())
|
||||
if (this.selectedPeriod === '7d') start.setDate(start.getDate() - 7)
|
||||
else if (this.selectedPeriod === '30d') start.setDate(start.getDate() - 30)
|
||||
else if (this.selectedPeriod === '90d') start.setDate(start.getDate() - 90)
|
||||
else if (this.selectedPeriod === '1y') start.setFullYear(start.getFullYear() - 1)
|
||||
const startIso = start.toISOString()
|
||||
const endIso = now.toISOString()
|
||||
const data = await fetchMarketTrends(this.selectedPeriod)
|
||||
|
||||
await ensureSupabaseReady()
|
||||
|
||||
// 1) 市场整体趋势(按天 GMV / 订单 / 用户)
|
||||
let trendRows: Array<UTSJSONObject> = []
|
||||
let categoryRows: Array<UTSJSONObject> = []
|
||||
let seasonalRows: Array<UTSJSONObject> = []
|
||||
let priceRows: Array<UTSJSONObject> = []
|
||||
let competitionRows: Array<UTSJSONObject> = []
|
||||
|
||||
const marketRes = await supa.rpc('rpc_analytics_market_trend_daily', {
|
||||
p_start: startIso,
|
||||
p_end: endIso
|
||||
})
|
||||
if (marketRes.status === 404) {
|
||||
console.warn('rpc_analytics_market_trend_daily not found, market trend will be empty')
|
||||
} else if (marketRes.error != null) {
|
||||
console.error('rpc_analytics_market_trend_daily error:', marketRes.error)
|
||||
} else {
|
||||
const anyData = marketRes.data as any
|
||||
trendRows = Array.isArray(anyData) ? anyData as Array<UTSJSONObject> : []
|
||||
}
|
||||
|
||||
// 2) 行业对比(按分类 GMV)
|
||||
const catRes = await supa.rpc('rpc_analytics_category_sales', {
|
||||
p_start_date: startIso.substring(0, 10),
|
||||
p_end_date: endIso.substring(0, 10)
|
||||
})
|
||||
if (catRes.status === 404) {
|
||||
console.warn('rpc_analytics_category_sales not found, industry comparison will be empty')
|
||||
} else if (catRes.error != null) {
|
||||
console.error('rpc_analytics_category_sales error:', catRes.error)
|
||||
} else {
|
||||
const cAny = catRes.data as any
|
||||
categoryRows = Array.isArray(cAny) ? cAny as Array<UTSJSONObject> : []
|
||||
}
|
||||
|
||||
// 3) 季节性趋势(按月 GMV)
|
||||
const seaRes = await supa.rpc('rpc_analytics_seasonal_trend', {
|
||||
p_start_date: startIso.substring(0, 10),
|
||||
p_end_date: endIso.substring(0, 10)
|
||||
})
|
||||
if (seaRes.status === 404) {
|
||||
console.warn('rpc_analytics_seasonal_trend not found, seasonal trend will be empty')
|
||||
} else if (seaRes.error != null) {
|
||||
console.error('rpc_analytics_seasonal_trend error:', seaRes.error)
|
||||
} else {
|
||||
const sAny = seaRes.data as any
|
||||
seasonalRows = Array.isArray(sAny) ? sAny as Array<UTSJSONObject> : []
|
||||
}
|
||||
|
||||
// 4) 价格趋势(按天平均单价)
|
||||
const priceRes = await supa.rpc('rpc_analytics_price_trend', {
|
||||
p_start: startIso,
|
||||
p_end: endIso
|
||||
})
|
||||
if (priceRes.status === 404) {
|
||||
console.warn('rpc_analytics_price_trend not found, price trend will be empty')
|
||||
} else if (priceRes.error != null) {
|
||||
console.error('rpc_analytics_price_trend error:', priceRes.error)
|
||||
} else {
|
||||
const pAny = priceRes.data as any
|
||||
priceRows = Array.isArray(pAny) ? pAny as Array<UTSJSONObject> : []
|
||||
}
|
||||
|
||||
// 5) 竞争分析(商家 GMV 榜单)
|
||||
const compRes = await supa.rpc('rpc_analytics_competition_share', {
|
||||
p_start_date: startIso.substring(0, 10),
|
||||
p_end_date: endIso.substring(0, 10)
|
||||
})
|
||||
if (compRes.status === 404) {
|
||||
console.warn('rpc_analytics_competition_share not found, competition analysis will be empty')
|
||||
} else if (compRes.error != null) {
|
||||
console.error('rpc_analytics_competition_share error:', compRes.error)
|
||||
} else {
|
||||
const cpAny = compRes.data as any
|
||||
competitionRows = Array.isArray(cpAny) ? cpAny as Array<UTSJSONObject> : []
|
||||
}
|
||||
|
||||
;(this as any)._marketTrendRows = trendRows
|
||||
;(this as any)._industryRows = categoryRows
|
||||
;(this as any)._seasonalRows = seasonalRows
|
||||
;(this as any)._priceRows = priceRows
|
||||
;(this as any)._competitionRows = competitionRows
|
||||
;(this as any)._marketTrendRows = data.trendRows
|
||||
;(this as any)._industryRows = data.categoryRows
|
||||
;(this as any)._seasonalRows = data.seasonalRows
|
||||
;(this as any)._priceRows = data.priceRows
|
||||
;(this as any)._competitionRows = data.competitionRows
|
||||
|
||||
this.updateTime()
|
||||
this.buildChartOptions()
|
||||
} catch (e) {
|
||||
console.error('loadMarketData failed:', e)
|
||||
this.updateTime()
|
||||
this.buildChartOptions()
|
||||
uni.showToast({ title: '市场趋势数据加载失败', icon: 'none' })
|
||||
this.updateTime()
|
||||
this.buildChartOptions()
|
||||
uni.showToast({ title: mapAnalyticsError(e, { fallbackMessage: '市场趋势数据加载失败' }), icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user