Support theme file editable.

pull/9/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

View File

@ -7,15 +7,14 @@
:md="18"
:sm="24"
:xs="24"
:style="{'padding-bottom':'12px'}"
>
:style="{'padding-bottom':'12px'}">
<a-card>
<a-form layout="vertical">
<a-form-item>
<codemirror :value="value"></codemirror>
<codemirror v-model="content" :options="options"></codemirror>
</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>
</a-card>
@ -26,10 +25,9 @@
:md="6"
:sm="24"
:xs="24"
:style="{'padding-bottom':'12px'}"
>
:style="{'padding-bottom':'12px'}">
<a-card title="Anatole 主题">
<theme-file :files="files" />
<theme-file :files="files" @listenToSelect="catchSelectFile"/>
</a-card>
</a-col>
</a-row>
@ -40,6 +38,7 @@
import themeApi from '@/api/theme'
import ThemeFile from './components/ThemeFile'
import { codemirror } from 'vue-codemirror-lite'
import 'codemirror/mode/htmlmixed/htmlmixed.js'
export default {
components: {
codemirror,
@ -47,8 +46,16 @@ export default {
},
data() {
return {
buttonDisabled: true,
options: {
tabSize: 4,
mode: 'text/html',
lineNumbers: true,
line: true
},
files: [],
value: 'Hello world'
file: {},
content: ''
}
},
created() {
@ -65,6 +72,34 @@ export default {
themeApi.listFiles().then(response => {
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('保存成功')
})
}
}
}
@ -72,7 +107,7 @@ export default {
<style lang="less">
.CodeMirror {
height: 560px;
height: 560px;
}
.CodeMirror-gutters {
border-right: 1px solid #fff3f3;

View File

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

View File

@ -34,7 +34,7 @@
<template slot="title">
<span>{{ tag.postCount }} 篇文章</span>
</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-card>
</a-col>