how to get / controllers/frontListNewsCenter.js
data
router.get ("/"
) of / routes/news.js
/ routes/news.js
const router = require("koa-router")({
prefix: "/news"
})
const config = require("../config")
const controllers = require("../controllers")
router.get("/", async (ctx, next) => {
const data = await controllers.frontListNewsCenter.get(ctx, next)
console.log(111, data) // undefined
// /controllers/frontListNewsCenter.js
await ctx.render("frontListNewsCenter", {
header: {
title: "",
javascript: config.javascript.concat("/js/jqpaginator.min.js", "/js/frontListNewsCenter.js"),
style: config.style.concat("/css/frontListNewsCenter.css"),
},
newBanner: {
imgSrc: "/images/newsbannenr.png",
},
tabNav: {
items: [{
cn: "",
en: "Company news",
}, {
cn: "",
en: "Industry information",
}],
},
companyNews: [],
industryNews: [],
})
})
router.get("/getList", controllers.frontListNewsCenter.get)
module.exports = router
/ controllers/frontListNewsCenter.js
const { getCompanyNewsList, getIndustryInfoList } = require("../config").service
const axios = require("axios")
async function get (ctx, next) {
const page = ctx.query.page || "1" // page
const size = ctx.query.size || "10" // size
const role = ctx.query.role || "news" // role
console.log(222, page, size, role)
if (role === "news") {
const companyNews = await axios.get(getCompanyNewsList, {
params: {
page: page,
size: size
}
})
if (companyNews.data.code === "2000") {
ctx.state.code = 0
ctx.state.data = companyNews.data.obj
} else {
ctx.state.code = -1
ctx.state.data = []
}
}
if (role === "industry") {
const industryNews = await axios.get(getIndustryInfoList, {
params: {
page: page,
size: size
}
})
if (industryNews.data.code === "2000") {
ctx.state.code = 0
ctx.state.data = industryNews.data.obj
} else {
ctx.state.code = -1
ctx.state.data = []
}
}
}
module.exports = {
get
}