diff --git a/client/components/share/StdDialog.vue b/client/components/share/StdDialog.vue
index d61aeedd..5bbb91ad 100644
--- a/client/components/share/StdDialog.vue
+++ b/client/components/share/StdDialog.vue
@@ -74,6 +74,34 @@
OK
+
+
+
+
+
+
+
+
+
Нет
+
{{ hotKeyCode }}
+
+
+
+
+ Отмена
+ OK
+
+
@@ -82,7 +110,7 @@
import Vue from 'vue';
import Component from 'vue-class-component';
-//import * as utils from '../../share/utils';
+import * as utils from '../../share/utils';
export default @Component({
watch: {
@@ -99,6 +127,7 @@ class StdDialog extends Vue {
inputValue = '';
error = '';
iconColor = '';
+ hotKeyCode = '';
created() {
if (this.$root.addKeyHook) {
@@ -120,6 +149,11 @@ class StdDialog extends Vue {
if (opts && opts.color) {
this.iconColor = `text-${opts.color}`;
}
+
+ this.hotKeyCode = '';
+ if (opts && opts.hotKeyCode) {
+ this.hotKeyCode = opts.hotKeyCode;
+ }
}
onHide() {
@@ -158,6 +192,12 @@ class StdDialog extends Vue {
this.$refs.dialog.shake();
return;
}
+
+ if (this.type == 'hotKey' && this.hotKeyCode == '') {
+ this.$refs.dialog.shake();
+ return;
+ }
+
this.ok = true;
this.$refs.dialog.hide();
}
@@ -218,9 +258,38 @@ class StdDialog extends Vue {
});
}
+ getHotKey(message, caption, opts) {
+ return new Promise((resolve) => {
+ this.init(message, caption, opts);
+
+ this.hideTrigger = () => {
+ if (this.ok) {
+ resolve(this.hotKeyCode);
+ } else {
+ resolve(false);
+ }
+ };
+
+ this.type = 'hotKey';
+ this.active = true;
+ });
+ }
+
keyHook(event) {
- if (this.active && event.code == 'Enter') {
- this.okClick();
+ if (this.active) {
+ if (this.type == 'hotKey') {
+ if (event.type == 'keydown') {
+ this.hotKeyCode = utils.keyEventToCode(event);
+ }
+ } else {
+ if (event.code == 'Enter')
+ this.okClick();
+ if (event.code == 'Escape') {
+ this.$nextTick(() => {
+ this.$refs.dialog.hide();
+ });
+ }
+ }
event.stopPropagation();
event.preventDefault();
}
diff --git a/client/share/utils.js b/client/share/utils.js
index a171a42f..b5e059c0 100644
--- a/client/share/utils.js
+++ b/client/share/utils.js
@@ -202,4 +202,20 @@ export function escapeXml(str) {
.replace(/"/g, '"')
.replace(/'/g, ''')
;
+}
+
+export function keyEventToCode(event) {
+ let result = [];
+ if (event.metaKey)
+ result.push('Meta');
+ if (event.ctrlKey)
+ result.push('Ctrl');
+ if (event.shiftKey)
+ result.push('Shift');
+ if (event.altKey)
+ result.push('Alt');
+
+ result.push(event.code);
+
+ return result.join('+');
}
\ No newline at end of file