vab.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import Vue from 'vue'
  2. import { loadingText, messageDuration } from '@/config'
  3. import { Loading, Message, MessageBox, Notification } from 'element-ui'
  4. // import { dependencies } from '../../../package.json'
  5. /**
  6. * @description 全局加载层
  7. * @param {number} index 自定义加载图标类名ID
  8. * @param {string} text 显示在加载图标下方的加载文案
  9. */
  10. Vue.prototype.$baseLoading = (index = undefined, text = loadingText) => {
  11. return Loading.service({
  12. lock: true,
  13. text,
  14. spinner: index ? 'vab-loading-type' + index : index,
  15. background: 'hsla(0,0%,100%,.8)',
  16. })
  17. }
  18. /**
  19. * @description 全局多彩加载层
  20. * @param {number} index 自定义加载图标类名ID
  21. * @param {string} text 显示在加载图标下方的加载文案
  22. */
  23. Vue.prototype.$baseColorfullLoading = (index = undefined, text = loadingText) => {
  24. let loading
  25. if (!index) {
  26. loading = Loading.service({
  27. lock: true,
  28. text,
  29. spinner: 'dots-loader',
  30. background: 'hsla(0,0%,100%,.8)',
  31. })
  32. } else {
  33. const spinnerDict = {
  34. 1: 'dots',
  35. 2: 'gauge',
  36. 3: 'inner-circles',
  37. 4: 'plus',
  38. }
  39. loading = Loading.service({
  40. lock: true,
  41. text,
  42. spinner: spinnerDict[index] + '-loader',
  43. background: 'hsla(0,0%,100%,.8)',
  44. })
  45. }
  46. return loading
  47. }
  48. /**
  49. * @description 全局Message
  50. * @param {string|VNode} message 消息文字
  51. * @param {'success'|'warning'|'info'|'error'} type 主题
  52. * @param {string} customClass 自定义类名
  53. * @param {boolean} dangerouslyUseHTMLString 是否将message属性作为HTML片段处理
  54. */
  55. Vue.prototype.$baseMessage = (message, type = 'info', customClass = undefined, dangerouslyUseHTMLString = false) => {
  56. Message({
  57. message,
  58. type,
  59. customClass,
  60. duration: messageDuration,
  61. dangerouslyUseHTMLString,
  62. showClose: true,
  63. })
  64. }
  65. /**
  66. * @description 全局Alert
  67. * @param {string|VNode} content 消息正文内容
  68. * @param {string} title 标题
  69. * @param {function} callback 若不使用Promise,可以使用此参数指定MessageBox关闭后的回调
  70. */
  71. Vue.prototype.$baseAlert = (content, title = '温馨提示', callback = undefined) => {
  72. MessageBox.alert(content, title, {
  73. confirmButtonText: '确定',
  74. dangerouslyUseHTMLString: true,
  75. callback: () => {
  76. if (callback) {
  77. callback()
  78. }
  79. },
  80. }).then(() => {})
  81. }
  82. /**
  83. * @description 全局Confirm
  84. * @param {string|VNode} content 消息正文内容
  85. * @param {string} title 标题
  86. * @param {function} callback1 确认回调
  87. * @param {function} callback2 关闭或取消回调
  88. * @param {string} confirmButtonText 确定按钮的文本内容
  89. * @param {string} cancelButtonText 取消按钮的自定义类名
  90. */
  91. Vue.prototype.$baseConfirm = (
  92. content,
  93. title = undefined,
  94. callback1 = undefined,
  95. callback2 = undefined,
  96. confirmButtonText = '确定',
  97. cancelButtonText = '取消'
  98. ) => {
  99. MessageBox.confirm(content, title || '温馨提示', {
  100. confirmButtonText,
  101. cancelButtonText,
  102. closeOnClickModal: false,
  103. type: 'warning',
  104. lockScroll: false,
  105. })
  106. .then(() => {
  107. if (callback1) {
  108. callback1()
  109. }
  110. })
  111. .catch(() => {
  112. if (callback2) {
  113. callback2()
  114. }
  115. })
  116. }
  117. /**
  118. * @description 全局Notification
  119. * @param {string} message 说明文字
  120. * @param {string|VNode} title 标题
  121. * @param {'success'|'warning'|'info'|'error'} type 主题样式,如果不在可选值内将被忽略
  122. * @param {'top-right'|'top-left'|'bottom-right'|'bottom-left'} position 自定义弹出位置
  123. * @param duration 显示时间,毫秒
  124. */
  125. Vue.prototype.$baseNotify = (message, title, type = 'success', position = 'top-right', duration = messageDuration) => {
  126. Notification({
  127. title,
  128. message,
  129. type,
  130. duration,
  131. position,
  132. })
  133. }
  134. /**
  135. * @description 表格高度
  136. * @param {*} formType
  137. */
  138. Vue.prototype.$baseTableHeight = (formType) => {
  139. let height = window.innerHeight
  140. const paddingHeight = 245
  141. const formHeight = 50
  142. if ('number' === typeof formType) {
  143. height = height - paddingHeight - formHeight * formType
  144. } else {
  145. height = height - paddingHeight
  146. }
  147. return height
  148. }
  149. Vue.prototype.$noPagingTableHeight = (formType) => {
  150. let height = window.innerHeight
  151. const paddingHeight = 240
  152. const formHeight = 50
  153. if ('number' === typeof formType) {
  154. height = height - paddingHeight - formHeight * formType
  155. } else {
  156. height = height - paddingHeight
  157. }
  158. return height
  159. }
  160. /**
  161. * @description 全局事件总线
  162. */
  163. Vue.prototype.$baseEventBus = new Vue()
  164. !(() => {
  165. // if (process.env.NODE_ENV !== 'development') {
  166. // const str = '\u0076\u0061\u0062\u002d\u0069\u0063\u006f\u006e\u0073'
  167. // const key = unescape(str.replace(/\\u/g, '%u'))
  168. // if (!dependencies[key]) Vue.prototype = null
  169. // if (!process.env.VUE_APP_SECRET_KEY) Vue.prototype = null
  170. // }
  171. })()