This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MFormItemImage.js
79 lines (72 loc) · 2.49 KB
/
MFormItemImage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* eslint-disable react/prop-types */
/* global requirejs */
import $ from 'miaoxing';
import { Component } from 'react';
import ReactDOM from 'react-dom';
import 'public/plugins/wechat-image/css/wechat-image.css';
class MFormItemImage extends Component {
componentDidMount() {
// 进入页面要刷新接口才能上传
requirejs(['plugins/wechat/js/wx'], function (wx) {
wx.reset();
});
/* eslint-disable-next-line react/no-find-dom-node */
const dom = ReactDOM.findDOMNode(this);
requirejs([
'plugins/wechat-image/js/wechat-image',
'plugins/wechat/js/wx',
'plugins/app/libs/artTemplate/template.min',
], (image, wx, template) => {
$('.js-upload-container', dom).html(template.render('wx-upload-image-tpl', {
title: '图片' + (this.props.required ? ' <span class="text-warning">*</span>' : ''),
}));
const img = new image.constructor;
img.init({
$container: $('.js-upload-container .js-wx-upload-image', dom),
images: this.props.images,
wx: wx,
max: 10,
uploadUrl: $.url('wechat-image/get-wechat-image'),
chooseImageOptions: this.props.chooseImageOptions,
});
});
}
render() {
return <div>
<div className="form-group js-upload-container"/>
<style>
{`
.wx-upload-image-cells {
margin-left: -47px;
}
`}
</style>
<script type="text/html" id="wx-upload-image-tpl">
{`
<div class="wx-upload-image js-wx-upload-image">
<div class="wx-upload-image-header">
<span><%== title ? title : '图片上传' %></span>
</div>
<div class="wx-upload-image-body js-upload">
<ul class="wx-upload-image-cells js-upload-cells">
<li class="wx-upload-image-add">
<% if(hasOption) { %>
<select class="js-upload-image-option img-select">
<% for(var i in options) {%>
<option value="<%= options[i].value %>"><%= options[i].key %></option>
<% } %>
</select>
<% } %>
<div class="wx-upload-image-select-wrp js-select">
<div class="wx-upload-image-select"></div>
</div>
</li>
</ul>
</div>
</div>
`}
</script>
</div>;
}
}
export default MFormItemImage;