gm-printer 10.34.0 → 10.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +8 -0
- package/build/demo.js +9 -9
- package/package.json +1 -1
- package/src/common/diy_summary_helper.js +223 -0
- package/src/common/editor_edit_field.js +180 -4
- package/src/common/editor_store.js +270 -15
- package/src/editor/context_menu.js +81 -2
- package/src/printer/store.js +16 -2
- package/src/printer/table.js +95 -8
- package/src/printer/table_diy_overallOrder_tr.js +110 -39
- package/src/printer/table_diy_summary_tr.js +127 -0
- package/src/util.js +42 -0
package/package.json
CHANGED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { set, toJS } from 'mobx'
|
|
2
|
+
import _ from 'lodash'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 创建自定义合计功能的通用方法体(不包含装饰器)
|
|
6
|
+
* @param {string} configKey - 配置键名,如 'diyOverallOrder', 'diySubtotal', 'diyTagSubtotal'
|
|
7
|
+
* @param {string} defaultName - 默认名称,如 '自定义整单合计', '自定义每页合计'
|
|
8
|
+
* @returns {Object} 包含所有方法体的对象
|
|
9
|
+
*/
|
|
10
|
+
export function createDiySummaryStoreMethods(configKey, defaultName) {
|
|
11
|
+
// 将 configKey 转换为方法名格式,如 'diyOverallOrder' -> 'DiyOverallOrder'
|
|
12
|
+
const methodName = configKey
|
|
13
|
+
.split(/(?=[A-Z])/)
|
|
14
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
15
|
+
.join('')
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
// 显示/隐藏
|
|
19
|
+
[`set${methodName}Show`]: function(name, show) {
|
|
20
|
+
const arr = name.split('.')
|
|
21
|
+
const table = this.config.contents[arr[2]]
|
|
22
|
+
|
|
23
|
+
this.overallOrderShow = !this.overallOrderShow
|
|
24
|
+
if (table[configKey]) {
|
|
25
|
+
set(table[configKey], {
|
|
26
|
+
show: show ?? !table[configKey].show
|
|
27
|
+
})
|
|
28
|
+
} else {
|
|
29
|
+
set(table, {
|
|
30
|
+
[configKey]: {
|
|
31
|
+
show: true,
|
|
32
|
+
fields: [
|
|
33
|
+
{
|
|
34
|
+
name: `${defaultName}:`,
|
|
35
|
+
valueField: '{{列.出库金额}}',
|
|
36
|
+
style: { fontWeight: 'bold' },
|
|
37
|
+
rightName: `${defaultName}:`
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
this.config = toJS(this.config)
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// 样式设置
|
|
47
|
+
[`set${methodName}Style`]: function(value) {
|
|
48
|
+
if (this.selectedRegion) {
|
|
49
|
+
const flexStyle = {
|
|
50
|
+
left: 'flex-start',
|
|
51
|
+
center: 'center',
|
|
52
|
+
right: 'flex-end'
|
|
53
|
+
}
|
|
54
|
+
const arr = this.selectedRegion.split('.')
|
|
55
|
+
const configFields = this.config.contents[arr[2]]?.[configKey].fields
|
|
56
|
+
_.forEach(configFields, item => {
|
|
57
|
+
const oldStyle = item.style || {}
|
|
58
|
+
set(item, {
|
|
59
|
+
style: {
|
|
60
|
+
...oldStyle,
|
|
61
|
+
...value,
|
|
62
|
+
'justify-content': flexStyle[value.textAlign]
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// 设置大写金额
|
|
70
|
+
[`set${methodName}UpperCase`]: function() {
|
|
71
|
+
if (this.selectedRegion) {
|
|
72
|
+
this.overallOrderShow = !this.overallOrderShow
|
|
73
|
+
const arr = this.selectedRegion.split('.')
|
|
74
|
+
const config = this.config.contents[arr[2]]?.[configKey]
|
|
75
|
+
|
|
76
|
+
const oldNeedUpperCase = config?.needUpperCase
|
|
77
|
+
this.config.contents[arr[2]]?.[configKey] &&
|
|
78
|
+
set(config, { needUpperCase: !oldNeedUpperCase })
|
|
79
|
+
if (
|
|
80
|
+
this.config.contents[arr[2]]?.[configKey] &&
|
|
81
|
+
config.needUpperCase === false
|
|
82
|
+
) {
|
|
83
|
+
config.isUpperCaseBefore && set(config, { isUpperCaseBefore: false })
|
|
84
|
+
config.isUpperLowerCaseSeparate &&
|
|
85
|
+
set(config, { isUpperLowerCaseSeparate: false })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// 设置大写金额在前
|
|
91
|
+
[`set${methodName}UpperCaseBefore`]: function() {
|
|
92
|
+
if (this.selectedRegion) {
|
|
93
|
+
this.overallOrderShow = !this.overallOrderShow
|
|
94
|
+
const arr = this.selectedRegion.split('.')
|
|
95
|
+
const config = this.config.contents[arr[2]]?.[configKey]
|
|
96
|
+
|
|
97
|
+
const oldUpperCaseBefore = config?.isUpperCaseBefore
|
|
98
|
+
this.config.contents[arr[2]]?.[configKey] &&
|
|
99
|
+
set(config, { isUpperCaseBefore: !oldUpperCaseBefore })
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// 设置大小写金额分开
|
|
104
|
+
[`set${methodName}UpperLowerCaseSeparate`]: function() {
|
|
105
|
+
if (this.selectedRegion) {
|
|
106
|
+
this.overallOrderShow = !this.overallOrderShow
|
|
107
|
+
const arr = this.selectedRegion.split('.')
|
|
108
|
+
const config = this.config.contents[arr[2]]?.[configKey]
|
|
109
|
+
|
|
110
|
+
const oldUpperLowerCaseSeparate = config.isUpperLowerCaseSeparate
|
|
111
|
+
set(config, {
|
|
112
|
+
isUpperLowerCaseSeparate: !oldUpperLowerCaseSeparate
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
// 字段设置
|
|
118
|
+
[`set${methodName}ValueField`]: function(value) {
|
|
119
|
+
if (this.selectedRegion) {
|
|
120
|
+
this.overallOrderShow = !this.overallOrderShow
|
|
121
|
+
const arr = this.selectedRegion.split('.')
|
|
122
|
+
const config = this.config.contents[arr[2]]?.[configKey]
|
|
123
|
+
|
|
124
|
+
const oldValueField = config.fields?.[0]
|
|
125
|
+
set(oldValueField, {
|
|
126
|
+
valueField: value
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// 文案设置
|
|
132
|
+
[`set${methodName}Fields`]: function(value, isModifyRightText) {
|
|
133
|
+
if (this.selectedRegion) {
|
|
134
|
+
this.overallOrderShow = !this.overallOrderShow
|
|
135
|
+
const arr = this.selectedRegion.split('.')
|
|
136
|
+
const table = this.config.contents[arr[2]]
|
|
137
|
+
const config = table?.[configKey]
|
|
138
|
+
|
|
139
|
+
if (!config.fields) {
|
|
140
|
+
config.fields = []
|
|
141
|
+
}
|
|
142
|
+
if (!config.fields[0]) {
|
|
143
|
+
config.fields = [
|
|
144
|
+
{
|
|
145
|
+
name: `${defaultName}:`,
|
|
146
|
+
valueField: '{{列.出库金额}}',
|
|
147
|
+
style: { fontWeight: 'bold' },
|
|
148
|
+
rightName: `${defaultName}:`
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const targetField = config.fields[0]
|
|
154
|
+
if (!isModifyRightText) {
|
|
155
|
+
set(targetField, { name: value })
|
|
156
|
+
} else {
|
|
157
|
+
set(targetField, { rightName: value })
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 创建自定义合计功能的 UI 渲染函数(Editor 层)
|
|
166
|
+
* @param {Object} params - 配置参数
|
|
167
|
+
* @param {string} params.configKey - 配置键名
|
|
168
|
+
* @param {string} params.label - 显示标签
|
|
169
|
+
* @param {string} params.placeholder - 输入框占位符
|
|
170
|
+
* @param {string} params.showConfigKey - config 中控制显示的键名,如 'showDiyOverAllOrder'
|
|
171
|
+
* @returns {Function} 返回渲染函数
|
|
172
|
+
*/
|
|
173
|
+
export function createDiySummaryEditorRender({
|
|
174
|
+
configKey,
|
|
175
|
+
label,
|
|
176
|
+
placeholder,
|
|
177
|
+
showConfigKey
|
|
178
|
+
}) {
|
|
179
|
+
return function(editStore, handleStyleChange) {
|
|
180
|
+
const diyConfig = editStore.computedTableSpecialConfig?.[configKey]
|
|
181
|
+
const style = (diyConfig && diyConfig?.fields?.[0]?.style) || {}
|
|
182
|
+
const needUpperCase =
|
|
183
|
+
(editStore.computedTableSpecialConfig?.[configKey] &&
|
|
184
|
+
diyConfig?.needUpperCase) ||
|
|
185
|
+
false
|
|
186
|
+
const caseBefore =
|
|
187
|
+
(editStore.computedTableSpecialConfig?.[configKey] &&
|
|
188
|
+
diyConfig?.isUpperCaseBefore) ||
|
|
189
|
+
false
|
|
190
|
+
const upperLowerCaseSeparate = diyConfig?.isUpperLowerCaseSeparate || false
|
|
191
|
+
const valueField =
|
|
192
|
+
editStore.computedTableSpecialConfig?.[configKey]?.fields?.[0]?.valueField
|
|
193
|
+
|
|
194
|
+
const methodName = configKey
|
|
195
|
+
.split(/(?=[A-Z])/)
|
|
196
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
197
|
+
.join('')
|
|
198
|
+
|
|
199
|
+
const setStyleMethod = editStore[`set${methodName}Style`]
|
|
200
|
+
const setUpperCaseMethod = editStore[`set${methodName}UpperCase`]
|
|
201
|
+
const setUpperCaseBeforeMethod =
|
|
202
|
+
editStore[`set${methodName}UpperCaseBefore`]
|
|
203
|
+
const setUpperLowerCaseSeparateMethod =
|
|
204
|
+
editStore[`set${methodName}UpperLowerCaseSeparate`]
|
|
205
|
+
const setValueFieldMethod = editStore[`set${methodName}ValueField`]
|
|
206
|
+
const setFieldsMethod = editStore[`set${methodName}Fields`]
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
diyConfig,
|
|
210
|
+
style,
|
|
211
|
+
needUpperCase,
|
|
212
|
+
caseBefore,
|
|
213
|
+
upperLowerCaseSeparate,
|
|
214
|
+
valueField,
|
|
215
|
+
setStyleMethod,
|
|
216
|
+
setUpperCaseMethod,
|
|
217
|
+
setUpperCaseBeforeMethod,
|
|
218
|
+
setUpperLowerCaseSeparateMethod,
|
|
219
|
+
setValueFieldMethod,
|
|
220
|
+
setFieldsMethod
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -601,6 +601,15 @@ class EditorField extends React.Component {
|
|
|
601
601
|
/>
|
|
602
602
|
</>
|
|
603
603
|
)}
|
|
604
|
+
|
|
605
|
+
{this.renderDiySummaryEditor({
|
|
606
|
+
label: '自定义每页合计',
|
|
607
|
+
placeholder: '请输入要每页合计字段',
|
|
608
|
+
showConfigKey: 'showDiySubtotal',
|
|
609
|
+
configKey: 'diySubtotal',
|
|
610
|
+
editStore
|
|
611
|
+
})}
|
|
612
|
+
|
|
604
613
|
<Flex>
|
|
605
614
|
<Flex>{i18next.t('整单合计')}:</Flex>
|
|
606
615
|
<Fonter
|
|
@@ -705,8 +714,8 @@ class EditorField extends React.Component {
|
|
|
705
714
|
subtotalCheckText='大、小写金额分左右两边展示'
|
|
706
715
|
marginLeft
|
|
707
716
|
/>
|
|
708
|
-
<Flex>
|
|
709
|
-
<Flex alignCenter
|
|
717
|
+
{/* <Flex>
|
|
718
|
+
<Flex alignCenter>左侧文案修改:</Flex>
|
|
710
719
|
<Text
|
|
711
720
|
value={
|
|
712
721
|
diyOverallOrder && diyOverallOrder?.fields?.[0]
|
|
@@ -719,7 +728,28 @@ class EditorField extends React.Component {
|
|
|
719
728
|
margin: '5px 0 5px 0px'
|
|
720
729
|
}}
|
|
721
730
|
/>
|
|
722
|
-
</Flex>
|
|
731
|
+
</Flex> */}
|
|
732
|
+
<EditorText
|
|
733
|
+
label={i18next.t('左侧文案修改')}
|
|
734
|
+
value={
|
|
735
|
+
diyOverallOrder && diyOverallOrder?.fields?.[0]
|
|
736
|
+
? diyOverallOrder.fields[0].name
|
|
737
|
+
: ''
|
|
738
|
+
}
|
|
739
|
+
onChange={e =>
|
|
740
|
+
editStore.setDiyOverallOrderFields(e.target.value, 0)
|
|
741
|
+
}
|
|
742
|
+
/>
|
|
743
|
+
{diyOverallOrder?.isUpperLowerCaseSeparate && (
|
|
744
|
+
<EditorText
|
|
745
|
+
label={i18next.t('右侧文案修改')}
|
|
746
|
+
value={diyOverallOrder?.fields?.[0]?.rightName || ''}
|
|
747
|
+
onChange={e =>
|
|
748
|
+
editStore.setDiyOverallOrderFields(e.target.value, 1)
|
|
749
|
+
}
|
|
750
|
+
/>
|
|
751
|
+
)}
|
|
752
|
+
|
|
723
753
|
<Textarea
|
|
724
754
|
value={diyOverallOrderValueField}
|
|
725
755
|
placeholder={i18next.t('请输入要整单合计字段')}
|
|
@@ -802,12 +832,136 @@ class EditorField extends React.Component {
|
|
|
802
832
|
/>
|
|
803
833
|
</div>
|
|
804
834
|
</Flex>
|
|
835
|
+
|
|
836
|
+
{(() => {
|
|
837
|
+
const { diyCategorySubtotal } =
|
|
838
|
+
editStore.computedTableSpecialConfig || {}
|
|
839
|
+
|
|
840
|
+
const activeConfig = diyCategorySubtotal?.show
|
|
841
|
+
? {
|
|
842
|
+
showConfigKey: 'showDiyCategorySubtotal',
|
|
843
|
+
configKey: 'diyCategorySubtotal'
|
|
844
|
+
}
|
|
845
|
+
: {
|
|
846
|
+
showConfigKey: 'showDiyTagSubtotal',
|
|
847
|
+
configKey: 'diyTagSubtotal'
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
return this.renderDiySummaryEditor({
|
|
851
|
+
...activeConfig,
|
|
852
|
+
label: i18next.t('自定义分类/标签小计'),
|
|
853
|
+
placeholder: '请输入要分类/标签小计字段',
|
|
854
|
+
editStore
|
|
855
|
+
})
|
|
856
|
+
})()}
|
|
805
857
|
</>
|
|
806
858
|
)}
|
|
807
859
|
</div>
|
|
808
860
|
)
|
|
809
861
|
}
|
|
810
862
|
|
|
863
|
+
// 通用的自定义合计编辑界面渲染
|
|
864
|
+
renderDiySummaryEditor({
|
|
865
|
+
label,
|
|
866
|
+
placeholder,
|
|
867
|
+
showConfigKey,
|
|
868
|
+
configKey,
|
|
869
|
+
editStore
|
|
870
|
+
}) {
|
|
871
|
+
if (
|
|
872
|
+
showConfigKey &&
|
|
873
|
+
Object.prototype.hasOwnProperty.call(
|
|
874
|
+
editStore.config || {},
|
|
875
|
+
showConfigKey
|
|
876
|
+
) &&
|
|
877
|
+
!editStore.config[showConfigKey]
|
|
878
|
+
) {
|
|
879
|
+
return null
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const diyConfig = editStore.computedTableSpecialConfig?.[configKey]
|
|
883
|
+
const style = (diyConfig && diyConfig?.fields?.[0]?.style) || {}
|
|
884
|
+
const needUpperCase =
|
|
885
|
+
(editStore.computedTableSpecialConfig?.[configKey] &&
|
|
886
|
+
diyConfig?.needUpperCase) ||
|
|
887
|
+
false
|
|
888
|
+
const caseBefore =
|
|
889
|
+
(editStore.computedTableSpecialConfig?.[configKey] &&
|
|
890
|
+
diyConfig?.isUpperCaseBefore) ||
|
|
891
|
+
false
|
|
892
|
+
const upperLowerCaseSeparate = diyConfig?.isUpperLowerCaseSeparate || false
|
|
893
|
+
const valueField =
|
|
894
|
+
editStore.computedTableSpecialConfig?.[configKey]?.fields?.[0]?.valueField
|
|
895
|
+
|
|
896
|
+
const methodName = configKey
|
|
897
|
+
.split(/(?=[A-Z])/)
|
|
898
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
899
|
+
.join('')
|
|
900
|
+
|
|
901
|
+
const setStyleMethod = editStore[`set${methodName}Style`]
|
|
902
|
+
const setUpperCaseMethod = editStore[`set${methodName}UpperCase`]
|
|
903
|
+
const setUpperCaseBeforeMethod =
|
|
904
|
+
editStore[`set${methodName}UpperCaseBefore`]
|
|
905
|
+
const setUpperLowerCaseSeparateMethod =
|
|
906
|
+
editStore[`set${methodName}UpperLowerCaseSeparate`]
|
|
907
|
+
const setValueFieldMethod = editStore[`set${methodName}ValueField`]
|
|
908
|
+
const setFieldsMethod = editStore[`set${methodName}Fields`]
|
|
909
|
+
|
|
910
|
+
return (
|
|
911
|
+
<Flex>
|
|
912
|
+
<Flex>{label}:</Flex>
|
|
913
|
+
<div>
|
|
914
|
+
<Fonter style={style} onChange={setStyleMethod} />
|
|
915
|
+
<Separator />
|
|
916
|
+
<TextAlign style={style} onChange={setStyleMethod} />
|
|
917
|
+
<EditorSubtotalCheck
|
|
918
|
+
subtotalCheckDisabled
|
|
919
|
+
subtotalChecked={needUpperCase}
|
|
920
|
+
subtotalCheckOnChange={setUpperCaseMethod}
|
|
921
|
+
subtotalCheckText='显示大写金额'
|
|
922
|
+
marginLeft
|
|
923
|
+
/>
|
|
924
|
+
<EditorSubtotalCheck
|
|
925
|
+
subtotalCheckDisabled={needUpperCase}
|
|
926
|
+
subtotalChecked={caseBefore}
|
|
927
|
+
subtotalCheckOnChange={setUpperCaseBeforeMethod}
|
|
928
|
+
subtotalCheckText='大写金额在前'
|
|
929
|
+
marginLeft
|
|
930
|
+
/>
|
|
931
|
+
<EditorSubtotalCheck
|
|
932
|
+
subtotalCheckDisabled={needUpperCase}
|
|
933
|
+
subtotalChecked={upperLowerCaseSeparate}
|
|
934
|
+
subtotalCheckOnChange={setUpperLowerCaseSeparateMethod}
|
|
935
|
+
subtotalCheckText='大、小写金额分左右两边展示'
|
|
936
|
+
marginLeft
|
|
937
|
+
/>
|
|
938
|
+
<EditorText
|
|
939
|
+
label={i18next.t('左侧文案修改')}
|
|
940
|
+
value={
|
|
941
|
+
diyConfig && diyConfig?.fields?.[0]
|
|
942
|
+
? diyConfig.fields[0].name
|
|
943
|
+
: ''
|
|
944
|
+
}
|
|
945
|
+
onChange={e => setFieldsMethod(e.target.value, 0)}
|
|
946
|
+
/>
|
|
947
|
+
{diyConfig?.isUpperLowerCaseSeparate && (
|
|
948
|
+
<EditorText
|
|
949
|
+
label={i18next.t('右侧文案修改')}
|
|
950
|
+
value={diyConfig?.fields?.[0]?.rightName || ''}
|
|
951
|
+
onChange={e => setFieldsMethod(e.target.value, 1)}
|
|
952
|
+
/>
|
|
953
|
+
)}
|
|
954
|
+
<Textarea
|
|
955
|
+
value={valueField}
|
|
956
|
+
placeholder={placeholder}
|
|
957
|
+
onChange={value => setValueFieldMethod(value)}
|
|
958
|
+
/>
|
|
959
|
+
<TipInfo text={i18next.t('不支持双栏和三栏模式')} />
|
|
960
|
+
</div>
|
|
961
|
+
</Flex>
|
|
962
|
+
)
|
|
963
|
+
}
|
|
964
|
+
|
|
811
965
|
render() {
|
|
812
966
|
const { editStore } = this.props
|
|
813
967
|
|
|
@@ -857,7 +1011,7 @@ class EditorSubtotalCheck extends React.Component {
|
|
|
857
1011
|
onChange={subtotalCheckOnChange}
|
|
858
1012
|
/>
|
|
859
1013
|
</Flex>
|
|
860
|
-
<Flex> {
|
|
1014
|
+
<Flex> {subtotalCheckText}</Flex>
|
|
861
1015
|
</Flex>
|
|
862
1016
|
)
|
|
863
1017
|
}
|
|
@@ -871,4 +1025,26 @@ EditorSubtotalCheck.propTypes = {
|
|
|
871
1025
|
marginLeft: PropTypes.string
|
|
872
1026
|
}
|
|
873
1027
|
|
|
1028
|
+
function EditorText({ label, value, onChange }) {
|
|
1029
|
+
return (
|
|
1030
|
+
<>
|
|
1031
|
+
<Flex alignCenter>{label}:</Flex>
|
|
1032
|
+
<Text
|
|
1033
|
+
value={value}
|
|
1034
|
+
onChange={onChange}
|
|
1035
|
+
style={{
|
|
1036
|
+
width: '100px',
|
|
1037
|
+
margin: '5px 0 5px 0px'
|
|
1038
|
+
}}
|
|
1039
|
+
/>
|
|
1040
|
+
</>
|
|
1041
|
+
)
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
EditorText.propTypes = {
|
|
1045
|
+
label: PropTypes.string.isRequired,
|
|
1046
|
+
value: PropTypes.string.isRequired,
|
|
1047
|
+
onChange: PropTypes.func.isRequired
|
|
1048
|
+
}
|
|
1049
|
+
|
|
874
1050
|
export default EditorField
|