0
点赞
收藏
分享

微信扫一扫

基于FastAPI实现本地大模型API封装调用

NicoalsNC 2024-11-19 阅读 8

需求:已知文件路径,通过点击列表页的操作按钮可查看文件内容。

提供思路:实现方式有两种:

(1)打开弹窗或客户端新开窗口。不同类型应用不同插件进行直接预览查看。

(2)通过electron的shell.openPath指定系统默认程序直接打开页面。(这种方式实现简单,样式规范,具有统一性)

这里介绍第二种实现方式:

主进程监听:main.js

const { shell } = require('electron')
// 通过系统打开窗口预览文件 
ipcMain.on('open-file', (event, filePath) => {
  // 打开文件
  shell
    .openPath(filePath)
    .then(() => {
      console.log('文件已使用系统默认程序打开')
    })
    .catch(err => {
      console.error('打开文件失败:', err)
    })
})

渲染进程preload.js

  // 打开窗口预览文件
  openFileSend: (...args) => ipcRenderer.send("open-file", ...args),

vue组件使用:

function previewFile (row) {
  // const filePath = 'D:\\work\\test.csv' 调试用
  window.electronAPI?.openFileSend(row.cached_file_path)
}
举报

相关推荐

0 条评论