index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Element
  2. import ElementUI from 'element-ui'
  3. import 'element-ui/lib/theme-chalk/index.css'
  4. // A modern alternative to CSS resets
  5. import 'normalize.css/normalize.css'
  6. // flex 布局库
  7. import 'flex.css'
  8. // ibps平台字体库
  9. import '@/assets/fonts/iconfont.css'
  10. // :focus-visible https://github.com/WICG/focus-visible/blob/master/explainer.md
  11. import 'focus-visible'
  12. // Internationalization 国际化
  13. import i18n from '@/i18n'
  14. // store
  15. import store from '@/store'
  16. // 工具类
  17. import Utils from '@/utils/util'
  18. // 全局方法
  19. import common from '@/utils'
  20. // global filters 全局过滤
  21. import * as filters from '@/filters'
  22. // 拼音指令
  23. import pinyin from '@/directives/pinyin'
  24. // 置顶
  25. import sticky from '@/directives/sticky'
  26. // 加载更多
  27. import loadMore from '@/directives/load-more'
  28. import { getToken } from '@/utils/auth'
  29. // 通用组件
  30. import '@/components'
  31. // svg 图标
  32. import '@/assets/svg-icons'
  33. // 功能插件
  34. import pluginError from '@/plugins/error'
  35. import pluginLog from '@/plugins/log'
  36. import pluginOpen from '@/plugins/open'
  37. // 平台配置文件
  38. import setting from '@/setting.js'
  39. import env from '@/env'
  40. const BASE_URL = process.env.VUE_APP_BASE_URL
  41. export default {
  42. async install (Vue, options) {
  43. // 设置为 false 以阻止 vue 在启动时生成生产提示。
  44. // https://cn.vuejs.org/v2/api/#productionTip
  45. Vue.config.productionTip = false
  46. // 当前环境
  47. Vue.prototype.$nodeEnv = env.NODE_ENV
  48. // 当前环境变量
  49. Vue.prototype.$env = env
  50. // 当前的 baseUrl 简化代码中 env.VUE_APP_PUBLIC_PATH 取值
  51. Vue.prototype.$baseUrl = env.VUE_APP_PUBLIC_PATH || '/'
  52. // 构建时间
  53. Vue.prototype.$buildTime = env.VUE_APP_BUILD_TIME
  54. Vue.prototype.$ibpsUrl = env.VUE_APP_BASE_API_0_0_TEST
  55. const reportPath = '金通医学实验室管理系统'
  56. // 格式化参数
  57. const getParams = (params) => {
  58. const parts = params.split('&')
  59. const result = []
  60. parts.forEach((item, index) => {
  61. const [key, value] = item.split('=')
  62. // 第一个参数转换=为%3D,后续参数不转换=
  63. if (index === 0) {
  64. result.push(`${key}%3D${encodeURIComponent(value)}`)
  65. } else {
  66. result.push(`${key}=${encodeURIComponent(value)}`)
  67. }
  68. })
  69. return result.join('&')
  70. }
  71. const downloadReport = (src, where, type = 6) => {
  72. // 目前可用type 6:生成报表的pdf文件【默认】 7:生成报表的word文件 3:生成报表的excel文件
  73. return `${BASE_URL}demo/reportServlet?action=${type}&file=${encodeURIComponent(reportPath + '/' + src)}&print=1&srcType=file&paramString=${getParams(where)}`
  74. }
  75. const timer = setInterval(() => { // 定时循环添加参数
  76. if (getToken()) {
  77. // 报表路径
  78. Vue.prototype.$reportPath = `${BASE_URL}demo/reportJsp/showReport.jsp?access_token=${getToken()}&rpx=${reportPath}/`
  79. Vue.prototype.$getReportFile = downloadReport // 通过方法函数,拼接url,并将字符串格式化
  80. Vue.prototype.$getSealUri = 'http://120.77.249.241:9999/no/getSealFile/' // 微签 回显获取文件地址
  81. Vue.prototype.$getFileDow = `${BASE_URL}ibps/platform/v3/file/download?attachmentId=` // 文件下载地址
  82. clearInterval(timer) // 添加成功后即删除定时任务
  83. }
  84. }, 500)
  85. // 获得用户设置的全局尺寸
  86. const size = await store.dispatch('ibps/db/get', {
  87. dbName: 'sys',
  88. path: 'size.value',
  89. defaultValue: setting.system.size,
  90. user: true
  91. })
  92. // 注册Element UI
  93. Vue.use(ElementUI, {
  94. size,
  95. i18n: (key, value) => i18n.t(key, value)
  96. })
  97. // 注册全局过滤器(register global utility filters. )
  98. Object.keys(filters).forEach(key => {
  99. Vue.filter(key, filters[key])
  100. })
  101. // 设置拼音指令
  102. Vue.directive('pinyin', pinyin)
  103. Vue.directive('sticky', sticky)
  104. Vue.directive('load-more', loadMore)
  105. // 插件
  106. Vue.use(pluginError)
  107. Vue.use(pluginLog)
  108. Vue.use(pluginOpen)
  109. // 使用帮助类
  110. Vue.prototype.$utils = Utils
  111. Vue.prototype.$common = common
  112. // 快速打印 log
  113. Vue.prototype.$log = Utils.log
  114. }
  115. }