Sheet Edit.

pull/9/head
ruibaby 2019-04-24 22:57:18 +08:00
parent af8262f616
commit 8e66102aa1
5 changed files with 194 additions and 61 deletions

54
src/api/sheet.js Normal file
View File

@ -0,0 +1,54 @@
import service from '@/utils/service'
const baseUrl = '/api/admin/sheets'
const sheetApi = {}
sheetApi.list = () => {
return service({
url: baseUrl,
method: 'get'
})
}
sheetApi.get = sheetId => {
return service({
url: `${baseUrl}/${sheetId}`,
method: 'get'
})
}
sheetApi.create = sheetToCreate => {
return service({
url: baseUrl,
method: 'post',
data: sheetToCreate
})
}
sheetApi.update = (sheetId, sheetToUpdate) => {
return service({
url: `${baseUrl}/${sheetId}`,
method: 'put',
data: sheetToUpdate
})
}
sheetApi.sheetStatus = {
PUBLISHED: {
color: 'green',
status: 'success',
text: '已发布'
},
DRAFT: {
color: 'yellow',
status: 'warning',
text: '草稿'
},
RECYCLE: {
color: 'red',
status: 'error',
text: '回收站'
}
}
export default sheetApi

View File

@ -58,7 +58,7 @@
v-model="postToStage.password" v-model="postToStage.password"
/> />
</a-form-item> </a-form-item>
<a-form-item label="是否关闭评论:"> <a-form-item label="开启评论:">
<a-radio-group <a-radio-group
v-model="postToStage.disallowComment" v-model="postToStage.disallowComment"
:defaultValue="false" :defaultValue="false"
@ -122,7 +122,7 @@
<a-divider /> <a-divider />
</div> </div>
<AttachmentSelectDrawer <AttachmentSelectDrawer
v-model="childDrawerVisible" v-model="thumDrawerVisible"
@listenToSelect="selectPostThumb" @listenToSelect="selectPostThumb"
:drawerWidth="460" :drawerWidth="460"
/> />
@ -161,14 +161,14 @@
import CategoryTree from './components/CategoryTree' import CategoryTree from './components/CategoryTree'
import TagSelect from './components/TagSelect' import TagSelect from './components/TagSelect'
import { mavonEditor } from 'mavon-editor' import { mavonEditor } from 'mavon-editor'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
import AttachmentSelectDrawer from '../attachment/components/AttachmentSelectDrawer'
import FooterToolBar from '@/components/FooterToolbar' import FooterToolBar from '@/components/FooterToolbar'
import { mixin, mixinDevice } from '@/utils/mixin.js' import { mixin, mixinDevice } from '@/utils/mixin.js'
import 'mavon-editor/dist/css/index.css' import 'mavon-editor/dist/css/index.css'
import tagApi from '@/api/tag' import tagApi from '@/api/tag'
import categoryApi from '@/api/category' import categoryApi from '@/api/category'
import postApi from '@/api/post' import postApi from '@/api/post'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
import AttachmentSelectDrawer from '../attachment/components/AttachmentSelectDrawer'
const toolbars = { const toolbars = {
bold: true, // bold: true, //
italic: true, // italic: true, //
@ -193,7 +193,6 @@ const toolbars = {
preview: true // preview: true //
} }
export default { export default {
name: 'Editor',
components: { components: {
TagSelect, TagSelect,
mavonEditor, mavonEditor,
@ -212,7 +211,7 @@ export default {
}, },
attachmentDrawerVisible: false, attachmentDrawerVisible: false,
visible: false, visible: false,
childDrawerVisible: false, thumDrawerVisible: false,
tags: [], tags: [],
categories: [], categories: [],
selectedCategoryIds: [], selectedCategoryIds: [],
@ -287,7 +286,7 @@ export default {
this.attachmentDrawerVisible = true this.attachmentDrawerVisible = true
}, },
showThumbDrawer() { showThumbDrawer() {
this.childDrawerVisible = true this.thumDrawerVisible = true
}, },
handlePublishClick() { handlePublishClick() {
this.postToStage.status = 'PUBLISHED' this.postToStage.status = 'PUBLISHED'
@ -300,12 +299,9 @@ export default {
onClose() { onClose() {
this.visible = false this.visible = false
}, },
onChildClose() {
this.childDrawerVisible = false
},
selectPostThumb(data) { selectPostThumb(data) {
this.postToStage.thumbnail = data.path this.postToStage.thumbnail = data.path
this.childDrawerVisible = false this.thumDrawerVisible = false
} }
} }
} }

View File

@ -129,11 +129,6 @@
>{{ tag.name }}</a-tag> >{{ tag.name }}</a-tag>
</span> </span>
<span
slot="createTime"
slot-scope="createTime"
>{{ createTime | timeAgo }}</span>
<span <span
slot="updateTime" slot="updateTime"
slot-scope="updateTime" slot-scope="updateTime"

View File

@ -10,7 +10,7 @@
> >
<div style="margin-bottom: 16px"> <div style="margin-bottom: 16px">
<a-input <a-input
v-model="postToStage.title" v-model="sheetToStage.title"
v-decorator="['title', { rules: [{ required: true, message: '请输入页面标题' }] }]" v-decorator="['title', { rules: [{ required: true, message: '请输入页面标题' }] }]"
size="large" size="large"
placeholder="请输入页面标题" placeholder="请输入页面标题"
@ -18,7 +18,7 @@
</div> </div>
<div id="editor"> <div id="editor">
<mavon-editor <mavon-editor
v-model="postToStage.originalContent" v-model="sheetToStage.originalContent"
:boxShadow="false" :boxShadow="false"
:toolbars="toolbars" :toolbars="toolbars"
:ishljs="true" :ishljs="true"
@ -47,19 +47,19 @@
<a-form layout="vertical"> <a-form layout="vertical">
<a-form-item <a-form-item
label="页面路径:" label="页面路径:"
:help="'https://localhost:8090/p/'+ (postToStage.url ? postToStage.url : '{auto_generate}')" :help="'https://localhost:8090/s/'+ (sheetToStage.url ? sheetToStage.url : '{auto_generate}')"
> >
<a-input v-model="postToStage.url" /> <a-input v-model="sheetToStage.url" />
</a-form-item> </a-form-item>
<a-form-item label="页面密码:"> <a-form-item label="页面密码:">
<a-input <a-input
type="password" type="password"
v-model="postToStage.password" v-model="sheetToStage.password"
/> />
</a-form-item> </a-form-item>
<a-form-item label="是否关闭评论:"> <a-form-item label="开启评论:">
<a-radio-group <a-radio-group
v-model="postToStage.disallowComment" v-model="sheetToStage.disallowComment"
:defaultValue="false" :defaultValue="false"
> >
<a-radio :value="false">开启</a-radio> <a-radio :value="false">开启</a-radio>
@ -67,7 +67,7 @@
</a-radio-group> </a-radio-group>
</a-form-item> </a-form-item>
<a-form-item label="自定义模板:"> <a-form-item label="自定义模板:">
<a-select v-model="postToStage.template"> <a-select v-model="sheetToStage.template">
<a-select-option <a-select-option
v-for="tpl in customTpls" v-for="tpl in customTpls"
:key="tpl" :key="tpl"
@ -83,17 +83,23 @@
<div :style="{ marginBottom: '16px' }"> <div :style="{ marginBottom: '16px' }">
<h3 class="post-setting-drawer-title">缩略图</h3> <h3 class="post-setting-drawer-title">缩略图</h3>
<div class="post-setting-drawer-item"> <div class="post-setting-drawer-item">
<div class="post-thum"> <div class="sheet-thum">
<img <img
class="img" class="img"
src="https://os.alipayobjects.com/rmsportal/mgesTPFxodmIwpi.png" :src="sheetToStage.thumbnail || 'https://os.alipayobjects.com/rmsportal/mgesTPFxodmIwpi.png'"
@click="showThumbDrawer"
> >
</div> </div>
</div> </div>
</div> </div>
<a-divider /> <a-divider />
</div> </div>
<div class="postControl"> <AttachmentSelectDrawer
v-model="thumDrawerVisible"
@listenToSelect="selectSheetThumb"
:drawerWidth="460"
/>
<div class="sheetControl">
<a-button <a-button
style="marginRight: 8px" style="marginRight: 8px"
@click="handleDraftClick" @click="handleDraftClick"
@ -124,10 +130,11 @@
<script> <script>
import { mavonEditor } from 'mavon-editor' import { mavonEditor } from 'mavon-editor'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer' import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
import AttachmentSelectDrawer from '../attachment/components/AttachmentSelectDrawer'
import FooterToolBar from '@/components/FooterToolbar' import FooterToolBar from '@/components/FooterToolbar'
import { mixin, mixinDevice } from '@/utils/mixin.js' import { mixin, mixinDevice } from '@/utils/mixin.js'
import 'mavon-editor/dist/css/index.css' import 'mavon-editor/dist/css/index.css'
import postApi from '@/api/post' import sheetApi from '@/api/sheet'
import themeApi from '@/api/theme' import themeApi from '@/api/theme'
const toolbars = { const toolbars = {
bold: true, // bold: true, //
@ -153,11 +160,11 @@ const toolbars = {
preview: true // preview: true //
} }
export default { export default {
name: 'Editor',
components: { components: {
mavonEditor, mavonEditor,
FooterToolBar, FooterToolBar,
AttachmentDrawer AttachmentDrawer,
AttachmentSelectDrawer
}, },
mixins: [mixin, mixinDevice], mixins: [mixin, mixinDevice],
data() { data() {
@ -168,16 +175,17 @@ export default {
xs: { span: 24 } xs: { span: 24 }
}, },
attachmentDrawerVisible: false, attachmentDrawerVisible: false,
thumDrawerVisible: false,
toolbars, toolbars,
visible: false, visible: false,
postUrl: 'hello-world', sheetUrl: 'hello-world',
customTpls: [], customTpls: [],
postToStage: {} sheetToStage: {}
} }
}, },
computed: { computed: {
publishText() { publishText() {
if (this.postToStage.id) { if (this.sheetToStage.id) {
return '更新并发布' return '更新并发布'
} }
return '创建并发布' return '创建并发布'
@ -187,16 +195,14 @@ export default {
this.loadCustomTpls() this.loadCustomTpls()
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
// Get post id from query // Get sheetId id from query
const postId = to.query.postId const sheetId = to.query.sheetId
next(vm => { next(vm => {
if (postId) { if (sheetId) {
postApi.get(postId).then(response => { sheetApi.get(sheetId).then(response => {
const post = response.data.data const sheet = response.data.data
vm.postToStage = post vm.sheetToStage = sheet
vm.selectedTagIds = post.tagIds
vm.selectedCategoryIds = post.categoryIds
}) })
} }
}) })
@ -210,35 +216,40 @@ export default {
showAttachDrawer() { showAttachDrawer() {
this.attachmentDrawerVisible = true this.attachmentDrawerVisible = true
}, },
showThumbDrawer() {
this.thumDrawerVisible = true
},
showDrawer() { showDrawer() {
this.visible = true this.visible = true
}, },
handlePublishClick() { handlePublishClick() {
this.postToStage.status = 'PUBLISHED' this.sheetToStage.status = 'PUBLISHED'
this.createOrUpdatePost() this.createOrUpdateSheet()
}, },
handleDraftClick() { handleDraftClick() {
this.postToStage.status = 'DRAFT' this.sheetToStage.status = 'DRAFT'
this.createOrUpdatePost() this.createOrUpdateSheet()
}, },
createOrUpdatePost() { createOrUpdateSheet() {
if (this.postToStage.id) { if (this.sheetToStage.id) {
// Update the post sheetApi.update(this.sheetToStage.id, this.sheetToStage).then(response => {
postApi.update(this.postToStage.id, this.postToStage).then(response => { this.$log.debug('Updated sheet', response.data.data)
this.$log.debug('Updated post', response.data.data)
this.$message.success('页面更新成功') this.$message.success('页面更新成功')
}) })
} else { } else {
// Create the post sheetApi.create(this.sheetToStage).then(response => {
postApi.create(this.postToStage).then(response => { this.$log.debug('Created sheet', response.data.data)
this.$log.debug('Created post', response.data.data)
this.$message.success('页面创建成功') this.$message.success('页面创建成功')
this.postToStage = response.data.data this.sheetToStage = response.data.data
}) })
} }
}, },
onClose() { onClose() {
this.visible = false this.visible = false
},
selectSheetThumb(data) {
this.sheetToStage.thumbnail = data.path
this.thumDrawerVisible = false
} }
} }
} }
@ -249,7 +260,7 @@ export default {
min-height: 580px; min-height: 580px;
} }
.postControl { .sheetControl {
position: absolute; position: absolute;
bottom: 0px; bottom: 0px;
width: 100%; width: 100%;
@ -261,7 +272,7 @@ export default {
border-radius: 0px 0px 4px 4px; border-radius: 0px 0px 4px 4px;
} }
.post-thum .img { .sheet-thum .img {
width: 100%; width: 100%;
} }
</style> </style>

View File

@ -74,9 +74,36 @@
</a-tab-pane> </a-tab-pane>
<a-tab-pane key="custom"> <a-tab-pane key="custom">
<span slot="tab"> <span slot="tab">
<a-icon type="fork" />内置页面 <a-icon type="fork" />自定义页面
</span> </span>
自定义页面 <a-table
:rowKey="sheet => sheet.id"
:columns="customColumns"
:dataSource="formattedSheets"
:pagination="false"
>
<span
slot="status"
slot-scope="statusProperty"
>
<a-badge :status="statusProperty.status" />
{{ statusProperty.text }}
</span>
<span
slot="updateTime"
slot-scope="updateTime"
>{{ updateTime | timeAgo }}</span>
<span
slot="action"
slot-scope="text, sheet"
>
<a href="javascript:;" @click="onEditClick(sheet)"></a>
<a-divider type="vertical" />
<a href="javascript:;">删除</a>
</span>
</a-table>
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
</div> </div>
@ -87,6 +114,7 @@
<script> <script>
import { mixin, mixinDevice } from '@/utils/mixin.js' import { mixin, mixinDevice } from '@/utils/mixin.js'
import sheetApi from '@/api/sheet'
const internalColumns = [ const internalColumns = [
{ {
title: '页面名称', title: '页面名称',
@ -103,6 +131,36 @@ const internalColumns = [
scopedSlots: { customRender: 'action' } scopedSlots: { customRender: 'action' }
} }
] ]
const customColumns = [
{
title: '标题',
dataIndex: 'title'
},
{
title: '状态',
className: 'status',
dataIndex: 'statusProperty',
scopedSlots: { customRender: 'status' }
},
{
title: '评论量',
dataIndex: 'commentCount'
},
{
title: '访问量',
dataIndex: 'visits'
},
{
title: '更新时间',
dataIndex: 'updateTime',
scopedSlots: { customRender: 'updateTime' }
},
{
title: '操作',
width: '150px',
scopedSlots: { customRender: 'action' }
}
]
const internalPages = [ const internalPages = [
{ {
id: '1', id: '1',
@ -124,13 +182,32 @@ export default {
mixins: [mixin, mixinDevice], mixins: [mixin, mixinDevice],
data() { data() {
return { return {
sheetStatus: sheetApi.sheetStatus,
internalColumns, internalColumns,
internalPages customColumns,
internalPages,
sheets: []
} }
}, },
computed: {
formattedSheets() {
return this.sheets.map(sheet => {
sheet.statusProperty = this.sheetStatus[sheet.status]
return sheet
})
}
},
created() {
this.loadSheets()
},
methods: { methods: {
editPage(id) { loadSheets() {
this.$message.success('编辑' + id) sheetApi.list().then(response => {
this.sheets = response.data.data.content
})
},
onEditClick(sheet) {
this.$router.push({ name: 'SheetEdit', query: { sheetId: sheet.id } })
}, },
viewPage(id) { viewPage(id) {
this.$message.success('查看' + id) this.$message.success('查看' + id)