完成search界面搜索组件后打开配置界面

This commit is contained in:
yuruo
2024-07-01 17:47:08 +08:00
parent a2baa605be
commit 6600840e0e
6 changed files with 23 additions and 20 deletions

View File

@@ -9,7 +9,7 @@ export interface OptionsType extends Partial<BrowserWindowConstructorOptions>{
hash?: string
initShow?: boolean
}
export function createWindow(options: OptionsType): BrowserWindow { // Create the browser window.
export function createWindow(options: OptionsType, router_url=""): BrowserWindow { // Create the browser window.
const win = new BrowserWindow(Object.assign({
width: 500,
height: 350,
@@ -39,15 +39,14 @@ export function createWindow(options: OptionsType): BrowserWindow { // Create t
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
// win.loadURL(process.env['ELECTRON_RENDERER_URL'] + "/#config/category/contentList")
win.loadURL(process.env['ELECTRON_RENDERER_URL'] + options.hash)
win.loadURL(process.env['ELECTRON_RENDERER_URL'] + options.hash + router_url)
} else {
win.loadURL(
url.format({
pathname: join(__dirname, '../renderer/index.html'),
protocol: 'file',
slashes: true,
hash: options.hash?.substring(1)
hash: options.hash?.substring(1) + router_url
})
)
}

View File

@@ -1,16 +1,15 @@
import {ipcMain, IpcMainEvent } from "electron"
import { getWindowByName, getWindowByEvent} from "./windows"
ipcMain.on('openWindow', (_event: IpcMainEvent, name: WindowNameType) => {
getWindowByName(name).show()
ipcMain.on('openWindow', (_event: IpcMainEvent, name: WindowNameType, router_url="") => {
const win = getWindowByName(name, router_url)
win.show()
})
ipcMain.on('closeWindow', (_event: IpcMainEvent, name: WindowNameType) => {
getWindowByName(name).hide()
})
ipcMain.on('setIgnoreMouseEvents',
(event: IpcMainEvent, ignore: boolean, options?:{forward: boolean}) => {
getWindowByEvent(event).setIgnoreMouseEvents(ignore, options)

View File

@@ -7,7 +7,7 @@ export const config = {
options: {
initShow: true,
hash: '',
openDevTools: true,
openDevTools: false,
}
},
code: {
@@ -16,7 +16,7 @@ export const config = {
initShow: true,
width: 1300,
height: 700,
openDevTools: true,
openDevTools: false,
frame: true,
transparent: false,
hash: '/#config/category/contentList'
@@ -28,7 +28,7 @@ export const config = {
initShow: true,
width: 600,
height: 400,
openDevTools: true,
openDevTools: false,
frame: true,
transparent: false,
hash: '/#config'
@@ -39,15 +39,16 @@ export const config = {
// createWindow({})
// 根据名称获取窗口
export const getWindowByName = (name: WindowNameType)=>{
export const getWindowByName = (name: WindowNameType, router_url="")=>{
// 根据id取得窗口
let win = BrowserWindow.fromId(config[name].id)
// 避免重复点击重复创建窗口
if (!win) {
win = createWindow(config[name].options)
win = createWindow(config[name].options,router_url)
config[name].id = win.id
}
return win
}
@@ -59,8 +60,8 @@ export const getWindowByEvent = (event: IpcMainEvent | IpcMainInvokeEvent) => {
app.whenReady().then(() => {
// getWindowByName('search')
getWindowByName('code')
getWindowByName('search')
// getWindowByName('code')
// getWindowByName('config')
})

View File

@@ -1,4 +1,5 @@
import { ElectronAPI } from '@electron-toolkit/preload'
import { BrowserWindow } from 'electron'
declare global {
interface Window {
@@ -8,7 +9,7 @@ declare global {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward: boolean }) => void,
openConfigWindow: () => void,
sql: <T>(sql: string, type: SqlActionType, params?: Record<string, any>) => Promise<T>
openWindow: (name: WindowNameType) => void,
openWindow: (name: WindowNameType, router_url?: string) => BrowserWindow,
closeWindow: (name: WindowNameType) => void,
initTable: () => void,
getConfig: () => Promise<ConfigType>

View File

@@ -15,8 +15,8 @@ const api = {
sql: (sql: string, type: SqlActionType, params={}) => {
return ipcRenderer.invoke("sql", sql, type, params)
},
openWindow: (name: WindowNameType) =>{
ipcRenderer.send("openWindow", name)
openWindow: (name: WindowNameType, router_url?: string) =>{
return ipcRenderer.send("openWindow", name, router_url)
},
closeWindow: (name: WindowNameType) =>{
ipcRenderer.send("closeWindow", name)

View File

@@ -1,11 +1,13 @@
import {useStore} from "@renderer/store/useStore"
import { useCallback, useEffect } from "react"
import { useNavigate } from "react-router-dom"
export default()=>{
const data = useStore((state)=>state.data)
const setData = useStore((state)=>state.setData)
const setSearch = useStore((state)=>state.setSearch)
const selectId = useStore((state)=>state.selectId)
const setSelectId = useStore((state)=>state.setSelectId)
const navigate = useNavigate()
const handleKeyEvent = useCallback((e: KeyboardEvent) => {
switch(e.key){
@@ -39,11 +41,12 @@ export default()=>{
// 选中代码块
async function select(id: Number){
const content = data.find((item)=>item.id == id)?.content
setData([])
setSearch('')
if (content) await navigator.clipboard.writeText(content)
// if (content) await navigator.clipboard.writeText(content)
window.api.closeWindow('search')
const category_id = data.find((item)=>item.id == id)?.category_id
window.api.openWindow('code', `/${category_id}/content/${id}`)
}
useEffect(() => {