Dashboard.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="dashboard-container">
  3. <!-- 顶部统计卡片 -->
  4. <el-row :gutter="20" class="stat-row">
  5. <el-col :span="6" v-for="(stat, idx) in statCards" :key="idx">
  6. <el-card class="stat-card" :class="'stat-card-' + stat.type">
  7. <div class="stat-icon">{{ stat.icon }}</div>
  8. <div class="stat-content">
  9. <div class="stat-value">{{ stat.value }}</div>
  10. <div class="stat-label">{{ stat.label }}</div>
  11. </div>
  12. </el-card>
  13. </el-col>
  14. </el-row>
  15. <!-- 收入和会员概览 -->
  16. <el-row :gutter="20" class="chart-row">
  17. <el-col :span="16">
  18. <el-card class="chart-card">
  19. <div slot="header" class="card-header">
  20. <span>用户与家庭增长趋势(近30天)</span>
  21. </div>
  22. <div ref="trendChart" class="echarts-container"></div>
  23. </el-card>
  24. </el-col>
  25. <el-col :span="8">
  26. <el-card class="chart-card">
  27. <div slot="header" class="card-header">
  28. <span>会员等级分布</span>
  29. </div>
  30. <div ref="memberPieChart" class="echarts-container"></div>
  31. </el-card>
  32. </el-col>
  33. </el-row>
  34. <!-- 收入概览 -->
  35. <el-row :gutter="20" class="chart-row">
  36. <el-col :span="8">
  37. <el-card class="chart-card">
  38. <div slot="header" class="card-header">
  39. <span>本月佣金</span>
  40. </div>
  41. <div class="revenue-value">¥{{ revenueData.monthCommission || 0 }}</div>
  42. <div class="revenue-sub">待结算: ¥{{ revenueData.pendingCommission || 0 }}</div>
  43. </el-card>
  44. </el-col>
  45. <el-col :span="8">
  46. <el-card class="chart-card">
  47. <div slot="header" class="card-header">
  48. <span>累计佣金</span>
  49. </div>
  50. <div class="revenue-value">¥{{ revenueData.totalCommission || 0 }}</div>
  51. </el-card>
  52. </el-col>
  53. <el-col :span="8">
  54. <el-card class="chart-card">
  55. <div slot="header" class="card-header">
  56. <span>本月会员升级</span>
  57. </div>
  58. <div class="revenue-value">{{ membershipData.monthUpgrades || 0 }}</div>
  59. <div class="revenue-sub">试用会员: {{ membershipData.trialCount || 0 }}</div>
  60. </el-card>
  61. </el-col>
  62. </el-row>
  63. </div>
  64. </template>
  65. <script>
  66. import * as echarts from 'echarts'
  67. export default {
  68. name: 'AdminDashboard',
  69. data() {
  70. return {
  71. statCards: [
  72. { label: '家庭总数', value: 0, icon: '👨‍👩‍👧', type: 'orange' },
  73. { label: '家长总数', value: 0, icon: '👤', type: 'blue' },
  74. { label: '成长规划师', value: 0, icon: '🎓', type: 'green' },
  75. { label: '待审核规划师', value: 0, icon: '⏳', type: 'red' }
  76. ],
  77. revenueData: {},
  78. membershipData: {},
  79. trendData: { familyTrend: {}, userTrend: {} }
  80. }
  81. },
  82. mounted() {
  83. this.loadOverview()
  84. this.loadRevenue()
  85. this.loadMembership()
  86. this.loadTrend()
  87. },
  88. methods: {
  89. async loadOverview() {
  90. try {
  91. const res = await this.$http.post('/api/stats/overview')
  92. if (res.data.code === 200) {
  93. const d = res.data.data
  94. this.statCards[0].value = d.totalFamilies || 0
  95. this.statCards[1].value = d.totalParents || 0
  96. this.statCards[2].value = d.totalTeachers || 0
  97. this.statCards[3].value = d.pendingGuides || 0
  98. }
  99. } catch (e) {
  100. console.error('加载概览失败', e)
  101. }
  102. },
  103. async loadRevenue() {
  104. try {
  105. const res = await this.$http.post('/api/stats/revenue')
  106. if (res.data.code === 200) {
  107. this.revenueData = res.data.data
  108. }
  109. } catch (e) {
  110. console.error('加载收入统计失败', e)
  111. }
  112. },
  113. async loadMembership() {
  114. try {
  115. const res = await this.$http.post('/api/stats/membership')
  116. if (res.data.code === 200) {
  117. this.membershipData = res.data.data
  118. this.initMemberPieChart()
  119. }
  120. } catch (e) {
  121. console.error('加载会员统计失败', e)
  122. }
  123. },
  124. async loadTrend() {
  125. try {
  126. const res = await this.$http.post('/api/stats/trend')
  127. if (res.data.code === 200) {
  128. this.trendData = res.data.data
  129. this.initTrendChart()
  130. }
  131. } catch (e) {
  132. console.error('加载趋势失败', e)
  133. }
  134. },
  135. initTrendChart() {
  136. const chart = echarts.init(this.$refs.trendChart)
  137. const familyData = Object.values(this.trendData.familyTrend || {})
  138. const userData = Object.values(this.trendData.userTrend || {})
  139. const xAxis = Object.keys(this.trendData.familyTrend || {})
  140. chart.setOption({
  141. tooltip: { trigger: 'axis' },
  142. legend: { data: ['新增家庭', '新增用户'] },
  143. xAxis: { type: 'category', data: xAxis },
  144. yAxis: { type: 'value' },
  145. series: [
  146. { name: '新增家庭', type: 'bar', data: familyData, itemStyle: { color: '#F97316' } },
  147. { name: '新增用户', type: 'line', data: userData, itemStyle: { color: '#0EA5E9' } }
  148. ]
  149. })
  150. },
  151. initMemberPieChart() {
  152. const chart = echarts.init(this.$refs.memberPieChart)
  153. chart.setOption({
  154. tooltip: { trigger: 'item' },
  155. legend: { orient: 'vertical', left: 'left' },
  156. series: [{
  157. type: 'pie',
  158. radius: ['40%', '70%'],
  159. data: [
  160. { value: this.membershipData.freeCount || 0, name: '免费用户' },
  161. { value: this.membershipData.familyCount || 0, name: '家庭会员' },
  162. { value: this.membershipData.providerCount || 0, name: '服务商' }
  163. ],
  164. itemStyle: {
  165. color: function(params) {
  166. var colors = ['#94A3B8', '#F97316', '#10B981']
  167. return colors[params.dataIndex]
  168. }
  169. }
  170. }]
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style scoped>
  177. .dashboard-container {
  178. padding: 20px;
  179. }
  180. .stat-row {
  181. margin-bottom: 20px;
  182. }
  183. .stat-card {
  184. display: flex;
  185. align-items: center;
  186. padding: 10px;
  187. }
  188. .stat-icon {
  189. font-size: 36px;
  190. margin-right: 16px;
  191. }
  192. .stat-value {
  193. font-size: 28px;
  194. font-weight: bold;
  195. color: #1E293B;
  196. }
  197. .stat-label {
  198. font-size: 14px;
  199. color: #64748B;
  200. margin-top: 4px;
  201. }
  202. .chart-card {
  203. min-height: 300px;
  204. }
  205. .echarts-container {
  206. height: 260px;
  207. }
  208. .card-header {
  209. font-weight: 600;
  210. color: #1E293B;
  211. }
  212. .revenue-value {
  213. font-size: 32px;
  214. font-weight: bold;
  215. color: #F97316;
  216. text-align: center;
  217. margin-top: 20px;
  218. }
  219. .revenue-sub {
  220. font-size: 14px;
  221. color: #64748B;
  222. text-align: center;
  223. margin-top: 8px;
  224. }
  225. </style>