Skip to content

Commit dd9d251

Browse files
authored
Rich text img (#863)
* feat: Md2Html 图片预览
1 parent b63f635 commit dd9d251

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

src/main/resources/web/assets/css/rb-page.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,6 +4378,7 @@ h3.modal-title > .rbv {
43784378
.editor-preview img {
43794379
max-width: 100% !important;
43804380
max-height: 100% !important;
4381+
cursor: zoom-in;
43814382
}
43824383

43834384
.mdedit-content th,

src/main/resources/web/assets/css/task-view.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ See LICENSE and COMMERCIAL in the project root for license information.
2121
bottom: 0;
2222
left: 0;
2323
width: 100%;
24+
z-index: 1;
2425
}
2526

2627
.task-form .form-group.row {

src/main/resources/web/assets/js/charts/charts.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,14 @@ const ECHART_AXIS_LABEL = {
376376
},
377377
}
378378

379-
const ECHART_MARK_LINE = {
380-
data: [{ type: 'average', name: $L('均线') }],
381-
symbol: 'none',
382-
silent: true,
383-
emphasis: { disabled: true },
384-
label: { show: false },
379+
const ECHART_MARK_LINE2 = function (showLabel = false) {
380+
return {
381+
data: [{ type: 'average', name: $L('均线') }],
382+
symbol: 'none',
383+
silent: true,
384+
emphasis: { disabled: true },
385+
label: { show: showLabel },
386+
}
385387
}
386388

387389
const ECHART_VALUE_LABEL2 = function (dataFlags = []) {
@@ -541,7 +543,7 @@ class ChartLine extends BaseChart {
541543
if (showAreaColor) yAxis.areaStyle = { opacity: 0.2 }
542544
if (showNumerical) yAxis.label = ECHART_VALUE_LABEL2(dataFlags)
543545
yAxis.cursor = 'default'
544-
if (showMarkLine) yAxis.markLine = { ...$clone(ECHART_MARK_LINE) }
546+
if (showMarkLine) yAxis.markLine = ECHART_MARK_LINE2(showNumerical)
545547
data.yyyAxis[i] = yAxis
546548
}
547549

@@ -614,7 +616,7 @@ class ChartBar extends BaseChart {
614616
yAxis.smooth = true
615617
yAxis.lineStyle = { width: 3 }
616618
}
617-
if (showMarkLine) yAxis.markLine = { ...$clone(ECHART_MARK_LINE) }
619+
if (showMarkLine) yAxis.markLine = ECHART_MARK_LINE2(showNumerical)
618620
data.yyyAxis[i] = yAxis
619621
}
620622

src/main/resources/web/assets/js/general/rb-forms.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ class RbFormNText extends RbFormElement {
14981498
$createUploader(this._fieldValue__upload, null, (res) => {
14991499
const pos = mde.codemirror.getCursor()
15001500
mde.codemirror.setSelection(pos, pos)
1501-
mde.codemirror.replaceSelection(`![${$L('图片')}](${rb.baseUrl}/filex/img/${res.key})`)
1501+
mde.codemirror.replaceSelection(`![](${rb.baseUrl}/filex/img/${res.key})`)
15021502
_mdeFocus()
15031503
})
15041504
if (this.props.onView) _mdeFocus()
@@ -1807,6 +1807,7 @@ class RbFormImage extends RbFormElement {
18071807
}
18081808
}
18091809
}
1810+
18101811
removeItem(item, e) {
18111812
e && $stopEvent(e, true)
18121813
const paths = this.state.value || []

src/main/resources/web/assets/js/project/task-view.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class ValueDescription extends ValueComp {
413413
return (
414414
<div className="form-control-plaintext" ref={(c) => (this._$mde = c)}>
415415
<textarea defaultValue={this.state.description || ''} ref={(c) => (this._$editor = c)} />
416-
<input type="file" className="hide" accept="image/*" ref={(c) => (this._fieldValue__upload = c)} />
416+
<input type="file" className="hide" accept="image/*" data-noname="true" ref={(c) => (this._fieldValue__upload = c)} />
417417
<div className="mt-2 text-right">
418418
<button onClick={() => this._handleEditMode(false)} className="btn btn-sm btn-link mr-1">
419419
{$L('取消')}
@@ -496,6 +496,16 @@ class ValueDescription extends ValueComp {
496496
})
497497
mde.codemirror.focus()
498498
mde.codemirror.setCursor(mde.codemirror.lineCount(), 0) // cursor at end
499+
500+
// v4.0
501+
mde.codemirror.on('paste', (_mde, e) => {
502+
const data = e.clipboardData || window.clipboardData
503+
if (data && data.items && data.files && data.files.length > 0) {
504+
$stopEvent(e, true)
505+
this._fieldValue__upload.files = data.files
506+
$(this._fieldValue__upload).trigger('change')
507+
}
508+
})
499509
}
500510
})
501511
}

src/main/resources/web/assets/js/rb-components.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,22 @@ class Md2Html extends React.Component {
11351135
$stopEvent(e, false)
11361136
})
11371137
})
1138-
// TODO 图片预览
1138+
1139+
// 图片预览
1140+
let imgs = []
1141+
$(this._$md2html)
1142+
.find('img[src]')
1143+
.each(function () {
1144+
const $img = $(this)
1145+
let isrc = $img.attr('src')
1146+
isrc = isrc.split('/filex/img/')[1].split(/[?&]imageView2/)[0]
1147+
imgs.push(isrc)
1148+
$img.on('click', (e) => {
1149+
$stopEvent(e, true)
1150+
const p = parent || window
1151+
p.RbPreview.create(imgs, imgs.indexOf(isrc) || 0)
1152+
})
1153+
})
11391154
})
11401155
}
11411156
}

0 commit comments

Comments
 (0)