Skip to content

Commit

Permalink
添加后台友情链接管理功能,增加审核、排序、隐藏功能
Browse files Browse the repository at this point in the history
  • Loading branch information
livisky committed Jan 23, 2017
1 parent 5f4ecf6 commit 1f4420a
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 253 deletions.
108 changes: 54 additions & 54 deletions src/admin/controller/item.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
'use strict';
let init={
mydb:"item",
title:"分类管理",
edit:"分类编辑",
add:"分类添加",
action:"item"
let init = {
mydb: "item",
title: "分类管理",
edit: "分类编辑",
add: "分类添加",
action: "item"
}
import Base from './base.js';
export default class extends Base {
/**
* index action
* @return {Promise} []
*/
async indexAction(){
let info={
db:init.mydb,
page:this.get("page")||1,
pagesize:this.get("pagesize")||10
}
let mydata=await this.model('util').getIndex(info);
this.assign("itemList",mydata.itemList);
this.assign('pageData',mydata.pageData);
this.assign("title",init.title);
this.assign("action",init.action);
return this.display();
}
/**
* index action
* @return {Promise} []
*/
async indexAction() {
let info = {
db: init.mydb,
page: this.get("page") || 1,
pagesize: this.get("pagesize") || 10
}
let mydata = await this.model('util').getIndex(info);
this.assign("itemList", mydata.itemList);
this.assign('pageData', mydata.pageData);
this.assign("title", init.title);
this.assign("action", init.action);
return this.display();
}

async itemAction(){
async itemAction() {

let info={
db:init.mydb,
edit:init.edit,
add:init.add,
id:this.get('id')
}
let mydata=await this.model('util').getItem(info);
this.assign("title",mydata.title);
this.assign('item',mydata.item);
this.assign("action",init.action);
return this.display();
}
let info = {
db: init.mydb,
edit: init.edit,
add: init.add,
id: this.get('id')
}
let mydata = await this.model('util').getItem(info);
this.assign("title", mydata.title);
this.assign('item', mydata.item);
this.assign("action", init.action);
return this.display();
}

//编辑或者新增接口
async saveAction() {
let info={
db:init.mydb,
data:this.post(),
id:this.post('id')
}
let mydata=await this.model('util').doSave(info);
if(mydata.status===1) return this.success();
//编辑或者新增接口
async saveAction() {
let info = {
db: init.mydb,
data: this.post(),
id: this.post('id')
}
let mydata = await this.model('util').doSave(info);
if (mydata.status === 1) return this.success();
}

//删除或批量删除接口
async delsomeAction(){
let info={
db:init.mydb,
arr:this.post('delarr[]')
}
let where={id: ["IN", info.arr]};
let rs=await this.model("admin").deleteRecord(info.db,where);
if(rs) return this.success();
async delsomeAction() {
let info = {
db: init.mydb,
arr: this.post('delarr[]')
}
let where = { id: ["IN", info.arr] };
let rs = await this.model("admin").deleteRecord(info.db, where);
if (rs) return this.success();
}

}
}
105 changes: 74 additions & 31 deletions src/admin/controller/links.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,80 @@
'use strict';
let init={
mydb:"links",
title:"友情链接管理",
action:"links"
let init = {
mydb: "links",
title: "友情链接管理",
action: "links"
}
import Base from './base.js';
export default class extends Base {
/**
* index action
* @return {Promise} []
*/
async indexAction(){
let info={
db:init.mydb,
page:this.get("page")||1,
pagesize:this.get("pagesize")||10
}
let mydata=await this.model('util').getIndex(info);
this.assign("itemList",mydata.itemList);
this.assign('pageData',mydata.pageData);
this.assign("title",init.title);
this.assign("action",init.action);
return this.display();
}
//删除或批量删除接口
async delsomeAction(){
let info={
db:init.mydb,
arr:this.post('delarr[]')
/**
* index action
* @return {Promise} []
*/
async indexAction() {
let info = {
db: init.mydb,
page: this.get("page") || 1,
pagesize: this.get("pagesize") || 10
}
let where={id: ["IN", info.arr]};
let rs=await this.model("admin").deleteRecord(info.db,where);
if(rs) return this.success();
}
let mydata = await this.model('util').getIndex(info, { flag: 0 });
this.assign("itemList", mydata.itemList);
this.assign('pageData', mydata.pageData);
this.assign("title", init.title);
this.assign("action", init.action);
return this.display();
}
async listAction() {
let info = {
db: init.mydb,
page: this.get("page") || 1,
pagesize: this.get("pagesize") || 10
}
let mydata = await this.model('util').getList(info);
this.assign("itemList", mydata.itemList);
this.assign('pageData', mydata.pageData);
this.assign("title", init.title);
this.assign("action", init.action);
return this.display();
}
// 列表页
async itemAction() {
let info = {
db: init.mydb,
edit: init.edit,
add: init.add,
id: this.get('id')
}
let mydata = await this.model('util').getItem(info);
this.assign("title", mydata.title);
this.assign('item', mydata.item);
this.assign("action", init.action);
return this.display();
}
//编辑或者新增接口
async saveAction() {
let info = {
db: init.mydb,
data: this.post(),
id: this.post('id')
}
let mydata = await this.model('util').doSave(info);
if (mydata.status === 1) return this.success();
}
// 更新友情链接状态
async upstatusAction() {
let newData = this.post();
let rs = this.model("links").where({ id: this.post("id") }).update(newData);
if (rs) return this.success();
}
//删除或批量删除接口
async delsomeAction() {
let info = {
db: init.mydb,
arr: this.post('delarr[]')
}
let where = { id: ["IN", info.arr] };
let rs = await this.model("admin").deleteRecord(info.db, where);
if (rs) return this.success();
}

}
}
94 changes: 55 additions & 39 deletions src/admin/model/util.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
'use strict';
export default class extends think.model.base {

async getIndex(info){
async getIndex(info, where) {

let itemList=await this.model(info.db).page(info.page,info.pagesize).select();
let result = await this.model(info.db).page(info.page,info.pagesize).countSelect();
let Page=think.adapter("template", "page");
let page = new Page();
let pageData=page.pagination(result,info.page);
let itemList = await this.model(info.db).where(where).page(info.page, info.pagesize).select();
let result = await this.model(info.db).page(info.page, info.pagesize).countSelect();
let Page = think.adapter("template", "page");
let page = new Page();
let pageData = page.pagination(result, info.page);

return {
itemList:itemList,
pageData:pageData
};
}
async getItem(info){
let title="",item={};
if(info.id){
title=info.edit;
item=await this.model(info.db).where({id:info.id}).find();
}else{
title=info.add;
item={}
}
return{
title:title,
item:item
}
}
async doSave(info){
let status=0
if(!think.isEmpty(info.id)){
let rs=await this.model(info.db).where({id:info.id}).update(info.data);
if(rs) status=1;
}else{
let rs=await this.model(info.db).add(info.data);
if(rs) status=1;
}
return{
status:status
}
}
}
return {
itemList: itemList,
pageData: pageData
};
}
async getList(info) {

let itemList = await this.model(info.db).where({
flag: 1
}).page(info.page, info.pagesize).select();
let result = await this.model(info.db).page(info.page, info.pagesize).countSelect();
let Page = think.adapter("template", "page");
let page = new Page();
let pageData = page.pagination(result, info.page);

return {
itemList: itemList,
pageData: pageData
};
}
async getItem(info) {
let title = "",
item = {};
if (info.id) {
title = info.edit;
item = await this.model(info.db).where({ id: info.id }).find();
} else {
title = info.add;
item = {}
}
return {
title: title,
item: item
}
}
async doSave(info) {
let status = 0
if (!think.isEmpty(info.id)) {
let rs = await this.model(info.db).where({ id: info.id }).update(info.data);
if (rs) status = 1;
} else {
let rs = await this.model(info.db).add(info.data);
if (rs) status = 1;
}
return {
status: status
}
}
}
4 changes: 4 additions & 0 deletions src/doc/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default class extends think.controller.base {
let navList = await this.model('doc').findAll('menu');
this.assign("navList", navList);

//获取友情链接
let linksList = await this.model("doc").getLinksList();
this.assign("linksList", linksList);

// 设置主题地址
this.THEME_VIEW_PATH = `${think.THEME_PATH}${think.sep}${_web.theme}${think.sep}${think.Modules_Src}${think.sep}${this.http.module}${think.sep}`;
this.assign("theme_url", 'static/theme/' + _web.theme + '/res');
Expand Down
21 changes: 13 additions & 8 deletions src/doc/model/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
*/
export default class extends think.model.base {
//返回全部列表
findAll(db,where){
return this.model(db).where(where).select();
}
//返回特定记录
findOne(db,where){
findAll(db, where) {
return this.model(db).where(where).select();
}
//返回特定记录
findOne(db, where) {
return this.model(db).where(where).find();
}
getOneArticle(db,where){
return this.model(db).where(where).find();
getOneArticle(db, where) {
return this.model(db).where(where).find();
}
//获取友情链接列表
getLinksList() {
return this.model("links").where({ flag: 1 }).order("orders").select();
}
}

}
4 changes: 4 additions & 0 deletions src/home/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default class extends think.controller.base {
let navList = await this.model("home").findAll('menu');
this.assign("navList", navList);

//获取友情链接
let linksList = await this.model("home").getLinksList();
this.assign("linksList", linksList);

//assgin页面action
let action = this.http.action;
this.assign("action", action);
Expand Down
Loading

0 comments on commit 1f4420a

Please sign in to comment.