StdDialog.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <q-dialog ref="dialog" v-model="active" @hide="onHide">
  3. <slot></slot>
  4. <div v-show="type == 'alert'" 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="type == 'confirm'" 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. type = '';
  57. created() {
  58. if (this.$root.addKeyHook) {
  59. this.$root.addKeyHook(this.keyHook);
  60. }
  61. }
  62. init(message, caption) {
  63. this.caption = caption;
  64. this.message = message;
  65. this.ok = false;
  66. this.type = '';
  67. }
  68. onHide() {
  69. if (this.hideTrigger) {
  70. this.hideTrigger();
  71. this.hideTrigger = null;
  72. }
  73. }
  74. okClick() {
  75. this.ok = true;
  76. }
  77. alert(message, caption) {
  78. return new Promise((resolve) => {
  79. this.init(message, caption);
  80. this.hideTrigger = () => {
  81. if (this.ok) {
  82. resolve(true);
  83. } else {
  84. resolve(false);
  85. }
  86. };
  87. this.type = 'alert';
  88. this.active = true;
  89. });
  90. }
  91. confirm(message, caption) {
  92. return new Promise((resolve) => {
  93. this.init(message, caption);
  94. this.hideTrigger = () => {
  95. if (this.ok) {
  96. resolve(true);
  97. } else {
  98. resolve(false);
  99. }
  100. };
  101. this.type = 'confirm';
  102. this.active = true;
  103. });
  104. }
  105. keyHook(event) {
  106. if (this.active && event.code == 'Enter') {
  107. this.okClick();
  108. this.$refs.dialog.hide();
  109. event.stopPropagation();
  110. event.preventDefault();
  111. }
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. </script>
  116. <style scoped>
  117. .header {
  118. height: 50px;
  119. }
  120. .caption {
  121. font-size: 110%;
  122. overflow: hidden;
  123. }
  124. .close-icon {
  125. width: 50px;
  126. }
  127. .buttons {
  128. height: 60px;
  129. }
  130. </style>