From 293df6e0a1ae2ea9ac680373b8d274430e9a94d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A6=E5=8E=98=E5=AD=90?= Date: Wed, 30 Nov 2022 23:45:42 +0800 Subject: [PATCH] =?UTF-8?q?feat=F0=9F=94=AB:=20=E4=BF=AE=E6=94=B9=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/build.ps1 | 9 ++------- src/api/bills.ts | 4 ++-- src/pages/Record/Record.tsx | 16 ++++++---------- src/store/index.ts | 4 ++-- vite.config.ts | 2 +- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index d1a52aa..3d253d0 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -1,8 +1,3 @@ -docker build . -t registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev +$server_path='fadinglight:/root/docker/caddy/site/www' -docker push registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev - -ssh fadinglight "cd /root/docker/bill-sys/; - docker compose down; - docker pull registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev; - docker compose up -d" +scp -r dist/* $server_path \ No newline at end of file diff --git a/src/api/bills.ts b/src/api/bills.ts index ac58057..d6b9ba7 100644 --- a/src/api/bills.ts +++ b/src/api/bills.ts @@ -11,7 +11,7 @@ export async function getLabels() { return data.data } -export async function createBill(bill: IBill) { - const data = await request.post(`/bill/`, bill) +export async function postBills(bills: Array) { + const data = await request.post(`/bill/`, bills) return data.data } \ No newline at end of file diff --git a/src/pages/Record/Record.tsx b/src/pages/Record/Record.tsx index 44647a5..fa7b1de 100644 --- a/src/pages/Record/Record.tsx +++ b/src/pages/Record/Record.tsx @@ -7,7 +7,7 @@ import { BillContext } from "../../store"; import { observer } from "mobx-react-lite"; import styles from "./Record.module.scss" import { BaseSelectRef } from "rc-select/lib/BaseSelect"; -import { createBill } from "../../api/bills"; +import { postBills } from "../../api/bills"; function Record() { @@ -117,16 +117,12 @@ function Record() { const [uploadLoading, setUploadLoading] = useState(false) const upload = async () => { setUploadLoading(true) - const failures = [] - for (let bill of datasource) { - try { - const { id } = await createBill(bill) - if (!id) failures.push(bill) - } catch (e) { - failures.push(bill) - } + datasource.forEach( it => Reflect.deleteProperty(it, "key")) + try { + await postBills(datasource) + setDataSource([]) + } catch (err) { } - setDataSource(failures) setUploadLoading(false) } diff --git a/src/store/index.ts b/src/store/index.ts index ee94974..b2f1d9b 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,6 +1,6 @@ import { makeAutoObservable, runInAction } from "mobx"; import { createContext } from "react"; -import { createBill, getBills, getLabels } from "../api/bills"; +import { postBills, getBills, getLabels } from "../api/bills"; import { BillType, IBill } from "../model"; import * as R from "ramda" import { BillLabel } from "./types"; @@ -110,7 +110,7 @@ export class Bill { async add(bill: IBill) { - const { id } = await createBill(bill) + const { id } = await postBills([bill]) bill.id = id runInAction(() => { this._bills.push(bill); diff --git a/vite.config.ts b/vite.config.ts index 98fba33..a5ccdb7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ server: { proxy: { "/api/": { - target: "http://localhost:8080/api/v1/", + target: "https://www.fadinglight.cn/api/", changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ""), }