index.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <div>
  3. <!-- <el-input v-model="folderPath" placeholder="请选择文件夹" readonly>
  4. <template #append>
  5. <el-button @click="selectFolder">选择文件夹</el-button>
  6. </template>
  7. </el-input> -->
  8. <el-button @click="openFolder('D:\ips')"> 打开文档文件夹 </el-button>
  9. </div>
  10. </template>
  11. <script>
  12. const { ipcRenderer } = require("electron");
  13. const { shell } = window.require("electron");
  14. export default {
  15. data() {
  16. return {
  17. folderPath: "",
  18. };
  19. },
  20. methods: {
  21. async selectFolder() {
  22. try {
  23. const path = await ipcRenderer.invoke("select-folder");
  24. if (path) {
  25. this.folderPath = path;
  26. this.$emit("path-selected", path);
  27. }
  28. } catch (error) {
  29. console.error("选择文件夹出错:", error);
  30. this.$message.error("选择文件夹失败");
  31. }
  32. },
  33. openFolder(path) {
  34. try {
  35. shell.openPath(path).then((result) => {
  36. if (result) {
  37. this.$message.error(`打开文件夹失败: ${result}`);
  38. }
  39. });
  40. } catch (error) {
  41. this.$message.error(`打开文件夹出错: ${error.message}`);
  42. }
  43. },
  44. },
  45. };
  46. </script>