Browse Source

feat: support resetting post slug #319 (#368)

pull/375/head
Ryan Wang 3 years ago committed by GitHub
parent
commit
b412671e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/views/post/components/PostSettingDrawer.vue
  2. 20
      src/views/sheet/components/SheetSettingDrawer.vue

20
src/views/post/components/PostSettingDrawer.vue

@ -18,7 +18,19 @@
<a-input v-model="selectedPost.title" />
</a-form-item>
<a-form-item label="文章别名:" :help="fullPath">
<a-input v-model="selectedPost.slug" />
<a-input v-model="selectedPost.slug">
<template #addonAfter>
<a-popconfirm
title="是否确定根据标题重新生成别名?"
ok-text="确定"
cancel-text="取消"
placement="left"
@confirm="handleSetPinyinSlug"
>
<a-icon class="cursor-pointer" type="sync" />
</a-popconfirm>
</template>
</a-input>
</a-form-item>
<a-form-item label="发表时间:">
@ -387,8 +399,10 @@ export default {
this.handleListCategories()
this.handleListPresetMetasField()
this.handleListCustomTpls()
if (!this.selectedPost.slug && !this.selectedPost.id) {
this.handleSetPinyinSlug()
}
}
},
handleListCategories() {
categoryApi.listAll().then(response => {
@ -534,10 +548,10 @@ export default {
})
},
handleSetPinyinSlug() {
if (this.selectedPost.title && this.selectedPost.title !== '' && !this.selectedPost.id) {
if (this.selectedPost.title) {
if (pinyin.isSupported()) {
let result = ''
const tokens = pinyin.parse(this.selectedPost.title)
const tokens = pinyin.parse(this.selectedPost.title.replace(/\s+/g, '').toLowerCase())
let lastToken
tokens.forEach(token => {
if (token.type === 2) {

20
src/views/sheet/components/SheetSettingDrawer.vue

@ -18,7 +18,19 @@
<a-input v-model="selectedSheet.title" />
</a-form-item>
<a-form-item label="页面别名:" :help="fullPath">
<a-input v-model="selectedSheet.slug" />
<a-input v-model="selectedSheet.slug">
<template #addonAfter>
<a-popconfirm
title="是否确定根据标题重新生成别名?"
ok-text="确定"
cancel-text="取消"
placement="left"
@confirm="handleSetPinyinSlug"
>
<a-icon class="cursor-pointer" type="sync" />
</a-popconfirm>
</template>
</a-input>
</a-form-item>
<a-form-item label="发表时间:">
<a-date-picker
@ -272,8 +284,10 @@ export default {
if (visible) {
this.handleListCustomTpls()
this.handleListPresetMetasField()
if (!this.selectedSheet.slug && !this.selectedSheet.id) {
this.handleSetPinyinSlug()
}
}
},
handleListPresetMetasField() {
if (this.metas.length <= 0) {
@ -397,10 +411,10 @@ export default {
})
},
handleSetPinyinSlug() {
if (this.selectedSheet.title && !this.selectedSheet.id) {
if (this.selectedSheet.title) {
if (pinyin.isSupported()) {
let result = ''
const tokens = pinyin.parse(this.selectedSheet.title)
const tokens = pinyin.parse(this.selectedSheet.title.replace(/\s+/g, '').toLowerCase())
let lastToken
tokens.forEach(token => {
if (token.type === 2) {

Loading…
Cancel
Save