Helius
2022-05-19 7e6bbd05a75b07cb0717812d0b51aad128361012
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<style>
    #newsInfo-update {
        padding: 20px 25px 25px 0;
    }
 
    #newsInfo-update .layui-treeSelect .ztree li a, .ztree li span {
        margin: 0 0 2px 3px !important;
    }
 
    #newsInfo-update #data-permission-tree-block {
        border: 1px solid #eee;
        border-radius: 2px;
        padding: 3px 0;
    }
 
    #newsInfo-update .layui-treeSelect .ztree li span.button.switch {
        top: 1px;
        left: 3px;
    }
 
    #newsInfo-update img {
        max-width: 100px
    }
 
</style>
<div className="layui-fluid" id="newsInfo-update">
    <form className="layui-form" action="" lay-filter="newsInfo-update-form">
        <div class="layui-form-item febs-hide">
            <label class="layui-form-label febs-form-item-require">id:</label>
            <div class="layui-input-block">
                <input type="text" name="id" data-th-value="${newsInfo.id}">
            </div>
        </div>
        <div className="layui-form-item">
            <label className="layui-form-label febs-form-item-require">标题:</label>
            <div className="layui-input-block">
                <input type="text" name="title" autoComplete="off" className="layui-input">
            </div>
        </div>
        <div className="layui-form-item">
            <label className="layui-form-label febs-form-item-require">分类:</label>
            <div className="layui-input-block">
                <select name="categoryId" className="news-category" id="news-category">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
 
        <div className="layui-form-item">
            <label className="layui-form-label">视频:</label>
            <div className="layui-input-block">
                <button type="button" className="layui-btn upload" id="upload"
                        style="background-color: #009688; margin-bottom: 2px">上传文件
                </button>
                <input type="text" name="videoUrl" autoComplete="off" value="" id="videoUrl" className="layui-input"
                       readOnly>
            </div>
        </div>
 
        <div className="layui-form-item">
            <label className="layui-form-label">缩略图:</label>
            <div className="layui-input-block">
                <button type="button" className="layui-btn" id="imageUpload"
                        style="background-color: #009688; margin-bottom: 2px">图片上传
                </button>
                <blockquote className="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                    <div className=" layui-upload-list view-images" id="thumbImage">
                    </div>
                </blockquote>
                <div className="febs-hide">
                    <input type="text" id="thumb" name="thumb" autoComplete="off" className="layui-input" readOnly>
                </div>
            </div>
        </div>
 
        <div className="layui-form-item">
            <label className="layui-form-label febs-form-item-require">内容:</label>
            <div className="layui-input-block">
                <textarea id="lay_edit" name="content" lay-verify="content" className="layui-textarea"></textarea>
            </div>
        </div>
        <div className="layui-form-item febs-hide">
            <button className="layui-btn" lay-submit="" lay-filter="newsInfo-update-form-submit" id="submit"></button>
        </div>
    </form>
</div>
 
<script data-th-inline="javascript">
    layui.use(['febs', 'form', 'formSelects', 'validate', 'treeSelect', 'eleTree', 'layedit', 'laydate', 'upload'], function () {
        var $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            upload = layui.upload,
            formSelects = layui.formSelects,
            form = layui.form,
            laydate = layui.laydate,
            layedit = layui.layedit,
            newsInfo = [[${newsInfo}]],
            $view = $('#newsInfo-update'),
            validate = layui.validate;
 
        //(下拉框)
        $.get(ctx + 'admin/news/findAllCategoryList', function (data) {
            var arr = data.data;
            for (let i = 0; i < arr.length; i++) {
                $(".news-category").append("<option value='" + arr[i].id + "'>" + arr[i].title + "</option>");
            }
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        });
 
        form.render();
        laydate.render({
            elem: '#febs-form-group-date'
        });
 
        layedit.set({    //设置图片接口
            uploadImage: {
                url: 'admin/goods/uploadFileBase64', //接口url
                type: 'post',
            }
        });
        //创建一个编辑器
        var index = layedit.build('lay_edit', {
            height: 300
        });
        form.verify({
            //content富文本域中的lay-verify值
            content: function (value) {
                return layedit.sync(index);
            }
        });
 
        formSelects.render();
        form.on('submit(newsInfo-update-form-submit)', function (data) {
            febs.post(ctx + 'admin/news/updateNewsInfo', data.field, function () {
                layer.closeAll();
                febs.alert.success('操作成功');
                $('#febs-newInfo').find('#reset').click();
            });
            return false;
        });
 
        upload.render({
            elem: '#imageUpload'
            , url: ctx + 'admin/goods/uploadFileBase64' //改成您自己的上传接口
            , multiple: false
            , before: function (obj) {
                //预读本地文件示例,不支持ie8
                obj.preview(function (index, file, result) {
                    $('#thumbImage').html('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" style="width: 100px">')
                });
            }
            , done: function (res) {
                $("#thumb").val(res.data.src);
            }
        });
 
 
        bindUpload();
 
        function bindUpload() {
            upload.render({
                elem: '.upload'
                , url: ctx + 'admin/goods/uploadFileBase64' //改成您自己的上传接口
                , accept: 'file'
                , before: function (obj) {
                    layer.msg('上传中', {icon: 16, time: 0});
                }
                , done: function (res) {
                    var item = this.item;
                    //如果上传失败
                    if (res.code !== 0) {
                        return layer.msg('上传失败');
                    }
 
                    // $(item).parent().prev().find('input').val(res.data[0]);
                    $("#videoUrl").val(res.data.src);
                    layer.msg('上传完毕', {icon: 1});
                }
                , error: function (err) {
                    return layer.msg('上传失败');
                }
            });
        }
 
        initUserValue();
        function initUserValue() {
            var thumb = newsInfo.thumb;
            $('#thumbImage').html('<img src="' + thumb + '" alt="" class="layui-upload-img" style="width: 100px">')
            form.val("newsInfo-update-form", {
                "id": newsInfo.id,
                "categoryId": newsInfo.categoryId,
                "title": newsInfo.title,
                "videoUrl": newsInfo.videoUrl,
                "thumb": newsInfo.thumb,
                "content": newsInfo.content,
            });
        }
    });
</script>