コード例 #1
0
ファイル: home.go プロジェクト: tcdog001/szm_lss
func (this *HomeController) Get() {
	//session认证
	session := this.GetSession("Admin")
	if session == nil {
		beego.Trace("session verify failed!")
		this.Redirect("/", 302)
		return
	}
	this.TplNames = "home.html"

	//重置参数
	devicesCount = 0
	totalPages = 0
	curPage = 1
	listCount = 10
	curCount = 0

	//获取每页显示条数
	listcount := this.Input().Get("ListCount")
	if listcount != "" {
		listCount, _ = strconv.ParseInt(listcount, 10, 0)
		beego.Debug("listCount=", listCount)
	}

	//获取设备总数
	devicescount := this.Input().Get("DevicesCount")
	if devicescount != "" {
		devicesCount, _ = strconv.ParseInt(devicescount, 10, 0)
		beego.Debug("devicesCount=", devicesCount)
	} else {
		devicesCount = models.GetDevicesCount()
	}

	//计算出总页数
	if devicesCount%listCount > 0 {
		totalPages = devicesCount/listCount + 1
	} else {
		totalPages = devicesCount / listCount
	}

	//获取当前页数
	curpage := this.Input().Get("CurPage")
	if curpage != "" {
		curPage, _ = strconv.ParseInt(curpage, 10, 0)
		beego.Debug("curPage=", curPage)
	} else {
		curPage = 1
	}
	if curPage > totalPages {
		curPage = totalPages
	}

	//计算出当前总条数
	curCount = listCount * (curPage - 1)

	//获取操作
	ope := this.Input().Get("op")
	switch ope {
	case "firstpage":
		curCount = 0
		curPage = 1
	case "prepage":
		if curPage > 1 {
			curCount -= listCount
			curPage -= 1
		}
	case "nextpage":
		if curPage < totalPages {
			curCount += listCount
			curPage += 1
		}
	case "lastpage":
		curCount = listCount * (totalPages - 1)
		curPage = totalPages
	}

	devices, nums, ok := models.GetDevices(listCount, curCount)
	if ok {
		this.Data["Devices"] = devices
		this.Data["DevicesNum"] = devicesCount
		this.Data["CurPage"] = curPage
		this.Data["ListCount"] = listCount
		this.Data["TotalPages"] = totalPages
	}
	if nums <= 0 {
		this.Data["CurPage"] = 0
		this.Data["NoInfo"] = "没有注册设备!"
	}
}
コード例 #2
0
ファイル: home.go プロジェクト: tcdog001/LTE_Security
func (this *HomeController) Get() {
	//check islogin
	session := this.GetSession("Admin")
	if session == nil {
		beego.Trace("session verify failed!")
		this.Redirect("/", 302)
		return
	}
	this.TplNames = "home.html"

	//recive request listcount info
	listcount := this.Input().Get("listcount")
	if !(listcount == "") {
		count, _ := strconv.Atoi(listcount)
		switch count {
		case 20:
			listCount = 20
			curCount = 0
			curPage = 1
		case 30:
			listCount = 30
			curCount = 0
			curPage = 1
		default:
			listCount = 10
			curCount = 0
			curPage = 1
		}
	}
	beego.Debug("listcount=", listCount)

	//calc variables to show
	devicesCount = models.GetDevicesCount()
	beego.Debug("devicesCount=", devicesCount)
	if devicesCount%listCount > 0 {
		totalPages = devicesCount/listCount + 1
	} else {
		totalPages = devicesCount / listCount
	}

	//recive request op info
	ope := this.Input().Get("op")
	beego.Debug("ope=", ope)
	switch ope {
	case "firstpage":
		curCount = 0
		curPage = 1
	case "prepage":
		if curPage > 1 {
			curCount -= listCount
			curPage -= 1
		}
	case "nextpage":
		if curPage < totalPages {
			curCount += listCount
			curPage += 1
		}
	case "lastpage":
		curCount = listCount * (totalPages - 1)
		curPage = totalPages
	}

	devices, _, ok := models.GetDevices(listCount, curCount)
	if ok {
		beego.Info("GetDevices success!")
		this.Data["Devices"] = devices
		this.Data["DevicesNum"] = devicesCount
		this.Data["CurPage"] = curPage
		this.Data["TotalPages"] = totalPages
	} else {
		this.Data["NoInfo"] = "There have no devices!"
	}
}