支持 setSubInput API

This commit is contained in:
muwoo
2021-12-07 11:19:08 +08:00
parent 1353c440aa
commit a9827c6db1
10 changed files with 60 additions and 13 deletions

View File

@@ -8,6 +8,7 @@
@openMenu="openMenu"
@changeSelect="changeSelect"
:searchValue="searchValue"
:placeholder="placeholder"
/>
</div>
<Result
@@ -36,6 +37,7 @@ const {
changeSelect,
openPlugin,
currentPlugin,
placeholder,
} = createPluginManager();
initPlugins();
@@ -89,5 +91,4 @@ const openMenu = () => {
width: 0;
}
}
</style>

View File

@@ -4,12 +4,12 @@
<a-input
id="search"
class="main-input"
placeholder="Hi, Rubick2"
@input="(e) => changeValue(e)"
@keydown.down="() => emit('changeCurrent', 1)"
@keydown.up="() => emit('changeCurrent', -1)"
@keydown="checkNeedInit"
:value="searchValue"
:placeholder="placeholder || 'Hi, Rubick2'"
>
<template #suffix>
<div @click="() => emit('openMenu')" class="suffix-tool" >
@@ -31,6 +31,10 @@ const props = defineProps({
type: [String, Number],
default: "",
},
placeholder: {
type: String,
default: "",
},
currentPlugin: {},
});

View File

@@ -47,10 +47,11 @@ const createPluginManager = (): any => {
// @ts-ignore
// document.getElementById("search").value = "";
// state.searchValue = "";
setSearchValue("");
}
};
const { searchValue, onSearch } = searchManager();
const { searchValue, onSearch, setSearchValue, placeholder } = searchManager();
const { options } = optionsManager({
searchValue,
baseDir,
@@ -91,6 +92,7 @@ const createPluginManager = (): any => {
changeSelect,
options,
searchValue,
placeholder,
};
};

View File

@@ -1,19 +1,34 @@
import { reactive, toRefs } from "vue";
import {ipcRenderer} from "electron";
const searchManager = () => {
const state = reactive({
searchValue: "",
placeholder: "",
});
// search Input operation
const onSearch = (e) => {
const value = e.target.value;
state.searchValue = value;
ipcRenderer.sendSync("msg-trigger", {
type: "sendSubInputChangeEvent",
data: value,
});
};
const setSearchValue = (value: string) => {
state.searchValue = value;
};
window.setSubInput = ({ placeholder }: { placeholder: string }) => {
state.placeholder = placeholder;
};
return {
...toRefs(state),
onSearch,
setSearchValue,
};
};

View File

@@ -12,3 +12,7 @@ declare module 'main' {
declare const __static: string
declare module 'lodash.throttle'
interface Window {
setSubInput: ({ placeholder }: { placeholder: string }) => void;
}