Skip to content

Commit 7959e46

Browse files
committed
feat: added options
1 parent 0f72adf commit 7959e46

File tree

4 files changed

+83
-15
lines changed

4 files changed

+83
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"es2015": "lib-esm/index.js",
1111
"repository": {
1212
"type": "git",
13-
"url": ""
13+
"url": "https://github.com/simplitech/vue-adap-table"
1414
},
1515
"license": "MIT",
1616
"engines": {

src/AdapOrderby.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const template = `
1414

1515
import { Component, Prop, Vue } from 'vue-property-decorator'
1616
import { PageCollection, IResource } from '@simpli/resource-collection'
17+
import AdapTableWrapper from './index'
1718

1819
@Component({ template })
1920
export class AdapOrderby extends Vue {
@@ -27,15 +28,29 @@ export class AdapOrderby extends Vue {
2728
label!: string
2829

2930
async orderBy() {
31+
const options = AdapTableWrapper.options
32+
3033
try {
3134
this.$emit('beforeQuery')
32-
PageCollection.defaultBeforeQueryAction()
35+
36+
if (options.defaultBeforeQueryAction) {
37+
options.defaultBeforeQueryAction()
38+
}
39+
3340
await this.collection.queryOrderBy(this.name)
41+
3442
this.$emit('afterQuery')
35-
PageCollection.defaultAfterQueryAction()
43+
44+
if (options.defaultAfterQueryAction) {
45+
options.defaultAfterQueryAction()
46+
}
3647
} catch (e) {
3748
this.$emit('errorQuery')
38-
PageCollection.defaultErrorQueryAction()
49+
50+
if (options.defaultErrorQueryAction) {
51+
options.defaultErrorQueryAction()
52+
}
53+
3954
throw e
4055
}
4156
}

src/AdapPagination.ts

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const template = `
3939

4040
import { Component, Prop, Vue } from 'vue-property-decorator'
4141
import { PageCollection, IResource } from '@simpli/resource-collection'
42+
import AdapTableWrapper from './index'
4243

4344
@Component({ template })
4445
export class AdapPagination extends Vue {
@@ -61,43 +62,85 @@ export class AdapPagination extends Vue {
6162
}
6263

6364
async goto(n: number) {
65+
const options = AdapTableWrapper.options
66+
6467
try {
6568
this.$emit('beforeGoto')
66-
PageCollection.defaultBeforeQueryAction()
69+
70+
if (options.defaultBeforeQueryAction) {
71+
options.defaultBeforeQueryAction()
72+
}
73+
6774
await this.collection.queryCurrentPage(n - 1)
75+
6876
this.$emit('afterGoto')
69-
PageCollection.defaultAfterQueryAction()
77+
78+
if (options.defaultAfterQueryAction) {
79+
options.defaultAfterQueryAction()
80+
}
7081
} catch (e) {
7182
this.$emit('errorGoto')
72-
PageCollection.defaultErrorQueryAction()
83+
84+
if (options.defaultErrorQueryAction) {
85+
options.defaultErrorQueryAction()
86+
}
87+
7388
throw e
7489
}
7590
}
7691

7792
async next() {
93+
const options = AdapTableWrapper.options
94+
7895
try {
7996
this.$emit('beforeNext')
80-
PageCollection.defaultBeforeQueryAction()
97+
98+
if (options.defaultBeforeQueryAction) {
99+
options.defaultBeforeQueryAction()
100+
}
101+
81102
await this.collection.queryNextPage()
103+
82104
this.$emit('afterNext')
83-
PageCollection.defaultAfterQueryAction()
105+
106+
if (options.defaultAfterQueryAction) {
107+
options.defaultAfterQueryAction()
108+
}
84109
} catch (e) {
85110
this.$emit('errorNext')
86-
PageCollection.defaultErrorQueryAction()
111+
112+
if (options.defaultErrorQueryAction) {
113+
options.defaultErrorQueryAction()
114+
}
115+
87116
throw e
88117
}
89118
}
90119

91120
async prev() {
121+
const options = AdapTableWrapper.options
122+
92123
try {
93124
this.$emit('beforePrev')
94-
PageCollection.defaultBeforeQueryAction()
125+
126+
if (options.defaultBeforeQueryAction) {
127+
options.defaultBeforeQueryAction()
128+
}
129+
95130
await this.collection.queryPrevPage()
131+
96132
this.$emit('afterPrev')
97-
PageCollection.defaultAfterQueryAction()
133+
134+
if (options.defaultAfterQueryAction) {
135+
options.defaultAfterQueryAction()
136+
}
98137
} catch (e) {
99138
this.$emit('errorPrev')
100-
PageCollection.defaultErrorQueryAction()
139+
140+
if (options.defaultErrorQueryAction) {
141+
options.defaultErrorQueryAction()
142+
}
143+
101144
throw e
102145
}
103146
}

src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import Vue from 'vue'
1+
import { Vue as _Vue } from 'vue/types/vue'
22
import { AdapOrderby } from './AdapOrderby'
33
import { AdapPagination } from './AdapPagination'
44
import { AdapSearchfield } from './AdapSearchfield'
55
import { MixinAdapRoute } from './MixinAdapRoute'
66

7+
export interface AdapTableOptions {
8+
defaultBeforeQueryAction?: () => void
9+
defaultAfterQueryAction?: () => void
10+
defaultErrorQueryAction?: () => void
11+
}
12+
713
export default class AdapTableWrapper {
8-
static install() {
14+
static options: AdapTableOptions = {}
15+
16+
static install(Vue: typeof _Vue, options?: AdapTableOptions) {
17+
this.options = options || {}
18+
919
Vue.component(AdapOrderby.name, AdapOrderby)
1020
Vue.component(AdapPagination.name, AdapPagination)
1121
Vue.component(AdapSearchfield.name, AdapSearchfield)

0 commit comments

Comments
 (0)