1
YM
2024-05-15 e4bbe681c35e9f8f2d2ef6a3e40f3645239987ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<template>
  <page>
    <div class="setting">
      <el-divider content-position="left">设置下载目录</el-divider>
      <div class="setDownloadPathBox">
        <el-input style="width: 300px; margin-right: 10px" v-model="downloadPath" disabled />
        <el-button type="primary" @click="setPath">设置目录</el-button>
        <el-button type="primary" @click="openPath">打开目录</el-button>
      </div>
    </div>
  </page>
</template>
 
<script setup lang="ts">
import { ref, reactive, inject, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
const downloadPath = ref('')
onMounted(() => {
  const path = window.electronAPI.getDownloadPath()
  downloadPath.value = path
})
const setPath = () => {
  const path = window.electronAPI.openSelectFileOrFolderDialog({
    title: '选择下载目录',
    properties: ['openDirectory']
  })
  downloadPath.value = path[0]
  const data = window.electronAPI.setDownloadPath(path[0])
  if (data.state) {
    ElMessage({
      message: '设置成功!',
      type: 'success'
    })
  } else {
    ElMessage({
      message: data.msg,
      type: 'error'
    })
  }
}
const openPath = () => {
  const data = window.electronAPI.openPath(downloadPath.value)
  if (!data.state) {
    ElMessage({
      message: data.msg,
      type: 'error'
    })
  }
}
</script>
 
<style lang="less">
.setting {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 10px 50px;
  .setDownloadPathBox {
    display: flex;
  }
}
</style>