Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
markliu2013 committed Jun 15, 2024
1 parent 1d35832 commit 9930611
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moneynote-pc",
"version": "1.0.91",
"version": "1.0.92",
"private": true,
"scripts": {
"analyze": "cross-env ANALYZE=1 max build",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en-US/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export default {
'account.audit': 'Audit',
'currency.description': 'Description',
'currency.base': 'Base Currency',
'currency.update': 'Change Rate',

}
1 change: 1 addition & 0 deletions src/locales/zh-CN/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export default {
'account.audit': '对账',
'currency.description': '描述',
'currency.base': '基准币种',
'currency.update': '修改汇率',

}
31 changes: 28 additions & 3 deletions src/pages/Currency/DataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import {query1, queryAll} from '@/services/common';
import {selectSingleProp, tableProp} from '@/utils/prop';
import {tableSortFormat} from "@/utils/util";
import {refresh} from "@/services/currency";
import RateForm from './RateForm';
import t from "@/utils/i18n";


export default () => {

const { initialState } = useModel('@@initialState');
const { data : currencyOptions = [], loading : currencyLoading, run : loadCurrencies} = useRequest(() => queryAll('currencies'), { manual: true });
const { loading : refreshCurrencyLoading, run : runRefreshCurrency} = useRequest(refresh, { manual: true });
const { show } = useModel('modal');
const { actionRef } = useModel('Currency.model');

const changeRate = (record) => {
show(<RateForm item={record} />, 2, record)
};

const columns = [
{
Expand All @@ -32,7 +38,7 @@ export default () => {
dataIndex: 'base',
hideInTable: true,
valueType: 'select',
initialValue: initialState.currentGroup.defaultCurrencyCode,
initialValue: 'USD',
fieldProps: {
...selectSingleProp,
allowClear: false,
Expand All @@ -53,13 +59,32 @@ export default () => {
dataIndex: 'description',
hideInSearch: true,
},
{
title: t('operation'),
align: 'center',
hideInSearch: true,
width: 250,
render: (_, record) => [
<Button size="small" type="link" onClick={() => changeRate(record)}>
{t('currency.update')}
</Button>,
],
},
]

return (
<ProTable
{...tableProp}
actionRef={actionRef}
toolBarRender={() => [
<Button type="primary" onClick={runRefreshCurrency} loading={refreshCurrencyLoading}>
<Button
type="primary"
onClick={async () => {
await runRefreshCurrency();
actionRef.current?.reload();
}}
loading={refreshCurrencyLoading}
>
{t('account.refresh.currency')}
</Button>,
]}
Expand Down
54 changes: 54 additions & 0 deletions src/pages/Currency/RateForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {useEffect, useState} from "react";
import {useModel, useRequest} from '@umijs/max';
import {ProFormSelect, ProFormText} from '@ant-design/pro-components';
import {requiredRules} from "@/utils/rules";
import {queryAll, update} from "@/services/common";
import {updateRates} from "@/services/currency";
import {selectSingleProp} from "@/utils/prop";
import MyModalForm from '@/components/MyModalForm';
import t from '@/utils/i18n';

export default ({ item }) => {

const { actionRef } = useModel('Currency.model');
const { action, currentRow } = useModel('modal');
const { data : currencyOptions = [], loading : currencyLoading, run : loadCurrencies} = useRequest(() => queryAll('currencies'), { manual: true });

const [initialValues, setInitialValues] = useState({});
useEffect(() => {
setInitialValues({...currentRow});
}, [action, currentRow]);

const successHandler = () => {
actionRef.current?.reload();
}

const requestHandler = async (values) => {
await updateRates(currentRow.id, values);
}

return (
<MyModalForm
title={ t('action.title', {'action': t('update'), 'title': t('account.rate')} ) + ' - ' + item.name }
labelWidth={100}
request={requestHandler}
onSuccess={successHandler}
initialValues={initialValues}
>
<ProFormSelect
name="base"
label={t('currency.base')}
rules={requiredRules()}
initialValue='USD'
fieldProps={{
...selectSingleProp,
onFocus: loadCurrencies,
options: currencyOptions,
loading: currencyLoading,
allowClear: false,
}}
/>
<ProFormText name="rate" label={t('account.rate')} rules={requiredRules()} />
</MyModalForm>
);
}
9 changes: 9 additions & 0 deletions src/pages/Currency/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useRef } from 'react';

export default () => {
const actionRef = useRef();

return {
actionRef,
};
};
9 changes: 0 additions & 9 deletions src/pages/Group/DataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default () => {

const { actionRef } = useModel('Group.model');
const { show } = useModel('modal');
const { initialState, setInitialState } = useModel('@@initialState');

function successHandler() {
actionRef.current?.reload();
Expand Down Expand Up @@ -65,14 +64,6 @@ export default () => {
const setDefaultHandler = async (record) => {
await setDefaultGroup(record.id);
window.location.reload();
// const response = await initialState.fetchUserInfo();
// setInitialState(prevState => ({
// ...prevState,
// currentUser: response.user,
// currentBook: response.book,
// currentGroup: response.group,
// }));
// successHandler();
};

const columns = [
Expand Down
8 changes: 8 additions & 0 deletions src/services/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ export async function rate(from, to) {
},
});
}

export async function updateRates(id, data) {
return request(`${prefix}/${id}/rate`, {
method: 'PUT',
data: data,
});

}

0 comments on commit 9930611

Please sign in to comment.