Support theme file editable.

pull/3445/head
ruibaby 2019-04-23 01:11:37 +08:00
parent 937b461374
commit 3439ec460d
4 changed files with 67 additions and 11 deletions

View File

@ -96,4 +96,25 @@ themeApi.fetching = url => {
}) })
} }
themeApi.getContent = path => {
return service({
url: `${baseUrl}/files/content`,
params: {
path: path
},
method: 'get'
})
}
themeApi.saveContent = (path, content) => {
return service({
url: `${baseUrl}/files/content`,
params: {
path: path,
content: content
},
method: 'put'
})
}
export default themeApi export default themeApi

View File

@ -7,15 +7,14 @@
:md="18" :md="18"
:sm="24" :sm="24"
:xs="24" :xs="24"
:style="{'padding-bottom':'12px'}" :style="{'padding-bottom':'12px'}">
>
<a-card> <a-card>
<a-form layout="vertical"> <a-form layout="vertical">
<a-form-item> <a-form-item>
<codemirror :value="value"></codemirror> <codemirror v-model="content" :options="options"></codemirror>
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
<a-button type="primary">保存</a-button> <a-button type="primary" @click="handlerSaveContent" :disabled="buttonDisabled">保存</a-button>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-card> </a-card>
@ -26,10 +25,9 @@
:md="6" :md="6"
:sm="24" :sm="24"
:xs="24" :xs="24"
:style="{'padding-bottom':'12px'}" :style="{'padding-bottom':'12px'}">
>
<a-card title="Anatole 主题"> <a-card title="Anatole 主题">
<theme-file :files="files" /> <theme-file :files="files" @listenToSelect="catchSelectFile"/>
</a-card> </a-card>
</a-col> </a-col>
</a-row> </a-row>
@ -40,6 +38,7 @@
import themeApi from '@/api/theme' import themeApi from '@/api/theme'
import ThemeFile from './components/ThemeFile' import ThemeFile from './components/ThemeFile'
import { codemirror } from 'vue-codemirror-lite' import { codemirror } from 'vue-codemirror-lite'
import 'codemirror/mode/htmlmixed/htmlmixed.js'
export default { export default {
components: { components: {
codemirror, codemirror,
@ -47,8 +46,16 @@ export default {
}, },
data() { data() {
return { return {
buttonDisabled: true,
options: {
tabSize: 4,
mode: 'text/html',
lineNumbers: true,
line: true
},
files: [], files: [],
value: 'Hello world' file: {},
content: ''
} }
}, },
created() { created() {
@ -65,6 +72,34 @@ export default {
themeApi.listFiles().then(response => { themeApi.listFiles().then(response => {
this.files = response.data.data this.files = response.data.data
}) })
},
catchSelectFile(file) {
const _this = this
if (!file.editable) {
this.$message.info('该文件不支持修改')
return
}
if (file.name === 'options.yaml' || file.name === 'options.yml') {
this.$confirm({
title: '警告:请谨慎修改该配置文件',
content: '修改之后可能会产生不可预料的问题',
onCancel() {
_this.content = ''
_this.file = {}
_this.buttonDisabled = true
}
})
}
themeApi.getContent(file.path).then(response => {
this.content = response.data.data
this.file = file
this.buttonDisabled = false
})
},
handlerSaveContent() {
themeApi.saveContent(this.file.path, this.content).then(response => {
this.$message.success('保存成功')
})
} }
} }
} }

View File

@ -10,7 +10,7 @@ export default {
}, },
methods: { methods: {
handleSelectFile(file) { handleSelectFile(file) {
this.$log.debug('加载文件', file) this.$emit('listenToSelect', file)
}, },
renderNode(h, file) { renderNode(h, file) {
const _this = this const _this = this

View File

@ -34,7 +34,7 @@
<template slot="title"> <template slot="title">
<span>{{ tag.postCount }} 篇文章</span> <span>{{ tag.postCount }} 篇文章</span>
</template> </template>
<a-tag closable @close="deleteTag(tag.id)" color="green">{{ tag.name }}</a-tag> <a-tag closable @close="deleteTag(tag.id)" color="blue">{{ tag.name }}</a-tag>
</a-tooltip> </a-tooltip>
</a-card> </a-card>
</a-col> </a-col>