index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="db-page">
  3. <view class="db-header" :style="safeAreaStyle">
  4. <view class="db-header__nav">
  5. <view class="db-header__left">
  6. <text class="db-header__back" @click="goWorkbench">←</text>
  7. <text class="db-header__title">仪表盘</text>
  8. </view>
  9. <text class="db-header__user">{{ username }}</text>
  10. <view />
  11. </view>
  12. </view>
  13. <view class="db-menu-grid">
  14. <view class="db-menu-item" @click="go(PAGE_PATHS.dbPlansList)">
  15. <view class="db-menu-icon">📋</view>
  16. <view class="db-menu-label">计划管理</view>
  17. </view>
  18. <view class="db-menu-item" @click="go(PAGE_PATHS.dbInventoryList)">
  19. <view class="db-menu-icon">📦</view>
  20. <view class="db-menu-label">出入库管理</view>
  21. </view>
  22. <view class="db-menu-item" @click="go(PAGE_PATHS.dbWeighingList)">
  23. <view class="db-menu-icon">⚖️</view>
  24. <view class="db-menu-label">地磅单管理</view>
  25. </view>
  26. </view>
  27. <view class="db-stat-grid">
  28. <view class="db-stat-card">
  29. <view class="db-stat-title">今日入库</view>
  30. <view class="db-stat-value">
  31. {{ inboundCount }}<text class="db-stat-suffix">车</text>
  32. </view>
  33. </view>
  34. <view class="db-stat-card">
  35. <view class="db-stat-title">今日出库</view>
  36. <view class="db-stat-value">
  37. {{ outboundCount }}<text class="db-stat-suffix">车</text>
  38. </view>
  39. </view>
  40. </view>
  41. <view v-for="block in chartBlocks" :key="block.title" class="db-chart-block">
  42. <view class="db-chart-title">{{ block.title }}</view>
  43. <view v-if="!block.rows.length" class="db-empty" style="padding: 16px">暂无数据</view>
  44. <view v-for="row in block.rows" :key="row.label" class="db-bar-row">
  45. <view class="db-bar-label">{{ row.label }}</view>
  46. <view class="db-bar-track">
  47. <view class="db-bar-planned" :style="{ width: barPct(row.planned, block.max) }" />
  48. <view class="db-bar-actual" :style="{ width: barPct(row.actual, block.max) }" />
  49. </view>
  50. <view class="db-bar-meta">计划 {{ fmt(row.planned) }} · 实绩 {{ fmt(row.actual) }}</view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script setup>
  56. import { ref, computed, onMounted } from 'vue'
  57. import { onShow } from '@dcloudio/uni-app'
  58. import { useUserStore } from '@/stores/user'
  59. import { PAGE_PATHS } from '@/config/api'
  60. import { dashboardApi } from '@/pages/db/api/db'
  61. import { getSafeAreaStyle } from '@/utils/safeArea'
  62. const safeAreaStyle = getSafeAreaStyle()
  63. const userStore = useUserStore()
  64. const inboundByCargo = ref([])
  65. const outboundByCargo = ref([])
  66. const inboundByPartner = ref([])
  67. const outboundByPartner = ref([])
  68. const username = computed(() => userStore.userInfo?.username || userStore.userInfo?.realName || '用户')
  69. const inboundCount = computed(() => {
  70. const set = new Set()
  71. inboundByCargo.value.forEach((i) => {
  72. if (Number(i.planned) > 0) set.add(i.label)
  73. })
  74. return set.size
  75. })
  76. const outboundCount = computed(() => {
  77. const set = new Set()
  78. outboundByCargo.value.forEach((i) => {
  79. if (Number(i.planned) > 0) set.add(i.label)
  80. })
  81. return set.size
  82. })
  83. const chartBlocks = computed(() => [
  84. pack('今日入库量(按货物,t)', inboundByCargo.value),
  85. pack('今日出库量(按货物,t)', outboundByCargo.value),
  86. pack('今日入库量(按往来单位+货物,t)', inboundByPartner.value),
  87. pack('今日出库量(按往来单位+货物,t)', outboundByPartner.value)
  88. ])
  89. function pack(title, rows) {
  90. const list = Array.isArray(rows) ? rows : []
  91. const max = Math.max(1, ...list.map((r) => Math.max(Number(r.planned) || 0, Number(r.actual) || 0)))
  92. return { title, rows: list, max }
  93. }
  94. function barPct(v, max) {
  95. const n = Number(v) || 0
  96. return `${Math.min(100, (n / max) * 100)}%`
  97. }
  98. function fmt(v) {
  99. const n = Number(v)
  100. return Number.isFinite(n) ? n.toFixed(2) : '0'
  101. }
  102. function goWorkbench() {
  103. uni.reLaunch({ url: PAGE_PATHS.workbench })
  104. }
  105. function go(url) {
  106. uni.navigateTo({ url })
  107. }
  108. async function load() {
  109. try {
  110. const [a, b, c, d] = await Promise.all([
  111. dashboardApi.getInboundByCargo(),
  112. dashboardApi.getOutboundByCargo(),
  113. dashboardApi.getInboundByPartnerCargo(),
  114. dashboardApi.getOutboundByPartnerCargo()
  115. ])
  116. inboundByCargo.value = a || []
  117. outboundByCargo.value = b || []
  118. inboundByPartner.value = c || []
  119. outboundByPartner.value = d || []
  120. } catch (e) {
  121. console.error(e)
  122. }
  123. }
  124. onMounted(load)
  125. onShow(() => {
  126. userStore.checkLoginStatus()
  127. if (!userStore.isLoggedIn) {
  128. uni.reLaunch({ url: PAGE_PATHS.login })
  129. }
  130. })
  131. </script>
  132. <style lang="scss">
  133. @import '@/styles/db-theme.scss';
  134. </style>