main.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import storage from 'store2'
  2. import request from '@/utils/request'
  3. /**
  4. * 路由定义(主进程与渲染进程通信频道定义)
  5. */
  6. const ipcApiRoute = {
  7. test: 'controller.example.test',
  8. messageShow: 'controller.example.messageShow',
  9. messageShowConfirm: 'controller.example.messageShowConfirm',
  10. selectFolder: 'controller.example.selectFolder',
  11. openDirectory: 'controller.example.openDirectory',
  12. loadViewContent: 'controller.example.loadViewContent',
  13. removeViewContent: 'controller.example.removeViewContent',
  14. createWindow: 'controller.example.createWindow',
  15. sendNotification: 'controller.example.sendNotification',
  16. initPowerMonitor: 'controller.example.initPowerMonitor',
  17. getScreen: 'controller.example.getScreen',
  18. openSoftware: 'controller.example.openSoftware',
  19. autoLaunch: 'controller.example.autoLaunch',
  20. setTheme: 'controller.example.setTheme',
  21. getTheme: 'controller.example.getTheme',
  22. checkForUpdater: 'controller.example.checkForUpdater',
  23. downloadApp: 'controller.example.downloadApp',
  24. dbOperation: 'controller.example.dbOperation',
  25. sqlitedbOperation: 'controller.example.sqlitedbOperation',
  26. uploadFile: 'controller.example.uploadFile',
  27. checkHttpServer: 'controller.example.checkHttpServer',
  28. doHttpRequest: 'controller.example.doHttpRequest',
  29. doSocketRequest: 'controller.example.doSocketRequest',
  30. ipcInvokeMsg: 'controller.example.ipcInvokeMsg',
  31. ipcSendSyncMsg: 'controller.example.ipcSendSyncMsg',
  32. ipcSendMsg: 'controller.example.ipcSendMsg',
  33. getWCid: 'controller.example.getWCid',
  34. hello: 'controller.example.hello',
  35. }
  36. /**
  37. * 特殊的路由(频道)定义
  38. */
  39. const specialIpcRoute = {
  40. appUpdater: 'app.updater', // 此频道在后端也有相同定义
  41. javaPort: 'app.javaPort', // 推送java端口
  42. window1ToWindow2: 'window1-to-window2', // 窗口之间通信
  43. window2ToWindow1: 'window2-to-window1', // 窗口之间通信
  44. }
  45. /**
  46. * 访问内置http服务
  47. */
  48. const requestHttp = (uri, parameter) => {
  49. // url转换
  50. const config = storage.get('httpServiceConfig');
  51. const host = config.server || 'http://127.0.0.1:7071';
  52. let url = uri.split('.').join('/');
  53. url = host + '/' + url;
  54. console.log('url:', url);
  55. return request({
  56. url: url,
  57. method: 'post',
  58. data: parameter, // body
  59. params: {}, // URL 参数
  60. timeout: 60000,
  61. })
  62. }
  63. const httpConfig = {
  64. baseURL: 'http://localhost:11111'
  65. }
  66. const requestJava = (uri, id) => {
  67. // url转换
  68. let url = httpConfig.baseURL + uri;
  69. console.log('url:', url);
  70. return request({
  71. url: url,
  72. method: 'get',
  73. params: { id: id}, // URL 参数
  74. timeout: 60000,
  75. })
  76. }
  77. export {
  78. ipcApiRoute,
  79. specialIpcRoute,
  80. requestHttp,
  81. requestJava,
  82. httpConfig
  83. }