Skip to content

Commit 5e73535

Browse files
author
sanfordsun
committed
feat: material
1 parent 026abe2 commit 5e73535

File tree

11 files changed

+657
-2
lines changed

11 files changed

+657
-2
lines changed

miniprogram/app.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@
190190
"pages/ai/mobilenet/index",
191191
"pages/ai/style-trans/index",
192192
"pages/ai/mobilenet_int8/index",
193-
"pages/chattool/activity_assist/activity_assist"
193+
"pages/chattool/activity_assist/activity_assist",
194+
"pages/chattool/material_open/material_open",
195+
"pages/chattool/material_view/material_view"
194196
]
195197
},
196198
{
@@ -507,5 +509,21 @@
507509
},
508510
"renderer": "skyline",
509511
"componentFramework": "glass-easel",
510-
"appBar": {}
512+
"appBar": {},
513+
"supportedMaterials": [
514+
{
515+
"materialType": "image/*",
516+
"name": "用${nickname}打开",
517+
"desc": "聊天内容长按打开",
518+
"path": "pages/chattool/material_open/material_open"
519+
}
520+
],
521+
"multiSelectSupportedMaterials": [
522+
{
523+
"materialType": ["image/*", "text/message"],
524+
"desc": "聊天内容长按多选打开",
525+
"path": "pages/chattool/material_open/material_open",
526+
"scopes": []
527+
}
528+
]
511529
}
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
import { getGroupEnterInfo } from '../util'
2+
3+
let needShowEntrance = true
4+
let entrancePath = 'pages/chattool/material_open/material_open'
5+
let templateId = '4A68CBB88A92B0A9311848DBA1E94A199B166463' // 完成
6+
// let templateId = '2A84254B945674A2F88CE4970782C402795EB607' // 参与
7+
8+
const fileUrl = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'
9+
const videoUrl = 'https://res.wx.qq.com/op_res/o3RWIC_o--wNf_qA3B4ghHbL_qKRRwsUM39dGTzltCR2__61DnEANInj5AJJmVXsHvx9FyHlDftU3KhcGCukDA'
10+
11+
Page({
12+
data: {
13+
members: [],
14+
needShowEntrance,
15+
entrancePath,
16+
shareText: `「团建目的地选择」统计结果:
17+
- 清远 5 票
18+
- 南沙 3 票
19+
- 惠州 2 票`,
20+
isTemplateComplete: true
21+
},
22+
23+
onUnload() {
24+
if (wx.offThemeChange) {
25+
wx.offThemeChange()
26+
}
27+
},
28+
29+
onLoad(options) {
30+
this._activityId = options.activityId
31+
32+
wx.cloud.init({
33+
// env 参数说明:
34+
// env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
35+
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
36+
// 如不填则使用默认环境(第一个创建的环境)
37+
env: "test-f0b102",
38+
traceUser: true,
39+
});
40+
41+
this.setData({
42+
theme: wx.getSystemInfoSync().theme || 'light'
43+
})
44+
45+
if (wx.onThemeChange) {
46+
wx.onThemeChange(({ theme }) => {
47+
this.setData({ theme })
48+
})
49+
}
50+
},
51+
52+
async signIn() {
53+
const activityId = this._activityId
54+
if (!activityId) {
55+
wx.showToast({
56+
title: '需从动态消息卡片',
57+
icon: 'none'
58+
})
59+
return
60+
}
61+
62+
await getGroupEnterInfo()
63+
.then(groupInfo => {
64+
const {groupOpenID} = groupInfo
65+
this.updateChatToolMsg(activityId, {
66+
targetState: 1,
67+
parameterList: [{
68+
groupOpenID,
69+
state: 1,
70+
}]
71+
})
72+
wx.showToast({
73+
title: '签到成功',
74+
icon: 'none'
75+
})
76+
}).catch(err => {
77+
console.error('getGroupEnterInfo fail: ', err)
78+
})
79+
},
80+
81+
remindExpiration() {
82+
const activityId = this._activityId
83+
if (!activityId) {
84+
wx.showToast({
85+
title: '需从动态消息卡片',
86+
icon: 'none'
87+
})
88+
return
89+
}
90+
this.updateChatToolMsg(activityId, {
91+
targetState: 2,
92+
})
93+
wx.showToast({
94+
title: '已触发',
95+
icon: 'none'
96+
})
97+
},
98+
99+
earlyTerminate() {
100+
const activityId = this._activityId
101+
if (!activityId) {
102+
wx.showToast({
103+
title: '需从动态消息卡片',
104+
icon: 'none'
105+
})
106+
return
107+
}
108+
this.updateChatToolMsg(activityId, {
109+
targetState: 3,
110+
})
111+
wx.showToast({
112+
title: '已触发',
113+
icon: 'none'
114+
})
115+
},
116+
117+
updateChatToolMsg(activityId, params = {}) {
118+
const {targetState, parameterList } = params
119+
wx.cloud.callFunction({
120+
name: 'openapi',
121+
data: {
122+
action: 'updateChatToolMsg',
123+
activityId,
124+
templateId,
125+
targetState: targetState || 1,
126+
parameterList: parameterList || [],
127+
versionType: 1
128+
}
129+
}).then(resp => {
130+
console.info('updateChatToolMsg: ', resp)
131+
}).catch(err => {
132+
console.info('updateChatToolMsg Fail: ', err)
133+
})
134+
},
135+
136+
viewChatMaterials() {
137+
wx.navigateTo({
138+
url: '../material_view/material_view',
139+
})
140+
},
141+
142+
changeNeedShowEntrance() {
143+
needShowEntrance = !needShowEntrance
144+
this.setData({
145+
needShowEntrance
146+
})
147+
},
148+
149+
shareUpdatableMessage() {
150+
wx.cloud.callFunction({
151+
name: 'openapi',
152+
data: {
153+
action: 'createActivityId',
154+
}
155+
}).then(resp => {
156+
const activityId = resp.result.activityId
157+
wx.updateShareMenu({
158+
withShareTicket: true,
159+
isUpdatableMessage: true,
160+
useForChatTool: true,
161+
chooseType: 2,
162+
activityId,
163+
templateInfo: {
164+
templateId,
165+
},
166+
success(res) {
167+
wx.shareAppMessageToGroup({
168+
title: '动态消息卡片',
169+
path: `${entrancePath}?activityId=${activityId}`,
170+
complete(res) {
171+
console.info('shareAppMessageToGroup: ', res)
172+
}
173+
})
174+
},
175+
complete(res) {
176+
console.info('updateShareMenu: ', res)
177+
}
178+
})
179+
})
180+
},
181+
182+
shareImage() {
183+
wx.downloadFile({
184+
url: 'https://res.wx.qq.com/wxdoc/dist/assets/img/demo.ef5c5bef.jpg',
185+
success: (res) => {
186+
wx.shareImageToGroup({
187+
imagePath: res.tempFilePath, // 本地路径或临时路径
188+
needShowEntrance,
189+
entrancePath,
190+
complete(res) {
191+
console.info('shareImageToGroup: ', res)
192+
}
193+
})
194+
}
195+
})
196+
},
197+
198+
shareEmoji() {
199+
wx.downloadFile({
200+
url: 'https://mmbiz.qpic.cn/mmbiz_gif/EXAZAY4U1KCcdEB1gicNwIL4lUrpVQ5H5jOSfiaVHJ5n4EQyPrLqgRtbb6X1hRIiaZqMIibVME51FYRf7p2kC4OdLA/0/132',
201+
success: (res) => {
202+
wx.shareEmojiToGroup({
203+
imagePath: res.tempFilePath, // 本地路径或临时路径
204+
needShowEntrance,
205+
entrancePath,
206+
complete(res) {
207+
console.info('shareEmojiToGroup: ', res)
208+
}
209+
})
210+
}
211+
})
212+
},
213+
214+
shareVideo() {
215+
wx.downloadFile({
216+
url: videoUrl,
217+
success (res) {
218+
wx.shareVideoToGroup({
219+
videoPath: res.tempFilePath,
220+
thumbPath: '',
221+
needShowEntrance,
222+
entrancePath,
223+
complete(res) {
224+
console.info('shareVideoToGroup: ', res)
225+
}
226+
})
227+
},
228+
fail: console.error,
229+
})
230+
},
231+
232+
shareFile() {
233+
wx.downloadFile({
234+
url: fileUrl,
235+
success (res) {
236+
wx.shareFileToGroup({
237+
filePath: res.tempFilePath,
238+
fileName: '',
239+
needShowEntrance,
240+
entrancePath,
241+
complete(res) {
242+
console.info('shareFileToGroup: ', res)
243+
}
244+
})
245+
},
246+
fail: console.error,
247+
})
248+
},
249+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"navigationBarTitleText": "聊天工具",
3+
"renderer": "webview",
4+
"componentFramework": "glass-easel",
5+
"usingComponents": {
6+
"t-collapse": "../../../components/tdesign-miniprogram/collapse/collapse",
7+
"t-collapse-panel": "../../../components/tdesign-miniprogram/collapse-panel/collapse-panel",
8+
"t-cell": "../../../components/tdesign-miniprogram/cell/cell",
9+
"t-cell-group": "../../../components/tdesign-miniprogram/cell-group/cell-group",
10+
"t-icon": "../../../components/tdesign-miniprogram/icon/icon"
11+
}
12+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**app.wxss**/
2+
page {
3+
background: rgb(237, 237, 237);
4+
height: 100vh;
5+
--td-navbar-bg-color: rgb(237, 237, 237);
6+
}
7+
8+
.center {
9+
display: flex;
10+
align-items: center;
11+
justify-content: center;
12+
}
13+
14+
.page-container {
15+
height: 100%;
16+
width: 100%;
17+
box-sizing: border-box;
18+
}
19+
20+
.container {
21+
display: flex;
22+
flex-direction: column;
23+
align-items: center;
24+
box-sizing: border-box;
25+
padding: 0 24rpx;
26+
}
27+
28+
.form-textarea {
29+
box-sizing: border-box;
30+
width: 100%;
31+
padding: 20px;
32+
background-color: rgb(233, 233, 182);
33+
border-radius: 10px;
34+
}
35+
36+
.btn {
37+
width: 100% !important;
38+
margin: 10px 0;
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<import src="../../../../common/head.wxml" />
2+
<import src="../../../../common/foot.wxml" />
3+
4+
<scroll-view type="list" class="page-container" scroll-y>
5+
<view class="container page" data-weui-theme="{{theme}}">
6+
<template is="head" data="{{title: '聊天内容长按打开'}}" />
7+
<view class="page-body">
8+
<button bind:tap="viewChatMaterials" class="btn" type="primary">查看聊天内容</button>
9+
<button bind:tap="shareUpdatableMessage" class="btn" type="primary">发送动态消息卡片</button>
10+
<button bind:tap="signIn" class="btn" type="primary">签到动态消息卡片</button>
11+
<button bind:tap="remindExpiration" class="btn" type="primary">设置动态消息即将结束</button>
12+
<button bind:tap="earlyTerminate" class="btn" type="primary">设置动态消息结束</button>
13+
<button bind:tap="changeNeedShowEntrance" class="btn" type="primary">{{needShowEntrance ? '显示' : '隐藏'}}发送消息小尾巴</button>
14+
<form bind:submitToGroup="onSubmitToGroup">
15+
<textarea class="form-textarea" value="{{shareText}}" />
16+
<button
17+
class="btn"
18+
style="width: 100%;"
19+
type="primary"
20+
form-type="submitToGroup"
21+
need-show-entrance="{{needShowEntrance}}"
22+
entrance-path="{{entrancePath}}"
23+
>发布文本到群
24+
</button>
25+
</form>
26+
<button bind:tap="shareImage" class="btn" type="primary">发送图片到群</button>
27+
<button bind:tap="shareEmoji" class="btn" type="primary">发送表情到群</button>
28+
<button bind:tap="shareVideo" class="btn" type="primary">发送视频到群</button>
29+
<button bind:tap="shareFile" class="btn" type="primary">发送文件到群</button>
30+
</view>
31+
<template is="foot" />
32+
</view>
33+
</scroll-view>
34+

0 commit comments

Comments
 (0)