doc-ui.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. (function(vc) {
  2. var vm = new Vue({
  3. el: '#component',
  4. data: {
  5. docInfo:{
  6. title:'',
  7. description:'',
  8. version:'',
  9. company:''
  10. },
  11. menus: [],
  12. pages: [],
  13. curMenuName: '',
  14. content: {
  15. title:'',
  16. url:'',
  17. method:'',
  18. headers:[],
  19. reqParam:[],
  20. resParam:[],
  21. reqBody:'',
  22. resBody:''
  23. },
  24. },
  25. mounted: function() {
  26. this.getDocumentAndMenus();
  27. },
  28. methods: {
  29. getDocumentAndMenus: function(_catalog) {
  30. let _that = this;
  31. let _param = {
  32. params: {
  33. }
  34. }
  35. //发送get请求
  36. //Vue.http.get('/doc/api', _param)
  37. Vue.http.get('mock/api.json', _param)
  38. .then(function(res) {
  39. _that.docInfo = res.data.api;
  40. _that.menus = res.data.mappings;
  41. _that.switchMenu(_that.menus[0])
  42. }, function(res) {
  43. });
  44. },
  45. _activeMenu: function (_menuName) {
  46. this.menus.forEach(item => {
  47. item.active = false;
  48. if (_menuName == item.name) {
  49. item.active = true;
  50. }
  51. });
  52. console.log(this.menus)
  53. },
  54. switchMenu: function(_menu){
  55. this.pages = [];
  56. this.curMenuName = _menu.name;
  57. this._activeMenu(_menu.name);
  58. this._listDocumentPages(_menu);
  59. },
  60. _gotoPage: function(_page){
  61. let _that = this;
  62. let _param = {
  63. params: {
  64. name: this.curMenuName,
  65. serviceCode:_page.serviceCode,
  66. resource:_page.resource
  67. }
  68. };
  69. //发送get请求
  70. //Vue.http.get('/doc/api/pageContent', _param)
  71. Vue.http.get('mock/pages.json', _param)
  72. .then(function(res) {
  73. _that.content = res.data;
  74. },
  75. function (errInfo, error) {
  76. console.log('请求失败处理');
  77. }
  78. );
  79. },
  80. _listDocumentPages: function (_menu) {
  81. let _that = this;
  82. let _param = {
  83. params: {
  84. name: _menu.name,
  85. resource:_menu.resource
  86. }
  87. };
  88. //发送get请求
  89. Vue.http.get('/doc/api/page', _param)
  90. // Vue.http.get('mock/pages.json', _param)
  91. .then(function(res) {
  92. _that.pages = res.data;
  93. if (_that.pages.length < 1) {
  94. return;
  95. }
  96. _that._gotoPage(res.data[0]);
  97. },
  98. function (errInfo, error) {
  99. console.log('请求失败处理');
  100. }
  101. );
  102. },
  103. },
  104. });
  105. })(window.vc)