2021-12-19 19:19:46 +08:00
|
|
|
|
import { h } from 'vue'
|
2021-12-17 11:55:42 +08:00
|
|
|
|
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
|
|
|
|
/**
|
2021-12-14 15:53:30 +08:00
|
|
|
|
* * 生成一个用不重复的ID
|
2021-12-10 14:11:49 +08:00
|
|
|
|
* @param { Number } randomLength
|
|
|
|
|
*/
|
2021-12-14 15:53:30 +08:00
|
|
|
|
export function getUUID(randomLength: number) {
|
2021-12-10 14:11:49 +08:00
|
|
|
|
return Number(
|
2021-12-17 11:55:42 +08:00
|
|
|
|
Math.random().toString().substr(2, randomLength) + Date.now()
|
|
|
|
|
).toString(36)
|
2021-12-10 14:11:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-14 15:53:30 +08:00
|
|
|
|
* * render 图标
|
|
|
|
|
*/
|
2021-12-18 16:36:43 +08:00
|
|
|
|
export const renderIcon = (icon: any) => {
|
2021-12-17 11:55:42 +08:00
|
|
|
|
return () => h(NIcon, null, { default: () => h(icon) })
|
2021-12-14 15:53:30 +08:00
|
|
|
|
}
|
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 的问题
|
2021-12-17 11:55:42 +08:00
|
|
|
|
* @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-17 11:55:42 +08:00
|
|
|
|
|
2021-12-20 13:36:54 +08:00
|
|
|
|
export const screenfullFn = (isFullscreen?: boolean, isEnabled?: boolean) => {
|
|
|
|
|
// 是否是全屏
|
|
|
|
|
if (isFullscreen) return screenfull.isFullscreen
|
2021-12-17 11:55:42 +08:00
|
|
|
|
|
2021-12-20 13:36:54 +08:00
|
|
|
|
// 是否支持全屏
|
|
|
|
|
if (isEnabled) return screenfull.isEnabled
|
2021-12-17 11:55:42 +08:00
|
|
|
|
|
2021-12-20 13:36:54 +08:00
|
|
|
|
if (screenfull.isEnabled) {
|
|
|
|
|
screenfull.toggle()
|
|
|
|
|
return
|
2021-12-17 11:55:42 +08:00
|
|
|
|
}
|
2021-12-20 13:36:54 +08:00
|
|
|
|
// TODO lang
|
|
|
|
|
window['$message'].warning('您的浏览器不支持全屏功能!')
|
2021-12-17 11:55:42 +08:00
|
|
|
|
}
|