StdDialog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <q-dialog ref="dialog" v-model="active" @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. <div v-show="confirmType" class="column bg-white">
  24. <div class="header row">
  25. <div class="caption col row items-center q-ml-md">
  26. <q-icon v-show="caption" class="text-warning q-mr-sm" name="las la-exclamation-circle" size="28px"></q-icon>
  27. <div v-html="caption"></div>
  28. </div>
  29. <div class="close-icon column justify-center items-center">
  30. <q-btn flat round dense v-close-popup>
  31. <q-icon name="la la-times" size="18px"></q-icon>
  32. </q-btn>
  33. </div>
  34. </div>
  35. <div class="col q-mx-md">
  36. <div v-html="message"></div>
  37. </div>
  38. <div class="buttons row justify-end q-pa-md">
  39. <q-btn class="q-px-md q-ml-sm" dense no-caps v-close-popup>Отмена</q-btn>
  40. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick" v-close-popup>OK</q-btn>
  41. </div>
  42. </div>
  43. </q-dialog>
  44. </template>
  45. <script>
  46. //-----------------------------------------------------------------------------
  47. import Vue from 'vue';
  48. import Component from 'vue-class-component';
  49. //import * as utils from '../../share/utils';
  50. export default @Component({
  51. })
  52. class StdDialog extends Vue {
  53. caption = '';
  54. message = '';
  55. active = false;
  56. alertType = false;
  57. confirmType = false;
  58. created() {
  59. if (this.$root.addKeyHook) {
  60. this.$root.addKeyHook(this.keyHook);
  61. }
  62. }
  63. init(message, caption) {
  64. this.caption = caption;
  65. this.message = message;
  66. this.ok = false;
  67. this.alertType = false;
  68. this.confirmType = false;
  69. }
  70. onHide() {
  71. if (this.hideTrigger) {
  72. this.hideTrigger();
  73. this.hideTrigger = null;
  74. }
  75. }
  76. okClick() {
  77. this.ok = true;
  78. }
  79. alert(message, caption) {
  80. return new Promise((resolve) => {
  81. this.init(message, caption);
  82. this.hideTrigger = () => {
  83. if (this.ok) {
  84. resolve(true);
  85. } else {
  86. resolve(false);
  87. }
  88. };
  89. this.alertType = true;
  90. this.active = true;
  91. });
  92. }
  93. confirm(message, caption) {
  94. return new Promise((resolve) => {
  95. this.init(message, caption);
  96. this.hideTrigger = () => {
  97. if (this.ok) {
  98. resolve(true);
  99. } else {
  100. resolve(false);
  101. }
  102. };
  103. this.confirmType = true;
  104. this.active = true;
  105. });
  106. }
  107. keyHook(event) {
  108. if (this.active && event.code == 'Enter') {
  109. this.okClick();
  110. this.$refs.dialog.hide();
  111. event.stopPropagation();
  112. event.preventDefault();
  113. }
  114. }
  115. }
  116. //-----------------------------------------------------------------------------
  117. </script>
  118. <style scoped>
  119. .header {
  120. height: 50px;
  121. }
  122. .caption {
  123. font-size: 110%;
  124. overflow: hidden;
  125. }
  126. .close-icon {
  127. width: 50px;
  128. }
  129. .buttons {
  130. height: 60px;
  131. }
  132. </style>