diff --git a/app.json b/app.json
index 1709046..fe256c5 100644
--- a/app.json
+++ b/app.json
@@ -85,7 +85,8 @@
"pages/creatorSelectPage/index",
"components/chat/text",
"components/chat/hello",
- "components/chat/html"
+ "components/chat/html",
+ "components/chat/loading"
],
"permission": {
"scope.userLocation": {
@@ -120,7 +121,12 @@
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black"
},
- "plugins": {},
+ "plugins": {
+ "WechatSI": {
+ "version": "0.3.1",
+ "provider": "wx069ba97219f66d99"
+ }
+ },
"tabBar": {
"custom": true,
"color": "#444",
diff --git a/components/chat/loading.js b/components/chat/loading.js
new file mode 100644
index 0000000..4ded714
--- /dev/null
+++ b/components/chat/loading.js
@@ -0,0 +1,66 @@
+// components/chat/loading.js
+Page({
+
+ /**
+ * 页面的初始数据
+ */
+ data: {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面加载
+ */
+ onLoad(options) {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面初次渲染完成
+ */
+ onReady() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面显示
+ */
+ onShow() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面隐藏
+ */
+ onHide() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面卸载
+ */
+ onUnload() {
+
+ },
+
+ /**
+ * 页面相关事件处理函数--监听用户下拉动作
+ */
+ onPullDownRefresh() {
+
+ },
+
+ /**
+ * 页面上拉触底事件的处理函数
+ */
+ onReachBottom() {
+
+ },
+
+ /**
+ * 用户点击右上角分享
+ */
+ onShareAppMessage() {
+
+ }
+})
\ No newline at end of file
diff --git a/components/chat/loading.json b/components/chat/loading.json
new file mode 100644
index 0000000..8835af0
--- /dev/null
+++ b/components/chat/loading.json
@@ -0,0 +1,3 @@
+{
+ "usingComponents": {}
+}
\ No newline at end of file
diff --git a/components/chat/loading.wxml b/components/chat/loading.wxml
new file mode 100644
index 0000000..f6a25b5
--- /dev/null
+++ b/components/chat/loading.wxml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/chat/loading.wxss b/components/chat/loading.wxss
new file mode 100644
index 0000000..303108f
--- /dev/null
+++ b/components/chat/loading.wxss
@@ -0,0 +1 @@
+/* components/chat/loading.wxss */
\ No newline at end of file
diff --git a/subPage/chat/index.js b/subPage/chat/index.js
index 22eb28f..d928848 100644
--- a/subPage/chat/index.js
+++ b/subPage/chat/index.js
@@ -1,4 +1,6 @@
// subPage/chat/index.js
+var plugin = requirePlugin("WechatSI")
+let manager = plugin.getRecordRecognitionManager()
Page({
/**
@@ -7,80 +9,117 @@ Page({
data: {
eventType:'input',// 底部事件类型 input 键盘输入,voice 语音输入
sendText:'',// 发送的输入框内容
+ voiceBtnText:'按住 说话',
+ screenHeight:'0',
list:[
{
id:-1,
type:'text',
isUp:false,
isDown:false,
+ loading:false,
},
- ]
+ ],
+ /* 录音状态
+ * -1 未录音,
+ * 0 按下
+ * 1 长按事件
+ * 2 同意授权,
+ * 3 拒绝授权,
+ * 4 没有进行授权操作
+ * 5 开始录音
+ * 6 抬起并结束录音
+ * 7 超出操作范围,提示取消录音
+ * 8 录音异常
+ * 9 抬起
+ */
+ voiceSpeed:-1,
},
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- wx.setNavigationBarTitle({
- title: options.title,
- })
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
/**
* 生命周期函数--监听页面显示
*/
onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
+ const res = wx.getSystemInfoSync();
+ console.log('设备数据',res);
+ this.setData({
+ screenHeight: res.screenHeight + 'px',
+ });
},
-
- handleEvent(e){
+ handleEvent(e) {
let that = this;
that.animate();
that.setData({
- eventType:e.currentTarget.dataset.type == 'input' ? 'voice':'input'
- })
+ eventType: e.currentTarget.dataset.type == 'input' ? 'voice' : 'input',
+ voiceSpeed:-1
+ });
+ if (that.data.eventType == 'voice') {
+ // 检查是否有录音权限
+ wx.getSetting({
+ success(res) {
+ if (!res.authSetting['scope.record']) {
+ that.setData({
+ voiceSpeed:4
+ });
+ wx.authorize({
+ scope: 'scope.record',
+ success() {
+ console.log('录音权限已授权');
+ // 继续执行其他逻辑
+ that.setData({
+ voiceSpeed:2
+ });
+ },
+ fail() {
+ console.log('录音权限未授权');
+ that.setData({
+ voiceSpeed:4
+ });
+ wx.showModal({
+ title: '提示',
+ content: '需要录音权限才能使用语音输入功能,请在设置中授权。',
+ confirmText: '去设置',
+ cancelText: '取消',
+ success(res) {
+ if (res.confirm) {
+ wx.openSetting({
+ success(res) {
+ console.log('用户打开设置', res.authSetting);
+ if (res.authSetting['scope.record']) {
+ console.log('用户已授权录音权限');
+ // 用户授权后可以继续执行其他逻辑
+ that.setData({
+ voiceSpeed:2
+ });
+ } else {
+ console.log('用户未授权录音权限');
+ // 用户未授权录音权限后的逻辑
+ that.setData({
+ voiceSpeed:3
+ });
+ }
+ }
+ });
+ } else if (res.cancel) {
+ console.log('用户取消授权');
+ // 用户取消授权后的逻辑
+ that.setData({
+ voiceSpeed:3
+ });
+ }
+ }
+ });
+ }
+ });
+ } else {
+ console.log('录音权限已授权');
+ // 继续执行其他逻辑
+ that.setData({
+ voiceSpeed:2
+ });
+ }
+ }
+ });
+ }
},
handleUp(e){
let that = this;
@@ -138,7 +177,6 @@ Page({
sendText:e.detail.value
});
},
-
animate($type='light') {
wx.vibrateShort({
type:$type
@@ -146,8 +184,6 @@ Page({
},
-
-
// 文本消息发送
handleSend(){
let that = this;
@@ -167,17 +203,103 @@ Page({
type:'text',
isUp:false,
isDown:false,
- content:that.data.sendText
+ content:that.data.sendText,
+ loading:false,
},
{
id:that.data.list.length + 1,
type:'html',
isUp:false,
isDown:false,
- content:`【北京奔驰连接器日结工】
🚻 男女 18-48, 18-48周岁, 男女不限, 要求26个英文字母, 纹身烟疤拍照确认, 黑户,明显纹身,临时身份证不予接收,两班倒,站班
💰 员工250元/天,支付60天;60天以后员工220元/天;每月10号发薪。培训工资100元/天,员工 16 元/时以上部分含税6个点的,打卡不满七天无工资;60天以后员工缴纳社保`
+ content:`【北京奔驰连接器日结工】
🚻 男女 18-48, 18-48周岁, 男女不限, 要求26个英文字母, 纹身烟疤拍照确认, 黑户,明显纹身,临时身份证不予接收,两班倒,站班
💰 员工250元/天,支付60天;60天以后员工220元/天;每月10号发薪。培训工资100元/天,员工 16 元/时以上部分含税6个点的,打卡不满七天无工资;60天以后员工缴纳社保`,
+ loading:true,
},
],
sendText:''
});
- }
+ },
+ /**
+ * 语音消息发送
+ */
+ handleTouchStart: function(event) {
+ console.log('手指按下事件触发');
+ let that = this;
+ that.setData({
+ voiceSpeed: 0 // 假设 0 表示按下
+ });
+ },
+ handleLongPress: function(event) {
+ let that = this;
+ console.log('长按事件触发');
+ that.setData({
+ voiceSpeed:1
+ });
+ manager.start({duration:30000, lang: "zh_CN"})
+ // 处理长按事件的逻辑
+ manager.onStart = function(res) {
+ that.setData({
+ voiceSpeed:5
+ });
+ console.log("成功开始录音识别", res)
+ }
+ },
+ handleTouchEnd: function(event) {
+ console.log('手指抬起事件触发',this.data.voiceSpeed);
+ let that = this;
+ if(that.data.voiceSpeed >= 1){
+ that.animate();
+ that.data.sendText = '模拟语音转文本';
+ that.setData({
+ list:[
+ ...that.data.list,
+ {
+ id:that.data.list.length,
+ type:'text',
+ isUp:false,
+ isDown:false,
+ content:that.data.sendText,
+ loading:false,
+ },
+ {
+ id:that.data.list.length + 1,
+ type:'html',
+ isUp:false,
+ isDown:false,
+ content:`【北京奔驰连接器日结工】
🚻 男女 18-48, 18-48周岁, 男女不限, 要求26个英文字母, 纹身烟疤拍照确认, 黑户,明显纹身,临时身份证不予接收,两班倒,站班
💰 员工250元/天,支付60天;60天以后员工220元/天;每月10号发薪。培训工资100元/天,员工 16 元/时以上部分含税6个点的,打卡不满七天无工资;60天以后员工缴纳社保`,
+ loading:true,
+ },
+ ],
+ sendText:''
+ });
+ setTimeout(()=>{
+ that.data.list.forEach(item => {
+ item.loading = false;
+ })
+ that.setData({
+ list:[
+ ...that.data.list,
+ ],
+ sendText:''
+ });
+ },300)
+ }
+ that.setData({
+ voiceSpeed:9
+ });
+ // 处理手指抬起事件的逻辑
+ manager.stop();
+ manager.onStop = function(res) {
+ that.setData({
+ voiceSpeed:6
+ });
+ console.log("监听录音结束 ;临时路径record file path", res.tempFilePath)
+ console.log("监听录音结束 结果result", res.result)
+ }
+ // manager.onError = function(res) {
+ // that.setData({
+ // voiceSpeed:8
+ // });
+ // console.error("监听录音异常 error msg", res.msg)
+ // }
+ },
})
\ No newline at end of file
diff --git a/subPage/chat/index.json b/subPage/chat/index.json
index a4fd187..b064874 100644
--- a/subPage/chat/index.json
+++ b/subPage/chat/index.json
@@ -2,6 +2,7 @@
"usingComponents": {
"hello-panel": "../../components/chat/hello",
"text-panel": "../../components/chat/text",
- "html-panel": "../../components/chat/html"
+ "html-panel": "../../components/chat/html",
+ "loading-panel": "../../components/chat/loading"
}
}
\ No newline at end of file
diff --git a/subPage/chat/index.wxml b/subPage/chat/index.wxml
index 7e5b73e..eba3e82 100644
--- a/subPage/chat/index.wxml
+++ b/subPage/chat/index.wxml
@@ -1,7 +1,7 @@
-
-
-
+
+
+
-
+
-
+
-
@@ -85,12 +88,17 @@
value="{{sendText}}"
/>
-
- 按住 说话
+
+ {{ voiceBtnText }}
-
diff --git a/subPage/chat/index.wxss b/subPage/chat/index.wxss
index 09e3c42..e39dcda 100644
--- a/subPage/chat/index.wxss
+++ b/subPage/chat/index.wxss
@@ -63,7 +63,6 @@
}
.p-home-chat .chat-operate .m-input .voice-box{
padding: 0 12px;
- width: 100%;
text-align: center;
font-size: 17px;
font-weight: 700;
@@ -250,4 +249,12 @@ textarea {
}
.max80{
max-width: 80vw;
+}
+
+
+.voice-click{
+ background-color: #1677ff !important;
+}
+.voice-click .event-icon,.voice-click .send-icon{
+ opacity: 0;
}
\ No newline at end of file