edit.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var editormd;
  2. $(function() {
  3. /*加载目录*/
  4. getCatList();
  5. function getCatList(){
  6. var default_cat_id = $("#default_cat_id").val();
  7. var item_id = $("#item_id").val();
  8. $.get(
  9. "../catalog/catList",
  10. { "item_id": item_id },
  11. function(data){
  12. $("#cat_id").html('<OPTION value="0">无</OPTION>');
  13. if (data.error_code == 0) {
  14. json = data.data;
  15. console.log(json);
  16. for (var i = 0; i < json.length; i++) {
  17. cat_html ='<OPTION value="'+json[i].cat_id+'" ';
  18. if (default_cat_id == json[i].cat_id ) {
  19. cat_html += ' selected ';
  20. }
  21. cat_html +=' ">'+json[i].cat_name+'</OPTION>';
  22. $("#cat_id").append(cat_html);
  23. };
  24. };
  25. },
  26. "json"
  27. );
  28. }
  29. /*初始化编辑器*/
  30. editormd = editormd("editormd", {
  31. width : "90%",
  32. height : 1000,
  33. syncScrolling : "single",
  34. path : DocConfig.pubile + "/editor.md/lib/" ,
  35. placeholder : "本编辑器支持Markdown编辑,左边编写,右边预览",
  36. imageUpload : true,
  37. imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
  38. imageUploadURL : "ImgUpload",
  39. });
  40. /*插入API接口模板*/
  41. $("#api-doc").click(function(){
  42. var tmpl = $("#api-doc-templ").html();
  43. editormd.insertValue(tmpl);
  44. });
  45. /*插入数据字典模板*/
  46. $("#database-doc").click(function(){
  47. var tmpl = $("#database-doc-templ").html();
  48. editormd.insertValue(tmpl);
  49. });
  50. /*保存*/
  51. $("#save").click(function(){
  52. var page_id = $("#page_id").val();
  53. var item_id = $("#item_id").val();
  54. var cat_id = $("#cat_id").val();
  55. var page_title = $("#page_title").val();
  56. var page_content = $("#page_content").val();
  57. var item_id = $("#item_id").val();
  58. var order = $("#order").val();
  59. $.post(
  60. "save",
  61. {"page_id":page_id ,"cat_id":cat_id ,"order":order ,"page_content":page_content,"page_title":page_title,"item_id":item_id },
  62. function(data){
  63. if (data.error_code == 0) {
  64. alert("保存成功!");
  65. window.location.href="../item/show?page_id="+data.data.page_id+"&item_id="+item_id;
  66. }else{
  67. alert("保存失败!");
  68. }
  69. },
  70. 'json'
  71. )
  72. })
  73. });