Răsfoiți Sursa

展示完整数据

john 8 luni în urmă
părinte
comite
93573ba0be

+ 7 - 1
frontEndMobile/src/api/api.ts

@@ -80,8 +80,14 @@ export const getAllType = async (book_id: string): Promise<User> => {
 }
 
 
-// 添加数据
+// 获取指定日期的所有数据
 export const getAllRecordyDate = async (book_id: string, time: string): Promise<User> => {
   const response = await http.get<User>(`/api/v1/record/${book_id}/${time}`)
   return response.data
 }
+
+// 获取指定月份的所有数据
+export const getAllRecordyMonth = async (book_id: string, time: string): Promise<User> => {
+  const response = await http.get<User>(`/api/v1/record/${book_id}/m/${time}`)
+  return response.data
+}

+ 0 - 3
frontEndMobile/src/views/AddAccountLogPage.vue

@@ -8,9 +8,6 @@
           name="totalFee"
           type="number"
           label="数字"
-          readonly
-          clickable
-          @touchstart.stop="showKeyboard = true"
         />
 
         <div class="types-box">

+ 35 - 13
frontEndMobile/src/views/HomePage.vue

@@ -18,7 +18,7 @@
         <div>0.00</div>
       </div>
       <div class="yarn-box">
-        <div>99999</div>
+        <div>{{ totalFee }}</div>
       </div>
     </div>
   </div>
@@ -47,7 +47,7 @@
 <script setup>
 import { ref, computed, watch, onMounted } from 'vue'
 import { register, login } from '@/api/base'
-import { getBookInfo } from '@/api/api'
+import { getBookInfo, getAllRecordyMonth } from '@/api/api'
 import dayjs from 'dayjs'
 import RecordInRow from '@/components/RecordInRow.vue'
 
@@ -59,7 +59,7 @@ const currentDate = ref([])
 const currentDateAfter = ref([])
 
 const time_record_list = ref([])
-
+const totalFee = ref(0)
 const selectTime = () => {
   if (!currentDate.value.length) {
     const timeStr = dayjs().format('YYYY,MM')
@@ -77,6 +77,7 @@ const cancelSelectTime = () => {
 const confirmSelectTime = ({ selectedValues }) => {
   currentDate.value = selectedValues
   cancelSelectTime()
+  pageInit()
 }
 
 const yearStr = computed(() => {
@@ -107,19 +108,40 @@ onMounted(() => {
   commonStore.initBook()
   // getBookInfoFn()
   // getLogin()
+  pageInit()
+})
 
-  for (let index = 0; index < 40; index++) {
-    const elm = {
-      name: 'name' + index,
-      record_list: []
-    }
-    for (let j = 0; j < 10; j++) {
-      elm.record_list.push({})
+// 分组函数
+const groupByTime = (data) => {
+  return data.reduce((acc, item) => {
+    const { time } = item
+    if (!acc[time]) {
+      acc[time] = [] // 初始化该分组
     }
+    acc[time].push(item) // 将当前项加入对应分组
+    return acc
+  }, {})
+}
 
-    time_record_list.value.push(elm)
-  }
-})
+const pageInit = async () => {
+  const res = await getAllRecordyMonth(1, `${yearStr.value}-${monthlyStr.value}`)
+  let _totalFee = 0
+  // 使用分组函数
+  const groupedData = groupByTime(res)
+  const new_time_record_list = []
+  Object.keys(groupedData).forEach((time) => {
+    new_time_record_list.push({
+      time: time,
+      totalFee: groupedData[time].reduce((fee, elm) => {
+        _totalFee += Number(elm.total_fee)
+        return (fee += Number(elm.total_fee))
+      }, 0),
+      record_list: groupedData[time]
+    })
+  })
+  totalFee.value = _totalFee
+  time_record_list.value = new_time_record_list
+}
 async function getRegister() {
   const res = await register({
     account: 'x.czvufulcym@qqxhjl.ee',

+ 17 - 0
node_expores/db/record.js

@@ -127,4 +127,21 @@ export function getRecordsInfoByTime(time, book_id) {
       },
     );
   });
+}
+// 根据月份查询记录
+export function getRecordsInfoByMonth(time, book_id) {
+  return new Promise((resolve, reject) => {
+    connection.query(
+      `SELECT * FROM record WHERE DATE_FORMAT(time, '%Y-%m') = ? AND book_id = ?`,
+      [time, book_id],
+      (err, rows) => {
+        if (err) {
+          // reject(err);
+          resolve(false); // 如果存在记录,则返回 true,否则返回 false
+        } else {
+          resolve(rows); // 如果存在记录,则返回 true,否则返回 false
+        }
+      },
+    );
+  });
 }

+ 1 - 0
node_expores/db/update.sql

@@ -11,3 +11,4 @@ ALTER TABLE cashbook.record_files CHANGE user_id author_id varchar(300) CHARACTE
 ALTER TABLE cashbook.types CHANGE user_id author_id varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL;
 
 ALTER TABLE cashbook.record ADD `time` TIMESTAMP NOT NULL;
+ALTER TABLE cashbook.record MODIFY COLUMN total_fee DECIMAL(15, 2) NOT NULL;

+ 21 - 1
node_expores/router/record/index.js

@@ -8,7 +8,8 @@ import {
   getRecordInfoById,
   addFileByRecordId,
   getFileByRecordId,
-  getRecordsInfoByTime
+  getRecordsInfoByTime,
+  getRecordsInfoByMonth
 } from "#db";
 import {shanghaiTime, shanghaiTimeFormat} from '#utils'
 import dayjs from "dayjs";
@@ -121,6 +122,25 @@ router.get("/:book_id/:time", async function (req, res) {
   const recordsInfoRes = await getRecordsInfoByTime(time, book_id);
   console.log(121, recordsInfoRes);
 
+  res.json({
+    code: 200,
+    data: recordsInfoRes.map(elm => ({
+      ...elm,
+      "time": shanghaiTimeFormat(elm.time, 'YYYY-MM-DD'),
+      "create_time": shanghaiTimeFormat(elm.create_time),
+      "update_time": shanghaiTimeFormat(elm.update_time),
+    }))
+  });
+});
+
+
+// 根据日期获取数据
+router.get("/:book_id/m/:time", async function (req, res) {
+  const time = req.params.time; // 获取 fileId 参数
+  const book_id = req.params.book_id; // 获取 fileId 参数
+  console.log(120, time, book_id);
+  const recordsInfoRes = await getRecordsInfoByMonth(time, book_id);
+  console.log(121, recordsInfoRes);
 
   res.json({
     code: 200,