init: v3 init

This commit is contained in:
陈凯龙
2021-12-07 14:36:07 +08:00
parent 2a7f3d2c46
commit 1ae75500de
206 changed files with 90 additions and 25740 deletions

View File

@@ -1,63 +0,0 @@
// import { requestAnimationFrame } from '@/utils/animation'
import { ref, unref } from 'vue'
export interface ScrollToParams {
el: HTMLElement
to: number
position: string
duration?: number
callback?: () => any
}
const easeInOutQuad = (t: number, b: number, c: number, d: number) => {
t /= d / 2
if (t < 1) {
return (c / 2) * t * t + b
}
t--
return (-c / 2) * (t * (t - 2) - 1) + b
}
const move = (el: HTMLElement, position: string, amount: number) => {
el[position] = amount
}
export function useScrollTo({
el,
position = 'scrollLeft',
to,
duration = 500,
callback
}: ScrollToParams) {
const isActiveRef = ref(false)
const start = el[position]
const change = to - start
const increment = 20
let currentTime = 0
function animateScroll() {
if (!unref(isActiveRef)) {
return
}
currentTime += increment
const val = easeInOutQuad(currentTime, start, change, duration)
move(el, position, val)
if (currentTime < duration && unref(isActiveRef)) {
requestAnimationFrame(animateScroll)
} else {
if (callback) {
callback()
}
}
}
function run() {
isActiveRef.value = true
animateScroll()
}
function stop() {
isActiveRef.value = false
}
return { start: run, stop }
}

View File

@@ -1,17 +0,0 @@
/**
* 配置浏览器本地存储的方式,可直接存储对象数组。
*/
import WebStorageCache from 'web-storage-cache'
type CacheType = 'sessionStorage' | 'localStorage'
export function useCache(type: CacheType = 'sessionStorage') {
const wsCache: WebStorageCache = new WebStorageCache({
storage: type
})
return {
wsCache
}
}

View File

@@ -1,31 +0,0 @@
import Clipboard from 'clipboard'
import { Message } from '_c/Message'
export function useClipboard() {
function clipboard(text: string, event: MouseEvent) {
const clipboard = new Clipboard(event.target as Element, {
text: () => text
})
clipboard.on('success', () => {
clipboardSuccess()
clipboard.destroy()
})
clipboard.on('error', () => {
clipboardError()
clipboard.destroy()
})
;(clipboard as any).onClick(event)
}
function clipboardSuccess() {
Message.success('复制成功')
}
function clipboardError() {
Message.error('复制失败')
}
return {
clipboard
}
}

View File

@@ -1,9 +0,0 @@
import screenfull from 'screenfull'
export function useFullscreen() {
const sf = screenfull as any
return {
sf
}
}

View File

@@ -1,10 +0,0 @@
import IntroJs from 'intro.js'
import 'intro.js/introjs.css'
export function useIntro() {
const intro: IntroJs.IntroJs = new (IntroJs as any)()
return {
intro
}
}

View File

@@ -1,20 +0,0 @@
import { ref, watch } from 'vue'
import { isString } from '@/utils/validate'
import { useAppStoreWithOut } from '@/store/modules/app'
const appStore = useAppStoreWithOut()
export function useTitle(newTitle?: string) {
const title = ref(newTitle ? `${appStore.getTitle} - ${newTitle}` : appStore.getTitle)
watch(
title,
(t, o) => {
if (isString(t) && t !== o && document) {
document.title = t
}
},
{ immediate: true }
)
return title
}

View File

@@ -1,55 +0,0 @@
const domSymbol = Symbol('watermark-dom')
export function useWatermark(appendEl: HTMLElement | null = document.body) {
let func: Fn = () => {}
const id = domSymbol.toString()
const clear = () => {
const domId = document.getElementById(id)
if (domId) {
const el = appendEl
el && el.removeChild(domId)
}
window.removeEventListener('resize', func)
}
const createWatermark = (str: string) => {
clear()
const can = document.createElement('canvas')
can.width = 300
can.height = 240
const cans = can.getContext('2d')
if (cans) {
cans.rotate((-20 * Math.PI) / 120)
cans.font = '15px Vedana'
cans.fillStyle = 'rgba(0, 0, 0, 0.15)'
cans.textAlign = 'left'
cans.textBaseline = 'middle'
cans.fillText(str, can.width / 20, can.height)
}
const div = document.createElement('div')
div.id = id
div.style.pointerEvents = 'none'
div.style.top = '0px'
div.style.left = '0px'
div.style.position = 'absolute'
div.style.zIndex = '100000000'
div.style.width = document.documentElement.clientWidth + 'px'
div.style.height = document.documentElement.clientHeight + 'px'
div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat'
const el = appendEl
el && el.appendChild(div)
return id
}
function setWatermark(str: string) {
createWatermark(str)
func = () => {
createWatermark(str)
}
window.addEventListener('resize', func)
}
return { setWatermark, clear }
}