goview_vue/src/utils/index.ts

81 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-12-19 19:19:46 +08:00
import { h } from 'vue'
import { NIcon } from 'naive-ui'
2021-12-20 13:36:54 +08:00
import screenfull from 'screenfull'
2021-12-10 14:11:49 +08:00
/**
* * ID
2021-12-10 14:11:49 +08:00
* @param { Number } randomLength
*/
export function getUUID(randomLength: number) {
2021-12-10 14:11:49 +08:00
return Number(
Math.random().toString().substr(2, randomLength) + Date.now()
).toString(36)
2021-12-10 14:11:49 +08:00
}
/**
* * render
*/
2021-12-18 16:36:43 +08:00
export const renderIcon = (icon: any) => {
return () => h(NIcon, null, { default: () => h(icon) })
}
2021-12-10 14:11:49 +08:00
2021-12-19 19:19:46 +08:00
/**
* * render
* @param { Function } dialogFn dialog函数
* @param { Object} params
*/
export const goDialog = (
dialogFn: Function,
params: {
// 基本
type: 'delete'
message?: string
onPositiveCallback?: Function
onNegativeCallback?: Function
// 渲染函数
render?: boolean
contentFn?: Function
actionFn?: Function
}
) => {
const { type, message, onPositiveCallback, onNegativeCallback } = params
const tip = {
delete: '是否删除此数据'
}
dialogFn({
title: '提示',
content: message || tip[type] || '',
positiveText: '确定',
negativeText: '取消',
onPositiveClick: () => {
onPositiveCallback && onPositiveCallback()
},
onNegativeClick: () => {
onNegativeCallback && onNegativeCallback()
}
})
}
2021-12-15 14:25:28 +08:00
/**
* * vite 使 require
* @param name
* @returns url
2021-12-15 14:25:28 +08:00
*/
export const requireUrl = (path: string, name: string) => {
return new URL(`${path}/${name}`, import.meta.url).href
}
2021-12-20 13:36:54 +08:00
export const screenfullFn = (isFullscreen?: boolean, isEnabled?: boolean) => {
// 是否是全屏
if (isFullscreen) return screenfull.isFullscreen
2021-12-20 13:36:54 +08:00
// 是否支持全屏
if (isEnabled) return screenfull.isEnabled
2021-12-20 13:36:54 +08:00
if (screenfull.isEnabled) {
screenfull.toggle()
return
}
2021-12-20 13:36:54 +08:00
// TODO lang
window['$message'].warning('您的浏览器不支持全屏功能!')
}