index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import XEUtils from 'xe-utils'
  2. import GlobalConfig from '../v-x-e-table/src/conf'
  3. import { interceptor } from './src/interceptor'
  4. import { renderer } from './src/renderer'
  5. import { commands } from './src/commands'
  6. import { menus } from './src/menus'
  7. import { formats } from './src/formats'
  8. import { setup } from './src/setup'
  9. import { UtilTools } from '../tools/utils'
  10. import { errLog } from '../tools/log'
  11. const installedPlugins = []
  12. export function use (Plugin, options) {
  13. /* eslint-disable @typescript-eslint/no-use-before-define */
  14. if (Plugin && Plugin.install) {
  15. if (installedPlugins.indexOf(Plugin) === -1) {
  16. Plugin.install(VXETable, options)
  17. installedPlugins.push(Plugin)
  18. }
  19. }
  20. return VXETable
  21. }
  22. /**
  23. * 检测模块的安装顺序是否正确
  24. */
  25. function reg (key) {
  26. /* eslint-disable @typescript-eslint/no-use-before-define */
  27. // 检测安装顺序是否正确
  28. if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
  29. if (VXETable.Table) {
  30. errLog('vxe.error.useErr', [key])
  31. }
  32. }
  33. VXETable[`_${key}`] = 1
  34. }
  35. function getExportOrImpotType (types, flag) {
  36. const rest = []
  37. XEUtils.objectEach(types, (val, type) => {
  38. if (val === 0 || val === flag) {
  39. rest.push(type)
  40. }
  41. })
  42. return rest
  43. }
  44. class VXETableConfig {
  45. /**
  46. * 获取当前的 zIndex
  47. */
  48. get zIndex () {
  49. return UtilTools.getLastZIndex()
  50. }
  51. /**
  52. * 获取下一个 zIndex
  53. */
  54. get nextZIndex () {
  55. return UtilTools.nextZIndex()
  56. }
  57. /**
  58. * 获取所有导出类型
  59. */
  60. get exportTypes () {
  61. return getExportOrImpotType(GlobalConfig.export.types, 1)
  62. }
  63. /**
  64. * 获取所有导入类型
  65. */
  66. get importTypes () {
  67. return getExportOrImpotType(GlobalConfig.export.types, 2)
  68. }
  69. }
  70. export const config = new VXETableConfig()
  71. export function t (key, args) {
  72. return GlobalConfig.i18n(key, args)
  73. }
  74. export function _t (key, args) {
  75. return key ? XEUtils.toValueString(GlobalConfig.translate ? GlobalConfig.translate(key, args) : key) : ''
  76. }
  77. export const v = 'v3'
  78. export const VXETable = {
  79. v,
  80. version: process.env.VUE_APP_VXE_TABLE_VERSION,
  81. reg,
  82. use,
  83. setup,
  84. interceptor,
  85. renderer,
  86. commands,
  87. formats,
  88. menus,
  89. config,
  90. t,
  91. _t
  92. }
  93. export * from './src/interceptor'
  94. export * from './src/renderer'
  95. export * from './src/commands'
  96. export * from './src/menus'
  97. export * from './src/formats'
  98. export * from './src/setup'
  99. export default VXETable