feat: 订单打印上边距可调整
This commit is contained in:
parent
5a7c78d791
commit
eb476a95e2
@ -12,13 +12,21 @@ export const PdfIsLoadContext = createContext({
|
||||
setSettingLoad: null,
|
||||
});
|
||||
|
||||
export const PdfMargingTopContext = createContext({
|
||||
margingTop: 0,
|
||||
setMargingTop: null,
|
||||
});
|
||||
|
||||
export const PdfIsDoubleProvider = (props) => {
|
||||
const [isDouble, setIsDouble] = useState(false);
|
||||
const [settingType, setSettingLoad] = useState(false);
|
||||
const [margingTop, setMargingTop] = useState(0);
|
||||
return (
|
||||
<PdfIsDoubleContext.Provider value={{ isDouble, setIsDouble }}>
|
||||
<PdfIsLoadContext.Provider value={{ settingType, setSettingLoad }}>{props.children}</PdfIsLoadContext.Provider>
|
||||
</PdfIsDoubleContext.Provider>
|
||||
<PdfMargingTopContext.Provider value={{ margingTop, setMargingTop }}>
|
||||
<PdfIsDoubleContext.Provider value={{ isDouble, setIsDouble }}>
|
||||
<PdfIsLoadContext.Provider value={{ settingType, setSettingLoad }}>{props.children}</PdfIsLoadContext.Provider>
|
||||
</PdfIsDoubleContext.Provider>
|
||||
</PdfMargingTopContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@ -26,7 +34,8 @@ export const useRecordPdfPath = () => {
|
||||
const record = useRecord();
|
||||
const { isDouble } = useContext(PdfIsDoubleContext);
|
||||
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 = () => {
|
||||
|
@ -32,7 +32,10 @@ import {
|
||||
useSettlementStyleSwitchActionProps,
|
||||
} from './schema-initializer/SettlementStyleSwitchActionInitializer';
|
||||
import { RecordPrintSetupActionInitializer, PrintSetup } from './schema-initializer/RecordPrintSetupActionInitializer';
|
||||
|
||||
import {
|
||||
RecordPrintSetupMargingTopInitializer,
|
||||
PrintSetupMargingTop,
|
||||
} from './schema-initializer/RecordPrintSetupMargingTopInitializer';
|
||||
export class PluginRentalClient extends Plugin {
|
||||
locale: Locale;
|
||||
async afterAdd() {}
|
||||
@ -69,6 +72,11 @@ export class PluginRentalClient extends Plugin {
|
||||
title: '{{t("Record print setup")}}',
|
||||
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', {
|
||||
type: 'item',
|
||||
title: '{{t("Settlement excel export")}}',
|
||||
@ -134,7 +142,9 @@ export class PluginRentalClient extends Plugin {
|
||||
SettlementStyleSwitchActionInitializer,
|
||||
SettlementStyleSwitchAction,
|
||||
RecordPrintSetupActionInitializer,
|
||||
RecordPrintSetupMargingTopInitializer,
|
||||
PrintSetup,
|
||||
PrintSetupMargingTop,
|
||||
});
|
||||
this.app.addScopes({
|
||||
useAddToChecklistActionProps,
|
||||
|
@ -0,0 +1,65 @@
|
||||
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({
|
||||
filterByTk: userId,
|
||||
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} />;
|
||||
};
|
@ -61,7 +61,7 @@ export class RecordPreviewController {
|
||||
@Action('pdf')
|
||||
async printPreview(ctx: Context) {
|
||||
const {
|
||||
params: { recordId, isDouble, settingType },
|
||||
params: { recordId, isDouble, settingType, margingTop },
|
||||
} = ctx.action;
|
||||
// 拉侧面文字说明
|
||||
const pdfExplain = await ctx.db.getRepository('basic_configuration').find();
|
||||
@ -87,6 +87,14 @@ export class RecordPreviewController {
|
||||
record.nickname = user?.nickname || '';
|
||||
record.userPhone = user?.phone || '';
|
||||
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'], {
|
||||
replacements: {
|
||||
|
@ -304,7 +304,7 @@ const PreviewDocument = ({
|
||||
}
|
||||
return (
|
||||
<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.subTitle}>{detail.category === RecordCategory.inventory ? '盘点' : outOfStorage}单</Text>
|
||||
<View style={styles.content}>
|
||||
|
Loading…
Reference in New Issue
Block a user