Index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div id="app-other">
  3. <div class="one-block-1">
  4. <span>
  5. 请求java服务接口
  6. </span>
  7. </div>
  8. <div class="one-block-2">
  9. <a-space>
  10. <a-button @click="startServer()"> 启动java项目 </a-button>
  11. <a-button @click="sendRequest()"> 测试接口 </a-button>
  12. <a-button @click="closeServer()"> 关闭java项目 </a-button>
  13. </a-space>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import storage from 'store2'
  19. import { ipcApiRoute } from '@/api/main';
  20. export default {
  21. data() {
  22. return {
  23. server: '',
  24. };
  25. },
  26. mounted() {
  27. },
  28. methods: {
  29. startServer () {
  30. this.$ipc.invoke(ipcApiRoute.startJavaServer, {}).then(r => {
  31. if (r.code != 0) {
  32. this.$message.error(r.msg);
  33. } else {
  34. this.$message.info('异步启动');
  35. storage.set('javaService', r.server);
  36. }
  37. })
  38. },
  39. closeServer () {
  40. this.$ipc.invoke(ipcApiRoute.closeJavaServer, {}).then(r => {
  41. if (r.code != 0) {
  42. this.$message.error(r.msg);
  43. }
  44. this.$message.info('异步关闭');
  45. storage.remove('javaService');
  46. })
  47. },
  48. sendRequest () {
  49. const server = storage.get('javaService') || '';
  50. if (server == '') {
  51. this.$message.error('服务未开启 或 正在启动中');
  52. return
  53. }
  54. let testApi = server + '/test1/get';
  55. let params = {
  56. url: testApi,
  57. method: 'get',
  58. params: { id: '1111111'},
  59. timeout: 60000,
  60. }
  61. this.$http(params).then(res => {
  62. this.$message.info(`java服务返回: ${res}`, );
  63. })
  64. },
  65. }
  66. };
  67. </script>
  68. <style lang="less" scoped>
  69. #app-other {
  70. padding: 0px 10px;
  71. text-align: left;
  72. width: 100%;
  73. .one-block-1 {
  74. font-size: 16px;
  75. padding-top: 10px;
  76. }
  77. .one-block-2 {
  78. padding-top: 10px;
  79. }
  80. }
  81. </style>