1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
$(function() {
    cheackForm("from");
    $("title").text("资讯发布 - " + systemTitle);
});
var vm = new Vue({
    el: '#rapp',
    data: {
        title: null,
        pubnews: {},
        form2: null
    },
    methods: {
        saveOrUpdate: function () {
            if (vm.title == "新增") {
                var url = "sys/pubnews/save";
            }
            if (vm.title == "编辑") {
                var url = "sys/pubnews/update";
            }
            var content = UE.getEditor('contents').getContent();
            if (content == "") {
                $("#contents .edui-editor").css("borderColor", "#b94a48");
            }
            if ($("#from").valid() && content != "") {
                $("#contents .edui-editor").css("borderColor", "");
                vm.pubnews.type = $("#type").val();
                vm.pubnews.contents = htmlEncodeByRegExp(content);
                $.ajax({
                    type: "POST",
                    url: restServerBaseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.pubnews),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功', function () {
                                if (vm.title == "新增") {
                                    window.location.href = window.location.href + "?newsid=" + r.newsid;
                                } else {
                                    window.location.reload();
                                }
                                if (parent.opener.vm && parent.opener.vm.reload) {
                                    parent.opener.vm.reload();
                                }
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }
        },
        getInfo: function (newsId) {
            $.get(restServerBaseURL + "sys/pubnews/info/" + newsId, function (r) {
                if (r.code == 0) {
                    vm.pubnews = r.info;
                    initType(r.info.type);
                    var contents = vm.pubnews.contents;
                    initEditor(htmlDecodeByRegExp(contents));
                }
            });
        }
    },
    created: function () {
        var search = window.location.search;
        var newsId = "";
        if (search.indexOf("?") > -1) {
            search = search.replace("?", "");
            newsId = search.split('=')[1];
        }
        if (newsId == "") {
            this.title = "新增";
            this.pubnews = {};
            initType(null);
            initEditor("");
        } else {
            this.title = "编辑";
            this.getInfo(newsId);
        }
    }
});
 
function initType(type) {
    $.ajax({
        type: "GET",
        url: restServerBaseURL + "sys/fieldvalue/queryListByKey?key=NewsType",
        contentType: "application/json",
        success: function (msg) {
            var sysFieldList = msg.sysFieldList;
            jQuery("#type").append("<option value='' >--请选择--</option>");
            jQuery.each(sysFieldList, function (i, item) {
                jQuery("#type").append("<option value=" + item.vcode + ">" + item.vtext + "</option>");
            });
            if (type != null) {
                $("#type").val(type);
            }
        }
    });
}
 
//实例化编辑器
function initEditor(content) {
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action){
        if(action == 'uploadimage' || action == 'uploadfile'){
            return restServerBaseURL + "sys/pubnews/uploadueditorfile";
        }else{
            return this._bkGetActionUrl.call(this,action);
        }
    }
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('contents', {
        toolbars: [
            [
                'insertcode', //代码语言
                'source', //源代码
                'undo', //撤销
                'redo', //重做
                '|',
                'bold', //加粗
                'italic', //斜体
                'strikethrough', //删除线
                'underline', //下划线
                '|',
                'forecolor', //字体颜色
                'backcolor', //背景色
                '|',
                'insertorderedlist', //有序列表
                'insertunorderedlist', //无序列表
                '|',
                'fontfamily', //字体
                'fontsize', //字号
                '|',
                'justifyleft', //居左对齐
                'justifyright', //居右对齐
                'justifycenter', //居中对齐
                'justifyjustify', //两端对齐
                '|',
                'link', //超链接
                'unlink', //取消链接
                '|',
                'simpleupload' //单图上传
            ]
        ],
        initialContent: content, //初始化显示内容
        initialFrameHeight: 300, //初始化高度
        enableAutoSave: false //是否启用自动保存
    });
 
    ue.addListener('selectionchange', function (editor) {
        var content = UE.getEditor('contents').getContent();
        if (content != "") {
            $("#contents .edui-editor").css("borderColor", "");
        }
    });
}
 
//解码
function htmlDecodeByRegExp(str){
    var s = "";
    if(str.length == 0) return "";
    s = str.replace(/&amp;/g,"&");
    s = s.replace(/&lt;/g,"<");
    s = s.replace(/&gt;/g,">");
    s = s.replace(/&nbsp;/g," ");
    s = s.replace(/&#39;/g,"\'");
    s = s.replace(/&quot;/g,"\"");
    return s;
}
 
//转码
function htmlEncodeByRegExp(str){
    var s = "";
    if(str.length == 0) return "";
    s = str.replace(/&/g,"&amp;");
    s = s.replace(/</g,"&lt;");
    s = s.replace(/>/g,"&gt;");
    s = s.replace(/ /g,"&nbsp;");
    s = s.replace(/\'/g,"&#39;");
    s = s.replace(/\"/g,"&quot;");
    return s;
}