Will done

This commit is contained in:
devezhao-mbp 2019-12-09 23:44:30 +08:00
parent 215082133e
commit 94efc05da6
8 changed files with 265 additions and 229 deletions

View file

@ -88,7 +88,8 @@
"$pgt": true,
"$stopEvent": true,
"$addResizeHandler": true,
"$lang": true
"$lang": true,
"$empty": true
},
"rules": {
"strict": 0,

View file

@ -23952,7 +23952,8 @@ fieldset[disabled] .full-calendar .fc-button:hover {
.select2-container--default .select2-selection--multiple .select2-selection__rendered .select2-selection__clear {
right: 20px;
font-size: 1.35rem;
top: -1px;
top: -2px;
font-weight: normal;
}
.select2-container--default .select2-selection--multiple .select2-selection__rendered .select2-selection__clear {

View file

@ -299,7 +299,7 @@ body {
color: #aaa;
width: 20px;
height: 20px;
margin-top: 8px;
margin-top: 7px;
text-align: center;
border-radius: 2px;
background-color: #eee;
@ -329,14 +329,43 @@ body {
text-align: right;
}
.rbview-form .form-group.row.editable>div .edit-oper>.btn {
width: 26px;
height: 26px;
.rbview-form .form-group.row.editable>div .edit-oper .btn {
width: 28px;
height: 28px;
overflow: hidden;
line-height: 1.1;
padding: 0;
min-width: 0;
min-height: 0;
font-weight: bold;
margin-left: -1px;
}
.type-AVATAR .edit-oper,
.type-BOOL .edit-oper,
.type-FILE .edit-oper,
.type-MULTISELECT .edit-oper,
.type-IMAGE .edit-oper {
border-top: 1px solid #dbdbdb;
}
.type-AVATAR .edit-oper {
margin-top: 7px;
}
.type-IMAGE .edit-oper {
margin-top: -2px;
}
.type-BOOL .edit-oper {
margin-top: -8px;
}
.type-MULTISELECT .edit-oper {
margin-top: -1px;
}
.rbview-form.readonly .form-group.row.editable a.edit {
display: none !important;
width: 0 !important;
height: 0 !important;
}

View file

@ -27,7 +27,7 @@ class ApprovalProcessor extends React.Component {
}
renderStateProcessing() {
$('.J_edit,.J_delete,.J_add-slave').attr('disabled', true)
window.RbViewPage && window.RbViewPage.setReadonly(true)
let aMsg = '当前记录正在审批中'
if (this.state.imApprover) {
if (this.state.imApproveSatate === 1) aMsg = '当前记录正在等待你审批'
@ -44,9 +44,7 @@ class ApprovalProcessor extends React.Component {
}
renderStateApproved() {
$('.J_edit,.J_delete,.J_add-slave').remove()
window.RbViewPage && window.RbViewPage.cleanViewActionButton()
window.RbViewPage && window.RbViewPage.setReadonly(true)
return (<div className="alert alert-success shadow-sm">
<button className="close btn btn-secondary" onClick={this.viewSteps}>详情</button>
<div className="icon"><span className="zmdi zmdi-check"></span></div>
@ -73,9 +71,7 @@ class ApprovalProcessor extends React.Component {
}
componentDidMount() {
$.get(`${rb.baseUrl}/app/entity/approval/state?record=${this.props.id}`, (res) => {
this.setState(res.data)
})
$.get(`${rb.baseUrl}/app/entity/approval/state?record=${this.props.id}`, (res) => this.setState(res.data))
}
submit = () => {

View file

@ -288,7 +288,6 @@ class RbList extends React.Component {
if ($this.prop('checked')) selected.push($this.parents('tr').data('id'))
})
if (selected.length === 0 && noWarn !== true) RbHighbar.create('未选中任何记录')
console.log(selected)
return selected
}

View file

@ -9,7 +9,9 @@ class RbFormAvatar extends RbFormElement {
let aUrl = rb.baseUrl + (this.state.value ? `/filex/img/${this.state.value}?imageView2/2/w/100/interlace/1/q/100` : '/assets/img/avatar.png')
return <div className="img-field avatar">
<span title={this.props.readonly ? null : '选择头像'}>
{!this.props.readonly && <input ref={(c) => this._fieldValue__input = c} type="file" className="inputfile" id={`${this.props.field}-input`} accept="image/png,image/jpeg,image/gif" />}
{!this.props.readonly &&
<input ref={(c) => this._fieldValue__input = c} type="file" className="inputfile" id={`${this.props.field}-input`} accept="image/png,image/jpeg,image/gif" />
}
<label htmlFor={`${this.props.field}-input`} className="img-thumbnail img-upload"><img src={aUrl} alt="头像" /></label>
</span>
</div>
@ -20,18 +22,19 @@ class RbFormAvatar extends RbFormElement {
return <div className="img-field avatar"><a className="img-thumbnail img-upload"><img src={aUrl} /></a></div>
}
componentDidMount() {
super.componentDidMount()
if (this.state.viewMode === true || this.props.readonly) return
let mp
$createUploader(this._fieldValue__input, (res) => {
if (!mp) mp = new Mprogress({ template: 1, start: true })
mp.set(res.percent / 100) // 0.x
}, (res) => {
mp.end()
this.handleChange({ target: { value: res.key } }, true)
})
onEditModeChanged(destroy) {
if (destroy) {
// NOOP
} else {
let mp
$createUploader(this._fieldValue__input, (res) => {
if (!mp) mp = new Mprogress({ template: 1, start: true })
mp.set(res.percent / 100) // 0.x
}, (res) => {
mp.end()
this.handleChange({ target: { value: res.key } }, true)
})
}
}
// Not implemented

View file

@ -146,7 +146,7 @@ class RbForm extends React.Component {
return <div className="rbform">
<div className="form" ref={(c) => this._form = c}>
{this.props.children.map((child) => {
return React.cloneElement(child, { $$$parent: this, ref: 'reffield-' + child.props.field })
return React.cloneElement(child, { $$$parent: this, ref: 'field-' + child.props.field })
// Has error in strict-mode
//child.$$$parent = that; return child
})}
@ -198,10 +198,10 @@ class RbForm extends React.Component {
if (!data || data.length === 0) return
data.forEach((item) => {
// eslint-disable-next-line react/no-string-refs
let ref = this.refs['reffield-' + item.field]
if (ref) {
if (item.fillinForce !== true && !!ref.getValue()) return
if ((this.isNew === true && item.whenCreate === true) || (this.isNew !== true && item.whenUpdate === true)) ref.setValue(item.value)
let reff = this.refs['field-' + item.field]
if (reff) {
if (item.fillinForce !== true && !!reff.getValue()) return
if ((this.isNew && item.whenCreate) || (!this.isNew && item.whenUpdate)) reff.setValue(item.value)
}
})
}
@ -280,6 +280,9 @@ class RbForm extends React.Component {
}
}
//
const EDIT_ON_VIEW = rb.env === 'dev'
//
class RbFormElement extends React.Component {
constructor(props) {
@ -298,16 +301,18 @@ class RbFormElement extends React.Component {
colWidths[0] = 4
if (props.isFull === true) colWidths = [2, 10]
}
const editable = props.onView && !props.readonly
const editable = EDIT_ON_VIEW && props.onView && !props.readonly
return <div className={`form-group row type-${props.type} ${editable ? 'editable' : ''}`} data-field={props.field}>
<label ref={(c) => this._fieldLabel = c} className={`col-12 col-form-label text-sm-right col-sm-${colWidths[0]} ${!props.onView && !props.nullable && 'required'}`}>{props.label}</label>
<div className={'col-12 col-sm-' + colWidths[1]}>
{this.state.viewMode ? this.renderViewElement() : this.renderElement()}
<div ref={(c) => this._fieldText = c} className={'col-12 col-sm-' + colWidths[1]}>
{(!props.onView || (editable && this.state.editMode)) ? this.renderElement() : this.renderViewElement()}
{!props.onView && props.tip && <p className="form-text">{props.tip}</p>}
{editable && this.state.viewMode && <a className="edit" title="编辑" onClick={() => this.toggleEdit(false)} />}
{editable && !this.state.viewMode && <div className="edit-oper">
<button className="btn btn-secondary" onClick={this.handleEdit}><i className="icon zmdi zmdi-check"></i></button>
<button className="btn btn-secondary" onClick={() => this.toggleEdit(true)}><i className="icon zmdi zmdi-close"></i></button>
{editable && !this.state.editMode && <a className="edit" title="编辑" onClick={() => this.toggleEditMode(true)} />}
{editable && this.state.editMode && <div className="edit-oper">
<div className="btn-group">
<button type="button" className="btn btn-secondary" onClick={this.handleEditConfirm}><i className="icon zmdi zmdi-check"></i></button>
<button type="button" className="btn btn-secondary" onClick={() => this.toggleEditMode(false)}><i className="icon zmdi zmdi-close"></i></button>
</div>
</div>}
</div>
</div>
@ -321,9 +326,9 @@ class RbFormElement extends React.Component {
}
//
renderViewElement(forceText) {
let text = forceText === undefined ? this.state.value : forceText
if ($.type(text) === 'array' && text.length === 0) text = null
renderViewElement() {
let text = arguments.length > 0 ? arguments[0] : this.state.value // use `forceText`
if (text && $empty(text)) text = null
return <React.Fragment>
<div className="form-control-plaintext">{text || (<span className="text-muted"></span>)}</div>
</React.Fragment>
@ -331,11 +336,25 @@ class RbFormElement extends React.Component {
componentDidMount() {
const props = this.props
//
if (props.nullable === false && props.readonly === false && props.onView !== true) {
if (!props.value) props.$$$parent.setFieldValue(props.field, null, props.label + '不能为空')
if (!props.onView) {
//
if (props.nullable === false && props.readonly === false) {
$empty(props.value) && props.$$$parent.setFieldValue(props.field, null, props.label + '不能为空')
}
props.tip && $(this._fieldLabel).find('i.zmdi').tooltip({ placement: 'right' })
}
if (!props.onView && !this.props.readonly) this.onEditModeChanged()
}
componentWillUnmount() { this.onEditModeChanged(true) }
onEditModeChanged(destroy) {
if (destroy) {
if (this.__select2) {
if ($.type(this.__select2) === 'array') $(this.__select2).each(function () { this.select2('destroy') })
else this.__select2.select2('destroy')
this.__select2 = null
}
}
if (!props.onView && props.tip) $(this._fieldLabel).find('i.zmdi').tooltip({ placement: 'right' })
}
//
@ -349,18 +368,19 @@ class RbFormElement extends React.Component {
this.setState({ value: '' }, () => this.checkValue())
}
//
toggleEdit(viewMode, newValue) {
this.setState({ viewMode: viewMode }, () => {
if (this.state.viewMode) {
if (newValue === undefined) {
newValue = this.state.newValue === undefined ? this.props.value : this.state.newValue
}
this.setState({ value: newValue, newValue: newValue })
//
toggleEditMode(mode) {
this.setState({ editMode: mode }, () => {
if (this.state.editMode) {
this.onEditModeChanged()
} else {
let newValue = arguments.length > 1 ? arguments[1] // use `newValue`
: (this.state.newValue === undefined ? this.props.value : this.state.newValue)
this.setState({ value: newValue, newValue: newValue || null }, () => this.onEditModeChanged(true))
}
})
}
handleEdit = () => {
handleEditConfirm = () => {
this.props.$$$parent.saveSingleFieldValue && this.props.$$$parent.saveSingleFieldValue(this)
}
@ -388,19 +408,13 @@ class RbFormElement extends React.Component {
//
isValueUnchanged() {
debugger
let propValue = this.state.newValue === undefined ? this.props.value : this.state.newValue
return $same(propValue || '', this.state.value || '')
}
// Getter / Setter
setValue(val) {
this.handleChange({ target: { value: val } }, true)
}
getValue() {
return this.state.value
}
setValue(val) { this.handleChange({ target: { value: val } }, true) }
getValue() { return this.state.value }
}
class RbFormText extends RbFormElement {
@ -434,7 +448,7 @@ class RbFormEMail extends RbFormText {
renderViewElement() {
if (!this.state.value) return super.renderViewElement()
return <div className="form-control-plaintext"><a href={'mailto:' + this.state.value} className="link">{this.state.value}</a></div>
return <div className="form-control-plaintext"><a title="发送邮件" href={'mailto:' + this.state.value} className="link">{this.state.value}</a></div>
}
isValueError() {
@ -449,11 +463,15 @@ class RbFormPhone extends RbFormText {
super(props)
}
renderViewElement() {
if (!this.state.value) return super.renderViewElement()
return <div className="form-control-plaintext"><a title="拨打电话" href={'tel:' + this.state.value} className="link">{this.state.value}</a></div>
}
isValueError() {
let err = super.isValueError()
if (err) return err
if (!!this.state.value && $regex.isTel(this.state.value) === false) '电话/手机格式不正确'
return null
return (!!this.state.value && $regex.isTel(this.state.value) === false) ? '电话/手机格式不正确' : null
}
}
@ -466,7 +484,8 @@ class RbFormNumber extends RbFormText {
let err = super.isValueError()
if (err) return err
if (!!this.state.value && $regex.isNumber(this.state.value) === false) return '整数格式不正确'
if (!!this.state.value && this.props.notNegative === 'true' && parseFloat(this.state.value) < 0) return '不允许为负数'
// eslint-disable-next-line eqeqeq
if (!!this.state.value && this.props.notNegative === true && parseFloat(this.state.value) < 0) return '不允许为负数'
return null
}
}
@ -480,7 +499,8 @@ class RbFormDecimal extends RbFormText {
let err = super.isValueError()
if (err) return err
if (!!this.state.value && $regex.isDecimal(this.state.value) === false) return '货币格式不正确'
if (!!this.state.value && this.props.notNegative === 'true' && parseFloat(this.state.value) < 0) return '不允许为负数'
// eslint-disable-next-line eqeqeq
if (!!this.state.value && this.props.notNegative == true && parseFloat(this.state.value) < 0) return '不允许为负数'
return null
}
}
@ -497,10 +517,21 @@ class RbFormTextarea extends RbFormElement {
renderViewElement() {
if (!this.state.value) return super.renderViewElement()
return <div className="form-control-plaintext">
return <div className="form-control-plaintext" ref={(c) => this._textarea = c}>
{this.state.value.split('\n').map((line, idx) => { return <p key={'kl-' + idx}>{line}</p> })}
</div>
}
componentDidMount() {
super.componentDidMount()
this.unmountFieldComp()
}
unmountFieldComp() {
if (this._textarea) $(this._textarea).perfectScrollbar()
}
mountFieldComp() {
if (this._textarea) $(this._textarea).perfectScrollbar('destroy')
}
}
class RbFormDateTime extends RbFormElement {
@ -519,40 +550,37 @@ class RbFormDateTime extends RbFormElement {
</div>
}
componentDidMount() {
super.componentDidMount()
if (this.state.viewMode || this.props.readonly) return
onEditModeChanged(destroy) {
if (destroy) {
if (this.__datetimepicker) {
this.__datetimepicker.datetimepicker('remove')
this.__datetimepicker = null
}
} else {
const format = (this.props.datetimeFormat || this.props.dateFormat).replace('mm', 'ii').toLowerCase()
let minView = 0
if (format.length === 7) minView = 'year'
else if (format.length === 10) minView = 'month'
const format = (this.props.datetimeFormat || this.props.dateFormat).replace('mm', 'ii').toLowerCase()
let minView = 0
if (format.length === 7) minView = 'year'
else if (format.length === 10) minView = 'month'
const that = this
this.__datetimepicker = $(this._fieldValue).datetimepicker({
componentIcon: 'zmdi zmdi-calendar',
navIcons: { rightIcon: 'zmdi zmdi-chevron-right', leftIcon: 'zmdi zmdi-chevron-left' },
format: format || 'yyyy-mm-dd hh:ii:ss',
minView: minView,
startView: minView === 'year' ? 'year' : 'month',
weekStart: 1,
autoclose: true,
language: 'zh',
todayHighlight: true,
showMeridian: false,
keyboardNavigation: false,
minuteStep: 5,
}).on('changeDate', function () {
let val = $(this).val()
that.handleChange({ target: { value: val } }, true)
})
$(this._fieldValue__icon).click(() => this.__datetimepicker.datetimepicker('show'))
}
componentWillUnmount() {
if (this.__datetimepicker) {
this.__datetimepicker.datetimepicker('remove')
this.__datetimepicker = null
const that = this
this.__datetimepicker = $(this._fieldValue).datetimepicker({
componentIcon: 'zmdi zmdi-calendar',
navIcons: { rightIcon: 'zmdi zmdi-chevron-right', leftIcon: 'zmdi zmdi-chevron-left' },
format: format || 'yyyy-mm-dd hh:ii:ss',
minView: minView,
startView: minView === 'year' ? 'year' : 'month',
weekStart: 1,
autoclose: true,
language: 'zh',
todayHighlight: true,
showMeridian: false,
keyboardNavigation: false,
minuteStep: 5,
}).on('changeDate', function () {
let val = $(this).val()
that.handleChange({ target: { value: val } }, true)
})
$(this._fieldValue__icon).click(() => this.__datetimepicker.datetimepicker('show'))
}
}
}
@ -594,8 +622,7 @@ class RbFormImage extends RbFormElement {
renderViewElement() {
const value = this.state.value
if (!value || value.length === 0) return super.renderViewElement()
if ($empty(value)) return super.renderViewElement()
return <div className="img-field">
{value.map((item, idx) => {
return <span key={'img-' + item}>
@ -607,20 +634,21 @@ class RbFormImage extends RbFormElement {
</div>
}
componentDidMount() {
super.componentDidMount()
if (this.state.viewMode || this.props.readonly) return
let mp
$createUploader(this._fieldValue__input, (res) => {
if (!mp) mp = new Mprogress({ template: 1, start: true })
mp.set(res.percent / 100) // 0.x
}, (res) => {
mp.end()
let paths = this.state.value || []
paths.push(res.key)
this.handleChange({ target: { value: paths } }, true)
})
onEditModeChanged(destroy) {
if (destroy) {
// NOOP
} else {
let mp
$createUploader(this._fieldValue__input, (res) => {
if (!mp) mp = new Mprogress({ template: 1, start: true })
mp.set(res.percent / 100) // 0.x
}, (res) => {
mp.end()
let paths = this.state.value || []
paths.push(res.key)
this.handleChange({ target: { value: paths } }, true)
})
}
}
removeItem(item) {
@ -636,11 +664,6 @@ class RbFormImage extends RbFormElement {
if (this.__minUpload > 0 && ups < this.__minUpload) return `至少需要上传 ${this.__minUpload}`
if (this.__maxUpload < ups) return `最多允许上传 ${this.__maxUpload}`
}
setValue(val) {
val = JSON.parse(val || '[]')
this.handleChange({ target: { value: val } }, true)
}
}
class RbFormFile extends RbFormImage {
@ -673,8 +696,7 @@ class RbFormFile extends RbFormImage {
renderViewElement() {
const value = this.state.value
if (!value || value.length === 0) return super.renderViewElement()
if ($empty(value)) return super.renderViewElement()
return <div className="file-field">
{value.map((item) => {
let fileName = $fileCutName(item)
@ -719,33 +741,23 @@ class RbFormPickList extends RbFormElement {
}
renderViewElement() {
return super.renderViewElement(__findOptionText(this.state.options, this.props.value))
return super.renderViewElement(__findOptionText(this.state.options, this.state.value))
}
componentDidMount() {
super.componentDidMount()
if (this.state.viewMode || this.props.readonly) return
onEditModeChanged(destroy) {
if (destroy) {
super.onEditModeChanged(destroy)
} else {
this.__select2 = $(this._fieldValue).select2({
placeholder: '选择' + this.props.label
})
if (!this.state.value) this.__select2.val(null)
this.__select2 = $(this._fieldValue).select2({
placeholder: '选择' + this.props.label
})
$setTimeout(() => {
// No value
if (!this.props.$$$parent.isNew && !this.props.value) this.__select2.val(null)
let that = this
const that = this
this.__select2.on('change', function (e) {
let val = e.target.value
that.handleChange({ target: { value: val } }, true)
}).trigger('change')
}, 100)
}
componentWillUnmount() {
if (this.__select2) {
this.__select2.select2('destroy')
this.__select2 = null
}
}
@ -771,7 +783,7 @@ class RbFormReference extends RbFormElement {
renderViewElement() {
const value = this.state.value
if (!value) return super.renderViewElement()
if ($empty(value)) return super.renderViewElement()
if (typeof value === 'string') return <div className="form-control-plaintext">{value}</div>
if (!value.id) return <div className="form-control-plaintext">{value.text}</div>
@ -781,45 +793,38 @@ class RbFormReference extends RbFormElement {
}
_clickView = (e) => window.RbViewPage && window.RbViewPage.clickView(e.target)
componentDidMount() {
super.componentDidMount()
if (this.state.viewMode || this.props.readonly) return
const entity = this.props.$$$parent.props.entity
const field = this.props.field
this.__select2 = $initReferenceSelect2(this._fieldValue, {
name: field,
label: this.props.label,
entity: entity
})
$setTimeout(() => {
const val = this.props.value
if (val) {
let o = new Option(val.text, val.id, true, true)
this.__select2.append(o).trigger('change')
}
let that = this
this.__select2.on('change', function (e) {
let v = e.target.value
if (v) {
$.post(`${rb.baseUrl}/commons/search/recently-add?id=${v}`)
//
$.post(`${rb.baseUrl}/app/entity/extras/fillin-value?entity=${entity}&field=${that.props.field}&source=${v}`, (res) => {
res.error_code === 0 && res.data.length > 0 && that.props.$$$parent.setAutoFillin(res.data)
})
}
that.handleChange({ target: { value: v } }, true)
onEditModeChanged(destroy) {
if (destroy) {
super.onEditModeChanged(destroy)
} else {
const entity = this.props.$$$parent.props.entity
const field = this.props.field
this.__select2 = $initReferenceSelect2(this._fieldValue, {
name: field,
label: this.props.label,
entity: entity
})
}, 100)
}
componentWillUnmount() {
if (this.__select2) {
this.__select2.select2('destroy')
this.__select2 = null
$setTimeout(() => {
const val = this.props.value
if (val) {
let o = new Option(val.text, val.id, true, true)
this.__select2.append(o).trigger('change')
}
const that = this
this.__select2.on('change', function (e) {
let v = e.target.value
if (v) {
$.post(`${rb.baseUrl}/commons/search/recently-add?id=${v}`)
//
$.post(`${rb.baseUrl}/app/entity/extras/fillin-value?entity=${entity}&field=${that.props.field}&source=${v}`, (res) => {
res.error_code === 0 && res.data.length > 0 && that.props.$$$parent.setAutoFillin(res.data)
})
}
that.handleChange({ target: { value: v } }, true)
})
}, 100)
}
}
@ -847,43 +852,39 @@ class RbFormClassification extends RbFormElement {
return <div className="input-group datetime-field">
<select ref={(c) => this._fieldValue = c} className="form-control form-control-sm" />
<div className="input-group-append">
<button className="btn btn-secondary" type="button" onClick={() => this.showSelector()}><i className="icon zmdi zmdi-search" /></button>
<button className="btn btn-secondary" type="button" onClick={this.showSelector}><i className="icon zmdi zmdi-search" /></button>
</div>
</div>
}
renderViewElement() {
return super.renderViewElement(this.props.value ? this.props.value.text : null)
return super.renderViewElement(this.state.value ? this.state.value.text : null)
}
componentDidMount() {
super.componentDidMount()
if (this.state.viewMode || this.props.readonly) return
onEditModeChanged(destroy) {
if (destroy) {
super.onEditModeChanged(destroy)
this.__cached = null
if (this.__selector) {
this.__selector.hide(true)
this.__selector = null
}
} else {
this.__select2 = $initReferenceSelect2(this._fieldValue, {
name: this.props.field,
label: this.props.label,
entity: this.props.$$$parent.props.entity,
searchType: 'classification'
})
this.__select2 = $initReferenceSelect2(this._fieldValue, {
name: this.props.field,
label: this.props.label,
entity: this.props.$$$parent.props.entity,
searchType: 'classification'
})
const value = this.state.newValue === undefined ? this.props.value : this.state.newValue
value && this.setClassificationValue(value)
if (this.props.value) this.giveValue(this.props.value)
this.__select2.on('change', () => {
let v = this.__select2.val()
if (v) $.post(`${rb.baseUrl}/commons/search/recently-add?id=${v}&type=d${this.props.classification}`)
this.handleChange({ target: { value: v } }, true)
})
}
componentWillUnmount() {
if (this.__select2) {
this.__select2.select2('destroy')
this.__select2 = null
}
if (this.__selector) {
this.__selector.hide(true)
this.__selector = null
this.__select2.on('change', () => {
let v = this.__select2.val()
if (v) $.post(`${rb.baseUrl}/commons/search/recently-add?id=${v}&type=d${this.props.classification}`)
this.handleChange({ target: { value: v } }, true)
})
}
}
@ -893,27 +894,27 @@ class RbFormClassification extends RbFormElement {
}
setValue(val) {
if (val) this.giveValue(val)
if (val && val.id) this.setClassificationValue(val)
else this.__select2.val(null).trigger('change')
}
showSelector() {
showSelector = () => {
if (this.__selector) this.__selector.show()
else {
let p = this.props
renderRbcomp(<ClassificationSelector entity={p.$$$parent.state.entity} field={p.field} label={p.label} openLevel={p.openLevel} $$$parent={this} />, null, function () { this.__selector = this })
}
}
giveValue(s) {
let data = this.__data || {}
setClassificationValue(s) {
if (!s.id) return
let data = this.__cached || {}
if (data[s.id]) {
this.__select2.val(s.id).trigger('change')
} else {
} else if (this._fieldValue) {
let o = new Option(s.text, s.id, true, true)
$(this._fieldValue).append(o).trigger('change')
data[s.id] = s.text
this.__data = data
this.__cached = data
}
}
}
@ -940,7 +941,6 @@ class RbFormMultiSelect extends RbFormElement {
renderViewElement() {
const value = this.state.value
if (!value) return super.renderViewElement()
return <div className="form-control-plaintext">
{__findMultiTexts(this.props.options, value).map((item) => {
return <span key={'m-' + item} className="badge">{item}</span>
@ -955,6 +955,7 @@ class RbFormMultiSelect extends RbFormElement {
}
}
const BoolOptions = { 'T': '是', 'F': '否' }
class RbFormBool extends RbFormElement {
constructor(props) {
super(props)
@ -976,8 +977,7 @@ class RbFormBool extends RbFormElement {
}
renderViewElement() {
let options = { 'T': '是', 'F': '否' }
return super.renderViewElement(this.state.value ? options[this.state.value] : null)
return super.renderViewElement(this.state.value ? BoolOptions[this.state.value] : null)
}
changeValue = (e) => {
@ -1202,7 +1202,7 @@ class ClassificationSelector extends React.Component {
$(this._select2).each(function () {
text.push(this.select2('data')[0].text)
})
this.props.$$$parent.giveValue({ id: v, text: text.join('.') })
this.props.$$$parent.setClassificationValue({ id: v, text: text.join('.') })
this.hide()
}
}

View file

@ -59,7 +59,6 @@ class RbViewForm extends React.Component {
hideLoading() {
let ph = (parent && parent.RbViewModal) ? parent.RbViewModal.holder(this.state.id) : null
ph && ph.hideLoading()
$(this._viewForm).find('.type-NTEXT .form-control-plaintext').perfectScrollbar()
}
showAgain = (handle) => this.checkDrityData(handle)
@ -96,10 +95,10 @@ class RbViewForm extends React.Component {
saveSingleFieldValue(fieldComp) { setTimeout(() => this._saveSingleFieldValue(fieldComp), 30) }
_saveSingleFieldValue(fieldComp) {
const fieldName = fieldComp.props.field
let val = this.__FormData[fieldName]
const val = this.__FormData[fieldName]
// Unchanged
if (!val) {
fieldComp.toggleEdit(true)
fieldComp.toggleEditMode(false)
return
}
if (val.error) {
@ -110,11 +109,12 @@ class RbViewForm extends React.Component {
let _data = { metadata: { entity: this.props.entity, id: this.props.id } }
_data[fieldName] = val.value
const btns = $(fieldComp._fieldText).find('.edit-oper .btn').button('loading')
$.post(`${rb.baseUrl}/app/entity/record-save?single=true`, JSON.stringify(_data), (res) => {
btns.button('reset')
if (res.error_code === 0) {
this.setFieldUnchanged(fieldName)
let newValue = (res.data || {})[fieldName] || fieldComp.state.value || null
fieldComp.toggleEdit(true, newValue)
fieldComp.toggleEditMode(false, res.data[fieldName])
}
else if (res.error_code === 499) renderRbcomp(<RepeatedViewer entity={this.props.entity} data={res.data} />)
else RbHighbar.error(res.error_msg)
@ -125,7 +125,7 @@ class RbViewForm extends React.Component {
const detectViewElement = function (item) {
if (!window.detectElement) throw 'detectElement undef'
item.onView = true
item.viewMode = true
item.editMode = false
item.key = 'col-' + (item.field === '$DIVIDER$' ? $random() : item.field)
return <div className={`col-12 col-sm-${item.isFull ? 12 : 6}`} key={item.key}>{window.detectElement(item)}</div>
}
@ -407,6 +407,13 @@ const RbViewPage = {
reload() {
parent && parent.RbViewModal && parent.RbViewModal.holder(this.__id, 'LOADING')
setTimeout(() => location.reload(), 20)
},
//
setReadonly() {
$(this._RbViewForm._viewForm).addClass('readonly')
$('.J_edit, .J_delete, .J_add-slave').remove()
this.cleanViewActionButton()
}
}