更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -10,27 +10,10 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// =============================================================
|
||||
// 官网前台只读接口:平台官网内容(yz_platform_website_*)
|
||||
//
|
||||
// 供 website SPA 调用,无需登录(与 /site/setting 同级)。
|
||||
// 数据由 platform 端「官网管理」模块维护;仅返回「已发布」的内容。
|
||||
//
|
||||
// GET /site/news 新闻列表(分页 / 分类 / 关键词)
|
||||
// GET /site/news/categories 新闻分类 + 各分类已发布数量
|
||||
// GET /site/news/:id 新闻详情(正文为 HTML)
|
||||
// GET /site/news/:id/related 相关推荐
|
||||
// POST /site/news/:id/view 浏览量 +1
|
||||
//
|
||||
// 说明:列表与详情中返回的 image 形如 /uploads/xxx,由前端拼接接口域名。
|
||||
// =============================================================
|
||||
|
||||
// 文章状态:与 platform 端「文章管理」保持一致
|
||||
const (
|
||||
articleStatusPublished int8 = 2
|
||||
)
|
||||
|
||||
// 导航菜单类型:与 platform 端「导航菜单」保持一致
|
||||
const (
|
||||
navTypeExternal int8 = 3
|
||||
)
|
||||
@@ -50,15 +33,12 @@ func (c *IndexWebsiteController) fail(httpStatus, bizCode int, msg string) {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// publishedArticleQuery 已发布文章的基础查询条件
|
||||
func publishedArticleCond() *orm.Condition {
|
||||
return orm.NewCondition().
|
||||
And("delete_time__isnull", true).
|
||||
And("status", articleStatusPublished)
|
||||
}
|
||||
|
||||
// articleListItem 列表项(不含正文,减小响应体)
|
||||
// image 与 category_image 分开返回,由前端决定兜底:文章没有封面时用所属分类的图片。
|
||||
func articleListItem(row models.PlatformWebsiteArticle, cate models.PlatformWebsiteCategory, tags []string) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": row.ID,
|
||||
@@ -78,21 +58,17 @@ func articleListItem(row models.PlatformWebsiteArticle, cate models.PlatformWebs
|
||||
}
|
||||
}
|
||||
|
||||
// navNode 导航菜单节点(递归结构,供页头渲染)
|
||||
type navNode struct {
|
||||
ID uint64 `json:"id"`
|
||||
Pid uint64 `json:"pid"`
|
||||
Title string `json:"title"`
|
||||
Type int8 `json:"type"` // 1 目录 / 2 页面 / 3 外链 / 4 单页
|
||||
Type int8 `json:"type"`
|
||||
Path string `json:"path"`
|
||||
Icon string `json:"icon"`
|
||||
External bool `json:"external"`
|
||||
Children []*navNode `json:"children"`
|
||||
}
|
||||
|
||||
// Nav GET /site/nav
|
||||
// 官网页头导航:仅返回启用且显示中的菜单项,按 pid 组树。
|
||||
// 父级被隐藏/禁用时其子项一并隐藏,避免出现无归属的顶层菜单。
|
||||
func (c *IndexWebsiteController) Nav() {
|
||||
var rows []models.PlatformWebsiteNav
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformWebsiteNav)).
|
||||
@@ -138,7 +114,6 @@ func (c *IndexWebsiteController) Nav() {
|
||||
c.ok(map[string]interface{}{"list": roots})
|
||||
}
|
||||
|
||||
// News GET /site/news?page=&pageSize=&category=&keyword=
|
||||
func (c *IndexWebsiteController) News() {
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 6)
|
||||
@@ -155,7 +130,6 @@ func (c *IndexWebsiteController) News() {
|
||||
cond := publishedArticleCond()
|
||||
if cateStr := strings.TrimSpace(c.GetString("category")); cateStr != "" {
|
||||
if cid, err := strconv.ParseUint(cateStr, 10, 64); err == nil && cid > 0 {
|
||||
// 选中父分类时把它整棵子树的文章一起返回,否则挂在子分类上的内容会查不到
|
||||
ids := append([]uint64{cid}, models.PlatformWebsiteCategoryDescendantMap()[cid]...)
|
||||
cond = cond.And("cate_id__in", ids)
|
||||
}
|
||||
@@ -216,8 +190,6 @@ func (c *IndexWebsiteController) News() {
|
||||
})
|
||||
}
|
||||
|
||||
// NewsCategories GET /site/news/categories
|
||||
// 返回启用中的分类及各自已发布文章数量,供列表页筛选条展示。
|
||||
func (c *IndexWebsiteController) NewsCategories() {
|
||||
var cates []models.PlatformWebsiteCategory
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformWebsiteCategory)).
|
||||
@@ -228,7 +200,6 @@ func (c *IndexWebsiteController) NewsCategories() {
|
||||
return
|
||||
}
|
||||
|
||||
// 父分类的数量包含其所有后代,与列表页按父分类筛选的口径保持一致
|
||||
descMap := models.PlatformWebsiteCategoryDescendantMap()
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(cates))
|
||||
@@ -256,7 +227,6 @@ func (c *IndexWebsiteController) NewsCategories() {
|
||||
c.ok(map[string]interface{}{"list": list, "total": total})
|
||||
}
|
||||
|
||||
// NewsDetail GET /site/news/:id
|
||||
func (c *IndexWebsiteController) NewsDetail() {
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
@@ -296,8 +266,6 @@ func (c *IndexWebsiteController) NewsDetail() {
|
||||
})
|
||||
}
|
||||
|
||||
// NewsRelated GET /site/news/:id/related?limit=3
|
||||
// 同分类优先,不足时用其它分类补齐。
|
||||
func (c *IndexWebsiteController) NewsRelated() {
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
@@ -314,7 +282,6 @@ func (c *IndexWebsiteController) NewsRelated() {
|
||||
SetCond(publishedArticleCond()).
|
||||
Filter("id", id).
|
||||
One(¤t); err != nil {
|
||||
// 当前内容不存在时返回空列表,由前端展示"暂无推荐"
|
||||
c.ok(map[string]interface{}{"list": []interface{}{}})
|
||||
return
|
||||
}
|
||||
@@ -322,7 +289,6 @@ func (c *IndexWebsiteController) NewsRelated() {
|
||||
pick := make([]models.PlatformWebsiteArticle, 0, limit)
|
||||
seen := map[uint64]bool{id: true}
|
||||
|
||||
// 1. 同分类
|
||||
if current.CateID > 0 {
|
||||
var same []models.PlatformWebsiteArticle
|
||||
_, _ = models.Orm.QueryTable(new(models.PlatformWebsiteArticle)).
|
||||
@@ -342,7 +308,6 @@ func (c *IndexWebsiteController) NewsRelated() {
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 不足时用最新其它文章补齐
|
||||
if len(pick) < limit {
|
||||
ids := make([]uint64, 0, len(seen))
|
||||
for k := range seen {
|
||||
@@ -381,7 +346,6 @@ func (c *IndexWebsiteController) NewsRelated() {
|
||||
c.ok(map[string]interface{}{"list": list})
|
||||
}
|
||||
|
||||
// NewsView POST /site/news/:id/view — 浏览量 +1(详情页打开时调用)
|
||||
func (c *IndexWebsiteController) NewsView() {
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
@@ -398,16 +362,6 @@ func (c *IndexWebsiteController) NewsView() {
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
// 站点公告 yz_platform_website_notice
|
||||
//
|
||||
// GET /site/notices 公告列表(?limit=6&popup=1 只取弹窗公告)
|
||||
// GET /site/notices/:id 公告详情(正文为 HTML,浏览量 +1)
|
||||
//
|
||||
// 仅返回「已发布」且当前时间处于有效期内的公告,条件见 noticeVisibleCond。
|
||||
// =============================================================
|
||||
|
||||
// noticeListItem 公告列表项(不含正文,减小响应体)
|
||||
func noticeListItem(r models.PlatformWebsiteNotice) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": r.ID,
|
||||
@@ -421,7 +375,6 @@ func noticeListItem(r models.PlatformWebsiteNotice) map[string]interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
// Notices GET /site/notices?limit=&popup=
|
||||
func (c *IndexWebsiteController) Notices() {
|
||||
limit, _ := c.GetInt("limit", 6)
|
||||
if limit < 1 {
|
||||
@@ -432,7 +385,6 @@ func (c *IndexWebsiteController) Notices() {
|
||||
}
|
||||
|
||||
cond := noticeVisibleCond()
|
||||
// popup 传 1 / true 时只取弹窗公告(首页弹窗、侧栏公告用)
|
||||
if pop := strings.TrimSpace(c.GetString("popup")); pop != "" && pop != "0" {
|
||||
cond = cond.And("is_popup", 1)
|
||||
}
|
||||
@@ -455,7 +407,6 @@ func (c *IndexWebsiteController) Notices() {
|
||||
c.ok(map[string]interface{}{"list": list, "total": len(list)})
|
||||
}
|
||||
|
||||
// NoticeDetail GET /site/notices/:id
|
||||
func (c *IndexWebsiteController) NoticeDetail() {
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
@@ -472,7 +423,6 @@ func (c *IndexWebsiteController) NoticeDetail() {
|
||||
return
|
||||
}
|
||||
|
||||
// 浏览量 +1,失败不影响正文展示
|
||||
_, _ = models.Orm.Raw(
|
||||
"UPDATE yz_platform_website_notice SET views = views + 1 WHERE id = ?",
|
||||
id,
|
||||
|
||||
Reference in new issue
Block a user