|
26 | 26 | </template> |
27 | 27 |
|
28 | 28 | <script type="text/babel"> |
29 | | - import {extend, throttle, throttleRunDelay} from './utils'; |
| 29 | + import {throttle, throttleRunDelay} from './utils'; |
30 | 30 | import {TOP_DEFAULT_CONFIG, BOTTOM_DEFAULT_CONFIG} from './config'; |
31 | 31 |
|
32 | 32 | export default { |
|
57 | 57 | topConfig: { |
58 | 58 | type: Object, |
59 | 59 | default: () => { |
60 | | - return TOP_DEFAULT_CONFIG; |
61 | | - }, |
62 | | - validator: (config) => { |
63 | | - extend(config, TOP_DEFAULT_CONFIG); |
64 | | - return config; |
| 60 | + return {}; |
65 | 61 | } |
66 | 62 | }, |
67 | 63 | bottomConfig: { |
68 | 64 | type: Object, |
69 | 65 | default: () => { |
70 | | - return BOTTOM_DEFAULT_CONFIG; |
71 | | - }, |
72 | | - validator: (config) => { |
73 | | - extend(config, BOTTOM_DEFAULT_CONFIG); |
74 | | - return config; |
| 66 | + return {}; |
75 | 67 | } |
76 | 68 | } |
77 | 69 | }, |
|
91 | 83 | bottomReached: false |
92 | 84 | }; |
93 | 85 | }, |
| 86 | + computed: { |
| 87 | + _topConfig: function () { |
| 88 | + return Object.assign(TOP_DEFAULT_CONFIG, this.topConfig); |
| 89 | + }, |
| 90 | + _bottomConfig: function () { |
| 91 | + return Object.assign(BOTTOM_DEFAULT_CONFIG, this.bottomConfig); |
| 92 | + } |
| 93 | + }, |
94 | 94 | watch: { |
95 | 95 | state(val) { |
96 | 96 | if (this.direction === 'down') { |
|
104 | 104 | actionPull() { |
105 | 105 | this.state = 'pull'; |
106 | 106 | this.direction === 'down' |
107 | | - ? this.topText = this.topConfig.pullText |
108 | | - : this.bottomText = this.bottomConfig.pullText; |
| 107 | + ? this.topText = this._topConfig.pullText |
| 108 | + : this.bottomText = this._bottomConfig.pullText; |
109 | 109 | }, |
110 | 110 | actionTrigger() { |
111 | 111 | this.state = 'trigger'; |
112 | 112 | this.direction === 'down' |
113 | | - ? this.topText = this.topConfig.triggerText |
114 | | - : this.bottomText = this.bottomConfig.triggerText; |
| 113 | + ? this.topText = this._topConfig.triggerText |
| 114 | + : this.bottomText = this._bottomConfig.triggerText; |
115 | 115 | }, |
116 | 116 | actionLoading() { |
117 | 117 | this.state = 'loading'; |
118 | 118 | if (this.direction === 'down') { |
119 | | - this.topText = this.topConfig.loadingText; |
| 119 | + this.topText = this._topConfig.loadingText; |
120 | 120 | /* eslint-disable no-useless-call */ |
121 | 121 | this.topLoadMethod.call(this, this.actionLoaded); |
122 | | - this.scrollTo(this.topConfig.stayDistance); |
| 122 | + this.scrollTo(this._topConfig.stayDistance); |
123 | 123 | } else { |
124 | | - this.bottomText = this.bottomConfig.loadingText; |
| 124 | + this.bottomText = this._bottomConfig.loadingText; |
125 | 125 | this.bottomLoadMethod.call(this, this.actionLoaded); |
126 | | - this.scrollTo(-this.bottomConfig.stayDistance); |
| 126 | + this.scrollTo(-this._bottomConfig.stayDistance); |
127 | 127 | } |
128 | 128 | }, |
129 | 129 | actionLoaded(loadState = 'done') { |
130 | 130 | this.state = `loaded-${loadState}`; |
131 | 131 | let loadedStayTime; |
132 | 132 | if (this.direction === 'down') { |
133 | 133 | this.topText = loadState === 'done' |
134 | | - ? this.topConfig.doneText |
135 | | - : this.topConfig.failText; |
136 | | - loadedStayTime = this.topConfig.loadedStayTime; |
| 134 | + ? this._topConfig.doneText |
| 135 | + : this._topConfig.failText; |
| 136 | + loadedStayTime = this._topConfig.loadedStayTime; |
137 | 137 | } else { |
138 | 138 | this.bottomText = loadState === 'done' |
139 | | - ? this.bottomConfig.doneText |
140 | | - : this.bottomConfig.failText; |
141 | | - loadedStayTime = this.bottomConfig.loadedStayTime; |
| 139 | + ? this._bottomConfig.doneText |
| 140 | + : this._bottomConfig.failText; |
| 141 | + loadedStayTime = this._bottomConfig.loadedStayTime; |
142 | 142 | } |
143 | 143 | setTimeout(() => { |
144 | 144 | this.scrollTo(0); |
|
184 | 184 |
|
185 | 185 | if (typeof this.topLoadMethod !== 'function') return; |
186 | 186 |
|
187 | | - if (this.distance < this.topConfig.triggerDistance && |
| 187 | + if (this.distance < this._topConfig.triggerDistance && |
188 | 188 | this.state !== 'pull' && this.state !== 'loading') { |
189 | 189 | this.actionPull(); |
190 | | - } else if (this.distance >= this.topConfig.triggerDistance && |
| 190 | + } else if (this.distance >= this._topConfig.triggerDistance && |
191 | 191 | this.state !== 'trigger' && this.state !== 'loading') { |
192 | 192 | this.actionTrigger(); |
193 | 193 | } |
|
199 | 199 |
|
200 | 200 | if (typeof this.bottomLoadMethod !== 'function') return; |
201 | 201 |
|
202 | | - if (Math.abs(this.distance) < this.bottomConfig.triggerDistance && |
| 202 | + if (Math.abs(this.distance) < this._bottomConfig.triggerDistance && |
203 | 203 | this.state !== 'pull' && this.state !== 'loading') { |
204 | 204 | this.actionPull(); |
205 | | - } else if (Math.abs(this.distance) >= this.bottomConfig.triggerDistance && |
| 205 | + } else if (Math.abs(this.distance) >= this._bottomConfig.triggerDistance && |
206 | 206 | this.state !== 'trigger' && this.state !== 'loading') { |
207 | 207 | this.actionTrigger(); |
208 | 208 | } |
|
0 commit comments