log
zhoudw
2022-02-14 56d09d42795eb26f7c3fae0ea00131d44a4c6f1a
src/views/iframe/iframe.vue
@@ -12,6 +12,7 @@
</template>
<script>
import { mapActions, mapState } from "vuex";
// import VConsole from 'vconsole';
export default {
  data(){
    return{
@@ -35,6 +36,7 @@
    this.iframeWin = this.$refs.iframe.contentWindow;
  },
  created () {
    //  let vConsole = new VConsole() // 初始化
     let item = JSON.parse(localStorage.getItem("item"));
     this.scenes_id = item.scenes_id;
     this.scenes_name = item.scenes_name;
@@ -42,7 +44,7 @@
     let url = process.env.INTERFACE_SERVER_PATH+process.env.ETS_APP_NEWRECORD_URL;
     this.live_url = url + "?scenes_id="+this.scenes_id+"&scenes_name="+this.scenes_name+"&client_id="+this.client_id+"&sid="+this.token;
     console.log(this.live_url);
     this.getwsConfig();
     this.loadWxjs();
  },
  methods:{
    ...mapActions({
@@ -71,24 +73,27 @@
      });;
    },
     postMessageEvent(){
       let _this = this;
       window.addEventListener("message", function(e){
            var data = e.data;
            console.log(data,'收到消息');
            switch (data.action) {
                case 'init': // 初始化
                    wx.config({
                        beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                        appId: appId, // 必填,企业微信的corpID
                        timestamp: timeStamp, // 必填,生成签名的时间戳
                        nonceStr: nonceStr, // 必填,生成签名的随机串
                        signature: signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
                        appId: _this.corpId, // 必填,企业微信的corpID
                        timestamp: _this.timeStamp, // 必填,生成签名的时间戳
                        nonceStr: _this.nonceStr, // 必填,生成签名的随机串
                        signature: _this.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
                        jsApiList: [
                                'startRecord',
                                'stopRecord',
                                'uploadVoice'
                        ], //必填,传入需要使用的接口名称
                        success: function (res) {
                          sendMsg({
                          console.log(res,'企业微信初始化');
                          _this.sendMsg({
                            action:'init',
                            state:'ok',
                            data:{}
@@ -96,7 +101,7 @@
                        }
                    });
                    wx.error(function(res){
                        sendMsg({
                        _this.sendMsg({
                          action:'init',
                          state:'fail',
                          data:{}
@@ -106,7 +111,8 @@
                case 'start': // 开始录音
                  wx.startRecord({
                    success: function (res) {
                      sendMsg({
                      console.log(res,'开始录音成功');
                      _this.sendMsg({
                        action:'start',
                        state:'ok',
                        data:{}
@@ -114,7 +120,7 @@
                    }
                  });
                  wx.error(function(res){
                      sendMsg({
                      _this.sendMsg({
                        action:'start',
                        state:'fail',
                        data:{}
@@ -124,13 +130,15 @@
                case 'stop':
                  wx.stopRecord({
                    success: function (res) {
                      console.log(res,'停止录音成功');
                      var localId = res.localId;
                      wx.uploadVoice({
                          localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得,音频时长不能超过60秒
                          isShowProgressTips: 0, // 默认为1,显示进度提示
                          success: function (ures) {
                            console.log(ures,'上传录音成功');
                            let serverId = ures.serverId;
                            sendMsg({
                            _this.sendMsg({
                              action:'stop',
                              state:'ok',
                              data:{
@@ -143,8 +151,28 @@
                    }
                  });
                  wx.error(function(res){
                      sendMsg({
                        action:'start',
                      _this.sendMsg({
                        action:'stop',
                        state:'fail',
                        data:{}
                      });
                  })
                  break;
                  case 'cleanup':
                  wx.stopRecord({
                    success: function (res) {
                      console.log(res,'清除录音成功');
                      _this.sendMsg({
                        action:'cleanup',
                        state:'ok',
                        data:{
                        }
                      });
                    }
                  });
                  wx.error(function(res){
                      _this.sendMsg({
                        action:'cleanup',
                        state:'fail',
                        data:{}
                      });
@@ -165,14 +193,13 @@
            script.type = 'text/javascript';
            script.src = wx_js;
            document.body.appendChild(script);
            if(index == 0){
              script.onload=function(){
                _this.jsload = true;
              }
            script.onload=function(){
              _this.jsload = true;
            }
        }else{
          _this.jsload = true;
        }
        this.getwsConfig();
     }
  }
}