Support post autosave.

pull/9/head
ruibaby 2019-04-28 22:17:57 +08:00
parent d0f8834799
commit 1e5283db84
4 changed files with 141 additions and 38 deletions

View File

@ -11,6 +11,16 @@ optionApi.listAll = () => {
}) })
} }
optionApi.listByKeys = keys => {
return service({
url: `/api/admin/options/map_keys`,
method: 'get',
params: {
keys: keys
}
})
}
optionApi.save = options => { optionApi.save = options => {
return service({ return service({
url: `${baseUrl}/saving`, url: `${baseUrl}/saving`,

View File

@ -1,31 +1,47 @@
<template> <template>
<div class="user-wrapper"> <div class="user-wrapper">
<a href="http://localhost:8090" target="_blank"> <a
:href="options.blog_url"
target="_blank"
>
<span class="action"> <span class="action">
<a-icon type="link" /> <a-icon type="link" />
</span> </span>
</a> </a>
<a href="javascript:void(0)" @click="showOptionModal"> <a
href="javascript:void(0)"
@click="showOptionModal"
>
<span class="action"> <span class="action">
<a-icon type="setting" /> <a-icon type="setting" />
</span> </span>
</a> </a>
<header-comment class="action"/> <header-comment class="action" />
<a-dropdown> <a-dropdown>
<span class="action ant-dropdown-link user-dropdown-menu"> <span class="action ant-dropdown-link user-dropdown-menu">
<a-avatar class="avatar" size="small" :src="avatar"/> <a-avatar
class="avatar"
size="small"
:src="user.avatar"
/>
</span> </span>
<a-menu slot="overlay" class="user-dropdown-menu-wrapper"> <a-menu
slot="overlay"
class="user-dropdown-menu-wrapper"
>
<a-menu-item key="0"> <a-menu-item key="0">
<router-link :to="{ name: 'Profile' }"> <router-link :to="{ name: 'Profile' }">
<a-icon type="user"/> <a-icon type="user" />
<span>个人资料</span> <span>个人资料</span>
</router-link> </router-link>
</a-menu-item> </a-menu-item>
<a-menu-divider/> <a-menu-divider />
<a-menu-item key="3"> <a-menu-item key="3">
<a href="javascript:;" @click="handleLogout"> <a
<a-icon type="logout"/> href="javascript:;"
@click="handleLogout"
>
<a-icon type="logout" />
<span>退出登录</span> <span>退出登录</span>
</a> </a>
</a-menu-item> </a-menu-item>
@ -39,6 +55,8 @@
import HeaderComment from './HeaderComment' import HeaderComment from './HeaderComment'
import SettingDrawer from '@/components/SettingDrawer/SettingDrawer' import SettingDrawer from '@/components/SettingDrawer/SettingDrawer'
import { mapActions, mapGetters } from 'vuex' import { mapActions, mapGetters } from 'vuex'
import userApi from '@/api/user'
import optionApi from '@/api/option'
export default { export default {
name: 'UserMenu', name: 'UserMenu',
@ -49,12 +67,18 @@ export default {
data() { data() {
return { return {
optionVisible: true, optionVisible: true,
avatar: 'https://gravatar.loli.net/avatar/?s=256&d=mm' user: {},
options: [],
keys: 'blog_url'
} }
}, },
mounted() { mounted() {
this.optionVisible = this.$refs.drawer.visible this.optionVisible = this.$refs.drawer.visible
}, },
created() {
this.loadUser()
this.loadOptions()
},
methods: { methods: {
...mapActions(['Logout']), ...mapActions(['Logout']),
...mapGetters(['nickname']), ...mapGetters(['nickname']),
@ -83,6 +107,16 @@ export default {
showOptionModal() { showOptionModal() {
this.optionVisible = this.$refs.drawer.visible this.optionVisible = this.$refs.drawer.visible
this.$refs.drawer.toggle() this.$refs.drawer.toggle()
},
loadUser() {
userApi.getProfile().then(response => {
this.user = response.data.data
})
},
loadOptions() {
optionApi.listByKeys(this.keys).then(response => {
this.options = response.data.data
})
} }
} }
} }

View File

@ -1,9 +1,7 @@
<template> <template>
<div class="page-header-index-wide"> <div class="page-header-index-wide">
<a-row :gutter="12"> <a-row :gutter="12">
<a-col <a-col :span="24">
:span="24"
>
<div style="margin-bottom: 16px"> <div style="margin-bottom: 16px">
<a-input <a-input
v-model="postToStage.title" v-model="postToStage.title"
@ -84,15 +82,34 @@
/> />
</a-form-item> </a-form-item>
<a-form-item v-if="categoryForm"> <a-form-item v-if="categoryForm">
<a-input placeholder="分类名称" v-model="categoryToCreate.name"/> <a-input
placeholder="分类名称"
v-model="categoryToCreate.name"
/>
</a-form-item> </a-form-item>
<a-form-item v-if="categoryForm"> <a-form-item v-if="categoryForm">
<a-input placeholder="分类路径" v-model="categoryToCreate.slugNames"/> <a-input
placeholder="分类路径"
v-model="categoryToCreate.slugNames"
/>
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
<a-button type="primary" style="marginRight: 8px" v-if="categoryForm" @click="handlerCreateCategory"></a-button> <a-button
<a-button type="dashed" style="marginRight: 8px" v-if="!categoryForm" @click="toggleCategoryForm"></a-button> type="primary"
<a-button v-if="categoryForm" @click="toggleCategoryForm"></a-button> style="marginRight: 8px"
v-if="categoryForm"
@click="handlerCreateCategory"
>保存</a-button>
<a-button
type="dashed"
style="marginRight: 8px"
v-if="!categoryForm"
@click="toggleCategoryForm"
>新增</a-button>
<a-button
v-if="categoryForm"
@click="toggleCategoryForm"
>取消</a-button>
</a-form-item> </a-form-item>
</a-form> </a-form>
</div> </div>
@ -145,7 +162,7 @@
<a-button <a-button
@click="handlePublishClick" @click="handlePublishClick"
type="primary" type="primary"
>{{ publishText }}</a-button> >发布</a-button>
</div> </div>
</a-drawer> </a-drawer>
</a-col> </a-col>
@ -209,20 +226,20 @@ export default {
selectedCategoryIds: [], selectedCategoryIds: [],
selectedTagIds: [], selectedTagIds: [],
postToStage: {}, postToStage: {},
categoryToCreate: {} categoryToCreate: {},
} timer: null
},
computed: {
publishText() {
if (this.postToStage.id) {
return '更新并发布'
}
return '创建并发布'
} }
}, },
created() { created() {
this.loadTags() this.loadTags()
this.loadCategories() this.loadCategories()
clearInterval(this.timer)
this.timer = null
this.autoSaveTimer()
},
destroyed: function() {
clearInterval(this.timer)
this.timer = null
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
// Get post id from query // Get post id from query
@ -306,6 +323,27 @@ export default {
handleSelectPostThumb(data) { handleSelectPostThumb(data) {
this.postToStage.thumbnail = data.path this.postToStage.thumbnail = data.path
this.thumDrawerVisible = false this.thumDrawerVisible = false
},
autoSaveTimer() {
if (this.timer == null) {
this.timer = setInterval(() => {
if (this.postToStage.title != null && this.postToStage.originalContent != null) {
this.postToStage.categoryIds = this.selectedCategoryIds
this.postToStage.tagIds = this.selectedTagIds
if (this.postToStage.id) {
postApi.update(this.postToStage.id, this.postToStage).then(response => {
this.$log.debug('Auto updated post', response.data.data)
})
} else {
postApi.create(this.postToStage).then(response => {
this.$log.debug('Auto saved post', response.data.data)
this.postToStage = response.data.data
})
}
}
}, 15000)
}
} }
} }
} }

View File

@ -106,7 +106,7 @@
<a-button <a-button
type="primary" type="primary"
@click="handlePublishClick" @click="handlePublishClick"
>{{ publishText }}</a-button> >发布</a-button>
</div> </div>
</a-drawer> </a-drawer>
</a-col> </a-col>
@ -156,19 +156,19 @@ export default {
thumDrawerVisible: false, thumDrawerVisible: false,
visible: false, visible: false,
customTpls: [], customTpls: [],
sheetToStage: {} sheetToStage: {},
} timer: null
},
computed: {
publishText() {
if (this.sheetToStage.id) {
return '更新并发布'
}
return '创建并发布'
} }
}, },
created() { created() {
this.loadCustomTpls() this.loadCustomTpls()
clearInterval(this.timer)
this.timer = null
this.autoSaveTimer()
},
destroyed: function() {
clearInterval(this.timer)
this.timer = null
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
// Get sheetId id from query // Get sheetId id from query
@ -229,6 +229,27 @@ export default {
handleSelectSheetThumb(data) { handleSelectSheetThumb(data) {
this.sheetToStage.thumbnail = data.path this.sheetToStage.thumbnail = data.path
this.thumDrawerVisible = false this.thumDrawerVisible = false
},
autoSaveTimer() {
if (this.timer == null) {
this.timer = setInterval(() => {
if (this.sheetToStage.title != null && this.sheetToStage.originalContent != null) {
this.sheetToStage.categoryIds = this.selectedCategoryIds
this.sheetToStage.tagIds = this.selectedTagIds
if (this.sheetToStage.id) {
sheetApi.update(this.sheetToStage.id, this.sheetToStage).then(response => {
this.$log.debug('Auto updated sheet', response.data.data)
})
} else {
sheetApi.create(this.sheetToStage).then(response => {
this.$log.debug('Auto saved sheet', response.data.data)
this.sheetToStage = response.data.data
})
}
}
}, 15000)
}
} }
} }
} }