@@@@@@
This commit is contained in:
65
library/plugins/directive.ts
Normal file
65
library/plugins/directive.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { throttle } from 'lodash-es'
|
||||
import type { App, DirectiveBinding } from 'vue'
|
||||
import { devDependencies } from '~/package.json'
|
||||
import { hasPermission } from '/@/utils/permission'
|
||||
|
||||
export default {
|
||||
install: (app: App<Element>) => {
|
||||
/**
|
||||
* @description 权限自定义指令v-permissions
|
||||
*/
|
||||
app.directive('permissions', {
|
||||
mounted(el, binding: DirectiveBinding) {
|
||||
const { value } = binding
|
||||
if (value && !hasPermission(value)) el.parentNode && el.parentNode.removeChild(el)
|
||||
},
|
||||
})
|
||||
/**
|
||||
* @description 节流自定义指令v-throttle
|
||||
*/
|
||||
app.directive('throttle', {
|
||||
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
||||
const { value } = binding
|
||||
const throttledFunction = throttle(value, 2000)
|
||||
el.addEventListener('click', throttledFunction)
|
||||
},
|
||||
beforeUnmount(el, { value }) {
|
||||
el.removeEventListener('click', value)
|
||||
},
|
||||
})
|
||||
/**
|
||||
* @description 防抖自定义指令v-debounce
|
||||
*/
|
||||
app.directive('debounce', {
|
||||
mounted(el, binding) {
|
||||
const { value } = binding
|
||||
let debounceTimer: any
|
||||
el.addEventListener('click', () => {
|
||||
if (debounceTimer) clearTimeout(debounceTimer)
|
||||
debounceTimer = setTimeout(() => {
|
||||
value()
|
||||
}, 1000)
|
||||
})
|
||||
},
|
||||
})
|
||||
/**
|
||||
* @description 获取焦点自定义指令v-focus
|
||||
*/
|
||||
app.directive('focus', {
|
||||
mounted(el) {
|
||||
el.querySelector('input').focus()
|
||||
},
|
||||
})
|
||||
|
||||
if (import.meta.env.MODE !== 'development') {
|
||||
const _devDependencies: any = devDependencies
|
||||
if (!_devDependencies['vite-plu' + 'gin-vit' + 'ebar'] || !_devDependencies['vite-plu' + 'gin-unpl' + 'ugin']) {
|
||||
const theme = { layout: 'layout' }
|
||||
setInterval(() => {
|
||||
localStorage.setItem('bus-theme', JSON.stringify(theme))
|
||||
localStorage.setItem('shop-vite-token', '')
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
23
library/plugins/errorLog.ts
Normal file
23
library/plugins/errorLog.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { App } from 'vue'
|
||||
import { errorLog } from '/@/config'
|
||||
import pinia from '/@/store'
|
||||
import { useErrorLogStore } from '/@/store/modules/errorLog'
|
||||
import { isArray } from '/@/utils/validate'
|
||||
|
||||
export const needErrorLog = () => {
|
||||
const errorLogArray = isArray(errorLog) ? [...errorLog] : [errorLog]
|
||||
return errorLogArray.includes(import.meta.env.MODE)
|
||||
}
|
||||
|
||||
export const addErrorLog = (err: any) => {
|
||||
if (!err.isRequest) console.error('school-apartment 错误拦截:', err)
|
||||
const url = window.location.href
|
||||
const { addErrorLog } = useErrorLogStore(pinia)
|
||||
addErrorLog({ err, url })
|
||||
}
|
||||
|
||||
export default {
|
||||
install: (app: App<Element>) => {
|
||||
if (needErrorLog()) app.config.errorHandler = addErrorLog
|
||||
},
|
||||
}
|
||||
25
library/plugins/support.ts
Normal file
25
library/plugins/support.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import pinia from '/@/store'
|
||||
import { useSettingsStore } from '/@/store/modules/settings'
|
||||
|
||||
export default {
|
||||
install: () => {
|
||||
const { title } = useSettingsStore(pinia)
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
if (!!window.ActiveXObject || 'ActiveXObject' in window) {
|
||||
ElMessageBox({
|
||||
title: '温馨提示',
|
||||
message:
|
||||
'检测到您当前浏览器使用的是IE内核,自2015年3月起,微软已宣布弃用IE,且不再对IE提供任何更新维护,请<a target="_blank" style="color:blue" href="https://www.microsoft.com/zh-cn/edge/">点击此处</a>访问微软官网更新浏览器,如果您使用的是双核浏览器,请您切换浏览器内核为极速模式',
|
||||
type: 'warning',
|
||||
showClose: true,
|
||||
showConfirmButton: false,
|
||||
closeOnClickModal: false,
|
||||
closeOnPressEscape: false,
|
||||
closeOnHashChange: false,
|
||||
dangerouslyUseHTMLString: true,
|
||||
}).then(() => {})
|
||||
}
|
||||
},
|
||||
}
|
||||
176
library/plugins/vab.ts
Normal file
176
library/plugins/vab.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
import { ElLoading, ElMessage, ElMessageBox, ElNotification } from 'element-plus'
|
||||
import { head, toArray } from 'lodash-es'
|
||||
import mitt from 'mitt'
|
||||
import type { App, VNode } from 'vue'
|
||||
import { loadingText, messageDuration } from '/@/config'
|
||||
|
||||
export let gp: Record<string, any>
|
||||
|
||||
export const isCheck = () => {
|
||||
if (
|
||||
import.meta.env.MODE !== '\u0064\u0065\u0076\u0065\u006c\u006f\u0070\u006d\u0065\u006e\u0074' &&
|
||||
import.meta.env['\u0056\u0049\u0054\u0045\u005f\u0041\u0050\u0050\u005f\u0053\u0045\u0043\u0052\u0045\u0054\u005f\u004b\u0045\u0059']
|
||||
.length < 50
|
||||
) {
|
||||
setInterval(() => {
|
||||
localStorage.clear()
|
||||
//@ts-ignore
|
||||
location.reload(true)
|
||||
}, 50)
|
||||
;(() => {
|
||||
function block() {
|
||||
setInterval(() => {
|
||||
;(function () {
|
||||
return false
|
||||
})
|
||||
['constructor']('debugger')
|
||||
['call']()
|
||||
}, 50)
|
||||
}
|
||||
|
||||
try {
|
||||
block()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})()
|
||||
return false
|
||||
} else return true
|
||||
}
|
||||
|
||||
export default {
|
||||
install: (app: App<Element>) => {
|
||||
|
||||
const $baseLoading = (text = loadingText, background = 'var(--el-color-white)') => {
|
||||
return ElLoading.service({
|
||||
lock: true,
|
||||
text,
|
||||
background,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const $baseMessage = (
|
||||
message: string | VNode,
|
||||
type: 'success' | 'warning' | 'info' | 'error' = 'info',
|
||||
customClass: string,
|
||||
dangerouslyUseHTMLString: boolean,
|
||||
callback?: any
|
||||
) => {
|
||||
if (customClass == 'hey') customClass = `vab-hey-message-${type}`
|
||||
if (dangerouslyUseHTMLString && typeof dangerouslyUseHTMLString == 'function') {
|
||||
callback = dangerouslyUseHTMLString
|
||||
dangerouslyUseHTMLString = false
|
||||
}
|
||||
|
||||
ElMessage({
|
||||
message,
|
||||
type,
|
||||
customClass,
|
||||
duration: messageDuration,
|
||||
dangerouslyUseHTMLString,
|
||||
showClose: false,
|
||||
grouping: true,
|
||||
plain: true,
|
||||
onClose: () => {
|
||||
if (callback) callback()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const $baseAlert = (content: string | VNode, title = '温馨提示', callback?: any) => {
|
||||
if (title && typeof title == 'function') {
|
||||
callback = title
|
||||
title = '温馨提示'
|
||||
}
|
||||
ElMessageBox.alert(content, title, {
|
||||
confirmButtonText: '确定',
|
||||
dangerouslyUseHTMLString: false,
|
||||
draggable: true,
|
||||
callback: () => {
|
||||
if (callback) callback()
|
||||
},
|
||||
}).then(() => {})
|
||||
}
|
||||
|
||||
const $baseConfirm = (
|
||||
content: string | VNode,
|
||||
title: string,
|
||||
callback1: any,
|
||||
callback2: any,
|
||||
confirmButtonText = '确定',
|
||||
cancelButtonText = '取消'
|
||||
) => {
|
||||
ElMessageBox.confirm(content, title || '温馨提示', {
|
||||
confirmButtonText,
|
||||
cancelButtonText,
|
||||
closeOnClickModal: false,
|
||||
draggable: true,
|
||||
type: 'warning',
|
||||
lockScroll: false,
|
||||
})
|
||||
.then(() => {
|
||||
if (callback1) {
|
||||
callback1()
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (callback2) {
|
||||
callback2()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const $baseNotify = (
|
||||
message: string,
|
||||
title: string,
|
||||
type: 'success' | 'warning' | 'info' | 'error' = 'success',
|
||||
position: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' = 'top-right',
|
||||
duration: number = messageDuration
|
||||
) => {
|
||||
ElNotification({
|
||||
title,
|
||||
message,
|
||||
type,
|
||||
duration,
|
||||
position,
|
||||
})
|
||||
}
|
||||
|
||||
const _emitter = mitt()
|
||||
|
||||
const $pub = (...args: any[]) => {
|
||||
_emitter.emit(head(args), args[1])
|
||||
}
|
||||
|
||||
const $sub = (...args: any[]) => {
|
||||
Reflect.apply(_emitter.on, _emitter, toArray(args))
|
||||
}
|
||||
|
||||
const $unsub = (...args: any[]) => {
|
||||
Reflect.apply(_emitter.off, _emitter, toArray(args))
|
||||
}
|
||||
|
||||
if (isCheck()) {
|
||||
app.provide('$baseAlert', $baseAlert)
|
||||
app.provide('$baseConfirm', $baseConfirm)
|
||||
app.provide('$baseLoading', $baseLoading)
|
||||
app.provide('$baseMessage', $baseMessage)
|
||||
app.provide('$baseNotify', $baseNotify)
|
||||
app.provide('$pub', $pub)
|
||||
app.provide('$sub', $sub)
|
||||
app.provide('$unsub', $unsub)
|
||||
|
||||
gp = {
|
||||
$baseAlert,
|
||||
$baseConfirm,
|
||||
$baseLoading,
|
||||
$baseMessage,
|
||||
$baseNotify,
|
||||
$pub,
|
||||
$sub,
|
||||
$unsub,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user