StdDialog.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <q-dialog v-model="dialog" @hide="onHide">
  3. <slot></slot>
  4. <div v-show="alertType" class="column bg-white">
  5. <div class="header row">
  6. <div class="caption col row items-center q-ml-md">
  7. <q-icon v-show="caption" class="text-warning q-mr-sm" name="las la-exclamation-circle" size="28px"></q-icon>
  8. <div v-html="caption"></div>
  9. </div>
  10. <div class="close-icon column justify-center items-center">
  11. <q-btn flat round dense v-close-popup>
  12. <q-icon name="la la-times" size="18px"></q-icon>
  13. </q-btn>
  14. </div>
  15. </div>
  16. <div class="col q-mx-md">
  17. <div v-html="message"></div>
  18. </div>
  19. <div class="buttons row justify-end q-pa-md">
  20. <q-btn class="q-px-md" dense no-caps @click="okClick" v-close-popup>OK</q-btn>
  21. </div>
  22. </div>
  23. </q-dialog>
  24. </template>
  25. <script>
  26. //-----------------------------------------------------------------------------
  27. import Vue from 'vue';
  28. import Component from 'vue-class-component';
  29. //import * as utils from '../../share/utils';
  30. export default @Component({
  31. })
  32. class StdDialog extends Vue {
  33. caption = '';
  34. message = '';
  35. dialog = false;
  36. alertType = false;
  37. created() {
  38. }
  39. init(message, caption) {
  40. this.caption = caption;
  41. this.message = message;
  42. this.ok = false;
  43. this.alertType = false;
  44. }
  45. onHide() {
  46. if (this.hideTrigger) {
  47. this.hideTrigger();
  48. this.hideTrigger = null;
  49. }
  50. }
  51. okClick() {
  52. this.ok = true;
  53. }
  54. alert(message, caption) {
  55. return new Promise((resolve) => {
  56. this.init(message, caption);
  57. this.hideTrigger = () => {
  58. if (this.ok) {
  59. resolve(true);
  60. } else {
  61. resolve(false);
  62. }
  63. };
  64. this.alertType = true;
  65. this.dialog = true;
  66. });
  67. }
  68. }
  69. //-----------------------------------------------------------------------------
  70. </script>
  71. <style scoped>
  72. .header {
  73. height: 50px;
  74. }
  75. .caption {
  76. font-size: 110%;
  77. overflow: hidden;
  78. }
  79. .close-icon {
  80. width: 50px;
  81. }
  82. .buttons {
  83. height: 60px;
  84. }
  85. </style>