john hai 8 meses
pai
achega
b9c7a94d3c

+ 5 - 0
frontEndMobile/src/api/api.ts

@@ -107,3 +107,8 @@ export const putRecordInfo = async (record_id: string, params): Promise<User> =>
   const response = await http.put<User>(`/api/v1/record/${record_id}`, params)
   return response.data
 }
+// 删除账单数据
+export const delRecordInfo = async (record_id: string): Promise<User> => {
+  const response = await http.delete<User>(`/api/v1/record/${record_id}`)
+  return response.data
+}

+ 3 - 2
frontEndMobile/src/api/http.ts

@@ -9,8 +9,9 @@ import 'nprogress/nprogress.css'
 
 // 创建一个 Axios 实例
 const http: AxiosInstance = axios.create({
-  baseURL: window.origin, // 替换为你的 API 基础 URL
-  // baseURL: 'http://127.0.0.1:3000', // 替换为你的 API 基础 URL
+  // baseURL: window.origin, // 替换为你的 API 基础 URL
+  // baseURL: 'http://192.168.2.101:6833', // 替换为你的 API 基础 URL
+  baseURL: 'http://127.0.0.1:3000', // 替换为你的 API 基础 URL
   timeout: 10000, // 请求超时时间
   headers: {
     'Content-Type': 'application/json'

+ 1 - 1
frontEndMobile/src/main.ts

@@ -18,7 +18,7 @@ import { setupStore } from './store'
 const vConsole = new VConsole();
 // or init with options
 // const vConsole = new VConsole({ theme: 'dark' });
-vConsole.setSwitchPosition(20, 20);
+vConsole.setSwitchPosition(0, 900);
 
 import './style.css'
 import App from './App.vue'

+ 33 - 2
frontEndMobile/src/views/MePage.vue

@@ -1,3 +1,34 @@
 <template>
-  <div>me</div>
-</template>
+  <div class="me-box">
+    <van-cell @click="toPage(item)" v-for="item in list" :key="item" :title="item" />
+  </div>
+</template>
+
+<script setup>
+import { onMounted, ref } from 'vue'
+import { useRouter } from 'vue-router';
+const router = useRouter()
+
+const list = ref([])
+
+onMounted(() => {
+  console.log(1313);
+  list.value = ['账本管理', '批量记录',]
+})
+
+
+const toPage = (item) => {
+  switch (item) {
+    case '账本管理':
+    router.push('/books')
+      break
+  }
+
+}
+</script>
+
+<style lang="scss" scoped>
+.me-box {
+  padding: 24px;
+}
+</style>

+ 18 - 2
frontEndMobile/src/views/RecordPage.vue

@@ -18,13 +18,14 @@
 
     <div>
       <van-button @click="toEdit" type="primary"> 编辑 </van-button>
+      <van-button @click="toDel" type="danger"> 删除 </van-button>
     </div>
   </div>
 </template>
 
 <script setup>
-import { getRecordInfo } from '@/api/api'
-import { showImagePreview } from 'vant'
+import { getRecordInfo, delRecordInfo } from '@/api/api'
+import { showImagePreview, showConfirmDialog } from 'vant'
 import { onMounted, ref } from 'vue'
 import { useRouter, useRoute } from 'vue-router'
 const route = useRoute()
@@ -52,6 +53,21 @@ function imagePreview(images, startPosition) {
 function toEdit() {
   router.push(`/edit_accountLog/${route.params.id}`)
 }
+
+function toDel() {
+  showConfirmDialog({
+    title: '删除趣儿',
+    message: '删除当前数据将无法恢复。'
+  })
+    .then(async () => {
+      await delRecordInfo(route.params.id)
+      router.back()
+    })
+    .catch(() => {
+      // on cancel
+    })
+  // router.push(`/edit_accountLog/${route.params.id}`)
+}
 </script>
 
 <style lang="scss" scoped>

+ 24 - 1
node_expores/db/record.js

@@ -157,7 +157,7 @@ export function getRecordInfoById(record_id) {
 export function getRecordsInfoByTime(time, book_id) {
   return new Promise((resolve, reject) => {
     connection.query(
-      `SELECT * FROM record WHERE time = ? AND book_id = ?`,
+      `SELECT * FROM record WHERE DATE_FORMAT(time, '%Y-%m-%d') = ? AND book_id = ?`,
       [time, book_id],
       (err, rows) => {
         if (err) {
@@ -187,3 +187,26 @@ export function getRecordsInfoByMonth(time, book_id) {
     );
   });
 }
+
+
+// 根据id删除数据
+export function delByRecordId(record_id, author_id) {
+  return new Promise((resolve, reject) => {
+    try {
+      const sql = `DELETE FROM record WHERE id = ? AND author_id = ?`;
+      connection.query(sql, [record_id, author_id], (err, result) => {
+        console.log(198, err, result);
+
+        if (err) {
+          // 如果执行过程中出现错误,返回 false
+          return resolve(false);
+        }
+        // 删除成功后返回结果
+        return resolve(result);
+      });
+    } catch (err) {
+      // 捕获异常并返回 false
+      return resolve(false);
+    }
+  });
+}

+ 29 - 2
node_expores/router/record/index.js

@@ -13,6 +13,7 @@ import {
   getRecordsInfoByMonth,
   getTypesById,
   delFileByRecordId,
+  delByRecordId,
 } from "#db";
 import { shanghaiTime, shanghaiTimeFormat } from "#utils";
 import dayjs from "dayjs";
@@ -115,9 +116,9 @@ router.get("/:record_id", async function (req, res) {
   }
   function getFileUrl(elm) {
     // 获取请求的来源域名
-    const host = req.headers['host']; // 主机名 + 端口
+    const host = req.headers["host"]; // 主机名 + 端口
     const origin = req.headers["referer"]; // 请求的来源域(适用于跨域)
-    if (`${origin}`.indexOf("3032") > -1 || `${host}`.indexOf('3000') > -1) {
+    if (`${origin}`.indexOf("3032") > -1 || `${host}`.indexOf("3000") > -1) {
       return "http://localhost:3000" + `/api_files_${elm.file_id}`;
     }
     if (`${origin}`.indexOf("zs_interval") > -1) {
@@ -243,4 +244,30 @@ router.get("/:book_id/m/:time", async function (req, res) {
     })),
   });
 });
+
+// 根据日期获取数据
+router.delete("/:record_id", async function (req, res) {
+  const record_id = req.params.record_id; // 获取 fileId 参数
+  const { userInfo = {} } = req.body;
+  console.log(251, userInfo, record_id);
+  const recordInfo = await getRecordInfoById(record_id);
+
+  // 删除附件映射关系
+  const getAllfiles = await getFileByRecordId(record_id);
+  if (getAllfiles.length) {
+    await Promise.all(
+      getAllfiles.map((elm) =>
+        delFileByRecordId(record_id, elm.file_id)
+      )
+    );
+  }
+
+  // 删除record数据
+  await delByRecordId(record_id, userInfo.user_id);
+
+  res.json({
+    code: 200,
+    data: '',
+  });
+});
 export default router;