Skip to content

Commit 7d1e091

Browse files
committed
feat: add advertisement switch
1 parent e0acfb2 commit 7d1e091

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

miniprogram/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"t-tabs": "tdesign-miniprogram/tabs/tabs",
2929
"t-tab-panel": "tdesign-miniprogram/tabs/tab-panel",
3030
"t-loading": "tdesign-miniprogram/loading/loading",
31+
"t-switch": "tdesign-miniprogram/switch/switch",
3132
"t-steps": "tdesign-miniprogram/steps/steps",
3233
"t-step": "tdesign-miniprogram/steps/step-item"
3334
}

miniprogram/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "HowToCookOnMiniprogram",
3+
"version": "0.2.1",
4+
"description": "",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"howtocook",
11+
"miniprogram",
12+
"wechat"
13+
],
14+
"author": "leejim",
15+
"license": "MIT",
16+
"dependencies": {
17+
"tdesign-miniprogram": "^0.6.1"
18+
}
19+
}

miniprogram/pages/detail/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Page({
1010
starred: false,
1111
done: false,
1212
stepIndexes: new Array(10).fill(0),
13+
adFlag: false,
1314
},
1415

1516
async onLoad(options) {
@@ -26,6 +27,14 @@ Page({
2627
}
2728
},
2829

30+
onShow() {
31+
const adFlagStorage = wx.getStorageSync('ad-flag')
32+
33+
this.setData({
34+
adFlag: adFlagStorage === '' ? true : adFlagStorage,
35+
})
36+
},
37+
2938
async getData() {
3039
const { id } = this.data;
3140

miniprogram/pages/detail/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</t-tab-panel>
4343
</t-tabs>
4444

45-
<ad-custom unit-id="adunit-376059436c4aaff9" style="margin-top: 32rpx"></ad-custom>
45+
<ad-custom wx:if="{{adFlag}}" unit-id="adunit-376059436c4aaff9" style="margin-top: 32rpx"></ad-custom>
4646

4747
<t-toast id="t-toast" />
4848
<view class="popup popup--top popup--{{startTimeout ? 'active' : 'normal'}}">

miniprogram/pages/my/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Page({
1212
value: 'my',
1313
icon: 'user'
1414
}],
15-
version: ''
15+
version: '',
16+
adFlag: true,
1617
},
1718

1819
onLoad() {
@@ -23,6 +24,14 @@ Page({
2324
})
2425
},
2526

27+
onShow() {
28+
const adFlagStorage = wx.getStorageSync('ad-flag')
29+
30+
this.setData({
31+
adFlag: adFlagStorage === '' ? true : adFlagStorage,
32+
})
33+
},
34+
2635
handleTabbarChange({ detail }) {
2736
const { value } = detail;
2837

@@ -61,6 +70,15 @@ Page({
6170
}
6271
})
6372
},
73+
74+
handleToggleAd({ detail }) {
75+
const adFlag = detail.value
76+
77+
wx.setStorageSync('ad-flag',adFlag)
78+
this.setData({
79+
adFlag
80+
})
81+
},
6482

6583
onShareAppMessage() {
6684
return {

miniprogram/pages/my/index.wxml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<t-cell title="订阅更新" hover arrow bind:click="handleSubscribe">
1515
<t-icon name="notification" slot="left-icon" />
1616
</t-cell>
17+
<t-cell title="广告开关">
18+
<t-icon name="money-circle" slot="left-icon" />
19+
<t-switch value="{{adFlag}}" bind:change="handleToggleAd" slot="note" />
20+
</t-cell>
1721
<t-cell title="收藏" hover arrow url="../myStarred/index">
1822
<t-icon name="control-platform" slot="left-icon" />
1923
</t-cell>

project.private.config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"setting": {},
23
"condition": {
34
"plugin": {
45
"list": []
@@ -15,6 +16,13 @@
1516
"name": "收藏页",
1617
"pathName": "pages/myStarred/index",
1718
"query": "",
19+
"launchMode": "default",
20+
"scene": null
21+
},
22+
{
23+
"name": "个人中心",
24+
"pathName": "pages/my/index",
25+
"query": "",
1826
"scene": null,
1927
"launchMode": "default"
2028
}

0 commit comments

Comments
 (0)