1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <template>
- <div>
- <!-- <el-input v-model="folderPath" placeholder="请选择文件夹" readonly>
- <template #append>
- <el-button @click="selectFolder">选择文件夹</el-button>
- </template>
- </el-input> -->
- <el-button @click="openFolder('D:\ips')"> 打开文档文件夹 </el-button>
- </div>
- </template>
- <script>
- const { ipcRenderer } = require("electron");
- const { shell } = window.require("electron");
- export default {
- data() {
- return {
- folderPath: "",
- };
- },
- methods: {
- async selectFolder() {
- try {
- const path = await ipcRenderer.invoke("select-folder");
- if (path) {
- this.folderPath = path;
- this.$emit("path-selected", path);
- }
- } catch (error) {
- console.error("选择文件夹出错:", error);
- this.$message.error("选择文件夹失败");
- }
- },
- openFolder(path) {
- try {
- shell.openPath(path).then((result) => {
- if (result) {
- this.$message.error(`打开文件夹失败: ${result}`);
- }
- });
- } catch (error) {
- this.$message.error(`打开文件夹出错: ${error.message}`);
- }
- },
- },
- };
- </script>
|