Skip to content

Commit 4cb7ef3

Browse files
Merge pull request #31 from TtTRz/dev
Add samples
2 parents d9a62db + 8f6d352 commit 4cb7ef3

File tree

798 files changed

+35624
-3474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

798 files changed

+35624
-3474
lines changed

cloudfunctions/getServerDataDemo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"dependencies": {
1212
"wx-server-sdk": "latest"
1313
}
14-
}
14+
}

cloudfunctions/getTempFileURL/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"dependencies": {
1212
"wx-server-sdk": "latest"
1313
}
14-
}
14+
}

cloudfunctions/wxContext/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"dependencies": {
1212
"wx-server-sdk": "latest"
1313
}
14-
}
14+
}

miniprogram/app-darkmode.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"window": {
3+
"navigationBarTextStyle": "white",
4+
"navigationBarBackgroundColor": "#191919",
5+
"backgroundColor": "#191919"
6+
},
7+
"tabBar": {
8+
"color": "#FCFCFC",
9+
"selectedColor": "#51A937",
10+
"borderStyle": "white",
11+
"backgroundColor": "#191919",
12+
"list": [
13+
{
14+
"pagePath": "page/component/index",
15+
"iconPath": "image/icon_component_HL.png",
16+
"selectedIconPath": "image/icon_component_dark.png",
17+
"text": "组件"
18+
},
19+
{
20+
"pagePath": "page/weui/example/index",
21+
"iconPath": "image/icon_component_HL.png",
22+
"selectedIconPath": "image/icon_component_dark.png",
23+
"text": "扩展能力"
24+
},
25+
{
26+
"pagePath": "page/API/index",
27+
"iconPath": "image/icon_API_HL.png",
28+
"selectedIconPath": "image/icon_API_dark.png",
29+
"text": "接口"
30+
},
31+
{
32+
"pagePath": "page/cloud/index",
33+
"iconPath": "image/icon_cloud_HL.png",
34+
"selectedIconPath": "image/icon_cloud_dark.png",
35+
"text": "云开发"
36+
}
37+
]
38+
}
39+
}

miniprogram/app.js

+62-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
const config = require('./config')
2-
2+
const themeListeners = []
33
global.isDemo = true
44
App({
5-
onLaunch(opts) {
5+
6+
onLaunch(opts, data) {
7+
const that = this;
8+
const canIUseSetBackgroundFetchToken = wx.canIUse('setBackgroundFetchToken')
9+
if (canIUseSetBackgroundFetchToken) {
10+
wx.setBackgroundFetchToken({
11+
token: 'getBackgroundFetchToken',
12+
})
13+
}
14+
if (wx.getBackgroundFetchData) {
15+
wx.getBackgroundFetchData({
16+
fetchType: 'pre',
17+
success(res) {
18+
that.globalData.backgroundFetchData = res;
19+
console.log('读取预拉取数据成功')
20+
},
21+
fail() {
22+
console.log('读取预拉取数据失败')
23+
wx.showToast({
24+
title: '无缓存数据',
25+
icon: 'none'
26+
})
27+
},
28+
complete() {
29+
console.log('结束读取')
30+
}
31+
})
32+
}
633
console.log('App Launch', opts)
34+
if (data && data.path) {
35+
wx.navigateTo({
36+
url: data.path,
37+
})
38+
}
739
if (!wx.cloud) {
840
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
941
} else {
@@ -13,15 +45,36 @@ App({
1345
})
1446
}
1547
},
48+
49+
1650
onShow(opts) {
1751
console.log('App Show', opts)
1852
},
1953
onHide() {
2054
console.log('App Hide')
2155
},
56+
onThemeChange({ theme }) {
57+
this.globalData.theme = theme
58+
themeListeners.forEach((listener) => {
59+
listener(theme)
60+
})
61+
},
62+
watchThemeChange(listener) {
63+
if (themeListeners.indexOf(listener) < 0) {
64+
themeListeners.push(listener)
65+
}
66+
},
67+
unWatchThemeChange(listener) {
68+
const index = themeListeners.indexOf(listener)
69+
if (index > -1) {
70+
themeListeners.splice(index, 1)
71+
}
72+
},
2273
globalData: {
74+
theme: wx.getSystemInfoSync().theme,
2375
hasLogin: false,
24-
openid: null
76+
openid: null,
77+
iconTabbar: '/page/weui/example/images/icon_tabbar.png',
2578
},
2679
// lazy loading openid
2780
getUserOpenId(callback) {
@@ -32,17 +85,17 @@ App({
3285
} else {
3386
wx.login({
3487
success(data) {
35-
wx.request({
36-
url: config.openIdUrl,
88+
wx.cloud.callFunction({
89+
name: 'login',
3790
data: {
38-
code: data.code
91+
action: 'openid'
3992
},
40-
success(res) {
93+
success: res => {
4194
console.log('拉取openid成功', res)
42-
self.globalData.openid = res.data.openid
95+
self.globalData.openid = res.result.openid
4396
callback(null, self.globalData.openid)
4497
},
45-
fail(res) {
98+
fail: err => {
4699
console.log('拉取用户openid失败,将无法正常使用开放接口等服务', res)
47100
callback(res)
48101
}

0 commit comments

Comments
 (0)