// 获取汉字转拼音 func (this *AdminController) PinYin() { str := this.Ctx.Input.Param(":str") if str == "" { this.Data["json"] = map[string]interface{}{"error": "1"} } else { str = common.GetSlug(str, true) this.Data["json"] = map[string]interface{}{"error": "0", "msg": str} } this.ServeJson() }
// 接受提交数据 func (this *AdminController) Edit() { if this.Ctx.Request.Method == "POST" { ids := this.GetString("id") id := bson.NewObjectId() if ids != "" { id = bson.ObjectIdHex(ids) } caption := this.GetString("caption") slug := this.GetString("slug") atype := this.GetString("type") markdown := this.GetString("editor-markdown-doc") html := this.GetString("html") cover := this.GetString("cover") tag := this.GetString("tag") splits := strings.Split(tag, ",") var tags []string if len(splits) > 0 && splits[0] != "" { for _, v := range splits { tags = append(tags, strings.TrimSpace(v)) s := common.GetSlug(v, false) models.Tag(strings.TrimSpace(v), strings.TrimSpace(s)) } } else { tags = splits } scpost := &models.SC_Post{ Id: id, Caption: caption, Slug: slug, Tags: tags, Markdown: markdown, Html: html, Cover: cover, Type: atype, } err := scpost.Save() if err != nil { beego.Error(err) } this.Redirect("/admin", 302) } ids := this.Ctx.Input.Param(":id") if ids == "" { this.Abort("404") } id := bson.ObjectIdHex(ids) var scpost models.SC_Post models.GetOneById(models.DbPost, id, &scpost) this.Data["Id"] = id.Hex() this.Data["Caption"] = scpost.Caption this.Data["Slug"] = scpost.Slug if scpost.Type == "page" { this.Data["IsPage"] = true } else { this.Data["IsPost"] = true } this.Data["Markdown"] = scpost.Markdown this.Data["Cover"] = scpost.Cover this.Data["Tags"] = scpost.Tags this.TplNames = "admin/new.html" }