Skip to content

Commit bea3b2e

Browse files
committed
feat: 保存用户目录配置
1 parent 5e8c83c commit bea3b2e

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

frontend/src/layout/DialogOpen.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ const addDir = (v: string) => {
125125
}
126126
127127
user.cfg.dir.unshift(v)
128+
129+
user.update()
128130
}
129131
130132
const deleteDir = (v: string) => {
@@ -135,6 +137,8 @@ const deleteDir = (v: string) => {
135137
if (cfg.value.folderDefOpen === v) {
136138
cfg.value.folderDefOpen = ''
137139
}
140+
141+
user.update()
138142
}
139143
}
140144
</script>

frontend/src/layout/ViewLeft/ViewHistory.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="view">
33
<div class="head">
4-
<div class="title">历史记录</div>
4+
<div class="title">文件打开记录</div>
55

66
<el-icon class="icon" @click="open.clearHistory()"><Delete /></el-icon>
77
</div>

frontend/src/store/user.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ref } from 'vue'
22
import { defineStore } from 'pinia'
3+
import axios from 'axios'
34

4-
import { IS_DEV } from '@/utils/env'
5+
import { HOST, IS_DEV, USER_CONFIG_PATH } from '@/utils/env'
56

67
import { useLikeStore } from '@/store/like'
78

@@ -10,7 +11,7 @@ interface LikeModel {
1011
}
1112

1213
const getDef = (): LikeModel => ({
13-
dir: IS_DEV ? ['/Users/flex/Downloads', '/Users/flex/Downloads/code.editor'] : ['/vol1/1000'],
14+
dir: IS_DEV ? ['/Users/flex/Downloads'] : ['/vol1/1000'],
1415
})
1516

1617
export const useUserStore = defineStore('user', () => {
@@ -21,18 +22,35 @@ export const useUserStore = defineStore('user', () => {
2122
const cfg = ref(getDef())
2223

2324
const load = async () => {
24-
// todo api
25+
const { data: result1 } = await axios.get(HOST, {
26+
params: { _api: 'read', path: USER_CONFIG_PATH },
27+
})
28+
29+
if (result1.code === 404) {
30+
await update()
31+
} else {
32+
cfg.value = result1 as LikeModel
33+
}
2534

2635
like.cfg.folderActive = like.cfg.folderDefOpen || cfg.value.dir[0] || ''
2736

2837
initialized.value = true
2938
}
3039

31-
return {
32-
initialized,
33-
34-
cfg,
35-
36-
load,
40+
const update = async () => {
41+
await axios.post(
42+
HOST,
43+
{
44+
encode: 'utf8',
45+
path: USER_CONFIG_PATH,
46+
value: JSON.stringify(cfg.value),
47+
force: 1,
48+
},
49+
{
50+
params: { _api: 'save' },
51+
},
52+
)
3753
}
54+
55+
return { initialized, cfg, load, update }
3856
})

frontend/src/utils/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export const IS_DEV = import.meta.env.MODE === 'development'
22

33
export const HOST = IS_DEV ? 'http://127.0.0.1:17746' : '/cgi/ThirdParty/code.editor/index.cgi'
4+
5+
export const USER_CONFIG_PATH = IS_DEV
6+
? '/Users/flex/Downloads/config.json'
7+
: '/var/apps/code.editor/shares/config.json'

0 commit comments

Comments
 (0)