@@ -187,6 +187,9 @@ func (this *BaseAuthMobileController) Detail() {
if inviteShareCode != "" {
go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_YANXUANSPECIAL, item.Title, inviteShareCode, specialId)
}
+ if userId == 0 {
+ item.Content = utils.InterceptHtmlLength(item.Content, 150)
+ }
var resp models.CygxYanxuanSpecialResp
resp.HasPermission = 1
resp.CygxYanxuanSpecialItem = *item
@@ -948,10 +948,26 @@ func InterceptHtmlLength(body string, length int) (newbody string) {
return
bodyText := doc.Text()
- if len(bodyText) < length {
+ //if len(bodyText) < length {
+ // length = len(bodyText)
+ //}
+ //newbody = bodyText[0:length]
+
+ totalCharCount := utf8.RuneCountInString(bodyText)
+ if totalCharCount < length {
length = len(bodyText)
- newbody = bodyText[0:length]
+ // 计算前15个汉字所需的字节位置
+ hanziCount := 0
+ byteIndex := 0
+ for byteIndex < len(bodyText) && hanziCount < length {
+ r, size := utf8.DecodeRuneInString(bodyText[byteIndex:])
+ if r != utf8.RuneError {
+ hanziCount++
+ byteIndex += size
+ newbody = bodyText[:byteIndex] + "…"