Browse Source

hotkey

main
hulei 3 months ago
parent
commit
df92fc92a8

+ 73
- 0
ant-design-pro-vue3/src/views/front/platfrom/hotkey/HotKeyHelper.ts View File

@@ -0,0 +1,73 @@
1
+// 假设 HotkeyParames 类的定义如下
2
+class HotkeyParames {
3
+    static CombHotKey(key: string): string {
4
+        // 实现具体逻辑
5
+        return key;
6
+    }
7
+    static GetNameByValue(keyValue: string): string {
8
+        // 实现具体逻辑
9
+        return keyValue;
10
+    }
11
+    static Separator: string = ",";
12
+}
13
+
14
+// 假设 Keyboard 类的定义如下
15
+class Keyboard {
16
+    static get Modifiers() {
17
+        // 实现具体逻辑
18
+        return { toString: () => "none" };
19
+    }
20
+}
21
+
22
+// 定义 Key 类型
23
+type Key = string;
24
+
25
+export class HotKeyHelper {
26
+    private static _dicKeys: { [key: string]: string } = null;
27
+
28
+    public static SetHotKey(dicKeys: { [key: string]: string }) {
29
+        if (Object.keys(dicKeys).length === 0) {
30
+            return;
31
+        }
32
+        this._dicKeys = dicKeys;
33
+    }
34
+
35
+    public static GetHotKey() {
36
+        return this._dicKeys;
37
+    }
38
+
39
+    public static GetKeyName(keyValue: Key) {
40
+        if (this._dicKeys === null) return "";
41
+        let key = HotkeyParames.CombHotKey(HotkeyParames.GetNameByValue(keyValue)).replace(" ", "");
42
+        if (Keyboard.Modifiers.toString().toLowerCase() === "none" && key.includes("Ctrl")) {
43
+            key = key.replace("Ctrl+", "");
44
+        }
45
+        if (key.length <= 0) return "";
46
+        const result = Object.entries(this._dicKeys)
47
+           .find(([_, value]) => value.startsWith(`${key}${HotkeyParames.Separator}`) || value.includes(`${HotkeyParames.Separator}${key}${HotkeyParames.Separator}`))
48
+           ?.[0].toUpperCase().trim();
49
+
50
+        return result;
51
+    }
52
+
53
+    public static GetKeyValue(keyName: string) {
54
+        if (this._dicKeys === null) return "";
55
+        const result = Object.entries(this._dicKeys)
56
+           .find(([key]) => key === keyName.toLowerCase())
57
+           ?.[1].replace(HotkeyParames.Separator, "; ");
58
+
59
+        return result;
60
+    }
61
+
62
+    public static get IsShift() {
63
+        return Keyboard.Modifiers.toString().toLowerCase() === "shift";
64
+    }
65
+
66
+    public static get IsControl() {
67
+        return Keyboard.Modifiers.toString().toLowerCase() === "control";
68
+    }
69
+
70
+    public static get IsAlt() {
71
+        return Keyboard.Modifiers.toString().toLowerCase() === "alt";
72
+    }
73
+}

+ 207
- 0
ant-design-pro-vue3/src/views/front/platfrom/hotkey/HotkeyParames.ts View File

@@ -0,0 +1,207 @@
1
+// 假设 Key 枚举类型已经定义
2
+enum Key {
3
+    A, B, C, D, E, F, G, H, I, J, K, M, L, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
4
+    D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
5
+    Up, Down, Left, Right,
6
+    Space, Enter, Tab, Delete, Insert,
7
+    PageDown, PageUp, Home, End,
8
+    Escape, LeftShift, LeftCtrl,
9
+    F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
10
+    Add, Subtract,
11
+    OemTilde, OemMinus, OemPlus, OemOpenBrackets, OemCloseBrackets, Oem5, OemComma, OemPeriod, OemSemicolon, OemQuotes, OemQuestion
12
+}
13
+
14
+class HotkeyParames {
15
+    static Separator: string = '@';
16
+    private static _keyList: { [key: string]: Key } = {
17
+        "A": Key.A,
18
+        "B": Key.B,
19
+        "C": Key.C,
20
+        "D": Key.D,
21
+        "E": Key.E,
22
+        "F": Key.F,
23
+        "G": Key.G,
24
+        "H": Key.H,
25
+        "I": Key.I,
26
+        "J": Key.J,
27
+        "K": Key.K,
28
+        "M": Key.M,
29
+        "L": Key.L,
30
+        "N": Key.N,
31
+        "O": Key.O,
32
+        "P": Key.P,
33
+        "Q": Key.Q,
34
+        "R": Key.R,
35
+        "S": Key.S,
36
+        "T": Key.T,
37
+        "U": Key.U,
38
+        "V": Key.V,
39
+        "W": Key.W,
40
+        "X": Key.X,
41
+        "Y": Key.Y,
42
+        "Z": Key.Z,
43
+
44
+        "0": Key.D0,
45
+        "1": Key.D1,
46
+        "2": Key.D2,
47
+        "3": Key.D3,
48
+        "4": Key.D4,
49
+        "5": Key.D5,
50
+        "6": Key.D6,
51
+        "7": Key.D7,
52
+        "8": Key.D8,
53
+        "9": Key.D9,
54
+
55
+        "Up": Key.Up,
56
+        "Down": Key.Down,
57
+        "Left": Key.Left,
58
+        "Right": Key.Right,
59
+
60
+        "Space": Key.Space,
61
+        "Enter": Key.Enter,
62
+        "Tab": Key.Tab,
63
+        "Del": Key.Delete,
64
+        "Insert": Key.Insert,
65
+
66
+        "PgDn": Key.PageDown,
67
+        "PgUp": Key.PageUp,
68
+        "Home": Key.Home,
69
+        "End": Key.End,
70
+
71
+        "Esc": Key.Escape,
72
+        "Shift": Key.LeftShift,
73
+        "Ctrl": Key.LeftCtrl,
74
+
75
+        "F1": Key.F1,
76
+        "F2": Key.F2,
77
+        "F3": Key.F3,
78
+        "F4": Key.F4,
79
+        "F5": Key.F5,
80
+        "F6": Key.F6,
81
+        "F7": Key.F7,
82
+        "F8": Key.F8,
83
+        "F9": Key.F9,
84
+        "F10": Key.F10,
85
+        "F11": Key.F11,
86
+        "F12": Key.F12,
87
+
88
+        "加号": Key.Add,
89
+        "减号": Key.Subtract,
90
+        "`": Key.OemTilde,
91
+        "-": Key.OemMinus,
92
+        "=": Key.OemPlus,
93
+        "[": Key.OemOpenBrackets,
94
+        "]": Key.OemCloseBrackets,
95
+        "\\": Key.Oem5,
96
+        ",": Key.OemComma,
97
+        ".": Key.OemPeriod,
98
+        ";": Key.OemSemicolon,
99
+        "'": Key.OemQuotes,
100
+        "/": Key.OemQuestion
101
+    };
102
+
103
+    private static _enableSelfKey: string[] = [
104
+        "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
105
+        "Tab", "Enter", "Esc", "Up", "Down", "Left", "Right", "PgUp", "PgDn", "Home", "End",
106
+        "Del", "Insert", "减号", "加号"
107
+    ];
108
+
109
+    static ParseKeyValue_FromIntToStr(keyValue: string): string {
110
+        keyValue = keyValue.replace("amp;", "");
111
+        let result = "";
112
+        if (keyValue === "") return result;
113
+        const parts = keyValue.split(HotkeyParames.Separator);
114
+        for (const item1 of parts) {
115
+            if (item1.trim().length <= 0) continue;
116
+            const subParts = item1.split('+');
117
+            for (const item2 of subParts) {
118
+                if (item2.trim().length <= 0) break;
119
+                result += HotkeyParames.GetNameByValue(Key[parseInt(item2)]) + " + ";
120
+            }
121
+            result = result.trim().substring(0, result.trim().length - 1).trim() + HotkeyParames.Separator;
122
+        }
123
+        return result;
124
+    }
125
+
126
+    static ParseKeyValue_FromStrToInt(keyValue: string): string {
127
+        let result = "";
128
+        if (keyValue === "") return "0;";
129
+        const parts = keyValue.split(HotkeyParames.Separator);
130
+        for (const item1 of parts) {
131
+            if (item1.trim().length <= 0) continue;
132
+            const subParts = item1.split('+');
133
+            for (const item of subParts) {
134
+                if (item.trim().length <= 0) break;
135
+                result += HotkeyParames.GetValueByName(item.trim()) + "+";
136
+            }
137
+            result = result.substring(0, result.length - 1) + HotkeyParames.Separator;
138
+        }
139
+        return result;
140
+    }
141
+
142
+    static GetNameByValue(keyValue: Key): string {
143
+        keyValue = HotkeyParames.UniKey(keyValue);
144
+        const keyName = Object.keys(HotkeyParames._keyList).find(key => HotkeyParames._keyList[key] === keyValue);
145
+        return keyName || "";
146
+    }
147
+
148
+    static GetValueByName(keyName: string): Key {
149
+        if (keyName === "") return Key.None;
150
+        return HotkeyParames._keyList[keyName] || Key.None;
151
+    }
152
+
153
+    static UniKey(keyValue: Key): Key {
154
+        switch (keyValue) {
155
+            case Key.RightCtrl:
156
+                return Key.LeftCtrl;
157
+            case Key.RightShift:
158
+                return Key.LeftShift;
159
+            case Key.Return:
160
+                return Key.Enter;
161
+            case Key.NumPad0:
162
+                return Key.D0;
163
+            case Key.NumPad1:
164
+                return Key.D1;
165
+            case Key.NumPad2:
166
+                return Key.D2;
167
+            case Key.NumPad3:
168
+                return Key.D3;
169
+            case Key.NumPad4:
170
+                return Key.D4;
171
+            case Key.NumPad5:
172
+                return Key.D5;
173
+            case Key.NumPad6:
174
+                return Key.D6;
175
+            case Key.NumPad7:
176
+                return Key.D7;
177
+            case Key.NumPad8:
178
+                return Key.D8;
179
+            case Key.NumPad9:
180
+                return Key.D9;
181
+            default:
182
+                return keyValue;
183
+        }
184
+    }
185
+
186
+    static CombHotKey(cont: string): string {
187
+        if (cont === "") return "";
188
+        let result: string;
189
+
190
+        if (cont === "Shift" || cont === "Ctrl") cont = "";
191
+        // 假设在 TypeScript 中可以通过某种方式获取键盘修饰键状态
192
+        const modifiers = ""; // 这里需要根据实际情况实现获取键盘修饰键状态的逻辑
193
+        if (modifiers.toLowerCase().includes("alt")) return "";
194
+        if (modifiers.toLowerCase() !== "none") {
195
+            result = modifiers.replace(',', '+') + "+" + cont;
196
+        } else if (HotkeyParames._enableSelfKey.includes(cont)) {
197
+            result = cont;
198
+        } else {
199
+            result = "Ctrl + " + cont;
200
+        }
201
+
202
+        result = result.replace("Control", "Ctrl").replace(" ", "").replace("+", " + ");
203
+        return result;
204
+    }
205
+}
206
+
207
+export default HotkeyParames;

+ 147
- 0
ant-design-pro-vue3/src/views/front/platfrom/hotkey/Hotkeys.ts View File

@@ -0,0 +1,147 @@
1
+// 假设这些类型已经在其他地方定义
2
+interface THotKeyMessage {
3
+    KeyName: string;
4
+    KeyValue: string;
5
+    KeyType: number;
6
+    Tellernum: string;
7
+}
8
+
9
+interface TTellerHotKey {
10
+    KeyValue: string;
11
+    TellerNum: string;
12
+    KeyName: string;
13
+}
14
+
15
+class HotKeyHelper {
16
+    static SetHotKey(dicKeys: { [key: string]: string }): void {
17
+        // 实现设置快捷键的逻辑
18
+    }
19
+}
20
+
21
+class HotKeysHandle {
22
+    static GetKeyByTeller(tellerNO: string): THotKeyMessage[] {
23
+        // 实现获取柜员快捷键的逻辑
24
+        return [];
25
+    }
26
+
27
+    static UpdateKeyMessage(tTellerHotKey: TTellerHotKey): void {
28
+        // 实现更新快捷键信息的逻辑
29
+    }
30
+
31
+    static DelKeyValue(keyName: string, tellerNO: string, valueInt: string): void {
32
+        // 实现删除键值的逻辑
33
+    }
34
+
35
+    static DelKeyMessage(keyName: string, tellerNO: string): void {
36
+        // 实现删除快捷键信息的逻辑
37
+    }
38
+}
39
+
40
+class HotkeyParames {
41
+    static ParseKeyValue_FromIntToStr(keyValue: string): string {
42
+        // 实现从整数到字符串的键值解析逻辑
43
+        return '';
44
+    }
45
+
46
+    static ParseKeyValue_FromStrToInt(keyValue: string): string {
47
+        // 实现从字符串到整数的键值解析逻辑
48
+        return '';
49
+    }
50
+
51
+    static Separator: string = ';';
52
+}
53
+
54
+export class Hotkey {
55
+    private _arrKeys: THotKeyMessage[] = [];
56
+    private _tellerNO: string;
57
+
58
+    constructor(tellerNO: string) {
59
+        this._tellerNO = tellerNO;
60
+    }
61
+
62
+    private SetHotkey(th: THotKeyMessage[]): void {
63
+        if (!th || th.length === 0) return;
64
+        const dicKeys: { [key: string]: string } = {};
65
+        th.forEach(item => {
66
+            dicKeys[item.KeyName] = HotkeyParames.ParseKeyValue_FromIntToStr(item.KeyValue).replace(' ', '');
67
+        });
68
+        HotKeyHelper.SetHotKey(dicKeys);
69
+    }
70
+
71
+    public Register(): void {
72
+        this._arrKeys = HotKeysHandle.GetKeyByTeller(this._tellerNO);
73
+        this.SetHotkey(this._arrKeys);
74
+    }
75
+
76
+    public GetKeys(): THotKeyMessage[] {
77
+        return this._arrKeys;
78
+    }
79
+
80
+    public UpdateValueByKey(keyName: string, keyValue: string): void {
81
+        if (this._arrKeys.length === 0) return;
82
+        const tTellerHotKey: TTellerHotKey = {
83
+            KeyValue: '',
84
+            TellerNum: this._tellerNO,
85
+            KeyName: keyName
86
+        };
87
+
88
+        for (const item of this._arrKeys) {
89
+            if (item.KeyName === keyName) {
90
+                tTellerHotKey.KeyValue = HotkeyParames.ParseKeyValue_FromStrToInt(keyValue);
91
+                if (item.KeyValue === tTellerHotKey.KeyValue && item.Tellernum === tTellerHotKey.TellerNum) {
92
+                    break;
93
+                }
94
+                HotKeysHandle.UpdateKeyMessage(tTellerHotKey);
95
+                // item.KeyValue = tTellerHotKey.KeyValue;
96
+                break;
97
+            }
98
+        }
99
+        // Register(); // 影响效率2013-8-23
100
+    }
101
+
102
+    public DelValue(keyName: string, keyValue: string): void {
103
+        let valueInt = '';
104
+        for (const item of this._arrKeys) {
105
+            if (item.KeyName === keyName) {
106
+                valueInt = HotkeyParames.ParseKeyValue_FromStrToInt(keyValue);
107
+                HotKeysHandle.DelKeyValue(keyName, this._tellerNO, valueInt);
108
+                item.KeyValue = item.KeyValue.replace(valueInt, '');
109
+                break;
110
+            }
111
+        }
112
+        this.Register();
113
+    }
114
+
115
+    public IsUniquenessKey(keyValue: string): boolean {
116
+        let result = true;
117
+        keyValue = HotkeyParames.ParseKeyValue_FromStrToInt(keyValue);
118
+
119
+        const str = this._arrKeys
120
+           .filter(x => x.KeyValue.startsWith(keyValue) || x.KeyValue.includes(HotkeyParames.Separator + keyValue))
121
+           .map(x => x.KeyName);
122
+        if (str.length > 0) {
123
+            result = false;
124
+        }
125
+        return result;
126
+    }
127
+
128
+    public ResetKeys(keyType: number): void {
129
+        if (this._arrKeys.length === 0) return;
130
+        this._arrKeys.forEach(item => {
131
+            if (item.KeyType === keyType) {
132
+                HotKeysHandle.DelKeyMessage(item.KeyName, this._tellerNO);
133
+            }
134
+        });
135
+        this.Register();
136
+    }
137
+
138
+    public ResetKeys(): void {
139
+        if (this._arrKeys.length === 0) return;
140
+        this._arrKeys.forEach(item => {
141
+            if (item.Tellernum === this._tellerNO) {
142
+                HotKeysHandle.DelKeyMessage(item.KeyName, this._tellerNO);
143
+            }
144
+        });
145
+        this.Register();
146
+    }
147
+}

Loading…
Cancel
Save