├── README.md
├── app.js
├── app.json
├── app.wxss
├── emoji
├── bishi.png
├── bugaoxing.png
├── chijing.png
├── deyi.png
├── exin.png
├── guai.png
├── haha.png
├── han.png
├── hehe.png
├── heixian.png
├── hu.png
├── huaji.png
├── jingku.png
├── jingya.png
├── kaixin.png
├── ku.png
├── kuanghan.png
├── lengmo.png
├── mengmengda.png
├── mianqiang.png
├── nu.png
├── pen.png
├── qie.png
├── qinqin.png
├── 吐舌.png
├── 咦.png
├── 委屈.png
├── 生气.png
├── 疑问.png
├── 真棒.png
├── 睡觉.png
├── 笑眼.png
└── 阴险.png
├── images
├── emotion.png
├── keyinput.png
├── robot.jpg
├── speech0.png
├── speech1.png
├── speech2.png
└── voice.png
├── pages
└── index
│ ├── index.js
│ ├── index.json
│ ├── index.wxml
│ └── index.wxss
├── utils
└── util.js
└── wa-ui
└── wa-ui.wxss
/README.md:
--------------------------------------------------------------------------------
1 | # partner-robot
2 | 微信小程序-语音聊天机器人,与机器人一对一聊天,支持语音、表情、文字等。
3 | 服务端项目地址
4 | + nodejs服务端 [partner-nodejs-server](https://github.com/zhukai-git/partner-nodejs-server)
5 | ### 已发布小程序:聊天机器人小Q
6 | #### 服务端被窝关掉了,所以发送消息没有回复了。。
7 | 
8 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | App({
2 | globalData: {
3 | host: 'https://homolo.top',
4 | emojisEn: ['bugaoxing', 'guai', 'qinqin', 'lengmo', 'qie', 'mianqiang', 'chijing', 'tushe', 'hehe', 'hu', 'yi', 'haha', 'ku', 'pen', 'weiqu', 'kaixin', 'deyi', 'nu', 'exin', 'jingku', 'jingya', 'han', 'huaji', 'kuanghan', 'shengqi', 'yiwen', 'zhenbang', 'shuijue', 'xiaoyan', 'mengmengda', 'bishi', 'yinxian', 'heixian'],
5 | emojis: ['不高兴', '乖', '亲亲', '冷漠', '切~', '勉强', '吃惊', '吐舌', '呵呵', '呼~', '咦', '哈哈', '哭', '喷', '委屈', '开心', '得意', '怒', '恶心', '惊哭', '惊讶', '汗', '滑稽', '狂汗', '生气', '疑问', '真棒', '睡觉', '笑眼', '萌萌哒', '鄙视', '阴险', '黑线']
6 | },
7 | onLaunch: function () {
8 | var that = this;
9 | wx.getSetting({
10 | success(res) {
11 | if (!res['scope.record']) {
12 | wx.authorize({
13 | scope: 'scope.record'
14 | })
15 | }
16 | if (!res['scope.userInfo']) {
17 | wx.authorize({
18 | scope: 'scope.userInfo'
19 | })
20 | }
21 | }
22 | })
23 | wx.login({
24 | success: function (data) {
25 | wx.getUserInfo({
26 | success: function (res) {
27 | wx.setStorage({
28 | key: 'userInfo',
29 | data: res.userInfo,
30 | })
31 | }
32 | })
33 | wx.request({
34 | method: 'GET',
35 | url: that.globalData.host + '/wx/getOpenid/' + data.code,
36 | success: function (res) {
37 | wx.setStorage({
38 | key: 'openid',
39 | data: res.data,
40 | })
41 | }
42 | });
43 | }
44 | })
45 | }
46 | })
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/index/index"
4 | ],
5 | "window": {
6 | "backgroundTextStyle": "light",
7 | "navigationBarBackgroundColor": "#000",
8 | "navigationBarTitleText": "小Q",
9 | "navigationBarTextStyle": "#fff"
10 | },
11 | "networkTimeout": {
12 | "request": 10000,
13 | "downloadFile": 10000
14 | }
15 | }
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | @import './wa-ui/wa-ui.wxss';
3 | page{
4 | height: 100%
5 | }
6 | .container {
7 | height: 100%;
8 | display: flex;
9 | flex-direction: column;
10 | align-items: center;
11 | justify-content: space-between;
12 | padding: 200rpx 0;
13 | box-sizing: border-box;
14 | }
15 | .padding{
16 | padding:20rpx;
17 | }
18 | .padding_half{
19 | padding: 10rpx;
20 | }
21 | .graySpace{
22 | padding-left: 40rpx;
23 | background: #eee;
24 | font-size: 12px;
25 | min-height: 30rpx;
26 | }
27 | .item-avatar .text_box,.item-avatar-lg .text_box{
28 | display: flex;
29 | flex-direction: column
30 | }
31 | .flex-row{
32 | display: flex;
33 | flex-direction: row;
34 | }
35 | .flex-column{
36 | display: flex;
37 | flex-direction: column
38 | }
39 | .flex-center{
40 | display: flex;
41 | justify-content: center;
42 | }
43 | .flex{
44 | display: flex;
45 | }
46 | .title{
47 | font-family: "微软雅黑";
48 | font-size: 32rpx;
49 | }
50 | .message{
51 | font-size: 30rpx;
52 | }
53 |
54 | .item-avatar-lg,.item-avatar-md,.item-avatar-sm,.item-avatar-xs{
55 | display: flex;
56 | padding: 20rpx 30rpx;
57 | border-bottom: 1rpx solid #eee;
58 | cursor: pointer;
59 | position:relative;
60 | }
61 | .item-avatar-lg image{
62 | float: left;
63 | width: 125rpx;
64 | height: 125rpx;
65 | box-sizing: border-box
66 | }
67 | .item-avatar-md image{
68 | float: left;
69 | width: 85rpx;
70 | height: 85rpx;
71 | box-sizing: border-box
72 | }
73 | .item-avatar-sm image{
74 | float: left;
75 | width: 65rpx;
76 | height: 65rpx;
77 | box-sizing: border-box
78 | }
79 | .item-avatar-xs image{
80 | float: left;
81 | width: 45rpx;
82 | height: 45rpx;
83 | box-sizing: border-box
84 | }
85 |
86 | .item-avatar-md .marks{
87 | position: absolute;
88 | top: 0px;
89 | left: 90rpx;
90 | width: 40rpx;
91 | height: 40rpx;
92 | line-height: 40rpx;
93 | background: red;
94 | border-radius: 50%;
95 | color: white;
96 | text-align: center;
97 | font-size: 28rpx;
98 | }
99 | .item-avatar-lg .item-text,.item-avatar-md .item-text,.item-avatar-sm .item-text,.item-avatar-xs .item-text{
100 | padding-left: 10px;
101 | }
102 | .item-avatar-md .item-time{
103 | position: absolute;
104 | right: 20rpx;
105 | }
106 | .clearfix{
107 | overflow: hidden;
108 | }
109 | .icon::before{
110 | font-size: 70rpx
111 | }
112 | .floatR{
113 | float: right;
114 | }
115 |
--------------------------------------------------------------------------------
/emoji/bishi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/bishi.png
--------------------------------------------------------------------------------
/emoji/bugaoxing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/bugaoxing.png
--------------------------------------------------------------------------------
/emoji/chijing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/chijing.png
--------------------------------------------------------------------------------
/emoji/deyi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/deyi.png
--------------------------------------------------------------------------------
/emoji/exin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/exin.png
--------------------------------------------------------------------------------
/emoji/guai.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/guai.png
--------------------------------------------------------------------------------
/emoji/haha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/haha.png
--------------------------------------------------------------------------------
/emoji/han.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/han.png
--------------------------------------------------------------------------------
/emoji/hehe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/hehe.png
--------------------------------------------------------------------------------
/emoji/heixian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/heixian.png
--------------------------------------------------------------------------------
/emoji/hu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/hu.png
--------------------------------------------------------------------------------
/emoji/huaji.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/huaji.png
--------------------------------------------------------------------------------
/emoji/jingku.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/jingku.png
--------------------------------------------------------------------------------
/emoji/jingya.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/jingya.png
--------------------------------------------------------------------------------
/emoji/kaixin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/kaixin.png
--------------------------------------------------------------------------------
/emoji/ku.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/ku.png
--------------------------------------------------------------------------------
/emoji/kuanghan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/kuanghan.png
--------------------------------------------------------------------------------
/emoji/lengmo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/lengmo.png
--------------------------------------------------------------------------------
/emoji/mengmengda.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/mengmengda.png
--------------------------------------------------------------------------------
/emoji/mianqiang.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/mianqiang.png
--------------------------------------------------------------------------------
/emoji/nu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/nu.png
--------------------------------------------------------------------------------
/emoji/pen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/pen.png
--------------------------------------------------------------------------------
/emoji/qie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/qie.png
--------------------------------------------------------------------------------
/emoji/qinqin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/qinqin.png
--------------------------------------------------------------------------------
/emoji/吐舌.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/吐舌.png
--------------------------------------------------------------------------------
/emoji/咦.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/咦.png
--------------------------------------------------------------------------------
/emoji/委屈.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/委屈.png
--------------------------------------------------------------------------------
/emoji/生气.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/生气.png
--------------------------------------------------------------------------------
/emoji/疑问.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/疑问.png
--------------------------------------------------------------------------------
/emoji/真棒.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/真棒.png
--------------------------------------------------------------------------------
/emoji/睡觉.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/睡觉.png
--------------------------------------------------------------------------------
/emoji/笑眼.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/笑眼.png
--------------------------------------------------------------------------------
/emoji/阴险.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/emoji/阴险.png
--------------------------------------------------------------------------------
/images/emotion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/emotion.png
--------------------------------------------------------------------------------
/images/keyinput.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/keyinput.png
--------------------------------------------------------------------------------
/images/robot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/robot.jpg
--------------------------------------------------------------------------------
/images/speech0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/speech0.png
--------------------------------------------------------------------------------
/images/speech1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/speech1.png
--------------------------------------------------------------------------------
/images/speech2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/speech2.png
--------------------------------------------------------------------------------
/images/voice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/novicezk/partner-robot/6c88fa0be16bc9deb590107166850b9fdc1ca17d/images/voice.png
--------------------------------------------------------------------------------
/pages/index/index.js:
--------------------------------------------------------------------------------
1 | var util = require('../../utils/util')
2 | const app = getApp()
3 | const host = app.globalData.host
4 | var emojis = app.globalData.emojis
5 | Page({
6 | data: {
7 | messages: [],
8 | isSpeech: false,
9 | scrollHeight: 0,
10 | toView: '',
11 | windowHeight: 0,
12 | windowWidth: 0,
13 | pxToRpx: 2,
14 | msg: '',
15 | emotionBox: false,
16 | emotions: [],
17 | speechText: '按住 说话',
18 | changeImageUrl: '/images/voice.png',
19 | speechIcon: '/images/speech0.png',
20 | defaultSpeechIcon: '/images/speech0.png',
21 | emotionIcon: '/images/emotion.png',
22 | playingSpeech: ''
23 | },
24 | chooseEmotion(e) {
25 | this.setData({
26 | msg: this.data.msg + '[' + e.target.dataset.name + ']',
27 | })
28 | },
29 | sendMessage(e) {
30 | this.setData({
31 | msg: e.detail.value,
32 | })
33 | },
34 | onLoad() {
35 | var that = this
36 | let emotions = []
37 | for (let i = 0; i < emojis.length; i++) {
38 | emotions.push({
39 | src: '/emoji/' + util.getEmojiEn(emojis[i]) + '.png',
40 | id: i,
41 | name: emojis[i]
42 | })
43 | }
44 | this.setData({
45 | emotions: emotions
46 | })
47 | wx.getSystemInfo({
48 | success: (res) => {
49 | this.setData({
50 | windowHeight: res.windowHeight,
51 | pxToRpx: 750 / res.screenWidth,
52 | scrollHeight: (res.windowHeight - 50) * 750 / res.screenWidth
53 | })
54 | }
55 | })
56 | },
57 | onShareAppMessage: function () {
58 | return {
59 | title: '伙伴小Q',
60 | path: '/pages/index/index'
61 | }
62 | },
63 | emotionBtn() {
64 | if (this.data.emotionBox) {
65 | this.setData({
66 | emotionBox: false,
67 | scrollHeight: (this.data.windowHeight - 50) * this.data.pxToRpx
68 | })
69 | } else {
70 | this.setData({
71 | emotionBox: true,
72 | scrollHeight: (this.data.windowHeight - 285) * this.data.pxToRpx
73 | })
74 | if (this.data.isSpeech) {
75 | this.setData({
76 | isSpeech: false,
77 | changeImageUrl: '/images/voice.png'
78 | });
79 | }
80 | }
81 | }, changeType: function () {
82 | if (this.data.isSpeech) {
83 | this.setData({
84 | isSpeech: false,
85 | changeImageUrl: '/images/voice.png'
86 | });
87 | } else {
88 | this.setData({
89 | isSpeech: true,
90 | changeImageUrl: '/images/keyinput.png',
91 | emotionBox: false,
92 | scrollHeight: (this.data.windowHeight - 50) * this.data.pxToRpx
93 | });
94 | }
95 | },
96 | send: function () {
97 | var that = this;
98 | let msg = this.data.msg
99 | let contents = util.getContents(msg)
100 | let id = 'id_' + Date.parse(new Date()) / 1000;
101 | let data = { id: id, contents: contents, me: true, avatar: wx.getStorageSync('userInfo').avatarUrl, speech: false }
102 | let messages = this.data.messages
103 | messages.push(data)
104 | this.setData({
105 | messages: messages,
106 | msg: ''
107 | })
108 | this.setData({
109 | toView: id
110 | })
111 | wx.request({
112 | url: host + '/wx/robot',
113 | method: 'POST',
114 | data: { 'info': msg, 'userid': wx.getStorageSync('openid'), 'username': wx.getStorageSync('userInfo').nickName },
115 | header: {
116 | "content-type": "application/json"
117 | },
118 | success: function (res) {
119 | if (res.statusCode == 200) {
120 | let answer = res.data.text;
121 | let contents = util.getContents(answer, res.data.url)
122 | let id = 'id_' + Date.parse(new Date()) / 1000;
123 | let data = { id: id, contents: contents, me: false, avatar: '/images/robot.jpg', speech: false }
124 | let messages = that.data.messages
125 | messages.push(data)
126 | console.log(messages)
127 | that.setData({
128 | messages: messages
129 | })
130 | that.setData({
131 | toView: id
132 | })
133 | }
134 | },
135 | fail: function (res) {
136 | console.log(res)
137 | }
138 | })
139 | },
140 | startRecord: function () {
141 | var that = this;
142 | this.setData({
143 | speechText: '松开 发送'
144 | })
145 | var seconds = 0;
146 | var interval = setInterval(function () {
147 | seconds++
148 | }, 1000);
149 | wx.startRecord({
150 | success: function (res) {
151 | clearInterval(interval);
152 | var tempFilePath = res.tempFilePath
153 | seconds = seconds == 0 ? 1 : seconds;
154 | let id = 'id_' + Date.parse(new Date()) / 1000;
155 | let data = { id: id, me: true, avatar: wx.getStorageSync('userInfo').avatarUrl, speech: true, seconds: seconds, filePath: tempFilePath }
156 | let messages = that.data.messages
157 | messages.push(data)
158 | that.setData({
159 | messages: messages
160 | });
161 | that.setData({
162 | toView: id
163 | })
164 | let nickName = wx.getStorageSync('userInfo').nickName;
165 | if (!nickName) nickName = 'null';
166 | wx.uploadFile({
167 | url: host + '/wx/uploadSilk',
168 | filePath: tempFilePath,
169 | name: 'file',
170 | formData: {
171 | 'userid': wx.getStorageSync('openid'),
172 | 'username': wx.getStorageSync('userInfo').nickName
173 | },
174 | success: function (res) {
175 | let resData = JSON.parse(res.data);
176 | if (resData.code == 102) {
177 | let answer = resData.text;
178 | let contents = util.getContents(answer)
179 | let id = 'id_' + Date.parse(new Date()) / 1000;
180 | let data = { id: id, contents: contents, me: false, avatar: '/images/robot.jpg', speech: false }
181 | let messages = that.data.messages
182 | messages.push(data)
183 | that.setData({
184 | messages: messages
185 | })
186 | that.setData({
187 | toView: id
188 | })
189 | } else if (resData.code == 101) {
190 | var isFirst = true;
191 | wx.playBackgroundAudio({
192 | dataUrl: host + '/static/' + resData.text
193 | });
194 | wx.onBackgroundAudioPlay(function () {
195 | wx.getBackgroundAudioPlayerState({
196 | success: function (res) {
197 | if (!isFirst) {
198 | return;
199 | }
200 | isFirst = false;
201 | let duration = res.duration;
202 | wx.stopBackgroundAudio();
203 | let id = 'id_' + Date.parse(new Date()) / 1000;
204 | let data = { id: id, me: false, avatar: '/images/robot.jpg', speech: true, seconds: duration == 0 ? 1 : duration, filePath: host + '/static/' + resData.text }
205 | let messages = that.data.messages
206 | messages.push(data)
207 | that.setData({
208 | messages: messages
209 | });
210 | that.setData({
211 | toView: id
212 | })
213 | }
214 | })
215 | });
216 | }
217 | },
218 | fail: function (err) {
219 | console.log(err)
220 | }
221 | })
222 | },
223 | fail: function (err) {
224 | console.log(err)
225 | }
226 | })
227 | },
228 | stopRecord: function () {
229 | this.setData({
230 | speechText: '按住 说话'
231 | })
232 | wx.stopRecord();
233 | },
234 | playSpeech: function (event) {
235 | var that = this;
236 | var filePath = event.currentTarget.dataset.filepath;
237 | that.setData({
238 | playingSpeech: filePath
239 | });
240 | var num = 1;
241 | var interval = setInterval(function () {
242 | that.setData({
243 | speechIcon: '/images/speech' + num % 3 + '.png'
244 | });
245 | num++;
246 | }, 500);
247 | wx.playVoice({
248 | filePath: filePath,
249 | complete: function () {
250 | clearInterval(interval);
251 | that.setData({
252 | speechIcon: '/images/speech0.png',
253 | playingSpeech: ''
254 | });
255 | }
256 | })
257 | },
258 | playRobotSpeech: function (event) {
259 | var that = this;
260 | var filePath = event.currentTarget.dataset.filepath;
261 | that.setData({
262 | playingSpeech: filePath
263 | });
264 | var num = 1;
265 | var interval = setInterval(function () {
266 | that.setData({
267 | speechIcon: '/images/speech' + num % 3 + '.png'
268 | });
269 | num++;
270 | }, 500);
271 | wx.playBackgroundAudio({
272 | dataUrl: filePath
273 | });
274 | wx.onBackgroundAudioStop(function () {
275 | clearInterval(interval);
276 | that.setData({
277 | speechIcon: '/images/speech0.png',
278 | playingSpeech: ''
279 | });
280 | })
281 | }
282 | })
283 |
284 |
--------------------------------------------------------------------------------
/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{item.text}}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | {{i.seconds}}″
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | {{i.seconds}}″
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | .right-Avatar {
2 | float: right;
3 | width: 85rpx;
4 | height: 85rpx;
5 | }
6 |
7 | .right-Triangle {
8 | float: right;
9 | margin-top: 35rpx;
10 | width: 0;
11 | height: 0;
12 | border-top: 16rpx solid transparent;
13 | border-left: 24rpx solid yellowgreen;
14 | border-bottom: 16rpx solid transparent;
15 | }
16 |
17 | .right-message {
18 | float: right;
19 | margin-top: 10rpx;
20 | line-height: 65rpx;
21 | background: yellowgreen;
22 | border-radius: 10rpx;
23 | font-size: 32rpx;
24 | }
25 |
26 | .right-speech-message {
27 | float: right;
28 | margin-top: 10rpx;
29 | line-height: 65rpx;
30 | background: yellowgreen;
31 | border-radius: 10rpx;
32 | font-size: 32rpx;
33 | width: 150rpx;
34 | }
35 |
36 | .left-speech-message {
37 | float: left;
38 | margin-top: 10rpx;
39 | line-height: 65rpx;
40 | background: yellowgreen;
41 | border-radius: 10rpx;
42 | font-size: 32rpx;
43 | width: 150rpx;
44 | }
45 |
46 | .left-Avatar {
47 | float: left;
48 | width: 85rpx;
49 | height: 85rpx;
50 | }
51 |
52 | .left-Triangle {
53 | float: left;
54 | margin-top: 35rpx;
55 | width: 0;
56 | height: 0;
57 | border-top: 16rpx solid transparent;
58 | border-right: 24rpx solid yellowgreen;
59 | border-bottom: 16rpx solid transparent;
60 | }
61 |
62 | .left-message {
63 | float: left;
64 | margin-top: 10rpx;
65 | line-height: 65rpx;
66 | background: yellowgreen;
67 | border-radius: 10rpx;
68 | font-size: 32rpx;
69 | }
70 |
71 | .speech-button {
72 | height: 70rpx;
73 | margin-left: 30rpx;
74 | margin-right: 30rpx;
75 | line-height: 70rpx;
76 | background: white;
77 | }
78 |
79 | .button-hover {
80 | background-color: rgba(0, 0, 0, 0.1);
81 | opacity: 0.7;
82 | }
83 |
84 | .icon {
85 | vertical-align: middle;
86 | margin-top: 8rpx;
87 | width: 64rpx;
88 | height: 64rpx;
89 | }
90 |
91 | .ion-ios {
92 | background-size: 64rpx 64rpx;
93 | background-repeat: no-repeat;
94 | background-position: center center;
95 | vertical-align: middle;
96 | }
97 |
98 | .emotion {
99 | width: 64rpx;
100 | height: 64rpx;
101 | line-height: 64rpx;
102 | margin: 10rpx;
103 | }
104 |
105 | #emotionPanel {
106 | padding-left: 40rpx;
107 | }
108 |
109 | .send-button {
110 | margin-left: 10rpx;
111 | margin-top: 8rpx;
112 | height: 64rpx;
113 | line-height: 64rpx;
114 | }
115 |
--------------------------------------------------------------------------------
/utils/util.js:
--------------------------------------------------------------------------------
1 | var globalData = getApp().globalData
2 | const host = globalData.host
3 | var emojis = globalData.emojis
4 | var emojisEn = globalData.emojisEn
5 |
6 | function formatTime(time) {
7 | const date = new Date(time)
8 | var year = date.getFullYear()
9 | var month = date.getMonth() + 1
10 | var day = date.getDate()
11 | var hour = date.getHours()
12 | var minute = date.getMinutes()
13 | var second = date.getSeconds()
14 | return [hour, minute, second].map(formatNumber).join(':')
15 | }
16 |
17 | function formatNumber(n) {
18 | n = n.toString()
19 | return n[1] ? n : '0' + n
20 | }
21 |
22 | function insertStrOnceSize(content, str, size) {
23 | if (content.length <= size) return content;
24 | return content.substring(0, size) + "\n" + insertStrOnceSize(content.substring(15, content.length), '\n', size);
25 | }
26 |
27 | function getContents(msg, url) {
28 | let contents = []
29 | if (url) {
30 | contents.push({
31 | type: 'text',
32 | text: msg + "\n" + insertStrOnceSize(url, '\n', 15)
33 | })
34 | return contents;
35 | }
36 | let arr = msg.match(/\[[^\[\]]+\]/g);
37 | for (let i in arr) {
38 | let emoji = arr[i].substring(1, arr[i].length - 1);
39 | let index = emojis.indexOf(emoji);
40 | if (index != -1) {
41 | let str = msg.substring(0, msg.indexOf(arr[i]));
42 | if (str) {
43 | contents.push({
44 | type: 'text',
45 | text: insertStrOnceSize(str, '\n', 15)
46 | })
47 | }
48 | contents.push({
49 | type: 'image',
50 | url: '/emoji/' + emojisEn.slice(index, index + 1)[0] + '.png'
51 | })
52 | msg = msg.substring(msg.indexOf(arr[i]) + arr[i].length, msg.length)
53 | }
54 | }
55 | if (msg) {
56 | contents.push({
57 | type: 'text',
58 | text: insertStrOnceSize(msg, '\n', 15)
59 | })
60 | }
61 | return contents
62 | }
63 |
64 | function getEmojiEn(emoji) {
65 | let index = emojis.indexOf(emoji);
66 | return emojisEn.slice(index, index + 1)[0];
67 | }
68 |
69 | module.exports = {
70 | formatTime: formatTime,
71 | getContents: getContents,
72 | getEmojiEn: getEmojiEn
73 | }
74 |
--------------------------------------------------------------------------------
/wa-ui/wa-ui.wxss:
--------------------------------------------------------------------------------
1 | /* Wa-UI V 0.7.5
2 | * author:liujians
3 | * https://github.com/liujians/weapp-ui
4 | */
5 | /*general*/
6 | page{
7 | height: 100%;
8 | }
9 | /*page text{
10 | font-size: 14px;
11 | line-height: 20px;
12 | font-family: "Helvetica Neue",Helvetica,'microsoft yahei ui', 'microsoft yahei','simhei',Arial,sans-serif
13 | }*/
14 | /*page view{
15 | font-size: 14px;
16 | line-height: 20px;
17 | font-family: "Helvetica Neue",Helvetica,'microsoft yahei ui', 'microsoft yahei','simhei',Arial,sans-serif
18 | }*/
19 | /*basic*/
20 | .text-center{
21 | text-align: center
22 | }
23 | .text-right{
24 | text-align: right
25 | }
26 | .text-left{
27 | text-align: left
28 | }
29 | /*.title{
30 | padding:20rpx;
31 | font-size: 20px;
32 | font-weight: bold;
33 | }*/
34 | .border-basic{
35 | border: 1px solid #ddd
36 | }
37 | .padding{
38 | padding:20rpx;
39 | }
40 | .padding-half{
41 | padding:10rpx;
42 | }
43 | .space{
44 | background: #f5f5f5;
45 | display:block;
46 | font-weight: 600;
47 | border: 1px solid #ddd;
48 | margin: -1px 0;
49 | padding:20rpx
50 | }
51 | .pull-right{
52 | float: right;
53 | margin-left: 5px;
54 | }
55 | /*background*/
56 | page .wa-primary{
57 | border-color: #0c63ee;
58 | background-color: #387ef5;
59 | color: #fff;
60 | }
61 | page .wa-info {
62 | border-color: #0a9ec7;
63 | background-color: #11c1f3;
64 | color: #fff;
65 | }
66 | page .wa-success {
67 | border-color: #28a54c;
68 | background-color: #33cd5f;
69 | color: #fff;
70 | }
71 | page .wa-warning {
72 | border-color: #e6b400;
73 | background-color: #ffc900;
74 | color: #fff;
75 | }
76 | page .wa-danger {
77 | border-color: #e42012;
78 | background-color: #ef473a;
79 | color: #fff;
80 | }
81 | page .wa-dark {
82 | border-color: #111;
83 | background-color: #444;
84 | color: #fff;
85 | }
86 | /*list*/
87 | .wa-list{
88 | width:100%;
89 | position:relative;
90 | }
91 | .wa-item{
92 | width: 100%;
93 | border: 1px solid #ddd;
94 | margin: -1px 0;
95 | font-size: 16px;
96 | display: block;
97 | color: #444;
98 | padding:10px;
99 | height: 40px;
100 | box-sizing: border-box;
101 | position:relative;
102 | background-color: #fff;
103 | }
104 | .wa-item-ava{
105 | padding-left:60px;
106 | min-height: 60px;
107 | }
108 | .wa-item-ava .item-img{
109 | position:absolute;
110 | top:10px;
111 | left: 10px;
112 | width: 40px;
113 | height: 40px;
114 | }
115 | .wa-item-ava .item-img-round{
116 | position:absolute;
117 | top:10px;
118 | left: 10px;
119 | width: 40px;
120 | height: 40px;
121 | border-radius: 50%;
122 | }
123 | .wa-item-thumbnail-left{
124 | padding-left:100px;
125 | min-height: 100px;
126 | }
127 | .wa-item-thumbnail-left .item-img{
128 | position:absolute;
129 | top:10px;
130 | left: 10px;
131 | width: 80px;
132 | height: 80px;
133 | }
134 | .wa-item-thumbnail-right{
135 | padding-right:100px;
136 | min-height: 100px;
137 | }
138 | .wa-item-thumbnail-right .item-img{
139 | position:absolute;
140 | top:10px;
141 | right: 10px;
142 | width: 80px;
143 | height: 80px;
144 | }
145 | .wa-item:active{
146 | background-color: #e5e5e5;
147 | }
148 | .wa-item .icon-left{
149 | float: left;
150 | font-size: 20px;
151 | line-height: 20px;
152 | }
153 | .wa-item .icon-right{
154 | float: right;
155 | font-size: 20px;
156 | line-height: 20px;
157 | opacity: .4;
158 | }
159 | .wa-item-thumbnail-left .icon-right{
160 | float: right;
161 | font-size: 20px;
162 | line-height: 80px;
163 | opacity: .4;
164 | }
165 | .wa-item-ava .icon-right{
166 | float: right;
167 | font-size: 20px;
168 | line-height: 40px;
169 | opacity: .4;
170 | }
171 | .icon-left::before{
172 | width: 20px;
173 | }
174 | .icon-right::before{
175 | width: 20px;
176 | }
177 | /*button*/
178 | .wa-button{
179 | border-color: #b2b2b2;
180 | background-color: #f8f8f8;
181 | color: #444;
182 | position: relative;
183 | display: inline-block;
184 | margin: 0;
185 | padding: 0 12px;
186 | min-width: 120rpx;
187 | min-height: 40px;
188 | border-width: 1px;
189 | border-style: solid;
190 | border-radius: 2px;
191 | vertical-align: top;
192 | text-align: center;
193 | text-overflow: ellipsis;
194 | font-size: 16px;
195 | line-height: 38px;
196 | }
197 |
198 | .wa-button-block{
199 | width:100%;
200 | }
201 | .wa-button-sm{
202 | padding: 0 8px;
203 | min-width: 90rpx;
204 | min-height: 28px;
205 | font-size: 12px;
206 | line-height: 26px;
207 | }
208 | .wa-button-lg{
209 | padding: 0 16px;
210 | min-width: 150rpx;
211 | min-height: 52px;
212 | font-size: 20px;
213 | line-height: 48px;
214 | }
215 | .wa-button:active{
216 | border-color: #999;
217 | background: #ccc;
218 | color: #444
219 | }
220 | /*.wa-button-dark:active{
221 | background: #333;
222 | color: #eee
223 | }*/
224 | .wa-button-outline{
225 | border-color: #b2b2b2;
226 | background: transparent;
227 | color: #b2b2b2;
228 | }
229 | .wa-button .icon-left{
230 | padding-right:8rpx;
231 | font-size: 36rpx;
232 | }
233 | .wa-button-sm .icon-left{
234 | padding-right:5px;
235 | font-size: 26rpx
236 | }
237 | .wa-button-lg .icon-left{
238 | padding-right:5px;
239 | font-size: 46rpx
240 | }
241 | .wa-button .icon-right{
242 | float:right;
243 | line-height: 38px;
244 | padding-left:5px;
245 | font-size: 36rpx;
246 | }
247 | .wa-button-sm .icon-right{
248 | float:right;
249 | line-height: 26px;
250 | padding-left:5px;
251 | font-size: 22rpx
252 | }
253 | .wa-button-lg .icon-right{
254 | float:right;
255 | line-height: 48px;
256 | padding-left:5px;
257 | font-size: 46rpx
258 | }
259 | /*input*/
260 | .wa-input{
261 | display: block;
262 | height: 34px;
263 | color: #111;
264 | font-size: 14px;
265 | line-height: 16px;
266 | flex: 1;
267 | }
268 | .wa-input-item{
269 | display: flex;
270 | padding:20rpx;
271 | border: 1px solid #ddd;
272 | margin: -1px 0;
273 | }
274 | .wa-input-label{
275 | flex: 0 0 100px;
276 | font-size: 14px;
277 | line-height: 26px;
278 | font-weight: bold;
279 | padding: 4px 0;
280 | }
281 | .wa-input-stacked{
282 | padding:20rpx;
283 | }
284 | .wa-input-stacked input{
285 | width: 100%
286 | }
287 | .wa-input-icon{
288 | padding: 5px;
289 | padding-left: 44px;
290 | position: relative;
291 | border: 1px solid #ddd;
292 | border-radius: 3px;
293 | }
294 | .wa-input-icon .icon-left{
295 | text-align: center;
296 | position: absolute;
297 | top: 5px;
298 | left: 5px;
299 | width: 34px;
300 | height: 34px;
301 | line-height: 34px;
302 | font-size: 20px;
303 | }
304 | .placeholder-icon{
305 | color: #aaa;
306 | }
307 | /*radio*/
308 | /*.wa-radio radio{
309 | visibility: hidden;
310 | }*/
311 | /*.wa-radio radio::before{
312 | content:" ";
313 | width:500px;
314 | height: 500px;
315 | background: red;
316 | }*/
317 | /*.wa-radio{
318 | background: red;
319 | }*/
320 | /*.wa-radio radio:checked:before{
321 | background: blue;
322 | }*/
323 | /*mark*/
324 | .wa-mark{
325 | border-radius: 20px;
326 | padding: 2px 6px;
327 | font-size: 12px;
328 |
329 | }
330 | .wa-item .wa-mark{
331 | margin-top: -2px;
332 | }
333 | /*grid*/
334 | .wa-row{
335 | display: flex;
336 | padding: 10rpx;
337 | width: 100%;
338 | box-sizing: border-box
339 | }
340 | .wa-col{
341 | flex:1;
342 | display: block;
343 | width:100%;
344 | box-sizing: border-box;
345 | }
346 | .wa-col-10{
347 | flex: 0 0 10%;
348 | max-width: 10%;
349 | box-sizing: border-box;
350 | }
351 | .wa-col-20{
352 | flex: 0 0 20%;
353 | max-width: 20%;
354 | box-sizing: border-box;
355 | }
356 | .wa-col-25{
357 | flex: 0 0 25%;
358 | max-width: 25%;
359 | box-sizing: border-box;
360 | }
361 | .wa-col-33{
362 | flex: 0 0 33%;
363 | max-width: 33%;
364 | box-sizing: border-box;
365 | }
366 | .wa-col-50{
367 | flex: 0 0 50%;
368 | max-width: 50%;
369 | box-sizing: border-box;
370 | }
371 | .wa-col-66{
372 | flex: 0 0 66%;
373 | max-width: 66%;
374 | box-sizing: border-box;
375 | }
376 | .wa-col-75{
377 | flex: 0 0 75%;
378 | max-width: 75%;
379 | box-sizing: border-box;
380 | }
381 | .wa-col-80{
382 | flex: 0 0 80%;
383 | max-width: 80%;
384 | box-sizing: border-box;
385 | }
386 | .wa-col-90{
387 | flex: 0 0 90%;
388 | max-width: 90%;
389 | box-sizing: border-box;
390 | }
--------------------------------------------------------------------------------