Skip to content

Commit cfcd3ca

Browse files
author
uniquexiaobai
committed
update showLoadingToast and onPullDownRefresh()
1 parent 933aa2b commit cfcd3ca

File tree

13 files changed

+189
-72
lines changed

13 files changed

+189
-72
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"files.associations": {"*.wxml":"html","*.wxss":"css"}
2+
"files.associations": {"editor":{"fontFamily":"Consolas, 'Courier New', monospace","fontWeight":"normal","fontSize":14,"lineHeight":20,"lineNumbers":"on","rulers":[],"wordSeparators":"`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?","tabSize":2,"insertSpaces":true,"detectIndentation":true,"roundedSelection":true,"scrollBeyondLastLine":true,"wrappingColumn":300,"wordWrap":false,"wrappingIndent":"same","mouseWheelScrollSensitivity":1,"quickSuggestions":true,"quickSuggestionsDelay":10,"parameterHints":true,"autoClosingBrackets":true,"formatOnType":false,"suggestOnTriggerCharacters":true,"acceptSuggestionOnEnter":true,"snippetSuggestions":"bottom","emptySelectionClipboard":true,"wordBasedSuggestions":true,"suggestFontSize":0,"suggestLineHeight":0,"tabCompletion":false,"selectionHighlight":true,"overviewRulerLanes":3,"cursorBlinking":"blink","mouseWheelZoom":false,"cursorStyle":"line","fontLigatures":false,"hideCursorInOverviewRuler":false,"renderWhitespace":"none","renderControlCharacters":false,"renderIndentGuides":true,"renderLineHighlight":true,"codeLens":true,"folding":true,"glyphMargin":true,"useTabStops":true,"trimAutoWhitespace":true,"stablePeek":false,"formatOnSave":false},"diffEditor":{"renderSideBySide":true,"ignoreTrimWhitespace":true},"emmet":{"triggerExpansionOnTab":true,"preferences":{},"syntaxProfiles":{},"excludeLanguages":[]},"workbench":{"editor":{"showTabs":true,"showIcons":true,"enablePreview":true,"enablePreviewFromQuickOpen":true,"openPositioning":"right"},"quickOpen":{"closeOnFocusLost":true},"settings":{"openDefaultSettings":true},"sideBar":{"location":"left"},"statusBar":{"visible":true}},"window":{"openFilesInNewWindow":true,"reopenFolders":"one","restoreFullscreen":false,"zoomLevel":0},"files":{"exclude":{"**/.git":true,"**/.svn":true,"**/.hg":true,"**/.DS_Store":true},"associations":{"*.wxml":"html","*.wxss":"css"},"encoding":"utf8","eol":"\r\n","trimTrailingWhitespace":false,"autoSave":"off","autoSaveDelay":1000,"watcherExclude":{"**/.git/objects/**":true}},"explorer":{"openEditors":{"visible":9,"dynamicHeight":true},"autoReveal":true,"enableDragAndDrop":true},"search":{"exclude":{"**/node_modules":true,"**/bower_components":true},"quickOpen":{"includeSymbols":false}},"git":{"enabled":true,"path":null,"autorefresh":true,"autofetch":true,"enableLongCommitWarning":true,"allowLargeRepositories":false,"confirmSync":true,"countBadge":"all"},"http":{"proxy":"","proxyStrictSSL":true,"proxyAuthorization":null},"css":{"validate":true,"lint":{"compatibleVendorPrefixes":"ignore","vendorPrefix":"warning","duplicateProperties":"ignore","emptyRules":"warning","importStatement":"ignore","boxModel":"ignore","universalSelector":"ignore","zeroUnits":"ignore","fontFaceProperties":"warning","hexColorLength":"error","argumentsInColorFunction":"error","unknownProperties":"warning","ieHack":"ignore","unknownVendorSpecificProperties":"ignore","propertyIgnoredDueToDisplay":"warning","important":"ignore","float":"ignore","idSelector":"ignore"}},"scss":{"validate":true,"lint":{"compatibleVendorPrefixes":"ignore","vendorPrefix":"warning","duplicateProperties":"ignore","emptyRules":"warning","importStatement":"ignore","boxModel":"ignore","universalSelector":"ignore","zeroUnits":"ignore","fontFaceProperties":"warning","hexColorLength":"error","argumentsInColorFunction":"error","unknownProperties":"warning","ieHack":"ignore","unknownVendorSpecificProperties":"ignore","propertyIgnoredDueToDisplay":"warning","important":"ignore","float":"ignore","idSelector":"ignore"}},"less":{"validate":true,"lint":{"compatibleVendorPrefixes":"ignore","vendorPrefix":"warning","duplicateProperties":"ignore","emptyRules":"warning","importStatement":"ignore","boxModel":"ignore","universalSelector":"ignore","zeroUnits":"ignore","fontFaceProperties":"warning","hexColorLength":"error","argumentsInColorFunction":"error","unknownProperties":"warning","ieHack":"ignore","unknownVendorSpecificProperties":"ignore","propertyIgnoredDueToDisplay":"warning","important":"ignore","float":"ignore","idSelector":"ignore"}},"debug":{"allowBreakpointsEverywhere":false,"openExplorerOnEnd":false},"html":{"format":{"enable":true,"wrapLineLength":120,"unformatted":"a, abbr, acronym, b, bdo, big, br, button, cite, code, dfn, em, i, img, input, kbd, label, map, object, q, samp, script, select, small, span, strong, sub, sup, textarea, tt, var","indentInnerHtml":false,"preserveNewLines":true,"maxPreserveNewLines":null,"indentHandlebars":false,"endWithNewline":false,"extraLiners":"head, body, /html"},"suggest":{"angular1":true,"ionic":true,"html5":true}},"json":{"schemas":[],"format":{"enable":true}},"markdown":{"styles":[]},"php":{"validate":{"enable":true,"executablePath":null,"run":"onSave"}},"typescript":{"tsdk":"C:\\Users\\uniqu\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib","check":{"workspaceVersion":true,"tscVersion":false},"tsserver":{"trace":"off"},"useCodeSnippetsOnMethodSuggest":false,"validate":{"enable":true},"format":{"enable":true,"insertSpaceAfterCommaDelimiter":true,"insertSpaceAfterSemicolonInForStatements":true,"insertSpaceBeforeAndAfterBinaryOperators":true,"insertSpaceAfterKeywordsInControlFlowStatements":true,"insertSpaceAfterFunctionKeywordForAnonymousFunctions":true,"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis":false,"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets":false,"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces":false,"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces":false,"placeOpenBraceOnNewLineForFunctions":false,"placeOpenBraceOnNewLineForControlBlocks":false}},"javascript":{"validate":{"enable":true},"format":{"enable":true,"insertSpaceAfterCommaDelimiter":true,"insertSpaceAfterSemicolonInForStatements":true,"insertSpaceBeforeAndAfterBinaryOperators":true,"insertSpaceAfterKeywordsInControlFlowStatements":true,"insertSpaceAfterFunctionKeywordForAnonymousFunctions":true,"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis":false,"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets":false,"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces":false,"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces":false,"placeOpenBraceOnNewLineForFunctions":false,"placeOpenBraceOnNewLineForControlBlocks":false}},"extensions":{"autoUpdate":false},"terminal":{"integrated":{"shell":{"linux":"sh","osx":"sh","windows":"C:\\WINDOWS\\system32\\cmd.exe"},"shellArgs":{"linux":[],"osx":[],"windows":[]},"fontFamily":"","fontLigatures":false,"fontSize":0,"lineHeight":1.2,"cursorBlinking":false,"setLocaleVariables":false,"commandsToSkipShell":["editor.action.toggleTabFocusMode","workbench.action.debug.continue","workbench.action.debug.restart","workbench.action.debug.run","workbench.action.debug.start","workbench.action.debug.stop","workbench.action.quickOpen","workbench.action.showCommands","workbench.action.terminal.clear","workbench.action.terminal.copySelection","workbench.action.terminal.focus","workbench.action.terminal.focusNext","workbench.action.terminal.focusPrevious","workbench.action.terminal.kill","workbench.action.terminal.new","workbench.action.terminal.paste","workbench.action.terminal.runSelectedText","workbench.action.terminal.scrollDown","workbench.action.terminal.scrollDownPage","workbench.action.terminal.scrollToBottom","workbench.action.terminal.scrollToTop","workbench.action.terminal.scrollUp","workbench.action.terminal.scrollUpPage","workbench.action.terminal.toggleTerminal"]},"external":{"windowsExec":"%COMSPEC%","osxExec":"Terminal.app","linuxExec":"xterm"}},"problems":{"autoReveal":true},"telemetry":{"enableTelemetry":true,"enableCrashReporter":true},"eslint":{"enable":true,"nodePath":null,"_legacyModuleResolve":false,"options":{},"trace":{"server":"off"},"run":"onType","autoFixOnSave":false},"react":{"beautify":{"onSave":false,"formatter":"prettydiff","configFilePath":".jsbeautifyrc"}},"color-highlight":{"enable":true,"languages":["javascript","scss","css","sass","less","php","xml","html","json"],"matchWords":true,"markerType":"background"},"csscomb":{"preset":{},"ignoreFilesOnSave":[],"supportEmbeddedStyles":true,"formatOnSave":false,"useLatestCore":false},"autoprefixer":{"findExternalAutoprefixer":false,"browsers":["last 2 versions","> 5%"],"formatOnSave":false},"path-autocomplete":{"extensionOnImport":false},"beautify":{"onSave":false,"onSaveIgnore":["**/*+(.|_|-)min.*"],"language":{"js":{"type":["javascript","json"],"filename":[".jshintrc",".jsbeautify"]},"css":["css","scss"],"html":["htm","html"]}},"*.wxml":"html","*.wxss":"css"}
33
}

app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"backgroundTextStyle": "light",
1515
"navigationBarTitleText": "wx-github-feed",
1616
"navigationBarTextStyle": "white",
17-
"navigationBarBackgroundColor": "#4078C0"
17+
"navigationBarBackgroundColor": "#4078C0",
18+
"enablePullDownRefresh": true
1819
},
1920

2021
"tabBar": {

pages/explore/explore.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ Page({
66
languageArray: ['All Languages', 'C', 'CSS', 'Go', 'HTML', 'Java', 'JavaScript', 'Lua', 'Objective-C', 'Perl', 'PHP', 'Python', 'R', 'Ruby', 'Scala', 'Shell', 'Swift'],
77
languageIndex: 0,
88
tabArray: ['Daily', 'Weekly', 'Monthly'],
9-
tabIndex: 0,
10-
loading_hidden: true
9+
tabIndex: 0
1110
},
1211

1312
onLoad() {
1413
this.refreshData();
1514
},
1615

17-
_reloadUrl() {
16+
onPullDownRefresh() {
17+
this.refreshData();
18+
},
19+
20+
_reloadUrl() {
1821
const basic_url = 'http://trending.codehub-app.com/v2/trending?since=';
1922

2023
// locationIndex may be 0 or '0'
@@ -24,39 +27,47 @@ Page({
2427
return `${basic_url}${this.data.tabArray[this.data.tabIndex].toLowerCase()}&language=${this.data.languageArray[this.data.languageIndex].toLowerCase()}`;
2528
},
2629

30+
handleLanguagePickerChange(e) {
31+
this.showLoadingToast();
32+
this.setData({
33+
languageIndex: e.detail.value
34+
});
35+
this.fetchReposData(this._reloadUrl());
36+
},
37+
38+
handleTabPickerChange(e) {
39+
this.showLoadingToast();
40+
this.setData({
41+
tabIndex: e.detail.value
42+
});
43+
this.fetchReposData(this._reloadUrl());
44+
},
45+
2746
fetchReposData(url) {
2847
services.fetch(url).then(res => {
2948
if (res.data) {
3049
this.setData({
3150
items: res.data
3251
});
3352
}
34-
this.setData({
35-
loading_hidden: true
36-
});
53+
this.hideLoadingToast();
3754
});
3855
},
3956

40-
handleLanguagePickerChange(e) {
41-
this.setData({
42-
languageIndex: e.detail.value,
43-
loading_hidden: false
44-
});
57+
refreshData() {
58+
this.showLoadingToast();
4559
this.fetchReposData(this._reloadUrl());
4660
},
4761

48-
handleTabPickerChange(e) {
49-
this.setData({
50-
tabIndex: e.detail.value,
51-
loading_hidden: false
62+
showLoadingToast() {
63+
wx.showToast({
64+
title: '玩命加载中...',
65+
icon: 'loading',
66+
duration: 10000
5267
});
53-
this.fetchReposData(this._reloadUrl());
5468
},
5569

56-
refreshData() {
57-
this.setData({
58-
loading_hidden: false
59-
});
60-
this.fetchReposData(this._reloadUrl());
70+
hideLoadingToast() {
71+
wx.hideToast();
6172
}
6273
});

pages/explore/explore.wxml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<view class="container">
2-
<loading hidden="{{loading_hidden}}">
3-
玩命加载中...
4-
</loading>
52
<view class="col explore">
63
<view class="col pickers">
74
<picker bindchange="handleLanguagePickerChange" mode="selector" value="{{languageIndex}}" range="{{languageArray}}">
@@ -15,7 +12,7 @@
1512
</view>
1613
</picker>
1714
</view>
18-
<scroll-view scroll-y="true" bindscrolltoupper="refreshData">
15+
<scroll-view scroll-y="true">
1916
<block wx:for="{{items}}" wx:key="explore">
2017
<navigator url="../repo/repo?repo_full_name={{item.full_name}}">
2118
<view class="row repo_item">

pages/famous/famous.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Page({
77
locationIndex: 2,
88
languageArray: ['All Languages', 'ActionScript', 'C', 'C#', 'C++', 'Clojure', 'CoffeeScript', 'CSS', 'Go', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Lua', 'Matlab', 'Objective-C', 'Objective-C++', 'Perl', 'PHP', 'Python', 'R', 'Ruby', 'Scala', 'Shell', 'Swift', 'TeX', 'VimL'],
99
languageIndex: 0,
10-
loading_hidden: true,
1110
items: [],
1211
page: 1,
1312
incomplete_results: false
@@ -17,6 +16,10 @@ Page({
1716
this.refreshData();
1817
},
1918

19+
onPullDownRefresh() {
20+
this.refreshData();
21+
},
22+
2023
_reloadUrl() {
2124
const basic_url = 'https://api.github.com/search/users?q=';
2225

@@ -47,17 +50,15 @@ Page({
4750
incomplete_results: res.data.incomplete_results
4851
});
4952
}
50-
this.setData({
51-
loading_hidden: true
52-
});
53+
this.hideLoadingToast();
5354
});
5455
},
5556

5657
handleLocationPickerChange(e) {
5758
if (this.data.languageIndex || e.detail.value) {
59+
this.showLoadingToast();
5860
this.setData({
59-
locationIndex: e.detail.value,
60-
loading_hidden: false
61+
locationIndex: e.detail.value
6162
});
6263
this._initData();
6364
this.fetchUsersData(this._reloadUrl());
@@ -66,9 +67,9 @@ Page({
6667

6768
handleLanguagePickerChange(e) {
6869
if (this.data.locationIndex || e.detail.value) {
70+
this.showLoadingToast();
6971
this.setData({
70-
languageIndex: e.detail.value,
71-
loading_hidden: false
72+
languageIndex: e.detail.value
7273
});
7374
this._initData();
7475
this.fetchUsersData(this._reloadUrl());
@@ -77,18 +78,28 @@ Page({
7778

7879
loadMoreData() {
7980
if (this.data.incomplete_results) return;
81+
this.showLoadingToast();
8082
this.setData({
81-
loading_hidden: false,
8283
page: ++this.data.page
8384
});
8485
this.fetchUsersData(this._reloadUrl());
8586
},
8687

8788
refreshData() {
88-
this.setData({
89-
loading_hidden: false
90-
});
89+
this.showLoadingToast();
9190
this._initData();
9291
this.fetchUsersData(this._reloadUrl());
92+
},
93+
94+
showLoadingToast() {
95+
wx.showToast({
96+
title: '玩命加载中...',
97+
icon: 'loading',
98+
duration: 10000
99+
});
100+
},
101+
102+
hideLoadingToast() {
103+
wx.hideToast();
93104
}
94105
});

pages/famous/famous.wxml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<view class="container">
2-
<loading hidden="{{loading_hidden}}">
3-
玩命加载中...
4-
</loading>
52
<view class="col famous">
63
<view class="col pickers">
74
<picker bindchange="handleLocationPickerChange" value="{{locationIndex}}" range="{{locationArray}}">
@@ -15,7 +12,7 @@
1512
</view>
1613
</picker>
1714
</view>
18-
<scroll-view scroll-y="true" bindscrolltolower="loadMoreData" bindscrolltoupper="refreshData">
15+
<scroll-view scroll-y="true" bindscrolltolower="loadMoreData">
1916
<block wx:for="{{items}}" wx:key="famous">
2017
<navigator url="../user/user?user_name={{item.login}}">
2118
<view class="row user_item">

pages/index/index.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import helpers from '../helpers/index';
55

66
Page({
77
data: {
8-
loading_hidden: true,
98
items: [],
109
page: 1
1110
},
1211

1312
onLoad() {
1413
const user = wx.getStorageSync('user');
1514

16-
console.log(user);
15+
console.log('#user#', user);
1716
if (!user) {
1817
wx.navigateTo({
1918
url: '../auth/onboard/onboard'
@@ -22,6 +21,10 @@ Page({
2221
this.refreshData();
2322
},
2423

24+
onPullDownRefresh() {
25+
this.refreshData();
26+
},
27+
2528
_reloadUrl() {
2629
const basic_url = 'https://api.github.com/users/uniquexiaobai/received_events?page=';
2730

@@ -42,25 +45,35 @@ Page({
4245
item.created_at = util.timesAgo(item.created_at);
4346
});
4447
this.setData({
45-
items: this.data.items.concat(res.data),
46-
loading_hidden: true
48+
items: this.data.items.concat(res.data)
4749
});
50+
this.hideLoadingToast();
4851
});
4952
},
5053

5154
loadMoreData() {
55+
this.showLoadingToast();
5256
this.setData({
53-
page: ++this.data.page,
54-
loading_hidden: false
57+
page: ++this.data.page
5558
});
5659
this.fetchEventsData(this._reloadUrl());
5760
},
5861

5962
refreshData() {
60-
this.setData({
61-
loading_hidden: false
62-
});
63+
this.showLoadingToast();
6364
this._initData();
6465
this.fetchEventsData(this._reloadUrl());
66+
},
67+
68+
showLoadingToast() {
69+
wx.showToast({
70+
title: '玩命加载中...',
71+
icon: 'loading',
72+
duration: 10000
73+
});
74+
},
75+
76+
hideLoadingToast() {
77+
wx.hideToast();
6578
}
6679
});

pages/index/index.wxml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<view class="container">
2-
<loading hidden="{{loading_hidden}}">
3-
玩命加载中...
4-
</loading>
5-
<scroll-view scroll-y="true" bindscrolltolower="loadMoreData" bindscrolltoupper="refreshData">
2+
<scroll-view scroll-y="true" bindscrolltolower="loadMoreData">
63
<block wx:for="{{items}}" wx:key="received_events">
74
<navigator url="../repo/repo?repo_full_name={{item.repo.name}}">
85
<view class="col received_events">

pages/repo/repo.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import services from '../../utils/services';
22

33
Page({
4-
data: {
5-
loading_hidden: true
6-
},
7-
84
onLoad(options) {
5+
this.showLoadingToast();
96
this.setData({
10-
repo_full_name: options.repo_full_name,
11-
loading_hidden: false
7+
repo_full_name: options.repo_full_name
128
});
139
this.fetchRepoData(this._reloadUrl());
1410
},
1511

12+
onReady() {
13+
wx.setNavigationBarTitle({
14+
title: this.data.repo_full_name
15+
});
16+
},
17+
1618
_reloadUrl() {
1719
const basic_url = 'https://api.github.com/repos/';
1820

@@ -22,15 +24,21 @@ Page({
2224
fetchRepoData(url) {
2325
services.fetch(url).then(res => {
2426
this.setData({
25-
repo: res.data,
26-
loading_hidden: true
27+
repo: res.data
2728
});
29+
this.hideLoadingToast();
2830
});
2931
},
3032

31-
onReady() {
32-
wx.setNavigationBarTitle({
33-
title: this.data.repo_full_name
33+
showLoadingToast() {
34+
wx.showToast({
35+
title: '玩命加载中...',
36+
icon: 'loading',
37+
duration: 10000
3438
});
39+
},
40+
41+
hideLoadingToast() {
42+
wx.hideToast();
3543
}
3644
});

pages/repo/repo.wxml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<view class="container col">
2-
<loading hidden="{{loading_hidden}}">
3-
玩命加载中...
4-
</loading>
52
<view class="repo">
63
<view class="row repo_header">
74
<view class="row align_center repo_top_item">

0 commit comments

Comments
 (0)