Notify.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div class="hidden"></div>
  3. </template>
  4. <script>
  5. //-----------------------------------------------------------------------------
  6. import Vue from 'vue';
  7. import Component from 'vue-class-component';
  8. export default @Component({
  9. })
  10. class Notify extends Vue {
  11. notify(opts) {
  12. let {
  13. caption = null,
  14. captionColor = 'black',
  15. color = 'positive',
  16. icon = '',
  17. iconColor = 'white',
  18. message = '',
  19. messageColor = 'black',
  20. position = 'top-right',
  21. } = opts;
  22. caption = (caption ? `<div style="font-size: 120%; color: ${captionColor}"><b>${caption}</b></div><br>` : '');
  23. return this.$q.notify({
  24. position,
  25. color,
  26. textColor: iconColor,
  27. icon,
  28. actions: [{icon: 'la la-times notify-button-icon', color: 'black'}],
  29. html: true,
  30. message:
  31. `<div style="max-width: 350px;">
  32. ${caption}
  33. <div style="color: ${messageColor}; overflow-wrap: break-word; word-wrap: break-word;">${message}</div>
  34. </div>`
  35. });
  36. }
  37. success(message, caption, options) {
  38. this.notify(Object.assign({color: 'positive', icon: 'la la-check-circle', message, caption}, options));
  39. }
  40. warning(message, caption, options) {
  41. this.notify(Object.assign({color: 'warning', icon: 'la la-exclamation-circle', message, caption}, options));
  42. }
  43. error(message, caption, options) {
  44. this.notify(Object.assign({color: 'negative', icon: 'la la-exclamation-circle', messageColor: 'yellow', captionColor: 'white', message, caption}, options));
  45. }
  46. info(message, caption, options) {
  47. this.notify(Object.assign({color: 'info', icon: 'la la-bell', message, caption}, options));
  48. }
  49. }
  50. //-----------------------------------------------------------------------------
  51. </script>