Skip to content

Commit dfa0a09

Browse files
- 新增快捷键
> ctrl + insert 跳转添加自选基金 > ctrl + delete 删除选中的自选基金 - 移除删除自选基金界面
1 parent b145491 commit dfa0a09

File tree

9 files changed

+130
-15
lines changed

9 files changed

+130
-15
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515

1616
![Instructions.gif](https://s1.ax1x.com/2020/08/19/dQ8R3t.gif)
1717

18+
### v1.6.0
19+
20+
- 新增快捷键
21+
22+
> ctrl + insert 跳转添加自选基金
23+
24+
> ctrl + delete 删除选中的自选基金
25+
26+
- 移除删除自选基金界面
27+
1828
### v1.5.1
1929

2030
- 今日收益确认无需等待持仓数量为0的基金

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "utools-fund",
3-
"version": "v1.5.1",
3+
"version": "v1.6.0",
44
"description": "自选基金助手",
55
"main": "main.ts",
66
"scripts": {
@@ -23,4 +23,4 @@
2323
"typescript": "^3.9.7"
2424
},
2525
"dependencies": {}
26-
}
26+
}

plugin.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const pluginConfig = {
2929
icon: 'assets/img/add.png',
3030
cmds: ['添加自选基金', '继续添加自选基金', '基金', 'fund'],
3131
},
32-
{
33-
code: 'utools_fund_del',
34-
explain: '删除自选基金',
35-
icon: 'assets/img/del.png',
36-
cmds: ['删除自选基金', '继续删除自选基金', '基金', 'fund'],
37-
},
32+
// {
33+
// code: 'utools_fund_del',
34+
// explain: '删除自选基金',
35+
// icon: 'assets/img/del.png',
36+
// cmds: ['删除自选基金', '继续删除自选基金', '基金', 'fund'],
37+
// },
3838
{
3939
code: 'utools_fund_my',
4040
explain: '我的自选基金',

rollup.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import commonjs from 'rollup-plugin-commonjs';
77
import pluginConfig from './plugin.config.js';
88
import copy from 'rollup-plugin-copy';
99
import replace from 'rollup-plugin-replace';
10-
import { terser } from "rollup-plugin-terser";
10+
import { terser } from 'rollup-plugin-terser';
1111

1212
/**
1313
* 当前环境
@@ -28,7 +28,7 @@ const rollupOptions = {
2828
format: 'cjs',
2929
sourcemap: NODE_ENV === 'production' ? false : 'inline',
3030
},
31-
external: ['../assets/js/axios.min.js'],
31+
external: ['../assets/js/axios.min.js', '../assets/js/mousetrap.min.js'],
3232
plugins: [
3333
cleaner({
3434
targets: ['dist'],
@@ -48,7 +48,7 @@ const rollupOptions = {
4848
rename: (name, extension) => 'plugin.json',
4949
},
5050
{ src: 'README.md', dest: 'dist' },
51-
{ src: 'src/assets/**/*', dest: 'dist' }
51+
{ src: 'src/assets/**/*', dest: 'dist' },
5252
],
5353
verbose: true,
5454
}),

src/assets/js/mousetrap.min.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/features/fundAdd.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,26 @@ import { ISearchFundResult } from '@/model/ISearchFundResult';
33
import { get } from '@/Helper/HttpHelper';
44
import FundDBHelper from '@/Helper/FundDBHelper';
55

6+
const DEFAULT_CB_LIST: CallbackListItem[] = [
7+
{
8+
title: `我的自选基金`,
9+
description: `回车键返回`,
10+
icon: 'assets/img/logo.png',
11+
},
12+
// {
13+
// title: `删除自选基金`,
14+
// description: ``,
15+
// icon: 'assets/img/del.png',
16+
// },
17+
];
18+
619
const fundAdd: TplFeature = {
720
mode: 'list',
821
args: {
922
placeholder: '输入基金简称/代码/拼音,回车键确认',
23+
enter: async (action, callbackSetList) => {
24+
callbackSetList(DEFAULT_CB_LIST);
25+
},
1026
search: async (action, searchWord, callbackSetList) => {
1127
// 获取一些数据
1228
let cbList: CallbackListItem[] = [];
@@ -29,10 +45,17 @@ const fundAdd: TplFeature = {
2945
});
3046
}
3147
}
48+
callbackSetList(cbList);
49+
} else {
50+
callbackSetList(DEFAULT_CB_LIST);
3251
}
33-
callbackSetList(cbList);
3452
}, // 用户选择列表中某个条目时被调用
3553
select: (action, itemData, callbackSetList) => {
54+
const defaultOpt = DEFAULT_CB_LIST.find(x => x.title === itemData.title);
55+
if (defaultOpt) {
56+
utools.redirect(itemData.title, '');
57+
return;
58+
}
3659
const existFund = FundDBHelper.get(itemData.title);
3760
if (!existFund) {
3861
FundDBHelper.set({

src/features/fundMy.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { IFundValuationDetailResult } from '@/model/IFundValuationDetailResult';
44
import { get } from '@/Helper/HttpHelper';
55
import { ISearchFundResult } from '@/model/ISearchFundResult';
66
import { IFundEnt } from '@/model/IFundEnt';
7+
import Mousetrap from '../assets/js/mousetrap.min.js';
78

89
// 缓存基金详情
910
let CACHE_FUND_DB_LIST: DBItem<IFundEnt>[];
1011
// 当前搜索关键字
1112
let CURRENT_SEARCH_WORD = '';
1213
let QUERY_TIMER: NodeJS.Timeout;
14+
let CACHE_CALLBACK_SET_LIST: CallbackSetList;
1315

1416
const getMyFundDetails = async () => {
1517
const dbList = FundDBHelper.getAll();
@@ -142,6 +144,7 @@ const hanlderUTools = {
142144
val.onPluginOut = cb => {
143145
console.log(`用户退出插件`);
144146
clearTimeout(QUERY_TIMER);
147+
unregisterShortCut();
145148
return rawOnPluginOut(cb);
146149
};
147150
val.onPluginOut.isMagicRevision = true;
@@ -157,18 +160,51 @@ const hanlderUTools = {
157160
// },
158161
};
159162

163+
const registerShortCut = async () => {
164+
// 删除
165+
Mousetrap.bind('mod+del', () => {
166+
const selectedItem = document.querySelector('.list-item-selected .list-item-title');
167+
if (selectedItem && selectedItem.innerHTML) {
168+
const fundId = selectedItem.innerHTML.split(' ')[0];
169+
if (CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 && CACHE_FUND_DB_LIST.some(x => x.data.id === fundId)) {
170+
FundDBHelper.del(fundId);
171+
if (CACHE_CALLBACK_SET_LIST) {
172+
clearTimeout(QUERY_TIMER);
173+
showFundDetails(CACHE_CALLBACK_SET_LIST);
174+
} else {
175+
console.error(`CACHE_CALLBACK_SET_LIST is null`);
176+
}
177+
} else {
178+
console.error(`del error :`);
179+
console.error(`fundId : ${fundId} , CACHE_FUND_DB_LIST : `, CACHE_FUND_DB_LIST);
180+
}
181+
}
182+
return false;
183+
});
184+
// 跳转新增
185+
Mousetrap.bind('mod+ins', () => {
186+
utools.redirect('添加自选基金', '');
187+
});
188+
};
189+
const unregisterShortCut = async () => {
190+
// Mousetrap.unbind(['up', 'down', 'mod+del', 'mod+ins']);
191+
};
192+
160193
const fundMy: TplFeature = {
161194
mode: 'list',
162195
args: {
163-
placeholder: '输入持有份额,选择对应基金,回车键保存,s前缀搜索',
196+
placeholder: '输入份额,选择基金,Enter 保存,ctrl + delete 删除 , ctrl + insert 添加 ,s前缀搜索',
164197
enter: async (action, callbackSetList) => {
198+
CACHE_CALLBACK_SET_LIST = callbackSetList;
165199
if (!utools.isMagicRevision) {
166200
utools = new Proxy(utools, hanlderUTools);
167201
}
168202
clearTimeout(QUERY_TIMER);
169203
showFundDetails(callbackSetList);
204+
registerShortCut();
170205
},
171206
search: async (action, searchWord, callbackSetList) => {
207+
CACHE_CALLBACK_SET_LIST = callbackSetList;
172208
let dbList = CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 ? CACHE_FUND_DB_LIST : await getMyFundDetails();
173209
if (searchWord && searchWord.startsWith('s')) {
174210
searchWord = searchWord.substring(1);
@@ -181,6 +217,7 @@ const fundMy: TplFeature = {
181217
callbackSetList(cbList);
182218
}, // 用户选择列表中某个条目时被调用
183219
select: (action, itemData, callbackSetList) => {
220+
CACHE_CALLBACK_SET_LIST = callbackSetList;
184221
if (!CACHE_FUND_DB_LIST || CACHE_FUND_DB_LIST.length === 0) {
185222
utools.redirect('添加自选基金', '');
186223
return;

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { TemplatePlugin } from '@/types/utools';
22
import fundAdd from './features/fundAdd';
3-
import fundDel from './features/fundDel';
3+
// import fundDel from './features/fundDel';
44
import fundMarket from './features/fundMarket';
55
import fundExport from './features/fundExport';
66
import fundMy from './features/fundMy';
77
import fundImport from './features/fundImport';
88

99
const preload: TemplatePlugin = {
1010
utools_fund_add: fundAdd,
11-
utools_fund_del: fundDel,
11+
// utools_fund_del: fundDel,
1212
utools_fund_my: fundMy,
1313
utools_fund_market: fundMarket,
1414
utools_fund_config_export: fundExport,

src/types/mousetrap.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare module '*/mousetrap.min.js' {
2+
namespace Mousetrap {
3+
interface ExtendedKeyboardEvent extends KeyboardEvent {
4+
returnValue: boolean; // IE returnValue
5+
}
6+
7+
interface MousetrapStatic {
8+
(el?: Element): MousetrapInstance;
9+
new (el?: Element): MousetrapInstance;
10+
addKeycodes(keycodes: { [key: number]: string }): void;
11+
stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
12+
bind(keys: string | string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): MousetrapInstance;
13+
unbind(keys: string | string[], action?: string): MousetrapInstance;
14+
trigger(keys: string, action?: string): MousetrapInstance;
15+
reset(): MousetrapInstance;
16+
17+
/** https://craig.is/killing/mice#extensions.global */
18+
bindGlobal(keyArray: string | string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): void;
19+
}
20+
21+
interface MousetrapInstance {
22+
stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
23+
bind(keys: string | string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): this;
24+
unbind(keys: string | string[], action?: string): this;
25+
trigger(keys: string, action?: string): this;
26+
handleKey(character: string, modifiers: string[], e: ExtendedKeyboardEvent): void;
27+
reset(): this;
28+
}
29+
}
30+
31+
const Mousetrap: Mousetrap.MousetrapStatic;
32+
33+
export default Mousetrap;
34+
}

0 commit comments

Comments
 (0)