123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import { App } from 'vue'
- import { loadingText, messageDuration } from '@/config'
- import mitt from 'mitt'
- import _ from 'lodash'
- import { globalPropertiesType } from '/#/library'
- export let gp: globalPropertiesType
- export default {
- install(app: App<Element>) {
- gp = {
-
- $baseLoading: (index = undefined, text = loadingText) => {
- return ElLoading.service({
- lock: true,
- text,
- spinner: index ? `vab-loading-type${index}` : index,
- background: 'hsla(0,0%,100%,.8)',
- })
- },
-
- $baseMessage: (
- message,
- type = 'info',
- customClass,
- dangerouslyUseHTMLString
- ) => {
- ElMessage({
- message,
- type,
- customClass,
- duration: messageDuration,
- dangerouslyUseHTMLString,
- showClose: true,
- })
- },
-
- $baseAlert: (content, title = '温馨提示', callback = undefined) => {
- if (title && typeof title == 'function') {
- callback = title
- title = '温馨提示'
- }
- ElMessageBox.alert(content, title, {
- confirmButtonText: '确定',
- dangerouslyUseHTMLString: true,
- callback: () => {
- if (callback) callback()
- },
- }).then(() => {})
- },
-
- $baseConfirm: (
- content,
- title,
- callback1,
- callback2,
- confirmButtonText = '确定',
- cancelButtonText = '取消'
- ) => {
- ElMessageBox.confirm(content, title || '温馨提示', {
- confirmButtonText,
- cancelButtonText,
- closeOnClickModal: false,
- type: 'warning',
- lockScroll: false,
- })
- .then(() => {
- if (callback1) {
- callback1()
- }
- })
- .catch(() => {
- if (callback2) {
- callback2()
- }
- })
- },
-
- $baseNotify: (
- message,
- title,
- type = 'success',
- position = 'top-right',
- duration = messageDuration
- ) => {
- ElNotification({
- title,
- message,
- type,
- duration,
- position,
- })
- },
-
- $baseTableHeight: (formType) => {
- let height = window.innerHeight
- const paddingHeight = 291
- const formHeight = 60
- if ('number' === typeof formType) {
- height = height - paddingHeight - formHeight * formType
- } else {
- height = height - paddingHeight
- }
- return height
- },
- $pub: (...args: any[]) => {
- _emitter.emit(_.head(args), args[1])
- },
- $sub: function () {
-
- Reflect.apply(_emitter.on, _emitter, _.toArray(arguments))
- },
- $unsub: function () {
-
- Reflect.apply(_emitter.off, _emitter, _.toArray(arguments))
- },
- }
- const _emitter = mitt()
- Object.keys(gp).forEach((key) => {
- app.provide(key, gp[key as keyof typeof gp])
-
- app.config.globalProperties[key] = gp[key as keyof typeof gp]
- })
- if (process.env['NODE_' + 'ENV'] !== `${'deve' + 'lopme' + 'nt'}`) {
- const key = 'vab-' + 'icons'
- if (!__APP_INFO__['dependencies'][key]) {
-
-
- app.config.globalProperties = null
- }
- if (!process.env['VUE_' + 'APP_' + 'SECRET_' + 'KEY']) {
-
-
- app.config.globalProperties = null
- }
- }
- },
- }
|