From eba209ea15169423fa12eb63c41af8927bd4573e Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Wed, 7 Aug 2024 15:05:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E5=87=BA=E9=94=99=E6=8F=90=E7=A4=BA=EF=BC=9B?= =?UTF-8?q?=E7=BB=99=E6=AF=8F=E4=B8=AA=20Store=20=E5=91=BD=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.js | 3 +- src/stores/Account.js | 5 ++- src/stores/Auth.js | 5 ++- src/stores/Feedback.js | 2 +- src/stores/Form.js | 2 +- src/stores/Invoice.js | 2 +- src/stores/Notice.js | 2 +- src/stores/Products/Index.js | 34 ++++++++++------- src/stores/Report.js | 2 +- src/stores/Reservation.js | 5 ++- src/views/account/RoleList.jsx | 1 - .../products/Detail/ProductInfoQuotation.jsx | 37 ++++++++++++------- 12 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/config.js b/src/config.js index 064071b..256e171 100644 --- a/src/config.js +++ b/src/config.js @@ -1,9 +1,8 @@ export const PROJECT_NAME = "GHHub"; +// mode: test,内部测试使用 export const HT_HOST = import.meta.env.MODE === 'test' ? 'http://202.103.68.144:890' : import.meta.env.PROD ? "https://p9axztuwd7x8a7.mycht.cn" : 'http://202.103.68.144:890' -// 内部测试使用,正式环境要切换到上面的配置⬆️ -// export const HT_HOST = "http://202.103.68.144:890"; export const DATE_FORMAT = "YYYY-MM-DD"; export const DATE_FORMAT_MONTH = "YYYY-MM"; diff --git a/src/stores/Account.js b/src/stores/Account.js index 195c46b..186a989 100644 --- a/src/stores/Account.js +++ b/src/stores/Account.js @@ -1,4 +1,5 @@ import { create } from 'zustand' +import { devtools } from 'zustand/middleware' import { fetchJSON, postForm } from '@/utils/request' import { isEmpty, isNotEmpty } from '@/utils/commons' import { HT_HOST } from "@/config" @@ -67,7 +68,7 @@ export const fetchTravelAgencyByName = async (name) => { return errcode !== 0 ? {} : result } -const useAccountStore = create((set, get) => ({ +const useAccountStore = create(devtools((set) => ({ accountList: [], @@ -171,6 +172,6 @@ const useAccountStore = create((set, get) => ({ accountList: mapAccoutList })) }, -})) +}), { name: 'accountStore' })) export default useAccountStore \ No newline at end of file diff --git a/src/stores/Auth.js b/src/stores/Auth.js index 7fc81b8..feab61c 100644 --- a/src/stores/Auth.js +++ b/src/stores/Auth.js @@ -1,4 +1,5 @@ import { create } from 'zustand' +import { devtools } from 'zustand/middleware' import { appendRequestParams, fetchJSON, postForm } from '@/utils/request' import { HT_HOST } from "@/config" import { loadPageSpy } from '@/pageSpy' @@ -56,7 +57,7 @@ const initialState = { permissionList: [] } -const useAuthStore = create((set, get) => ({ +const useAuthStore = create(devtools((set, get) => ({ ...initialState, @@ -197,6 +198,6 @@ const useAuthStore = create((set, get) => ({ }) }, -})) +}), { name: 'authStore' })) export default useAuthStore diff --git a/src/stores/Feedback.js b/src/stores/Feedback.js index 9b2356e..e9f544c 100644 --- a/src/stores/Feedback.js +++ b/src/stores/Feedback.js @@ -116,7 +116,7 @@ const useFeedbackStore = create( setFeedbackList(filterV); setLoading(false); }, - })) + }), { name: 'feedbackStore'}) ); export default useFeedbackStore; diff --git a/src/stores/Form.js b/src/stores/Form.js index 61a30f8..d81fff6 100644 --- a/src/stores/Form.js +++ b/src/stores/Form.js @@ -7,6 +7,6 @@ export const useFormStore = create( setFormValues: (values) => set((state) => ({ formValues: { ...state.formValues, ...values } })), formValuesToSub: {}, setFormValuesToSub: (values) => set((state) => ({ formValuesToSub: { ...state.formValuesToSub, ...values } })), - })) + }), { name: 'formStore' }) ); export default useFormStore; diff --git a/src/stores/Invoice.js b/src/stores/Invoice.js index 09ac0f2..dc489bc 100644 --- a/src/stores/Invoice.js +++ b/src/stores/Invoice.js @@ -129,7 +129,7 @@ const useInvoiceStore = create( setLoading(false); }, - })) + }), { name: 'invoiceStore'}) ); export default useInvoiceStore; diff --git a/src/stores/Notice.js b/src/stores/Notice.js index b3f4e57..212d8a6 100644 --- a/src/stores/Notice.js +++ b/src/stores/Notice.js @@ -48,6 +48,6 @@ export const useNoticeStore = create( setNoticeUnRead(noticeUnRead); }, - })) + }), { name: 'noticeStore' }) ); export default useNoticeStore; diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index b22dd87..e326e10 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -286,24 +286,30 @@ export const useProductsStore = create( return mergedList }, - deleteQuotation: (quotaionId) => { + deleteQuotationById: async(quotaionId) => { const { editingProduct, quotationList, agencyProducts } = get() const productTypeId = editingProduct.info.product_type_id; const newList = quotationList.filter(q => { return q.id != quotaionId }) - deleteQuotationAction(quotaionId) - - set({ - agencyProducts: { - ...agencyProducts, - [productTypeId]: [{ - ...editingProduct, - quotation: newList - }] - }, - quotationList: newList - }) + + const { result, success } = await deleteQuotationAction(quotaionId) + + if (success) { + set({ + agencyProducts: { + ...agencyProducts, + [productTypeId]: [{ + ...editingProduct, + quotation: newList + }] + }, + quotationList: newList + }) + return Promise.resolve(result) + } else { + return Promise.reject(result) + } }, // side effects @@ -339,6 +345,6 @@ export const useProductsStore = create( const res = await getAgencyProductExtrasAction(param); // todo: }, - })) + }), { name: 'productStore' }) ); export default useProductsStore; diff --git a/src/stores/Report.js b/src/stores/Report.js index c3b05d7..f68d154 100644 --- a/src/stores/Report.js +++ b/src/stores/Report.js @@ -64,6 +64,6 @@ export const useReportStore = create( setCommendScoresData(errcode === 0 ? Result : {}); // setLoading(false); }, - })) + }), { name: 'reportStore'}) ); export default useReportStore; diff --git a/src/stores/Reservation.js b/src/stores/Reservation.js index 2984fe2..e28ea15 100644 --- a/src/stores/Reservation.js +++ b/src/stores/Reservation.js @@ -1,4 +1,5 @@ import { create } from 'zustand' +import { devtools } from 'zustand/middleware' import { fetchJSON, postForm } from '@/utils/request' import { HT_HOST } from "@/config" import { prepareUrl } from '@/utils/commons' @@ -34,7 +35,7 @@ export const fetchAttachList = async (reservationId) => { return errcode !== 0 ? {} : result } -const useReservationStore = create((set, get) => ({ +const useReservationStore = create(devtools((set, get) => ({ cityList: [], @@ -265,6 +266,6 @@ const useReservationStore = create((set, get) => ({ } }) } -})) +}), { name: 'reservationStore' })) export default useReservationStore diff --git a/src/views/account/RoleList.jsx b/src/views/account/RoleList.jsx index 5143081..08c4226 100644 --- a/src/views/account/RoleList.jsx +++ b/src/views/account/RoleList.jsx @@ -236,7 +236,6 @@ function RoleList() { showSizeChanger: true, showTotal: (total) => { return t('Total') + `:${total}` } }} - onChange={(pagination) => { onSearchClick(pagination.current) }} columns={roleListColumns} dataSource={roleAllList} /> diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index c21b744..593ed36 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -242,14 +242,14 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const [isQuotationModalOpen, setQuotationModalOpen] = useState(false) const [isBatchSetupModalOpen, setBatchSetupModalOpen] = useState(false) - const { modal } = App.useApp(); + const { modal, notification } = App.useApp(); const [quotationForm] = Form.useForm() const [batchSetupForm] = Form.useForm() const datePresets = useDatePresets() - const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation] = - useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation]) + const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotationById] = + useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotationById]) const triggerChange = (changedValue) => { onChange?.( @@ -284,6 +284,26 @@ const ProductInfoQuotation = ({ editable, ...props }) => { setBatchSetupModalOpen(false) } + const onDeleteQuotation = (quotationId) => { + modal.confirm({ + title: '请确认', + icon: , + content: '你要删除这条价格吗?', + onOk() { + deleteQuotationById(quotationId) + .catch(ex => { + console.info(ex.message) + notification.error({ + message: 'Notification', + description: ex.message, + placement: 'top', + duration: 4, + }) + }) + }, + }) + } + const quotationColumns = [ { title: t('products:adultPrice'), dataIndex: 'adult_cost', width: '4rem' }, { title: t('products:childrenPrice'), dataIndex: 'child_cost', width: '4rem' }, @@ -317,16 +337,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => { return ( - + ) },