This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="toggle-button-wrapper"> | |
<input | |
id="toggle-button" | |
type="checkbox" | |
name="switch" | |
:checked="checked" | |
v-on="listeners" | |
@change="onChange" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
canvas { | |
border: 1px solid black; | |
} | |
</style> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const getLoadTime = function () { | |
let loadTime = new Date().getTime() | |
let unloadTime = localStorage.getItem('timeUnLoad') | |
let loadPage = localStorage.getItem('timeLoadCount') || 0 | |
let loadCount = isNaN(loadPage) ? 0 : Number(loadPage) /* remember load page count */ | |
localStorage.setItem('timeLoad', loadTime) | |
localStorage.setItem('timeLoadGap', loadTime - unloadTime) | |
const gap = loadTime - unloadTime | |
if (gap > 500 && loadCount === 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dayjs from 'dayjs' | |
import 'dayjs/locale/zh-cn' | |
dayjs.locale('zh-cn') | |
/** | |
* 日期格式化 | |
* @param d | |
* @param format YYYY/MM/DD HH:mm:ss | |
*/ | |
export const formatDate = (d, format) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventBus { | |
constructor() { | |
this.eventMap = new Map() | |
} | |
$on(name, fn, once = false) { | |
if (!this.eventMap.has(name)) { | |
this.eventMap.set(name, []) | |
} | |
const eventList = this.eventMap.get(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<div class="keybord-wrap"> | |
<header class="keybord-header"> | |
<span @click="cancel()">{{ $t('取消') }}</span> | |
<span v-if="previewOnKeyboard" :class="['preview', { 'new-energy': keybord.newEnergy }]">{{ keybord.inputValue.join('') }}</span> | |
<span :class="[{ gray: keybord.inputValue.length < 7 }]" @click="submit()">{{ $t('完成') }}</span> | |
</header> | |
<div class="keybord-keys"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uuidv4: function () { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( | |
/[xy]/g, | |
function (c) { | |
var r = (Math.random() * 16) | 0, | |
v = c == 'x' ? r : (r & 0x3) | 0x8; | |
return v.toString(16); | |
} | |
); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Storage原型上挂载对应方法 (过期实现,方法一) | |
// 存值函数 | |
// 接收三个参数:键、值、有效天数 | |
Storage.prototype.setCanExpireLocal = (key, value, expire) => { | |
// 判断传入的有效期是否为数值或有效 | |
// isNaN是js的内置函数,用于判断一个值是否为NaN(非数值), | |
// 非数值返回true,数值返回false | |
// 还可以限制一下有效期为整数,这里就不做了 | |
if (isNaN(expire) || expire < 1) { | |
throw new Error('有效期应为一个有效数值') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 返回数据下划线转化为驼峰命名 | |
* @param {data} 'obj或ary' | |
* @param {type} 'hump' 为下划线转驼峰,'line' 为驼峰转下划线 | |
* @return {Array||Object} | |
*/ | |
export const formatHumpLineTransfer = (data, type = 'hump') => { | |
// 判断传入的值是对象还是数组 | |
const newData = | |
Object.prototype.toString.call(data) === '[object Object]' | |
? [JSON.parse(JSON.stringify(data))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shake.js | |
let shakeInfo = { | |
openFlag: false, // 是否开启摇一摇,如果是小程序全局监听摇一摇,这里默认为true | |
shakeSpeed: 110, //设置阈值,越小越灵敏 | |
shakeStep: 2000, //摇一摇成功后间隔 | |
lastTime: 0, //此变量用来记录上次摇动的时间 | |
x: 0, | |
y: 0, | |
z: 0, | |
lastX: 0, |
NewerOlder