diff --git a/App.vue b/App.vue index b11624a..17b4ae9 100644 --- a/App.vue +++ b/App.vue @@ -25,6 +25,28 @@ }, methods: { + + // 时分秒转换为秒 + TIMEEVENT(e) { + var time = e; + var len = time.split(':') + if (len.length == 3) { + var hour = time.split(':')[0]; + var min = time.split(':')[1]; + var sec = time.split(':')[2]; + return Number(hour * 3600) + Number(min * 60) + Number(sec); + } + if (len.length == 2) { + var min = time.split(':')[0]; + var sec = time.split(':')[1]; + return Number(min * 60) + Number(sec); + } + if (len.length == 1) { + var sec = time.split(':')[0]; + return Number(sec); + } + + }, // 目前使用页面为录音页面 SPEAKERSTYLE(index) { let obj = { @@ -138,8 +160,8 @@ let pushon = uni.getStorageSync('weapp_session_userInfo_data').loginName uni.connectSocket({ url: 'wss://hfju.com/ws?uid=' + pushon + '_applets', - header: { - "content-type": "application/json", + header: { + "content-type": "application/json", 'Access-Token': uni.getStorageSync('weapp_session_login_data').token } }); diff --git a/components/uniapp-zaudio/dist/util.d.ts b/components/uniapp-zaudio/dist/util.d.ts new file mode 100644 index 0000000..fe935a1 --- /dev/null +++ b/components/uniapp-zaudio/dist/util.d.ts @@ -0,0 +1,10 @@ +export declare function formatSeconds(seconds: number | string): string; +export declare function throttle(fn: Function, wait: number): Function; +export declare class EventBus { + private _events; + constructor(); + protected on(event: any, action: any, fn: () => {}): void; + private has; + protected emit(event: any, data?: any): void; + protected off(event: any, action: any): void; +} diff --git a/components/uniapp-zaudio/dist/util.js b/components/uniapp-zaudio/dist/util.js new file mode 100644 index 0000000..d55954b --- /dev/null +++ b/components/uniapp-zaudio/dist/util.js @@ -0,0 +1,73 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.EventBus = exports.throttle = exports.formatSeconds = void 0; + +function formatSeconds(seconds) { + var result = typeof seconds === "string" ? parseFloat(seconds) : seconds; + if (isNaN(result)) return ""; + let h = Math.floor(result / 3600) < 10 ? "0" + Math.floor(result / 3600) : Math.floor(result / 3600); + let m = Math.floor((result / 60) % 60) < 10 ? "0" + Math.floor((result / 60) % 60) : Math.floor((result / 60) % 60); + let s = Math.floor(result % 60) < 10 ? "0" + Math.floor(result % 60) : Math.floor(result % 60); + + return `${h}:${m}:${s}`; + //time为毫秒数 +} +exports.formatSeconds = formatSeconds; + +function throttle(fn, wait) { + let previous = 0; + return function(...arg) { + let context = this; + let now = Date.now(); + //每隔一段时间执行一次; + if (now - previous > wait) { + fn.apply(context, arg); + previous = now; + } + }; +} +exports.throttle = throttle; +class EventBus { + constructor() { + this._events = new Map(); + } + on(event, action, fn) { + let arr = this._events.get(event); + let hasAction = arr ? + arr.findIndex((i) => i.action == action) : + -1; + if (hasAction > -1) { + return; + } + this._events.set(event, [ + ...(this._events.get(event) || []), + { + action, + fn, + }, + ]); + } + has(event) { + return this._events.has(event); + } + emit(event, data) { + if (!this.has(event)) { + return; + } + let arr = this._events.get(event); + arr.forEach((i) => { + i.fn(data); + }); + } + off(event, action) { + if (!this.has(event)) { + return; + } + let arr = this._events.get(event); + let newdata = arr.filter((i) => i.action !== action); + this._events.set(event, [...newdata]); + } +} +exports.EventBus = EventBus; diff --git a/components/uniapp-zaudio/dist/zaudio.d.ts b/components/uniapp-zaudio/dist/zaudio.d.ts new file mode 100644 index 0000000..d59f679 --- /dev/null +++ b/components/uniapp-zaudio/dist/zaudio.d.ts @@ -0,0 +1,213 @@ +interface audio { + src: string; + title: string; + singer: string; + coverImgUrl: string; +} +interface audioInfo extends audio { + current: string; + duration: string; + duration_value: number; + current_value: number; +} +declare enum zaudioCbName { + onWaiting = "waiting", + onError = "error", + onTimeUpdate = "playing", + onCanplay = "canPlay", + onPause = "pause", + onEnded = "ended", + setAudio = "setAudio", + updateAudio = "updateAudio", + seek = "seek", + onStop = "stop", + syncStateOn = "syncStateOn" +} +import { EventBus } from "./util"; +/** + * ZAudio类 + * @class ZAudio + * @constructor + * @param {String} defaultCover 音频默认封面 + * @param {Boolean} continuePlay 继续播放,错误播放或结束播放后执行 + * @param {Boolean} autoPlay 自动播放,部分浏览器不支持 + * @property {Number} renderIndex 当前渲染索引 + * @property {} renderinfo 当前渲染数据 + * @property {Array