Merge pull request 'feat: 订单打印上边距可调整' (#367) from feat_recordpdf_top_margin into @hera/dev

Reviewed-on: daoyoucloud/tachycode#367
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
This commit is contained in:
sealday 2024-03-14 10:33:29 +08:00
commit 83deef45d0
5 changed files with 98 additions and 7 deletions

View File

@ -12,13 +12,21 @@ export const PdfIsLoadContext = createContext({
setSettingLoad: null, setSettingLoad: null,
}); });
export const PdfMargingTopContext = createContext({
margingTop: 0,
setMargingTop: null,
});
export const PdfIsDoubleProvider = (props) => { export const PdfIsDoubleProvider = (props) => {
const [isDouble, setIsDouble] = useState(false); const [isDouble, setIsDouble] = useState(false);
const [settingType, setSettingLoad] = useState(false); const [settingType, setSettingLoad] = useState(false);
const [margingTop, setMargingTop] = useState(0);
return ( return (
<PdfIsDoubleContext.Provider value={{ isDouble, setIsDouble }}> <PdfMargingTopContext.Provider value={{ margingTop, setMargingTop }}>
<PdfIsLoadContext.Provider value={{ settingType, setSettingLoad }}>{props.children}</PdfIsLoadContext.Provider> <PdfIsDoubleContext.Provider value={{ isDouble, setIsDouble }}>
</PdfIsDoubleContext.Provider> <PdfIsLoadContext.Provider value={{ settingType, setSettingLoad }}>{props.children}</PdfIsLoadContext.Provider>
</PdfIsDoubleContext.Provider>
</PdfMargingTopContext.Provider>
); );
}; };
@ -26,7 +34,8 @@ export const useRecordPdfPath = () => {
const record = useRecord(); const record = useRecord();
const { isDouble } = useContext(PdfIsDoubleContext); const { isDouble } = useContext(PdfIsDoubleContext);
const { settingType } = useContext(PdfIsLoadContext); const { settingType } = useContext(PdfIsLoadContext);
return `/records:pdf?recordId=${record.id}&isDouble=${isDouble}&settingType=${settingType}`; const { margingTop } = useContext(PdfMargingTopContext);
return `/records:pdf?recordId=${record.id}&isDouble=${isDouble}&settingType=${settingType}&margingTop=${margingTop}`;
}; };
export const useWaybillPdfPath = () => { export const useWaybillPdfPath = () => {

View File

@ -32,7 +32,10 @@ import {
useSettlementStyleSwitchActionProps, useSettlementStyleSwitchActionProps,
} from './schema-initializer/SettlementStyleSwitchActionInitializer'; } from './schema-initializer/SettlementStyleSwitchActionInitializer';
import { RecordPrintSetupActionInitializer, PrintSetup } from './schema-initializer/RecordPrintSetupActionInitializer'; import { RecordPrintSetupActionInitializer, PrintSetup } from './schema-initializer/RecordPrintSetupActionInitializer';
import {
RecordPrintSetupMargingTopInitializer,
PrintSetupMargingTop,
} from './schema-initializer/RecordPrintSetupMargingTopInitializer';
export class PluginRentalClient extends Plugin { export class PluginRentalClient extends Plugin {
locale: Locale; locale: Locale;
async afterAdd() {} async afterAdd() {}
@ -69,6 +72,11 @@ export class PluginRentalClient extends Plugin {
title: '{{t("Record print setup")}}', title: '{{t("Record print setup")}}',
component: 'RecordPrintSetupActionInitializer', component: 'RecordPrintSetupActionInitializer',
}); });
this.app.schemaInitializerManager.addItem('PDFViewActionInitializer', 'enbaleActions.recordPrintMargingTop', {
type: 'item',
title: '{{t("Record print margingtop")}}',
component: 'RecordPrintSetupMargingTopInitializer',
});
this.app.schemaInitializerManager.addItem('PDFViewActionInitializer', 'enbaleActions.settlementExcelExport', { this.app.schemaInitializerManager.addItem('PDFViewActionInitializer', 'enbaleActions.settlementExcelExport', {
type: 'item', type: 'item',
title: '{{t("Settlement excel export")}}', title: '{{t("Settlement excel export")}}',
@ -134,7 +142,9 @@ export class PluginRentalClient extends Plugin {
SettlementStyleSwitchActionInitializer, SettlementStyleSwitchActionInitializer,
SettlementStyleSwitchAction, SettlementStyleSwitchAction,
RecordPrintSetupActionInitializer, RecordPrintSetupActionInitializer,
RecordPrintSetupMargingTopInitializer,
PrintSetup, PrintSetup,
PrintSetupMargingTop,
}); });
this.app.addScopes({ this.app.addScopes({
useAddToChecklistActionProps, useAddToChecklistActionProps,

View File

@ -0,0 +1,64 @@
import React, { useContext, useEffect, useState } from 'react';
import { ActionInitializer, useAPIClient } from '@nocobase/client';
import { Input } from 'antd';
import { useRequest } from '@nocobase/client';
import { PdfMargingTopContext } from '../hooks/usePdfPath';
import { debounce } from 'lodash';
import { useCurrentUserContext } from '@nocobase/client';
export const PrintSetupMargingTop = (props) => {
const { data } = useCurrentUserContext();
const userId = data.data?.id;
const api = useAPIClient();
const [value, setValue] = useState('0');
const { setMargingTop } = useContext(PdfMargingTopContext);
const users = useRequest<any>({
resource: 'users',
action: 'get',
params: {
filter: {
id: userId,
},
},
});
useEffect(() => {
if (!users.loading) {
setValue(users.data.data?.pdf_top_margin || 0);
}
}, [users.loading]);
const change = debounce(async (v) => {
await api.resource('users').update({
filter: {
id: userId,
},
values: {
pdf_top_margin: Number(v),
},
});
setMargingTop(v);
}, 2000);
return (
<Input
placeholder=""
prefix="距上"
suffix="像素"
style={{ width: 100 }}
value={value}
onChange={(e) => {
change(e.target.value);
setValue(e.target.value);
}}
/>
);
};
export const RecordPrintSetupMargingTopInitializer = (props) => {
const schema = {
title: '{{ t("record print setup margingTop") }}',
'x-action': 'printSetupMargingTop',
'x-component': 'PrintSetupMargingTop',
'x-designer': 'Action.Designer',
};
return <ActionInitializer {...props} schema={schema} />;
};

View File

@ -61,7 +61,7 @@ export class RecordPreviewController {
@Action('pdf') @Action('pdf')
async printPreview(ctx: Context) { async printPreview(ctx: Context) {
const { const {
params: { recordId, isDouble, settingType }, params: { recordId, isDouble, settingType, margingTop },
} = ctx.action; } = ctx.action;
// 拉侧面文字说明 // 拉侧面文字说明
const pdfExplain = await ctx.db.getRepository('basic_configuration').find(); const pdfExplain = await ctx.db.getRepository('basic_configuration').find();
@ -87,6 +87,14 @@ export class RecordPreviewController {
record.nickname = user?.nickname || ''; record.nickname = user?.nickname || '';
record.userPhone = user?.phone || ''; record.userPhone = user?.phone || '';
record.pdfExplain = pdfExplain[0]?.out_of_storage_explain; record.pdfExplain = pdfExplain[0]?.out_of_storage_explain;
if (Number(margingTop)) {
record.margingTop = Number(margingTop);
} else {
// 查询当前用户信息
const currentUser = await ctx.db.getRepository('users').findOne({ filter: { id: ctx.state.currentUser.id } });
record.margingTop = Number(currentUser?.pdf_top_margin) || 0;
}
// 费用数据 // 费用数据
const feeData = await ctx.db.sequelize.query(this.sqlLoader.sqlFiles['pdf_record_fee'], { const feeData = await ctx.db.sequelize.query(this.sqlLoader.sqlFiles['pdf_record_fee'], {
replacements: { replacements: {

View File

@ -304,7 +304,7 @@ const PreviewDocument = ({
} }
return ( return (
<Document> <Document>
<Page size="A4" style={styles.page}> <Page size="A4" style={{ ...styles.page, marginTop: detail.margingTop }}>
<Text style={styles.title}>{recordsName}</Text> <Text style={styles.title}>{recordsName}</Text>
<Text style={styles.subTitle}>{detail.category === RecordCategory.inventory ? '盘点' : outOfStorage}</Text> <Text style={styles.subTitle}>{detail.category === RecordCategory.inventory ? '盘点' : outOfStorage}</Text>
<View style={styles.content}> <View style={styles.content}>