-
Notifications
You must be signed in to change notification settings - Fork 0
/
PageViewModel.cs
143 lines (130 loc) · 3.38 KB
/
PageViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sh.Knockout
{
public class PageViewModel
{
private int _index;
/// <summary>
/// 第几页
/// </summary>
public int Index
{
get
{
if (_index < 1)
{
_index = 1;
}
if (Totaile < _index)
{
_index = Totaile;
}
return _index;
}
set { _index = value; }
}
/// <summary>
/// 页面大小
/// </summary>
public int Size { get; set; } = 20;
public string ActionString { get; set; }
/// <summary>
/// 总页数
/// </summary>
public int Totaile
{
get
{
var a = Count / Size;
a = Count % Size != 0 ? ++a : a;
return a;
}
}
private int showCount = 5;
/// <summary>
/// 显示信息
/// </summary>
public List<int> List
{
get
{
var result = new List<int>();
if (Totaile <= showCount)
{
for (int i = 1; i <= Totaile; i++)
{
result.Add(i);
}
}
else
{
if (Index <= showCount / 2 + 1)
{
for (int i = 1; i <= 5; i++)
{
result.Add(i);
}
}
else if ((Index + showCount / 2 + 1) >= Totaile)
{
for (int i = Totaile - showCount; i <= Totaile; i++)
{
result.Add(i);
}
}
else
{
for (int i = Index - (showCount / 2 + 1); i < Index + (showCount / 2 + 1); i++)
{
result.Add(i);
}
}
}
return result;
}
}
public int Count { get; set; }
}
/// <summary>
/// 分页数据模型
/// </summary>
/// <typeparam name="T"></typeparam>
public class PageDataModel<T>
{
/// <summary>
/// 总数
/// </summary>
public int Count { get; set; }
/// <summary>
/// 数据集合
/// </summary>
///
public T Data { get; set; }
private int _index;
/// <summary>
/// 第几页
/// </summary>
public int Index
{
get
{
return _index;
}
set { _index = value; }
}
public int Size { get; set; } = 20;
public PageViewModel ToPageViewModel(string ActionString)
{
var result = new PageViewModel();
result.ActionString = ActionString;
result.Count = Count;
result.Index = Index;
result.Size = Size;
return result;
}
}
}