$(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(/&/g,"&");
|
s = s.replace(/</g,"<");
|
s = s.replace(/>/g,">");
|
s = s.replace(/ /g," ");
|
s = s.replace(/'/g,"\'");
|
s = s.replace(/"/g,"\"");
|
return s;
|
}
|
|
//转码
|
function htmlEncodeByRegExp(str){
|
var s = "";
|
if(str.length == 0) return "";
|
s = str.replace(/&/g,"&");
|
s = s.replace(/</g,"<");
|
s = s.replace(/>/g,">");
|
s = s.replace(/ /g," ");
|
s = s.replace(/\'/g,"'");
|
s = s.replace(/\"/g,""");
|
return s;
|
}
|