feat: support sheet meta.

pull/59/head
ruibaby 2019-12-10 13:00:59 +08:00
parent 6d77de0e96
commit 1754aca957
4 changed files with 88 additions and 1 deletions

View File

@ -753,7 +753,6 @@ export default {
this.selectedPost = response.data.data this.selectedPost = response.data.data
this.selectedTagIds = this.selectedPost.tagIds this.selectedTagIds = this.selectedPost.tagIds
this.selectedCategoryIds = this.selectedPost.categoryIds this.selectedCategoryIds = this.selectedPost.categoryIds
this.selectedPostMetaIds = this.selectedPost.postMetaIds
this.selectedPostMetas = this.selectedPost.postMetas this.selectedPostMetas = this.selectedPost.postMetas
this.postSettingVisible = true this.postSettingVisible = true
}) })

View File

@ -27,9 +27,11 @@
<SheetSettingDrawer <SheetSettingDrawer
:sheet="sheetToStage" :sheet="sheetToStage"
:sheetMetas="selectedSheetMetas"
:visible="sheetSettingVisible" :visible="sheetSettingVisible"
@close="onSheetSettingsClose" @close="onSheetSettingsClose"
@onRefreshSheet="onRefreshSheetFromSetting" @onRefreshSheet="onRefreshSheetFromSetting"
@onRefreshSheetMetas="onRefreshSheetMetasFromSetting"
@onSaved="onSaved" @onSaved="onSaved"
/> />
@ -83,6 +85,7 @@ export default {
attachmentDrawerVisible: false, attachmentDrawerVisible: false,
sheetSettingVisible: false, sheetSettingVisible: false,
sheetToStage: {}, sheetToStage: {},
selectedSheetMetas: [],
isSaved: false isSaved: false
} }
}, },
@ -95,6 +98,7 @@ export default {
sheetApi.get(sheetId).then(response => { sheetApi.get(sheetId).then(response => {
const sheet = response.data.data const sheet = response.data.data
vm.sheetToStage = sheet vm.sheetToStage = sheet
vm.selectedSheetMetas = sheet.sheetMetas
}) })
} }
}) })
@ -214,6 +218,9 @@ export default {
onRefreshSheetFromSetting(sheet) { onRefreshSheetFromSetting(sheet) {
this.sheetToStage = sheet this.sheetToStage = sheet
}, },
onRefreshSheetMetasFromSetting(sheetMetas) {
this.selectedSheetMetas = sheetMetas
},
onSaved(isSaved) { onSaved(isSaved) {
this.isSaved = isSaved this.isSaved = isSaved
} }

View File

@ -482,10 +482,12 @@
<SheetSettingDrawer <SheetSettingDrawer
:sheet="selectedSheet" :sheet="selectedSheet"
:sheetMetas="selectedSheetMetas"
:visible="sheetSettingVisible" :visible="sheetSettingVisible"
:needTitle="true" :needTitle="true"
@close="onSheetSettingsClose" @close="onSheetSettingsClose"
@onRefreshSheet="onRefreshSheetFromSetting" @onRefreshSheet="onRefreshSheetFromSetting"
@onRefreshSheetMetas="onRefreshSheetMetasFromSetting"
/> />
<TargetCommentDrawer <TargetCommentDrawer
@ -587,6 +589,7 @@ export default {
internalColumns, internalColumns,
customColumns, customColumns,
selectedSheet: {}, selectedSheet: {},
selectedSheetMetas: [],
sheetSettingVisible: false, sheetSettingVisible: false,
sheetCommentVisible: false, sheetCommentVisible: false,
internalSheets: [], internalSheets: [],
@ -661,6 +664,7 @@ export default {
handleShowSheetSettings(sheet) { handleShowSheetSettings(sheet) {
sheetApi.get(sheet.id).then(response => { sheetApi.get(sheet.id).then(response => {
this.selectedSheet = response.data.data this.selectedSheet = response.data.data
this.selectedSheetMetas = this.selectedSheet.sheetMetas
this.sheetSettingVisible = true this.sheetSettingVisible = true
}) })
}, },
@ -697,6 +701,9 @@ export default {
}, },
onRefreshSheetFromSetting(sheet) { onRefreshSheetFromSetting(sheet) {
this.selectedSheet = sheet this.selectedSheet = sheet
},
onRefreshSheetMetasFromSetting(sheetMetas) {
this.selectedSheetMetas = sheetMetas
} }
} }
} }

View File

@ -84,6 +84,41 @@
</div> </div>
</div> </div>
</div> </div>
<a-divider />
<div :style="{ marginBottom: '16px' }">
<h3 class="post-setting-drawer-title">元数据</h3>
<a-form layout="vertical">
<a-form-item
v-for="(sheetMeta, index) in selectedSheetMetas"
:key="index"
:prop="'sheetMeta.' + index + '.value'"
>
<a-row :gutter="5">
<a-col :span="12">
<a-input v-model="sheetMeta.key"><i slot="addonBefore">K</i></a-input>
</a-col>
<a-col :span="12">
<a-input v-model="sheetMeta.value">
<i slot="addonBefore">V</i>
<a
href="javascript:void(0);"
slot="addonAfter"
@click.prevent="handleRemoveSheetMeta(sheetMeta)"
>
<a-icon type="close" />
</a>
</a-input>
</a-col>
</a-row>
</a-form-item>
<a-form-item>
<a-button
type="dashed"
@click="handleInsertSheetMeta()"
>新增</a-button>
</a-form-item>
</a-form>
</div>
<a-divider class="divider-transparent" /> <a-divider class="divider-transparent" />
</div> </div>
</a-skeleton> </a-skeleton>
@ -130,6 +165,10 @@ export default {
type: Object, type: Object,
required: true required: true
}, },
sheetMetas: {
type: Array,
required: true
},
needTitle: { needTitle: {
type: Boolean, type: Boolean,
required: false, required: false,
@ -152,13 +191,20 @@ export default {
selectedSheet(val) { selectedSheet(val) {
this.$emit('onRefreshSheet', val) this.$emit('onRefreshSheet', val)
}, },
selectedSheetMetas(val) {
this.$emit('onRefreshSheetMetas', val)
},
visible: function(newValue, oldValue) { visible: function(newValue, oldValue) {
if (newValue) { if (newValue) {
this.loadSkeleton() this.loadSkeleton()
this.loadPresetMetasField()
} }
} }
}, },
computed: { computed: {
selectedSheetMetas() {
return this.sheetMetas
},
pickerDefaultValue() { pickerDefaultValue() {
if (this.selectedSheet.createTime) { if (this.selectedSheet.createTime) {
var date = new Date(this.selectedSheet.createTime) var date = new Date(this.selectedSheet.createTime)
@ -175,6 +221,21 @@ export default {
this.settingLoading = false this.settingLoading = false
}, 500) }, 500)
}, },
loadPresetMetasField() {
if (this.sheetMetas.length <= 0) {
themeApi.getActivatedTheme().then(response => {
const fields = response.data.data.sheetMetaField
if (fields && fields.length > 0) {
for (let i = 0, len = fields.length; i < len; i++) {
this.selectedSheetMetas.push({
value: '',
key: fields[i]
})
}
}
})
}
},
loadCustomTpls() { loadCustomTpls() {
themeApi.customTpls().then(response => { themeApi.customTpls().then(response => {
this.customTpls = response.data.data this.customTpls = response.data.data
@ -210,6 +271,7 @@ export default {
}) })
return return
} }
this.selectedSheet.sheetMetas = this.selectedSheetMetas
if (this.selectedSheet.id) { if (this.selectedSheet.id) {
sheetApi.update(this.selectedSheet.id, this.selectedSheet, autoSave).then(response => { sheetApi.update(this.selectedSheet.id, this.selectedSheet, autoSave).then(response => {
this.$log.debug('Updated sheet', response.data.data) this.$log.debug('Updated sheet', response.data.data)
@ -239,6 +301,18 @@ export default {
}, },
onSheetDateOk(value) { onSheetDateOk(value) {
this.selectedSheet.createTime = value.valueOf() this.selectedSheet.createTime = value.valueOf()
},
handleRemoveSheetMeta(item) {
var index = this.selectedSheetMetas.indexOf(item)
if (index !== -1) {
this.selectedSheetMetas.splice(index, 1)
}
},
handleInsertSheetMeta() {
this.selectedSheetMetas.push({
value: '',
key: ''
})
} }
} }
} }