newsEdit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. var smallClick =1;
  2. var articleId ='';
  3. var is_head = -2;
  4. var editorOption = {
  5. //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
  6. toolbars: [[
  7. //'anchor', //锚点
  8. 'undo', //撤销
  9. 'redo', //重做
  10. 'bold', //加粗
  11. 'indent', //首行缩进
  12. //'snapscreen', //截图
  13. 'italic', //斜体
  14. 'underline', //下划线
  15. // 'strikethrough', //删除线
  16. 'subscript', //下标
  17. 'fontborder', //字符边框
  18. 'superscript', //上标
  19. 'formatmatch', //格式刷
  20. // 'blockquote', //引用
  21. 'pasteplain', //纯文本粘贴模式
  22. 'selectall', //全选
  23. // 'print', //打印
  24. // 'insertcode', //代码语言
  25. 'fontfamily', //字体
  26. 'fontsize', //字号
  27. 'paragraph', //段落格式
  28. 'simpleupload', //单图上传
  29. 'insertimage', //多图上传
  30. 'edittable', //表格属性
  31. 'edittd', //单元格属性
  32. 'link', //超链接
  33. //'emotion', //表情
  34. 'spechars', //特殊字符
  35. 'searchreplace', //查询替换
  36. 'horizontal', //分隔线
  37. 'removeformat', //清除格式
  38. 'justifyleft', //居左对齐
  39. 'justifyright', //居右对齐
  40. 'justifycenter', //居中对齐
  41. 'justifyjustify', //两端对齐
  42. 'forecolor', //字体颜色
  43. 'backcolor', //背景色
  44. 'insertorderedlist', //有序列表
  45. 'insertunorderedlist', //无序列表
  46. 'fullscreen', //全屏
  47. 'directionalityltr', //从左向右输入
  48. 'directionalityrtl', //从右向左输入
  49. 'rowspacingtop', //段前距
  50. 'rowspacingbottom', //段后距
  51. 'time', //时间
  52. 'date', //日期
  53. 'unlink', //取消链接
  54. //'anchor', //锚点
  55. 'simpleupload', //单图上传
  56. //'insertimage', //多图上传
  57. 'edittable', //表格属性
  58. 'touppercase', //字母大写
  59. 'tolowercase', //字母小写
  60. 'imagecenter', //居中
  61. //'wordimage', //图片转存
  62. 'edittip ', //编辑提示
  63. 'charts' // 图表
  64. ]],
  65. //focus时自动清空初始化时的内容
  66. autoClearinitialContent: true,
  67. wordCount:false,
  68. //关闭elementPath
  69. elementPathEnabled: false,
  70. catchRemoteImageEnable:false,
  71. scaleEnabled:true
  72. };
  73. var formate_data =[{'id':'0','text':'新闻动态'},
  74. {'id':'1','text':'通知公告'},
  75. {'id':'2','text':'健康宣教'}];
  76. $(function(){
  77. initImage();
  78. articleId = QueryString('Id');
  79. if(articleId ==undefined || articleId == ''){
  80. return;
  81. }
  82. article._loadData(articleId);
  83. $('.select-img').on("change",function(){
  84. if($(this).find("option:selected").attr('data-val') == 'img'){
  85. $("#ar3").show();
  86. }else{
  87. $("#ar3").hide();
  88. }
  89. });
  90. $(".artClass").on("change",function(){
  91. if($(this).find("option:selected").attr('data-val') == 'article'){
  92. $("#ar2").show();
  93. $("#ar1").hide();
  94. }else{
  95. $("#ar2").hide();
  96. $("#ar1").show();
  97. }
  98. });
  99. });
  100. function clearData(){
  101. $("#dtype").val(0);
  102. $("#title").val('');
  103. $("#dlink").val('');
  104. $("#dstatus").val(0);
  105. $("#dtypeClass").val(0);
  106. $('#SmallImgV').attr('src','http://f1.yihuimg.com/TFS/upfile/WBJ/1023577/2014-07-23/003320_1406097193619_fullsize.jpg');
  107. $('#BigImgV').attr('src','http://f1.yihuimg.com/TFS/upfile/WBJ/1023577/2014-07-23/003320_1406097193619_fullsize.jpg');
  108. if($("#dtypeClass").find("option:selected").attr('data-val') == 'img'){
  109. $("#ar3").show();
  110. }else{
  111. $("#ar3").hide();
  112. }
  113. if($("#dtype").find("option:selected").attr('data-val') == 'article'){
  114. $("#ar2").show();
  115. $("#ar1").hide();
  116. }else{
  117. $("#ar2").hide();
  118. $("#ar1").show();
  119. }
  120. }
  121. function initUe(val){
  122. $("#_td").append("<script id=\"editor\" type=\"text/plain\" style=\"width:500px;height:200px;\"></script>");
  123. var UE = new baidu.editor.ui.Editor(editorOption);
  124. UE.render('editor');
  125. UE.ready(function() {
  126. //editor_a.hide();//隐藏编辑器
  127. UE.setContent(unescape(val));
  128. //赋值给UEditor du.Data.Contents
  129. UE.addListener('beforeInsertImage', function (t,arg)
  130. {
  131. // alert('这是图片地址:'+arg[0].src);
  132. });
  133. });
  134. }
  135. function saveNewsInfo(){
  136. _save($("#dtype").val(),$("#dtitle").val(),$("#SmallImgV").attr('src'),$("#BigImgV").attr('src'),UE.getEditor('editor').getContent(),$("#dstatus").val(),$("#dlink").val(),$("#dtypeClass").val());
  137. }
  138. function _save(dtype,title,smallPic,bigPic,contents,status,link,typeClass){
  139. var Service = {};
  140. var page = {};
  141. var code = 1016;
  142. Service.Title =title;
  143. Service.SmallImgUrl = "<![CDATA["+smallPic+"]]>";
  144. Service.BigImgUrl = "<![CDATA["+bigPic+"]]>";
  145. Service.TypeClass = typeClass;
  146. Service.LinkUrl = link;
  147. Service.Status = status;
  148. Service.Contents = escape(contents);
  149. if(escape(contents) == null || escape(contents) == ''){
  150. Service.isNeed = 0;
  151. }else{
  152. Service.IsNeed = 1;
  153. }
  154. Service.ArticleId = articleId;
  155. Service.Lastmodify = 1;
  156. Service.Type = dtype;
  157. Service.IsHead = is_head;
  158. var param = {};
  159. var params = Commonjs.getParams(code,Service);//获取参数
  160. param.Api = "UpdateArticle";
  161. param.Params = Commonjs.jsonToString(params);
  162. var du = Commonjs.ajax('./art_callArticleApi.do',param,false);
  163. if(du.RespCode == '10000'){
  164. art.dialog({
  165. lock: true,
  166. width: '300px',
  167. height: '100px',
  168. time: 3,
  169. content: du.RespMessage
  170. });
  171. }else{
  172. art.dialog({
  173. lock: true,
  174. width: '300px',
  175. height: '100px',
  176. time: 3,
  177. content: du.RespMessage
  178. });
  179. }
  180. window.location.href='article.html?isBack=0';
  181. }
  182. function newGuid() {
  183. var guid = "";
  184. for (var i = 1; i <= 32; i++){
  185. var n = Math.floor(Math.random()*16.0).toString(16);
  186. guid += n;
  187. if((i==8)||(i==12)||(i==16)||(i==20))
  188. guid += "-";
  189. }
  190. return guid;
  191. }
  192. function initImage(){
  193. var id = newGuid();
  194. var html = '<div style="margin-top: 2px; position:relative;" class="sel"><input id="'
  195. + id
  196. + '" style="position:absolute;filter:alpha(opacity=0);opacity:0;height:120px;width:120px;cursor: pointer;" title="点击上传图片" value="点击上传图片" onchange=upload("'
  197. + id
  198. + '","SmallImgV"); onpaste="return false;" type="file" name="0"><img id="SmallImgV" src="http://f1.yihuimg.com/TFS/upfile/WBJ/1023577/2014-07-23/003320_1406097193619_fullsize.jpg" style="height:120px;width:120px;" /></div>';
  199. $("#addSmallImg").empty();
  200. $("#addSmallImg").append(html);
  201. var id2 = newGuid();
  202. var html = '<div style="margin-top: 2px; position:relative;" class="sel"><input id="'
  203. + id2
  204. + '" style="position:absolute;filter:alpha(opacity=0);opacity:0;height:80px;width:230px;cursor: pointer;" title="点击上传图片" value="点击上传图片" onchange=upload("'
  205. + id2
  206. + '","BigImgV"); onpaste="return false;" type="file" name="0"><img id="BigImgV" src="http://f1.yihuimg.com/TFS/upfile/WBJ/1023577/2014-07-23/003320_1406097193619_fullsize.jpg" style="height:80px;width:230px;" /></div>';
  207. $("#addBigImg").empty();
  208. $("#addBigImg").append(html);
  209. }
  210. function upload(id,image) {
  211. var filename = $("#"+id).val();
  212. var index = filename.lastIndexOf('.');
  213. var type = filename.substring(index+1,filename.length);
  214. if(type.toLowerCase() != 'jpg' && type.toLowerCase() != 'gif'
  215. &&type.toLowerCase() != 'png'&&type.toLowerCase() != 'jpeg'){
  216. YihuUtil.art.warning('注意喔:图片格式必须为.jpeg|.gif|.jpg|.png','warning');
  217. return ;
  218. }
  219. var arrID = [ id ];
  220. $.yihuUpload.ajaxFileUpload( {
  221. url : '/Hos-Process/servlets/UploadFileServlet', // 用于文件上传的服务器端请求地址
  222. secureuri : false,// 一般设置为false
  223. fileElementId : arrID,// 文件上传空间的id属性 <input type="file" id="file"
  224. // name="file" />
  225. dataType : 'json',// 返回值类型 一般设置为json
  226. success : function(data, status) {
  227. var uri = data.url;
  228. uri=uri.replace('fullsize','small');
  229. var name = data.NewFileName;
  230. var fname = data.FileName;
  231. var size = data.Size;
  232. var old = $("#" + id + "_f");
  233. if (image=='SmallImgV') {
  234. $("#SmallImgV").attr("src", uri);
  235. $("#ImgUrl").val(uri);
  236. $("#hidVal").val(uri);
  237. smallClick++;
  238. // if($("#BigImgUrl").val()==''||$("#BigImgUrl").val()==null){
  239. // $("#BigImgV").attr("src", uri);
  240. // $("#BigImgUrl").val(uri);}
  241. }else{
  242. bigClick++;
  243. $("#BigImgV").attr("src", uri);
  244. $("#BigImgUrl").val(uri);
  245. }
  246. },
  247. error : function(data, status, e) {
  248. //YihuUtil.art.warning("图片上传失败:建议您选择不超过1M的图片且在良好的网络环境下继续上传");
  249. }
  250. });
  251. }
  252. function formateData(dat){
  253. if(dat == undefined){
  254. return "";
  255. }
  256. var back = "";
  257. $.each(formate_data,function(k,v){
  258. if(v.id === dat){
  259. back = v.text;
  260. return false;
  261. }
  262. });
  263. return back;
  264. }
  265. function QueryString(val) {
  266. var uri = window.location.search;
  267. var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
  268. return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
  269. }
  270. var article = function(){
  271. var loadData = function(id){
  272. var index = 1;
  273. var Service = {};
  274. var page = {};
  275. var code = 1014;
  276. Service.StartDate ='';
  277. Service.EndDate = '';
  278. Service.Title = '';
  279. Service.TypeClass = -1;
  280. Service.IsHead = -1;
  281. Service.Status = -1;
  282. Service.ArticleId = id;
  283. Service.HosId = Commonjs.hospitalId;
  284. $('#pagenumber').val(index);
  285. var pageIndex = index-1;
  286. var pageSize = 10;
  287. var page = {};
  288. page.PIndex = pageIndex;
  289. page.PSize = pageSize;
  290. // Service.Page = page;
  291. var param = {};
  292. var params = Commonjs.getParams(code,Service,page);//获取参数
  293. param.Api = "QueryArticle";
  294. param.Params = Commonjs.jsonToString(params);
  295. var du = Commonjs.ajax('./art_callArticleApi.do',param,false);
  296. if(du.RespCode == '10000'){
  297. smallClick =1;
  298. bigClick =1;
  299. initUe((du.Data.Contents == undefined || du.Data.Contents == '') ? '' : du.Data.Contents);
  300. $("#SmallImgV").attr('src',du.Data.ImgUrl);
  301. $("#BigImgV").attr('src',du.Data.BigImgUrl);
  302. $("#dtitle").val(du.Data.Title);
  303. $("#dtypeClass").val(du.Data.TypeClass);
  304. $("#dtype").val(du.Data.Type);
  305. $("#dlink").val(du.Data.LinkUrl);
  306. $("#dstatus").val(du.Data.Status);
  307. is_head = du.Data.IsHead;
  308. if( $("#dtypeClass").val()==0){
  309. $("#ar3").show();
  310. }else{
  311. $("#ar3").hide();
  312. }
  313. if( parseInt(du.Data.FinalDeal) == 0){
  314. $("#ar2").show();
  315. $("#ar1").hide();
  316. $("#dtype").val(0);
  317. }else{
  318. $("#dtype").val(1);
  319. $("#ar2").hide();
  320. $("#ar1").show();
  321. }
  322. $("#trStatus").hide();
  323. }
  324. }
  325. return {
  326. _loadData : loadData
  327. }
  328. }();