vab.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { loadingText, messageDuration, title } from '@/config/settings'
  2. import * as lodash from 'lodash'
  3. import { Loading, Message, MessageBox, Notification } from 'element-ui'
  4. import store from '@/store'
  5. import { getAccessToken } from '@/utils/accessToken'
  6. const accessToken = store.getters['user/accessToken']
  7. const layout = store.getters['settings/layout']
  8. const install = (Vue, opts = {}) => {
  9. /* 全局accessToken */
  10. Vue.prototype.$baseAccessToken = () => {
  11. return accessToken || getAccessToken()
  12. }
  13. /* 全局标题 */
  14. Vue.prototype.$baseTitle = (() => {
  15. return title
  16. })()
  17. /* 全局加载层 */
  18. Vue.prototype.$baseLoading = (index, text) => {
  19. let loading
  20. if (!index) {
  21. loading = Loading.service({
  22. lock: true,
  23. text: text || loadingText,
  24. background: 'hsla(0,0%,100%,.8)',
  25. })
  26. } else {
  27. loading = Loading.service({
  28. lock: true,
  29. text: text || loadingText,
  30. spinner: 'vab-loading-type' + index,
  31. background: 'hsla(0,0%,100%,.8)',
  32. })
  33. }
  34. return loading
  35. }
  36. /* 全局多彩加载层 */
  37. Vue.prototype.$baseColorfullLoading = (index, text) => {
  38. let loading
  39. if (!index) {
  40. loading = Loading.service({
  41. lock: true,
  42. text: text || loadingText,
  43. spinner: 'dots-loader',
  44. background: 'hsla(0,0%,100%,.8)',
  45. })
  46. } else {
  47. switch (index) {
  48. case 1:
  49. index = 'dots'
  50. break
  51. case 2:
  52. index = 'gauge'
  53. break
  54. case 3:
  55. index = 'inner-circles'
  56. break
  57. case 4:
  58. index = 'plus'
  59. break
  60. }
  61. loading = Loading.service({
  62. lock: true,
  63. text: text || loadingText,
  64. spinner: index + '-loader',
  65. background: 'hsla(0,0%,100%,.8)',
  66. })
  67. }
  68. return loading
  69. }
  70. /* 全局Message */
  71. Vue.prototype.$baseMessage = (message, type) => {
  72. Message({
  73. offset: 60,
  74. showClose: true,
  75. message: message,
  76. type: type,
  77. dangerouslyUseHTMLString: true,
  78. duration: messageDuration,
  79. })
  80. }
  81. /* 全局Alert */
  82. Vue.prototype.$baseAlert = (content, title, callback) => {
  83. MessageBox.alert(content, title || '温馨提示', {
  84. confirmButtonText: '确定',
  85. dangerouslyUseHTMLString: true,
  86. callback: (action) => {
  87. if (callback) {
  88. callback()
  89. }
  90. },
  91. })
  92. }
  93. /* 全局Confirm */
  94. Vue.prototype.$baseConfirm = (content, title, callback1, callback2) => {
  95. MessageBox.confirm(content, title || '温馨提示', {
  96. confirmButtonText: '确定',
  97. cancelButtonText: '取消',
  98. closeOnClickModal: false,
  99. type: 'warning',
  100. })
  101. .then(() => {
  102. if (callback1) {
  103. callback1()
  104. }
  105. })
  106. .catch(() => {
  107. if (callback2) {
  108. callback2()
  109. }
  110. })
  111. }
  112. /* 全局Notification */
  113. Vue.prototype.$baseNotify = (message, title, type, position) => {
  114. Notification({
  115. title: title,
  116. message: message,
  117. position: position || 'top-right',
  118. type: type || 'success',
  119. duration: messageDuration,
  120. })
  121. }
  122. /* 全局TableHeight */
  123. Vue.prototype.$baseTableHeight = (formType) => {
  124. let height = window.innerHeight
  125. let paddingHeight = 400
  126. const formHeight = 50
  127. if (layout === 'vertical') {
  128. paddingHeight = 365
  129. }
  130. if ('number' == typeof formType) {
  131. height = height - paddingHeight - formHeight * formType
  132. } else {
  133. height = height - paddingHeight
  134. }
  135. return height
  136. }
  137. /* 全局map图层 */
  138. Vue.prototype.$baseMap = () => {
  139. return new maptalks.Map('map', {
  140. center: [116.41348403785, 39.910843952376],
  141. zoom: 12,
  142. minZoom: 1,
  143. maxZoom: 19,
  144. spatialReference: {
  145. projection: 'baidu',
  146. },
  147. attribution: {
  148. content: '© vue-admin-beautiful',
  149. },
  150. baseLayer: new maptalks.TileLayer('base', {
  151. cssFilter: 'sepia(100%) invert(90%)',
  152. urlTemplate:
  153. 'http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1',
  154. subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  155. attribution:
  156. '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
  157. }),
  158. })
  159. }
  160. /* 全局lodash */
  161. Vue.prototype.$baseLodash = lodash
  162. /* 全局事件总线 */
  163. Vue.prototype.$baseEventBus = new Vue()
  164. }
  165. if (typeof window !== 'undefined' && window.Vue) {
  166. install(window.Vue)
  167. }
  168. export default install