123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /**
- * Add class to element
- * @param {HTMLElement} elm
- * @param {string} cls
- */
- export function addClass(ele, cls) {
- if (!hasClass(ele, cls)) ele.className += ' ' + cls
- }
- /**
- * Remove class from element
- * @param {HTMLElement} elm
- * @param {string} cls
- */
- export function removeClass(ele, cls) {
- if (hasClass(ele, cls)) {
- const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
- ele.className = ele.className.replace(reg, ' ')
- }
- }
- export function isLogin() {
- if (!localStorage.token || !parseInt(localStorage.uid)) {
- return false
- }
- return true
- }
- export function getMediaOptions(img, url) {
- return {
- // playbackRates: [0.5, 1.0, 1.5, 2.0], // 播放速度
- autoplay: false, // 如果true,浏览器准备好时开始回放。
- muted: false, // 默认情况下将会消除任何音频。
- loop: false, // 导致视频一结束就重新开始。
- preload: "true", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
- language: 'zh-CN',
- aspectRatio: '4:3', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
- fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
- sources: [{
- src: url
- }],
- poster: img, // 你的封面地址
- notSupportedMessage: '无法播放媒体源', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
- playtimes: '',
- controlBar: {
- timeDivider: false,
- durationDisplay: false,
- remainingTimeDisplay: false,
- fullscreenToggle: true // 全屏按钮
- }
- }
- }
- export function parseTime(time, cFormat) {
- if (arguments.length === 0) {
- return null
- }
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'object') {
- date = time
- } else {
- if ((typeof time === 'string')) {
- if ((/^[0-9]+$/.test(time))) {
- // support "1548221490638"
- time = parseInt(time)
- } else {
- // support safari
- // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
- time = time.replace(new RegExp(/-/gm), '/')
- }
- }
- if ((typeof time === 'number') && (time.toString().length === 10)) {
- time = time * 1000
- }
- date = new Date(time)
- }
- const formatObj = {
- y: date.getFullYear(),
- m: date.getMonth() + 1,
- d: date.getDate(),
- h: date.getHours(),
- i: date.getMinutes(),
- s: date.getSeconds(),
- a: date.getDay()
- }
- const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
- const value = formatObj[key]
- // Note: getDay() returns 0 on Sunday
- if (key === 'a') {
- return ['日', '一', '二', '三', '四', '五', '六'][value]
- }
- return value.toString().padStart(2, '0')
- })
- return time_str
- }
- export function getPercent( item ){
- if( item.isFinish ) 100;
- let percent = parseInt(item.position * 10000 / item.duration) / 100;
- if( percent >= 100) return 99.99;
- return parseInt(item.position * 10000 / item.duration) / 100
- }
|