Skip to content

Commit d73f9c6

Browse files
committed
feat: add subscribe entry
1 parent af9db83 commit d73f9c6

File tree

7 files changed

+73
-33
lines changed

7 files changed

+73
-33
lines changed

miniprogram/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"t-button-group": "tdesign-miniprogram/button-group/button-group",
2626
"t-cell": "tdesign-miniprogram/cell/cell",
2727
"t-count-down": "tdesign-miniprogram/count-down/count-down",
28+
"t-dialog": "tdesign-miniprogram/dialog/dialog",
2829
"t-empty": "tdesign-miniprogram/empty/empty",
2930
"t-icon": "tdesign-miniprogram/icon/icon",
3031
"t-toast": "tdesign-miniprogram/toast/toast",

miniprogram/pages/index/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import infos from '../../data'
22
import utils from '../../utils/index.js'
33
import config from '../../config/index.js'
4+
import Toast from 'tdesign-miniprogram/toast/index';
5+
6+
let isSubscribeShow = false;
47

58
Page({
69
data: {
710
list: [],
811
value: 'index',
912
searchKeyword: '',
13+
subscribeModalVisible: false,
1014
tabbars: [{
1115
text: '首页',
1216
value: 'index',
@@ -43,6 +47,14 @@ Page({
4347
canIUseGetUserProfile: true
4448
})
4549
}
50+
51+
const { scene } = wx.getLaunchOptionsSync() // https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
52+
if (scene === 1107 && !isSubscribeShow) {
53+
this.setData({
54+
subscribeModalVisible: true
55+
})
56+
isSubscribeShow = true
57+
}
4658
},
4759

4860
handleTap(e) {
@@ -70,6 +82,24 @@ Page({
7082
})
7183
},
7284

85+
handleSubscribe() {
86+
const tmplIds = ['vjEDlUYrVJ05CauSw_V9jIWF-okt3OMCBtlz9yvjrfg', 'Sbtj4X4gIKWRy0xDeWU8xCl8LejbTpIQ3gWiKh5JFp4'];
87+
wx.requestSubscribeMessage({
88+
tmplIds,
89+
success: async (res) => {
90+
const accept = tmplIds.some(key => res[key] === 'accept')
91+
Toast({
92+
context: this,
93+
selector: '#t-toast',
94+
message: accept ? '订阅成功' : '你拒绝了订阅',
95+
});
96+
},
97+
complete: () => {
98+
this.setData({ subscribeModalVisible: false })
99+
}
100+
})
101+
},
102+
73103
onShareAppMessage() {
74104
return {
75105
title: '程序员做饭指南',

miniprogram/pages/index/index.wxml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@
2020
list="{{item.list}}" />
2121
</view>
2222

23+
<t-dialog
24+
visible="{{subscribeModalVisible}}"
25+
title="订阅新版本通知"
26+
content="第一时间接收【最新功能】的消息"
27+
confirm-btn="我知道了"
28+
bind:confirm="handleSubscribe"
29+
/>
30+
2331
<include src="/templates/tabbar.wxml" />
32+
<include src="/templates/base.wxml" />

miniprogram/pages/my/index.wxml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
<t-icon name="info-circle" slot="left-icon" />
3333
<view slot="note">{{version}}</view>
3434
</t-cell>
35-
36-
<t-toast id="t-toast" />
3735
</view>
3836

39-
<include src="/templates/tabbar.wxml" />
37+
<include src="/templates/tabbar.wxml" />
38+
<include src="/templates/base.wxml" />

miniprogram/templates/base.wxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<t-toast id="t-toast" />

project.config.json

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
2-
"description": "项目配置文件",
2+
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
33
"miniprogramRoot": "miniprogram/",
44
"cloudfunctionRoot": "cloudfunctions/",
55
"packOptions": {
66
"ignore": [
77
{
8-
"type": "folder",
9-
"value": "HowToCook"
8+
"value": "HowToCook",
9+
"type": "folder"
1010
},
1111
{
12-
"type": "folder",
13-
"value": "node_modules"
12+
"value": "node_modules",
13+
"type": "folder"
1414
}
15-
]
15+
],
16+
"include": []
1617
},
1718
"setting": {
1819
"urlCheck": true,
@@ -52,22 +53,14 @@
5253
"useCompilerPlugins": [
5354
"less"
5455
],
55-
"ignoreUploadUnusedFiles": true
56+
"ignoreUploadUnusedFiles": true,
57+
"useStaticServer": true
5658
},
5759
"compileType": "miniprogram",
5860
"libVersion": "2.22.1",
5961
"appid": "wx01462be634a0d447",
6062
"projectname": "HowToCookOnMiniprogram",
61-
"debugOptions": {
62-
"hidedInDevtools": []
63-
},
64-
"scripts": {},
65-
"staticServerOptions": {
66-
"baseURL": "",
67-
"servePath": ""
68-
},
69-
"isGameTourist": false,
70-
"cloudfunctionTemplateRoot": "cloudfunctionTemplate",
63+
"cloudfunctionTemplateRoot": "cloudfunctionTemplate/",
7164
"condition": {
7265
"search": {
7366
"list": []
@@ -87,5 +80,10 @@
8780
"miniprogram": {
8881
"list": []
8982
}
83+
},
84+
"srcMiniprogramRoot": "miniprogram/",
85+
"editorSetting": {
86+
"tabIndent": "insertSpaces",
87+
"tabSize": 2
9088
}
9189
}

project.private.config.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
2-
"setting": {},
2+
"setting": {
3+
"compileHotReLoad": true
4+
},
35
"condition": {
4-
"plugin": {
5-
"list": []
6-
},
7-
"game": {
8-
"list": []
9-
},
10-
"gamePlugin": {
11-
"list": []
12-
},
136
"miniprogram": {
147
"list": [
158
{
@@ -51,10 +44,19 @@
5144
"name": "search",
5245
"pathName": "pages/search/index",
5346
"query": "keyword=鸡蛋",
54-
"scene": null,
55-
"launchMode": "default"
47+
"launchMode": "default",
48+
"scene": null
49+
},
50+
{
51+
"name": "订阅",
52+
"pathName": "pages/index/index",
53+
"query": "from=subscribe",
54+
"launchMode": "default",
55+
"scene": 1107
5656
}
5757
]
5858
}
59-
}
59+
},
60+
"projectname": "HowToCookOnMiniprogram",
61+
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html"
6062
}

0 commit comments

Comments
 (0)