feat: support sheet meta.

pull/3445/head
ruibaby 2019-12-10 13:00:59 +08:00
parent 0618a34d68
commit 5347289091
4 changed files with 88 additions and 1 deletions

View File

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

View File

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

View File

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

View File

@ -84,6 +84,41 @@
</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" />
</div>
</a-skeleton>
@ -130,6 +165,10 @@ export default {
type: Object,
required: true
},
sheetMetas: {
type: Array,
required: true
},
needTitle: {
type: Boolean,
required: false,
@ -152,13 +191,20 @@ export default {
selectedSheet(val) {
this.$emit('onRefreshSheet', val)
},
selectedSheetMetas(val) {
this.$emit('onRefreshSheetMetas', val)
},
visible: function(newValue, oldValue) {
if (newValue) {
this.loadSkeleton()
this.loadPresetMetasField()
}
}
},
computed: {
selectedSheetMetas() {
return this.sheetMetas
},
pickerDefaultValue() {
if (this.selectedSheet.createTime) {
var date = new Date(this.selectedSheet.createTime)
@ -175,6 +221,21 @@ export default {
this.settingLoading = false
}, 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() {
themeApi.customTpls().then(response => {
this.customTpls = response.data.data
@ -210,6 +271,7 @@ export default {
})
return
}
this.selectedSheet.sheetMetas = this.selectedSheetMetas
if (this.selectedSheet.id) {
sheetApi.update(this.selectedSheet.id, this.selectedSheet, autoSave).then(response => {
this.$log.debug('Updated sheet', response.data.data)
@ -239,6 +301,18 @@ export default {
},
onSheetDateOk(value) {
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: ''
})
}
}
}