Api.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div>
  3. </div>
  4. </template>
  5. <script>
  6. //-----------------------------------------------------------------------------
  7. import vueComponent from '../vueComponent.js';
  8. import wsc from './webSocketConnection';
  9. //import _ from 'lodash';
  10. const componentOptions = {
  11. components: {
  12. },
  13. watch: {
  14. },
  15. };
  16. class Api {
  17. _options = componentOptions;
  18. created() {
  19. this.commit = this.$store.commit;
  20. }
  21. mounted() {
  22. this.updateConfig();//no await
  23. }
  24. async updateConfig() {
  25. try {
  26. const config = await this.getConfig();
  27. this.commit('setConfig', config);
  28. } catch (e) {
  29. this.$root.stdDialog.alert(e.message, 'Ошибка');
  30. }
  31. }
  32. get config() {
  33. return this.$store.state.config;
  34. }
  35. async request(params) {
  36. return await wsc.message(await wsc.send(params));
  37. }
  38. async search(query) {
  39. const response = await this.request({action: 'search', query});
  40. if (response.error) {
  41. throw new Error(response.error);
  42. }
  43. return response;
  44. }
  45. async getConfig() {
  46. const response = await this.request({action: 'get-config'});
  47. if (response.error) {
  48. throw new Error(response.error);
  49. }
  50. return response;
  51. }
  52. }
  53. export default vueComponent(Api);
  54. //-----------------------------------------------------------------------------
  55. </script>
  56. <style scoped>
  57. </style>