|
5 | 5 | <view class="example-body">
|
6 | 6 | <uni-grid :column="3" :highlight="true" @change="change">
|
7 | 7 | <uni-grid-item v-for="(item, index) in list" :key="index">
|
8 |
| - <image :src="item.url" class="image" mode="aspectFill" /> |
9 |
| - <text class="text">{{ item.text }}</text> |
| 8 | + <view class="grid-item-box"> |
| 9 | + <image :src="item.url" class="image" mode="aspectFill" /> |
| 10 | + <text class="text">{{ item.text }}</text> |
| 11 | + </view> |
10 | 12 | </uni-grid-item>
|
11 | 13 | </uni-grid>
|
12 | 14 | </view>
|
13 |
| - <uni-section title="动态加载宫格" type="line"></uni-section> |
| 15 | + <uni-section title="动态加载" type="line"></uni-section> |
14 | 16 | <view class="example-body">
|
15 |
| - <view v-if="dynamicList.length!==0" class="box"> |
| 17 | + <view v-if="dynamicList.length!==0" class="grid-dynamic-box"> |
16 | 18 | <uni-grid :column="3" :highlight="true" @change="change">
|
17 | 19 | <uni-grid-item v-for="(item, index) in dynamicList" :key="index">
|
18 |
| - <image :src="item.url" class="image" mode="aspectFill" /> |
19 |
| - <text class="text">{{ item.text }}</text> |
| 20 | + <view class="grid-item-box" :style="{'backgroundColor':item.color}"> |
| 21 | + <image :src="item.url" class="image" mode="aspectFill" /> |
| 22 | + <text class="text">{{ item.text }}</text> |
| 23 | + </view> |
20 | 24 | </uni-grid-item>
|
21 | 25 | </uni-grid>
|
22 | 26 | </view>
|
23 | 27 | <button type="primary" @click="add">点击添加一个宫格</button>
|
24 | 28 | </view>
|
25 |
| - <uni-section title="无边框(3列)" type="line"></uni-section> |
| 29 | + <uni-section title="无边框带角标(3列)" type="line"></uni-section> |
26 | 30 | <view class="example-body">
|
27 | 31 | <uni-grid :column="3" :show-border="false" :square="false" @change="change">
|
28 |
| - <uni-grid-item :hor="0" :ver="0" marker="badge" type="error" text="12"> |
29 |
| - <image class="image" src="/static/c1.png" mode="aspectFill" /> |
30 |
| - <text class="text">Grid 1</text> |
31 |
| - </uni-grid-item> |
32 |
| - <uni-grid-item :hor="0" :ver="0" :img-width="30" marker="image"> |
33 |
| - <image class="image" src="/static/c2.png" mode="aspectFill" /> |
34 |
| - <text class="text">Grid 2</text> |
35 |
| - </uni-grid-item> |
36 |
| - <uni-grid-item> |
37 |
| - <image class="image" src="/static/c3.png" mode="aspectFill" /> |
38 |
| - <text class="text">Grid 3</text> |
39 |
| - </uni-grid-item> |
40 |
| - <uni-grid-item> |
41 |
| - <image class="image" src="/static/c4.png" mode="aspectFill" /> |
42 |
| - <text class="text">Grid 4</text> |
43 |
| - </uni-grid-item> |
44 |
| - <uni-grid-item> |
45 |
| - <image class="image" src="/static/c5.png" mode="aspectFill" /> |
46 |
| - <text class="text">Grid 5</text> |
47 |
| - </uni-grid-item> |
48 |
| - <uni-grid-item> |
49 |
| - <image class="image" src="/static/c6.png" mode="aspectFill" /> |
50 |
| - <text class="text">Grid 6</text> |
| 32 | + <uni-grid-item v-if="index <6" v-for="(item ,index) in list" :key="index"> |
| 33 | + <view class="grid-item-box"> |
| 34 | + <image class="image" :src="item.url" mode="aspectFill" /> |
| 35 | + <text class="text">{{item.text}}</text> |
| 36 | + <view v-if="item.badge" class="grid-dot"> |
| 37 | + <uni-badge :text="item.badge" :type="item.type" /> |
| 38 | + </view> |
| 39 | + </view> |
51 | 40 | </uni-grid-item>
|
52 | 41 | </uni-grid>
|
53 | 42 | </view>
|
54 | 43 | <uni-section title="矩形宫格(3列)" type="line"></uni-section>
|
55 | 44 | <view class="example-body">
|
56 | 45 | <uni-grid :column="3" :square="false" :highlight="false" @change="change">
|
57 | 46 | <uni-grid-item v-for="(item, index) in list" :key="index">
|
58 |
| - <image :src="item.url" class="image" mode="aspectFill" /> |
59 |
| - <text class="text">{{ item.text }}</text> |
| 47 | + <view class="grid-item-box"> |
| 48 | + <image :src="item.url" class="image" mode="aspectFill" /> |
| 49 | + <text class="text">{{ item.text }}</text> |
| 50 | + </view> |
60 | 51 | </uni-grid-item>
|
61 | 52 | </uni-grid>
|
62 | 53 | </view>
|
63 | 54 | <uni-section title="边框颜色(4列 无文字)" type="line"></uni-section>
|
64 | 55 | <view class="example-body">
|
65 | 56 | <uni-grid :column="4" border-color="#03a9f4" @change="change">
|
66 | 57 | <uni-grid-item>
|
67 |
| - <image class="image" src="/static/c1.png" mode="aspectFill" /> |
68 |
| - <!-- <text class="text">Grid 1</text> --> |
| 58 | + <view class="grid-item-box"> |
| 59 | + <image class="image" src="/static/c1.png" mode="aspectFill" /> |
| 60 | + </view> |
69 | 61 | </uni-grid-item>
|
70 | 62 | <uni-grid-item>
|
71 |
| - <image class="image" src="/static/c2.png" mode="aspectFill" /> |
72 |
| - <!-- <text class="text">Grid 2</text> --> |
| 63 | + <view class="grid-item-box"> |
| 64 | + <image class="image" src="/static/c2.png" mode="aspectFill" /> |
| 65 | + </view> |
73 | 66 | </uni-grid-item>
|
74 | 67 | <uni-grid-item>
|
75 |
| - <image class="image" src="/static/c3.png" mode="aspectFill" /> |
76 |
| - <!-- <text class="text">Grid 3</text> --> |
| 68 | + <view class="grid-item-box"> |
| 69 | + <image class="image" src="/static/c3.png" mode="aspectFill" /> |
| 70 | + </view> |
77 | 71 | </uni-grid-item>
|
78 | 72 | <uni-grid-item>
|
79 |
| - <image class="image" src="/static/c4.png" mode="aspectFill" /> |
80 |
| - <!-- <text class="text">Grid 4</text> --> |
| 73 | + <view class="grid-item-box"> |
| 74 | + <image class="image" src="/static/c4.png" mode="aspectFill" /> |
| 75 | + </view> |
81 | 76 | </uni-grid-item>
|
82 | 77 |
|
83 | 78 | </uni-grid>
|
|
89 | 84 | import uniSection from '@/components/uni-section/uni-section.vue'
|
90 | 85 | import uniGrid from '@/components/uni-grid/uni-grid.vue'
|
91 | 86 | import uniGridItem from '@/components/uni-grid-item/uni-grid-item.vue'
|
| 87 | + import uniBadge from '@/components/uni-badge/uni-badge.vue' |
92 | 88 | export default {
|
93 | 89 | components: {
|
94 | 90 | uniSection,
|
95 | 91 | uniGrid,
|
96 |
| - uniGridItem |
| 92 | + uniGridItem, |
| 93 | + uniBadge |
97 | 94 | },
|
98 | 95 | data() {
|
99 | 96 | return {
|
100 | 97 | dynamicList: [],
|
101 | 98 | list: [{
|
102 | 99 | url: '/static/c1.png',
|
103 |
| - text: 'Grid 1' |
| 100 | + text: 'Grid 1', |
| 101 | + badge: '0', |
| 102 | + type: "primary" |
104 | 103 | },
|
105 | 104 | {
|
106 | 105 | url: '/static/c2.png',
|
107 |
| - text: 'Grid 2' |
| 106 | + text: 'Grid 2', |
| 107 | + badge: '1', |
| 108 | + type: "success" |
108 | 109 | },
|
109 | 110 | {
|
110 | 111 | url: '/static/c3.png',
|
111 |
| - text: 'Grid 3' |
| 112 | + text: 'Grid 3', |
| 113 | + badge: '99', |
| 114 | + type: "warning" |
112 | 115 | },
|
113 | 116 | {
|
114 | 117 | url: '/static/c4.png',
|
115 |
| - text: 'Grid 4' |
| 118 | + text: 'Grid 4', |
| 119 | + badge: '2', |
| 120 | + type: "error" |
116 | 121 | },
|
117 | 122 | {
|
118 | 123 | url: '/static/c5.png',
|
|
142 | 147 | let {
|
143 | 148 | index
|
144 | 149 | } = e.detail
|
145 |
| - uni.showToast({ |
146 |
| - title: `点击第${index+1}个宫格`, |
147 |
| - icon: 'none' |
| 150 | + this.list[index].badge && this.list[index].badge++ |
| 151 | + |
| 152 | + uni.showToast({ |
| 153 | + title: `点击第${index+1}个宫格`, |
| 154 | + icon: 'none' |
148 | 155 | })
|
149 | 156 | },
|
150 | 157 | add() {
|
151 | 158 | if (this.dynamicList.length < 9) {
|
152 | 159 | this.dynamicList.push({
|
153 | 160 | url: `/static/c${this.dynamicList.length+1}.png`,
|
154 |
| - text: `Grid ${this.dynamicList.length+1}` |
| 161 | + text: `Grid ${this.dynamicList.length+1}`, |
| 162 | + color: this.dynamicList.length % 2 === 0? '#f5f5f5': "#fff" |
155 | 163 | })
|
156 | 164 | } else {
|
157 | 165 | uni.showToast({
|
|
183 | 191 | /* #endif */
|
184 | 192 | }
|
185 | 193 |
|
186 |
| - .box { |
| 194 | + .grid-dynamic-box { |
187 | 195 | margin-bottom: 15px;
|
188 | 196 | }
|
| 197 | + |
| 198 | + .grid-item-box { |
| 199 | + flex: 1; |
| 200 | + // position: relative; |
| 201 | + /* #ifndef APP-NVUE */ |
| 202 | + display: flex; |
| 203 | + /* #endif */ |
| 204 | + flex-direction: column; |
| 205 | + align-items: center; |
| 206 | + justify-content: center; |
| 207 | + padding: 15px 0; |
| 208 | + } |
| 209 | + |
| 210 | + .grid-dot { |
| 211 | + position: absolute; |
| 212 | + top: 5px; |
| 213 | + right: 15px; |
| 214 | + } |
189 | 215 | </style>
|
0 commit comments