Skip to content

Commit

Permalink
Merge pull request #68 from gmfe/feature/salemenus
Browse files Browse the repository at this point in the history
自定义报价单打印
  • Loading branch information
Damon authored Oct 9, 2020
2 parents 0583600 + e133d83 commit 116f6ae
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 63 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gm-printer",
"version": "10.9.2",
"version": "10.10.0",
"description": "diy printer",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -36,14 +36,14 @@
"jsbarcode": "^3.11.0",
"lodash": "^4.17.10",
"mobx": "^4.3.0",
"mobx-react": "^6.0.3",
"mobx-react": "^6.1.1",
"moment": "^2.22.2",
"precss": "^4.0.0",
"prop-types": "^15.6.2",
"qrcode.react": "^0.9.2",
"query-string": "^6.1.0",
"react": "^16.8.5",
"react-dom": "^16.8.6"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@babel/cli": "^7.6.0",
Expand Down Expand Up @@ -88,16 +88,16 @@
"lodash": "^4.17.10",
"mini-css-extract-plugin": "^0.8.0",
"mobx": "^4.3.0",
"mobx-react": "^6.0.3",
"mobx-react": "^6.1.1",
"moment": "^2.22.2",
"path": "^0.12.7",
"postcss-loader": "^3.0.0",
"precss": "^4.0.0",
"prettier": "^1.18.2",
"prop-types": "^15.6.2",
"query-string": "^6.1.0",
"react": "^16.10.1",
"react-dom": "^16.10.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hot-loader": "^4.12.14",
"shelljs": "^0.8.3",
"style-loader": "^0.23.0",
Expand Down
39 changes: 20 additions & 19 deletions src/common/common_context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class CommonContextMenu extends React.Component {
handleSetTableConfig(value) {
const { editStore } = this.props
editStore.setConfigTableBy(this.state.name, 'className', value)
this.setState({
name: null
})
}

detectContextMenuTop = () => {
Expand Down Expand Up @@ -338,25 +341,23 @@ class CommonContextMenu extends React.Component {
{children}
{name && (
<Menu detectContextMenuTop={this.detectContextMenuTop}>
{
<div
ref={this.menuRef}
className='gm-printer-edit-contextmenu'
style={{
position: 'fixed',
...popup
}}
>
{arr.length === 1 && this.renderPanel()}
{arr.length === 3 && arr[1] === 'panel' && this.renderPanel()}
{arr.length === 3 && arr[1] === 'block' && this.renderBlock()}
{arr.length === 5 && arr[3] === 'block' && this.renderBlock()}
{arr.length === 5 && arr[1] === 'table' && this.renderColumn()}
{arr.length === 6 &&
arr[5] === 'counter' &&
this.renderCounterMenu()}
</div>
}
<div
ref={this.menuRef}
className='gm-printer-edit-contextmenu'
style={{
position: 'fixed',
...popup
}}
>
{arr.length === 1 && this.renderPanel()}
{arr.length === 3 && arr[1] === 'panel' && this.renderPanel()}
{arr.length === 3 && arr[1] === 'block' && this.renderBlock()}
{arr.length === 5 && arr[3] === 'block' && this.renderBlock()}
{arr.length === 5 && arr[1] === 'table' && this.renderColumn()}
{arr.length === 6 &&
arr[5] === 'counter' &&
this.renderCounterMenu()}
</div>
</Menu>
)}
</div>
Expand Down
8 changes: 3 additions & 5 deletions src/common/editor_edit_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Title,
TipInfo
} from '../common/component'
import { get, has } from 'mobx'
import { get } from 'mobx'
import PropTypes from 'prop-types'

@inject('editStore')
Expand Down Expand Up @@ -178,17 +178,15 @@ class EditorField extends React.Component {
const { specialConfig, subtotal } = editStore.computedTableSpecialConfig
// 小计样式,specialConfig可能是undefined
const specialStyle =
(has(editStore.computedTableSpecialConfig, 'specialConfig') &&
specialConfig.style) ||
{}
editStore.computedTableSpecialConfig?.specialConfig?.style || {}
// 小计是否大写
const specialTrNeedUpperCase =
(specialConfig && specialConfig.needUpperCase) || false
// 每页合计样式
const subtotalStyle = (subtotal && subtotal.style) || {}
// 每页合计是否大写
const subtotalNeedUpperCase =
(has(editStore.computedTableSpecialConfig, 'subtotal') &&
(editStore.computedTableSpecialConfig.subtotal &&
get(subtotal, 'needUpperCase')) ||
false

Expand Down
18 changes: 12 additions & 6 deletions src/common/editor_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class EditorStore {
@observable
tableCustomStyle = 'default'

@action
changeTableCustomStyle = v => {
@action.bound
changeTableCustomStyle(v) {
if (this.selectedRegion) {
const arr = this.selectedRegion.split('.')
if (arr.includes('table')) {
Expand All @@ -22,12 +22,15 @@ class EditorStore {
@computed
get computedPrinterKey() {
return _.map(this.config, (v, k) => {
if (k === 'page') {
return v.type + '_' + v.printDirection + v.size.width + v.size.height
if (k === '__key__' && v) {
return v
} else if (k === 'page') {
return v.type + 'PAGE' + v.printDirection + v.size.width + v.size.height
} else if (k === 'contents') {
return _.map(v, vv => {
if (vv.type === 'table') {
return (
'TABLE' +
vv.columns.length +
vv.className +
vv.dataKey +
Expand All @@ -38,7 +41,7 @@ class EditorStore {
} else {
return vv.style ? vv.style.height : ''
}
}).join('_')
}).join('/')
} else {
return v.style ? v.style.height : ''
}
Expand Down Expand Up @@ -593,13 +596,16 @@ class EditorStore {
if (type === 'table') {
this.config.contents.splice(index, 0, {
type: 'table',
className: '',
specialConfig: { style: {} },
dataKey: defaultTableDataKey, // 默认
subtotal: defaultTableSubtotal, // 默认的每页合计配置
columns: [
{
head: i18next.t('表头'),
headStyle: {
textAlign: 'center'
textAlign: 'center',
minWidth: '30px'
},
text: i18next.t('内容'),
style: {
Expand Down
1 change: 1 addition & 0 deletions src/common/editor_title.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class EditorTitle extends React.Component {
// 重置模板配置,但是保留原来模板名字
const config = {
...editStore.originConfig,
__key__: Date.now(), // 时间戳的key,直接让页面重新渲染!
name: editStore.config.name
}
editStore.init(config)
Expand Down
105 changes: 105 additions & 0 deletions src/editor_salemenus/context_menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import i18next from '../../locales'
import React from 'react'
import _ from 'lodash'
import CommonContextMenu from '../common/common_context_menu'
import { inject, observer } from 'mobx-react'
import { Printer } from '../printer'
import { hasSubtotalBtnTableDataKeySet } from './editor'

const blockTypeList = [
{ value: '', text: i18next.t('插入文本') },
{ value: 'line', text: i18next.t('插入线条') },
{ value: 'image', text: i18next.t('插入图片') },
{ value: 'qrcode', text: i18next.t('分享二维码') }
]

@inject(stores => ({
editStore: stores.editStore,
mockData: stores.mockData
}))
@observer
class ContextMenu extends React.Component {
/**
* 是否存在每页合计按钮,非异常明细才有按钮
* @param name => ContextMenu 的 this.state.name
* @return {boolean}
*/
hasSubtotalBtn = name => {
if (!name) return false

const arr = name.split('.')
if (_.includes(arr, 'table')) {
const dataKey = this.props.editStore.config.contents[arr[2]].dataKey
return hasSubtotalBtnTableDataKeySet.has(dataKey)
}
}

handleChangeTableDataKey = (key, name) => {
const { editStore } = this.props

editStore.changeTableDataKey(name, key)
}

handleSubtotal = name => {
const { editStore } = this.props

editStore.setSubtotalShow(name)
}

renderOrderActionBtn = name => {
if (!this.hasSubtotalBtn(name)) {
return null
}

const arr = name.split('.')
const { dataKey, subtotal } = this.props.editStore.config.contents[arr[2]]
const keyArr = dataKey.split('_')

const isMultiActive = keyArr.includes('multi')
const isCategoryActive = keyArr.includes('category')
const isSubtotalActive = subtotal.show

return (
<>
<div
onClick={this.handleChangeTableDataKey.bind(this, 'multi', name)}
className={isMultiActive ? 'active' : ''}
>
{i18next.t('双栏商品')}
</div>
<div
onClick={this.handleChangeTableDataKey.bind(this, 'category', name)}
className={isCategoryActive ? 'active' : ''}
>
{i18next.t('商品分类')}
</div>
<div
onClick={this.handleSubtotal.bind(this, name)}
className={isSubtotalActive ? 'active' : ''}
>
{i18next.t('每页合计')}
</div>
</>
)
}

render() {
const { editStore, mockData } = this.props
return (
<CommonContextMenu
renderTableAction={this.renderOrderActionBtn}
insertBlockList={blockTypeList}
>
<Printer
key={editStore.computedPrinterKey}
selected={editStore.selected}
selectedRegion={editStore.selectedRegion}
config={editStore.config}
data={mockData}
/>
</CommonContextMenu>
)
}
}

export default ContextMenu
Loading

0 comments on commit 116f6ae

Please sign in to comment.