12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- export default {
- data(){
- return {
- innerAudioContext: null,
- address: ''
- }
- },
- methods: {
- getLocationInfoByLatLnt(lat, lng) {
- const that = this;
- const locationInfoURL = `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=G4BBZ-YSMCJ-56AFX-KD4FQ-23RQZ-S7FX3`;
- wx.request({
- url: locationInfoURL, //仅为示例,并非真实的接口地址
- success (res) {
- const resultData = res.data;
- that.address= resultData['result'].address
- }
- })
- },
- setTabBarIndex(index) {
- if (typeof this.$scope.getTabBar === 'function' && this.$scope.getTabBar()) {
- this.$scope.getTabBar().setData({
- selected: index
- })
- }
- },
- getTimeFuns(sTimeStr, eTimeStr) {
- const sTime = new Date(sTimeStr);
- const eTime = +new Date(eTimeStr) //返回的是用户输入时间总的毫秒数
- const secondTime = (eTime - sTime) / 1000; //剩余时间总的秒数
- let d = parseInt(secondTime / 60 / 60 / 24); //计算天数
- let h = parseInt(secondTime / 60 / 60 % 24); //计算小时
- let m = parseInt(secondTime / 60 % 60); //计算分
- let s = parseInt(secondTime % 60); //计算当前秒数
- return {
- time: Math.abs(d) + '天' + Math.abs(h) + '时' + Math.abs(m) + '分',
- time2: {
- a: d,
- b: h,
- c: m
- }
- };
- },
- //播放语音
- createAudio: function(srcMic) {
- if(this.innerAudioContext) return;
- let that = this
- //创建内部 audio 上下文 InnerAudioContext 对象。
- that.innerAudioContext = wx.createInnerAudioContext();
- that.innerAudioContext.onError(function(error) {
- console.error("自定义报错(checkedDetail 137行):" + error)
- })
- that.innerAudioContext.src = srcMic //设置音频地址
- },
- //播放
- audioPlay(srcMic) {
- this.createAudio(srcMic);
- this.innerAudioContext.play(); //播放音频
- return this.innerAudioContext;
- },
- // 停止播放
- audioPause() {
- if (!this.innerAudioContext) return;
- this.innerAudioContext.pause(); //播放音频
- },
- }
- }
|