Skip to content

Commit

Permalink
- 新增快捷键
Browse files Browse the repository at this point in the history
  > ctrl + insert 跳转添加自选基金

  > ctrl + delete 删除选中的自选基金

- 移除删除自选基金界面
  • Loading branch information
adams549659584 committed Jan 6, 2021
1 parent b145491 commit dfa0a09
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 15 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@

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

### v1.6.0

- 新增快捷键

> ctrl + insert 跳转添加自选基金
> ctrl + delete 删除选中的自选基金
- 移除删除自选基金界面

### v1.5.1

- 今日收益确认无需等待持仓数量为0的基金
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "utools-fund",
"version": "v1.5.1",
"version": "v1.6.0",
"description": "自选基金助手",
"main": "main.ts",
"scripts": {
Expand All @@ -23,4 +23,4 @@
"typescript": "^3.9.7"
},
"dependencies": {}
}
}
12 changes: 6 additions & 6 deletions plugin.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const pluginConfig = {
icon: 'assets/img/add.png',
cmds: ['添加自选基金', '继续添加自选基金', '基金', 'fund'],
},
{
code: 'utools_fund_del',
explain: '删除自选基金',
icon: 'assets/img/del.png',
cmds: ['删除自选基金', '继续删除自选基金', '基金', 'fund'],
},
// {
// code: 'utools_fund_del',
// explain: '删除自选基金',
// icon: 'assets/img/del.png',
// cmds: ['删除自选基金', '继续删除自选基金', '基金', 'fund'],
// },
{
code: 'utools_fund_my',
explain: '我的自选基金',
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import commonjs from 'rollup-plugin-commonjs';
import pluginConfig from './plugin.config.js';
import copy from 'rollup-plugin-copy';
import replace from 'rollup-plugin-replace';
import { terser } from "rollup-plugin-terser";
import { terser } from 'rollup-plugin-terser';

/**
* 当前环境
Expand All @@ -28,7 +28,7 @@ const rollupOptions = {
format: 'cjs',
sourcemap: NODE_ENV === 'production' ? false : 'inline',
},
external: ['../assets/js/axios.min.js'],
external: ['../assets/js/axios.min.js', '../assets/js/mousetrap.min.js'],
plugins: [
cleaner({
targets: ['dist'],
Expand All @@ -48,7 +48,7 @@ const rollupOptions = {
rename: (name, extension) => 'plugin.json',
},
{ src: 'README.md', dest: 'dist' },
{ src: 'src/assets/**/*', dest: 'dist' }
{ src: 'src/assets/**/*', dest: 'dist' },
],
verbose: true,
}),
Expand Down
11 changes: 11 additions & 0 deletions src/assets/js/mousetrap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion src/features/fundAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@ import { ISearchFundResult } from '@/model/ISearchFundResult';
import { get } from '@/Helper/HttpHelper';
import FundDBHelper from '@/Helper/FundDBHelper';

const DEFAULT_CB_LIST: CallbackListItem[] = [
{
title: `我的自选基金`,
description: `回车键返回`,
icon: 'assets/img/logo.png',
},
// {
// title: `删除自选基金`,
// description: ``,
// icon: 'assets/img/del.png',
// },
];

const fundAdd: TplFeature = {
mode: 'list',
args: {
placeholder: '输入基金简称/代码/拼音,回车键确认',
enter: async (action, callbackSetList) => {
callbackSetList(DEFAULT_CB_LIST);
},
search: async (action, searchWord, callbackSetList) => {
// 获取一些数据
let cbList: CallbackListItem[] = [];
Expand All @@ -29,10 +45,17 @@ const fundAdd: TplFeature = {
});
}
}
callbackSetList(cbList);
} else {
callbackSetList(DEFAULT_CB_LIST);
}
callbackSetList(cbList);
}, // 用户选择列表中某个条目时被调用
select: (action, itemData, callbackSetList) => {
const defaultOpt = DEFAULT_CB_LIST.find(x => x.title === itemData.title);
if (defaultOpt) {
utools.redirect(itemData.title, '');
return;
}
const existFund = FundDBHelper.get(itemData.title);
if (!existFund) {
FundDBHelper.set({
Expand Down
39 changes: 38 additions & 1 deletion src/features/fundMy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { IFundValuationDetailResult } from '@/model/IFundValuationDetailResult';
import { get } from '@/Helper/HttpHelper';
import { ISearchFundResult } from '@/model/ISearchFundResult';
import { IFundEnt } from '@/model/IFundEnt';
import Mousetrap from '../assets/js/mousetrap.min.js';

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

const getMyFundDetails = async () => {
const dbList = FundDBHelper.getAll();
Expand Down Expand Up @@ -142,6 +144,7 @@ const hanlderUTools = {
val.onPluginOut = cb => {
console.log(`用户退出插件`);
clearTimeout(QUERY_TIMER);
unregisterShortCut();
return rawOnPluginOut(cb);
};
val.onPluginOut.isMagicRevision = true;
Expand All @@ -157,18 +160,51 @@ const hanlderUTools = {
// },
};

const registerShortCut = async () => {
// 删除
Mousetrap.bind('mod+del', () => {
const selectedItem = document.querySelector('.list-item-selected .list-item-title');
if (selectedItem && selectedItem.innerHTML) {
const fundId = selectedItem.innerHTML.split(' ')[0];
if (CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 && CACHE_FUND_DB_LIST.some(x => x.data.id === fundId)) {
FundDBHelper.del(fundId);
if (CACHE_CALLBACK_SET_LIST) {
clearTimeout(QUERY_TIMER);
showFundDetails(CACHE_CALLBACK_SET_LIST);
} else {
console.error(`CACHE_CALLBACK_SET_LIST is null`);
}
} else {
console.error(`del error :`);
console.error(`fundId : ${fundId} , CACHE_FUND_DB_LIST : `, CACHE_FUND_DB_LIST);
}
}
return false;
});
// 跳转新增
Mousetrap.bind('mod+ins', () => {
utools.redirect('添加自选基金', '');
});
};
const unregisterShortCut = async () => {
// Mousetrap.unbind(['up', 'down', 'mod+del', 'mod+ins']);
};

const fundMy: TplFeature = {
mode: 'list',
args: {
placeholder: '输入持有份额,选择对应基金,回车键保存,s前缀搜索',
placeholder: '输入份额,选择基金,Enter 保存,ctrl + delete 删除 , ctrl + insert 添加 ,s前缀搜索',
enter: async (action, callbackSetList) => {
CACHE_CALLBACK_SET_LIST = callbackSetList;
if (!utools.isMagicRevision) {
utools = new Proxy(utools, hanlderUTools);
}
clearTimeout(QUERY_TIMER);
showFundDetails(callbackSetList);
registerShortCut();
},
search: async (action, searchWord, callbackSetList) => {
CACHE_CALLBACK_SET_LIST = callbackSetList;
let dbList = CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 ? CACHE_FUND_DB_LIST : await getMyFundDetails();
if (searchWord && searchWord.startsWith('s')) {
searchWord = searchWord.substring(1);
Expand All @@ -181,6 +217,7 @@ const fundMy: TplFeature = {
callbackSetList(cbList);
}, // 用户选择列表中某个条目时被调用
select: (action, itemData, callbackSetList) => {
CACHE_CALLBACK_SET_LIST = callbackSetList;
if (!CACHE_FUND_DB_LIST || CACHE_FUND_DB_LIST.length === 0) {
utools.redirect('添加自选基金', '');
return;
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { TemplatePlugin } from '@/types/utools';
import fundAdd from './features/fundAdd';
import fundDel from './features/fundDel';
// import fundDel from './features/fundDel';
import fundMarket from './features/fundMarket';
import fundExport from './features/fundExport';
import fundMy from './features/fundMy';
import fundImport from './features/fundImport';

const preload: TemplatePlugin = {
utools_fund_add: fundAdd,
utools_fund_del: fundDel,
// utools_fund_del: fundDel,
utools_fund_my: fundMy,
utools_fund_market: fundMarket,
utools_fund_config_export: fundExport,
Expand Down
34 changes: 34 additions & 0 deletions src/types/mousetrap.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module '*/mousetrap.min.js' {
namespace Mousetrap {
interface ExtendedKeyboardEvent extends KeyboardEvent {
returnValue: boolean; // IE returnValue
}

interface MousetrapStatic {
(el?: Element): MousetrapInstance;
new (el?: Element): MousetrapInstance;
addKeycodes(keycodes: { [key: number]: string }): void;
stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
bind(keys: string | string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): MousetrapInstance;
unbind(keys: string | string[], action?: string): MousetrapInstance;
trigger(keys: string, action?: string): MousetrapInstance;
reset(): MousetrapInstance;

/** https://craig.is/killing/mice#extensions.global */
bindGlobal(keyArray: string | string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): void;
}

interface MousetrapInstance {
stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
bind(keys: string | string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): this;
unbind(keys: string | string[], action?: string): this;
trigger(keys: string, action?: string): this;
handleKey(character: string, modifiers: string[], e: ExtendedKeyboardEvent): void;
reset(): this;
}
}

const Mousetrap: Mousetrap.MousetrapStatic;

export default Mousetrap;
}

0 comments on commit dfa0a09

Please sign in to comment.