mirror of https://github.com/halo-dev/halo-admin
fix: halo-dev/halo#1157 (#273)
parent
17eb64ebff
commit
132d2fad39
|
@ -602,9 +602,21 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleSetPinyinSlug() {
|
handleSetPinyinSlug() {
|
||||||
if (this.selectedPost.title && !this.selectedPost.id) {
|
if (this.selectedPost.title && this.selectedPost.title !== '' && !this.selectedPost.id) {
|
||||||
if (pinyin.isSupported()) {
|
if (pinyin.isSupported()) {
|
||||||
this.$set(this.selectedPost, 'slug', pinyin.convertToPinyin(this.selectedPost.title, '-', true))
|
let result = ''
|
||||||
|
const tokens = pinyin.parse(this.selectedPost.title)
|
||||||
|
let lastToken
|
||||||
|
tokens.forEach((token, i) => {
|
||||||
|
if (token.type === 2) {
|
||||||
|
const target = token.target ? token.target.toLowerCase() : ''
|
||||||
|
result += result && !/\n|\s/.test(lastToken.target) ? '-' + target : target
|
||||||
|
} else {
|
||||||
|
result += (lastToken && lastToken.type === 2 ? '-' : '') + token.target
|
||||||
|
}
|
||||||
|
lastToken = token
|
||||||
|
})
|
||||||
|
this.$set(this.selectedPost, 'slug', result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -444,7 +444,19 @@ export default {
|
||||||
handleSetPinyinSlug() {
|
handleSetPinyinSlug() {
|
||||||
if (this.selectedSheet.title && !this.selectedSheet.id) {
|
if (this.selectedSheet.title && !this.selectedSheet.id) {
|
||||||
if (pinyin.isSupported()) {
|
if (pinyin.isSupported()) {
|
||||||
this.$set(this.selectedSheet, 'slug', pinyin.convertToPinyin(this.selectedSheet.title, '-', true))
|
let result = ''
|
||||||
|
const tokens = pinyin.parse(this.selectedSheet.title)
|
||||||
|
let lastToken
|
||||||
|
tokens.forEach((token, i) => {
|
||||||
|
if (token.type === 2) {
|
||||||
|
const target = token.target ? token.target.toLowerCase() : ''
|
||||||
|
result += result && !/\n|\s/.test(lastToken.target) ? '-' + target : target
|
||||||
|
} else {
|
||||||
|
result += (lastToken && lastToken.type === 2 ? '-' : '') + token.target
|
||||||
|
}
|
||||||
|
lastToken = token
|
||||||
|
})
|
||||||
|
this.$set(this.selectedSheet, 'slug', result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue