bind4comm.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // 绑定公共接口
  2. package main
  3. import (
  4. "github.com/wailsapp/wails/v2/pkg/runtime"
  5. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. )
  7. // Greet returns a greeting for the given name
  8. func (a *App) Dispatch(event string, data interface{}) error {
  9. runtime.EventsEmit(a.ctx, event, data)
  10. return nil
  11. }
  12. // SelectSaveFilePath
  13. func (a *App) SelectSaveFilePath(defaultDirectory, defaultFileName string) string {
  14. qu.Debug("导出文件位置:", defaultDirectory, defaultFileName)
  15. path, err := runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{Filters: []runtime.FileFilter{
  16. {Pattern: "*.epub", DisplayName: "epub file *.epub"},
  17. {Pattern: "*.xlsx", DisplayName: "excel file *.xlsx"},
  18. {Pattern: "*.json", DisplayName: "json file *.json"},
  19. },
  20. DefaultFilename: defaultFileName,
  21. DefaultDirectory: defaultDirectory,
  22. })
  23. if err != nil {
  24. qu.Debug(err.Error())
  25. return ""
  26. }
  27. return path
  28. }
  29. // SelectOpenFilePath
  30. func (a *App) SelectOpenFilePath() string {
  31. path, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{Filters: []runtime.FileFilter{
  32. {Pattern: "*.xlsx", DisplayName: "excel file *.xlsx"},
  33. }})
  34. if err != nil {
  35. qu.Debug(err.Error())
  36. return ""
  37. }
  38. return path
  39. }