Skip to content

Commit 8953f27

Browse files
committed
refactor(filter): 优化文章状态过滤器
1 parent e9d39e9 commit 8953f27

File tree

9 files changed

+31
-75
lines changed

9 files changed

+31
-75
lines changed

src/directives/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue from 'vue';
1+
import Vue, { DirectiveOptions } from 'vue';
22

33
import permission from './permission';
44
import waves from './waves';
@@ -13,5 +13,5 @@ const directives = {
1313
};
1414

1515
Object.keys(directives).forEach((key) => {
16-
Vue.directive(key, directives[key]);
16+
Vue.directive(key, (directives as { [key: string]: DirectiveOptions })[key]);
1717
});

src/filters/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,29 @@ export function toThousandFilter(num) {
4343
return (+num || 0).toString().replace(/^-?\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','));
4444
}
4545

46+
// Filter for article status
47+
export const articleStatusFilter = (status: string) => {
48+
const statusMap: { [key: string]: string } = {
49+
published: 'success',
50+
success: 'success',
51+
draft: 'info',
52+
deleted: 'danger',
53+
pending: 'danger'
54+
};
55+
return statusMap[status];
56+
};
57+
4658
// register global utility filters.
4759
const filters = {
4860
formatDate,
4961
parseTime,
5062
formatTime,
5163
numberFormatter,
52-
toThousandFilter
64+
toThousandFilter,
65+
articleStatusFilter
5366
};
5467

5568
Object.keys(filters).forEach((key) => {
56-
Vue.filter(key, filters[key]);
69+
// tslint:disable-next-line:ban-types
70+
Vue.filter(key, (filters as { [key: string]: Function })[key]);
5771
});

src/views/dashboard/admin/components/BoxCard.vue

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,10 @@ import {
3434
} from '@/components';
3535
3636
@Component({
37+
name: 'BoxCard',
3738
components: {
3839
PanThumb,
3940
Mallki
40-
},
41-
filters: {
42-
statusFilter(status) {
43-
const statusMap = {
44-
success: 'success',
45-
pending: 'danger'
46-
};
47-
return statusMap[status];
48-
}
4941
}
5042
})
5143
export default class BoxCard extends Vue {

src/views/dashboard/admin/components/TransactionTable.vue

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</el-table-column>
1313
<el-table-column label="Status" width="100" align="center">
1414
<template slot-scope="scope">
15-
<el-tag :type="scope.row.status | statusFilter"> {{ scope.row.status }}</el-tag>
15+
<el-tag :type="scope.row.status | articleStatusFilter"> {{ scope.row.status }}</el-tag>
1616
</template>
1717
</el-table-column>
1818
</el-table>
@@ -23,14 +23,8 @@ import { Component, Vue } from 'vue-property-decorator';
2323
import {SUCCESS_STATUS} from '@/constant';
2424
2525
@Component({
26+
name: 'TransactionTable',
2627
filters: {
27-
statusFilter(status) {
28-
const statusMap = {
29-
success: 'success',
30-
pending: 'danger'
31-
};
32-
return statusMap[status];
33-
},
3428
orderNoFilter(str) {
3529
return str.substring(0, 30);
3630
}

src/views/example/list.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<el-table-column class-name="status-col" label="Status" width="110">
3030
<template slot-scope="scope">
31-
<el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
31+
<el-tag :type="scope.row.status | articleStatusFilter">{{ scope.row.status }}</el-tag>
3232
</template>
3333
</el-table-column>
3434

@@ -63,18 +63,9 @@
6363
import {SUCCESS_STATUS} from '@/constant';
6464
6565
@Component({
66+
name: 'List',
6667
components: {
6768
Pagination
68-
},
69-
filters: {
70-
statusFilter(status) {
71-
const statusMap = {
72-
published: 'success',
73-
draft: 'info',
74-
deleted: 'danger'
75-
};
76-
return statusMap[status];
77-
}
7869
}
7970
})
8071
export default class List extends Vue {
@@ -128,4 +119,3 @@
128119
top: 10px;
129120
}
130121
</style>
131-

src/views/tab/components/tabPane.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
<el-table-column class-name="status-col" label="Status" width="110">
4747
<template slot-scope="scope">
48-
<el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
48+
<el-tag :type="scope.row.status | articleStatusFilter">{{ scope.row.status }}</el-tag>
4949
</template>
5050
</el-table-column>
5151

@@ -63,16 +63,7 @@
6363
}
6464
6565
@Component({
66-
filters: {
67-
statusFilter(status) {
68-
const statusMap = {
69-
published: 'success',
70-
draft: 'info',
71-
deleted: 'danger'
72-
};
73-
return statusMap[status];
74-
}
75-
}
66+
name: 'TabPane'
7667
})
7768
export default class TabPane extends Vue {
7869
@Prop({default: 'CN'}) type!: string;

src/views/table/complexTable.vue

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</el-table-column>
7777
<el-table-column :label="$t('table.status')" class-name="status-col" width="100">
7878
<template slot-scope="scope">
79-
<el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
79+
<el-tag :type="scope.row.status | articleStatusFilter">{{ scope.row.status }}</el-tag>
8080
</template>
8181
</el-table-column>
8282
<el-table-column :label="$t('table.actions')" align="center" width="230" class-name="small-padding fixed-width">
@@ -190,18 +190,11 @@
190190
}, {});
191191
192192
@Component({
193+
name: 'ComplexTable',
193194
components: {
194195
Pagination
195196
},
196197
filters: {
197-
statusFilter(status) {
198-
const statusMap = {
199-
published: 'success',
200-
draft: 'info',
201-
deleted: 'danger'
202-
};
203-
return statusMap[status];
204-
},
205198
typeFilter(type) {
206199
return calendarTypeKeyValue[type];
207200
}

src/views/table/dragTable.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
<el-table-column class-name="status-col" label="Status" width="110">
4343
<template slot-scope="scope">
44-
<el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
44+
<el-tag :type="scope.row.status | articleStatusFilter">{{ scope.row.status }}</el-tag>
4545
</template>
4646
</el-table-column>
4747

@@ -66,16 +66,7 @@ import Sortable from 'sortablejs';
6666
import {SUCCESS_STATUS} from '@/constant';
6767
6868
@Component({
69-
filters: {
70-
statusFilter(status) {
71-
const statusMap = {
72-
published: 'success',
73-
draft: 'info',
74-
deleted: 'danger'
75-
};
76-
return statusMap[status];
77-
}
78-
}
69+
name: 'DragTable'
7970
})
8071
export default class DragTable extends Vue {
8172
list: any[] = [];

src/views/table/inlineEditTable.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<el-table-column class-name="status-col" label="Status" width="110">
3131
<template slot-scope="scope">
32-
<el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
32+
<el-tag :type="scope.row.status | articleStatusFilter">{{ scope.row.status }}</el-tag>
3333
</template>
3434
</el-table-column>
3535

@@ -66,16 +66,7 @@
6666
import {SUCCESS_STATUS} from '@/constant';
6767
6868
@Component({
69-
filters: {
70-
statusFilter(status) {
71-
const statusMap = {
72-
published: 'success',
73-
draft: 'info',
74-
deleted: 'danger'
75-
};
76-
return statusMap[status];
77-
}
78-
}
69+
name: 'InlineEditTabele'
7970
})
8071
export default class InlineEditTable extends Vue {
8172
list: string[] | number[] = [];

0 commit comments

Comments
 (0)