CustomMixins.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. export default {
  2. data(){
  3. return {
  4. innerAudioContext: null,
  5. address: ''
  6. }
  7. },
  8. methods: {
  9. getLocationInfoByLatLnt(lat, lng) {
  10. const that = this;
  11. const locationInfoURL = `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=G4BBZ-YSMCJ-56AFX-KD4FQ-23RQZ-S7FX3`;
  12. wx.request({
  13. url: locationInfoURL, //仅为示例,并非真实的接口地址
  14. success (res) {
  15. const resultData = res.data;
  16. that.address= resultData['result'].address
  17. }
  18. })
  19. },
  20. setTabBarIndex(index) {
  21. if (typeof this.$scope.getTabBar === 'function' && this.$scope.getTabBar()) {
  22. this.$scope.getTabBar().setData({
  23. selected: index
  24. })
  25. }
  26. },
  27. getTimeFuns(sTimeStr, eTimeStr) {
  28. const sTime = new Date(sTimeStr);
  29. const eTime = +new Date(eTimeStr) //返回的是用户输入时间总的毫秒数
  30. const secondTime = (eTime - sTime) / 1000; //剩余时间总的秒数
  31. let d = parseInt(secondTime / 60 / 60 / 24); //计算天数
  32. let h = parseInt(secondTime / 60 / 60 % 24); //计算小时
  33. let m = parseInt(secondTime / 60 % 60); //计算分
  34. let s = parseInt(secondTime % 60); //计算当前秒数
  35. return {
  36. time: Math.abs(d) + '天' + Math.abs(h) + '时' + Math.abs(m) + '分',
  37. time2: {
  38. a: d,
  39. b: h,
  40. c: m
  41. }
  42. };
  43. },
  44. //播放语音
  45. createAudio: function(srcMic) {
  46. if(this.innerAudioContext) return;
  47. let that = this
  48. //创建内部 audio 上下文 InnerAudioContext 对象。
  49. that.innerAudioContext = wx.createInnerAudioContext();
  50. that.innerAudioContext.onError(function(error) {
  51. console.error("自定义报错(checkedDetail 137行):" + error)
  52. })
  53. that.innerAudioContext.src = srcMic //设置音频地址
  54. },
  55. //播放
  56. audioPlay(srcMic) {
  57. this.createAudio(srcMic);
  58. this.innerAudioContext.play(); //播放音频
  59. return this.innerAudioContext;
  60. },
  61. // 停止播放
  62. audioPause() {
  63. if (!this.innerAudioContext) return;
  64. this.innerAudioContext.pause(); //播放音频
  65. },
  66. }
  67. }