StdDialog.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <q-dialog ref="dialog" v-model="active" @show="onShow" @hide="onHide">
  3. <slot></slot>
  4. <!--------------------------------------------------->
  5. <div v-show="type == 'alert'" class="column bg-white">
  6. <div class="header row">
  7. <div class="caption col row items-center q-ml-md">
  8. <q-icon v-show="caption" class="text-warning q-mr-sm" name="las la-exclamation-circle" size="28px"></q-icon>
  9. <div v-html="caption"></div>
  10. </div>
  11. <div class="close-icon column justify-center items-center">
  12. <q-btn flat round dense v-close-popup>
  13. <q-icon name="la la-times" size="18px"></q-icon>
  14. </q-btn>
  15. </div>
  16. </div>
  17. <div class="col q-mx-md">
  18. <div v-html="message"></div>
  19. </div>
  20. <div class="buttons row justify-end q-pa-md">
  21. <q-btn class="q-px-md" dense no-caps @click="okClick" v-close-popup>OK</q-btn>
  22. </div>
  23. </div>
  24. <!--------------------------------------------------->
  25. <div v-show="type == 'confirm'" class="column bg-white">
  26. <div class="header row">
  27. <div class="caption col row items-center q-ml-md">
  28. <q-icon v-show="caption" class="text-warning q-mr-sm" name="las la-exclamation-circle" size="28px"></q-icon>
  29. <div v-html="caption"></div>
  30. </div>
  31. <div class="close-icon column justify-center items-center">
  32. <q-btn flat round dense v-close-popup>
  33. <q-icon name="la la-times" size="18px"></q-icon>
  34. </q-btn>
  35. </div>
  36. </div>
  37. <div class="col q-mx-md">
  38. <div v-html="message"></div>
  39. </div>
  40. <div class="buttons row justify-end q-pa-md">
  41. <q-btn class="q-px-md q-ml-sm" dense no-caps v-close-popup>Отмена</q-btn>
  42. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick" v-close-popup>OK</q-btn>
  43. </div>
  44. </div>
  45. <!--------------------------------------------------->
  46. <div v-show="type == 'prompt'" class="column bg-white">
  47. <div class="header row">
  48. <div class="caption col row items-center q-ml-md">
  49. <q-icon v-show="caption" class="text-warning q-mr-sm" name="las la-exclamation-circle" size="28px"></q-icon>
  50. <div v-html="caption"></div>
  51. </div>
  52. <div class="close-icon column justify-center items-center">
  53. <q-btn flat round dense v-close-popup>
  54. <q-icon name="la la-times" size="18px"></q-icon>
  55. </q-btn>
  56. </div>
  57. </div>
  58. <div class="col q-mx-md">
  59. <div v-html="message"></div>
  60. <q-input ref="input" outlined dense v-model="inputValue"/>
  61. </div>
  62. <div class="buttons row justify-end q-pa-md">
  63. <q-btn class="q-px-md q-ml-sm" dense no-caps v-close-popup>Отмена</q-btn>
  64. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick" v-close-popup>OK</q-btn>
  65. </div>
  66. </div>
  67. </q-dialog>
  68. </template>
  69. <script>
  70. //-----------------------------------------------------------------------------
  71. import Vue from 'vue';
  72. import Component from 'vue-class-component';
  73. //import * as utils from '../../share/utils';
  74. export default @Component({
  75. })
  76. class StdDialog extends Vue {
  77. caption = '';
  78. message = '';
  79. active = false;
  80. type = '';
  81. inputValue = '';
  82. created() {
  83. if (this.$root.addKeyHook) {
  84. this.$root.addKeyHook(this.keyHook);
  85. }
  86. }
  87. init(message, caption) {
  88. this.caption = caption;
  89. this.message = message;
  90. this.ok = false;
  91. this.type = '';
  92. }
  93. onHide() {
  94. if (this.hideTrigger) {
  95. this.hideTrigger();
  96. this.hideTrigger = null;
  97. }
  98. }
  99. onShow() {
  100. if (this.type == 'prompt') {
  101. this.$refs.input.focus();
  102. }
  103. }
  104. okClick() {
  105. this.ok = true;
  106. }
  107. alert(message, caption) {
  108. return new Promise((resolve) => {
  109. this.init(message, caption);
  110. this.hideTrigger = () => {
  111. if (this.ok) {
  112. resolve(true);
  113. } else {
  114. resolve(false);
  115. }
  116. };
  117. this.type = 'alert';
  118. this.active = true;
  119. });
  120. }
  121. confirm(message, caption) {
  122. return new Promise((resolve) => {
  123. this.init(message, caption);
  124. this.hideTrigger = () => {
  125. if (this.ok) {
  126. resolve(true);
  127. } else {
  128. resolve(false);
  129. }
  130. };
  131. this.type = 'confirm';
  132. this.active = true;
  133. });
  134. }
  135. prompt(message, caption, opts) {
  136. return new Promise((resolve) => {
  137. this.init(message, caption);
  138. this.hideTrigger = () => {
  139. if (this.ok) {
  140. resolve(true);
  141. } else {
  142. resolve(false);
  143. }
  144. };
  145. this.type = 'prompt';
  146. this.inputValue = opts.inputValue || '';
  147. this.inputValidator = opts.inputValidator || null;
  148. this.active = true;
  149. });
  150. }
  151. keyHook(event) {
  152. if (this.active && event.code == 'Enter') {
  153. this.okClick();
  154. this.$refs.dialog.hide();
  155. event.stopPropagation();
  156. event.preventDefault();
  157. }
  158. }
  159. }
  160. //-----------------------------------------------------------------------------
  161. </script>
  162. <style scoped>
  163. .header {
  164. height: 50px;
  165. }
  166. .caption {
  167. font-size: 110%;
  168. overflow: hidden;
  169. }
  170. .close-icon {
  171. width: 50px;
  172. }
  173. .buttons {
  174. height: 60px;
  175. }
  176. </style>