wangzhibo
6 天以前 7bd866831780abcf5a59c4cbb7d1be456eea7c99
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
    <div class="card">
        <div class="card__header">
            <span class="label">{{ $t('热门商品排行') }}</span>
 
            <cl-select-button v-model="type" :options="options.type" small />
        </div>
 
        <div class="card__container">
            <cl-crud ref="Crud" padding="0">
                <cl-table ref="Table" />
            </cl-crud>
        </div>
    </div>
</template>
 
<script lang="ts" setup>
import { useCrud, useTable } from '@cool-vue/crud';
import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
 
const { t } = useI18n();
 
// 类型
const type = ref('day');
 
// 选项
const options = reactive({
    type: [
        {
            label: t('今日'),
            value: 'day'
        },
        {
            label: t('本周'),
            value: 'week'
        },
        {
            label: t('本月'),
            value: 'month'
        },
        {
            label: t('全年'),
            value: 'year'
        }
    ]
});
 
const Crud = useCrud(
    {
        service: {
            page() {
                return Promise.resolve({
                    list: [
                        {
                            keyWord: '无线耳机',
                            count: 983,
                            ud: 5,
                            launchDate: '2023-01-01',
                            price: 299
                        },
                        {
                            keyWord: '运动耳机',
                            count: 763,
                            ud: -3,
                            launchDate: '2023-02-15',
                            price: 199
                        },
                        {
                            keyWord: '蓝牙音箱',
                            count: 328,
                            ud: 7,
                            launchDate: '2023-03-10',
                            price: 399
                        },
                        {
                            keyWord: '4k显示屏',
                            count: 144,
                            ud: 4,
                            launchDate: '2023-04-05',
                            price: 999
                        },
                        {
                            keyWord: '罗技 G530',
                            count: 121,
                            ud: -1,
                            launchDate: '2023-05-20',
                            price: 499
                        },
                        {
                            keyWord: '智能手表',
                            count: 450,
                            ud: 2,
                            launchDate: '2023-06-15',
                            price: 599
                        },
                        {
                            keyWord: '游戏鼠标',
                            count: 300,
                            ud: 6,
                            launchDate: '2023-07-01',
                            price: 150
                        },
                        {
                            keyWord: '机械键盘',
                            count: 200,
                            ud: -2,
                            launchDate: '2023-08-10',
                            price: 350
                        },
                        {
                            keyWord: 'VR眼镜',
                            count: 150,
                            ud: 8,
                            launchDate: '2023-09-05',
                            price: 799
                        },
                        {
                            keyWord: '智能音箱',
                            count: 100,
                            ud: 3,
                            launchDate: '2023-10-01',
                            price: 250
                        }
                    ]
                });
            }
        }
    },
    app => {
        app.refresh();
    }
);
 
const Table = useTable({
    autoHeight: false,
    contextMenu: ['order-asc', 'order-desc'],
    columns: [
        {
            label: t('排名'),
            type: 'index',
            width: 60
        },
        {
            label: t('商品名称'),
            prop: 'keyWord',
            minWidth: 120
        },
        {
            label: t('商品金额'),
            prop: 'price',
            minWidth: 100
        },
        {
            label: t('下单次数'),
            prop: 'count',
            minWidth: 100,
            sortable: true
        },
        {
            label: t('日涨幅'),
            prop: 'ud',
            sortable: true,
            minWidth: 100
        },
        {
            label: t('上架时间'),
            prop: 'launchDate',
            minWidth: 120
        }
    ]
});
</script>
 
<style lang="scss" scoped>
.card {
    padding-bottom: 20px;
}
</style>