From eb476a95e27cd30ab93362daa9594aeaa0162b33 Mon Sep 17 00:00:00 2001
From: lyx <2027667395@qq.com>
Date: Wed, 13 Mar 2024 21:29:43 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A2=E5=8D=95=E6=89=93=E5=8D=B0?=
=?UTF-8?q?=E4=B8=8A=E8=BE=B9=E8=B7=9D=E5=8F=AF=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/client/hooks/usePdfPath.tsx | 17 +++--
.../@hera/plugin-rental/src/client/index.tsx | 12 +++-
.../RecordPrintSetupMargingTopInitializer.tsx | 65 +++++++++++++++++++
.../src/server/actions/records-controller.ts | 10 ++-
.../pdf-documents/records-documentV2.tsx | 2 +-
5 files changed, 99 insertions(+), 7 deletions(-)
create mode 100644 packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx
diff --git a/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx b/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx
index 354ba5d7e..8e1d349a4 100644
--- a/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx
+++ b/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx
@@ -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 (
-
- {props.children}
-
+
+
+ {props.children}
+
+
);
};
@@ -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 = () => {
diff --git a/packages/plugins/@hera/plugin-rental/src/client/index.tsx b/packages/plugins/@hera/plugin-rental/src/client/index.tsx
index 59dadf520..398535839 100644
--- a/packages/plugins/@hera/plugin-rental/src/client/index.tsx
+++ b/packages/plugins/@hera/plugin-rental/src/client/index.tsx
@@ -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,
diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx
new file mode 100644
index 000000000..e303bffaa
--- /dev/null
+++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx
@@ -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({
+ 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 (
+ {
+ 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 ;
+};
diff --git a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts
index a192a824c..6a33a371c 100644
--- a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts
+++ b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts
@@ -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: {
diff --git a/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx b/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx
index 5bf5111a4..581e0d4c0 100644
--- a/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx
+++ b/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx
@@ -304,7 +304,7 @@ const PreviewDocument = ({
}
return (
-
+
{recordsName}
{detail.category === RecordCategory.inventory ? '盘点' : outOfStorage}单