index.js 2.3 KB

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