edit.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. });
  37. /*插入API接口模板*/
  38. $("#api-doc").click(function(){
  39. var tmpl = $("#api-doc-templ").html();
  40. editormd.insertValue(tmpl);
  41. });
  42. /*插入数据字典模板*/
  43. $("#database-doc").click(function(){
  44. var tmpl = $("#database-doc-templ").html();
  45. editormd.insertValue(tmpl);
  46. });
  47. /*保存*/
  48. $("#save").click(function(){
  49. var page_id = $("#page_id").val();
  50. var item_id = $("#item_id").val();
  51. var cat_id = $("#cat_id").val();
  52. var page_title = $("#page_title").val();
  53. var page_content = $("#page_content").val();
  54. var item_id = $("#item_id").val();
  55. var order = $("#order").val();
  56. $.post(
  57. "save",
  58. {"page_id":page_id ,"cat_id":cat_id ,"order":order ,"page_content":page_content,"page_title":page_title,"item_id":item_id },
  59. function(data){
  60. if (data.error_code == 0) {
  61. alert("保存成功!");
  62. window.location.href="../item/show?page_id="+data.data.page_id+"&item_id="+item_id;
  63. }else{
  64. alert("保存失败!");
  65. }
  66. },
  67. 'json'
  68. )
  69. })
  70. });