main.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import Vue from 'vue'
  2. import 'normalize.css/normalize.css' // A modern alternative to CSS resets
  3. import ElementUI from 'element-ui'
  4. import 'element-ui/lib/theme-chalk/index.css'
  5. import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n zh-CN/en
  6. import '@/styles/index.scss' // global css
  7. import '@/styles/common.scss' // global css
  8. import App from './App'
  9. import store from './store'
  10. import router from './router'
  11. import '@/icons' // icon
  12. import '@/permission' // permission control
  13. import 'echarts-liquidfill'
  14. // 引入富文本编译器
  15. import VueQuillEditor from 'vue-quill-editor'
  16. import 'quill/dist/quill.core.css'
  17. import 'quill/dist/quill.snow.css'
  18. import 'quill/dist/quill.bubble.css'
  19. // 图片放大
  20. import Viewer from 'v-viewer'
  21. import 'viewerjs/dist/viewer.css'
  22. import * as echarts from 'echarts'
  23. import echartsGL from 'echarts-gl' // 引入echarts
  24. import axios from 'axios'
  25. import Qs from 'qs'
  26. import constant from './static/utils/constant.js'
  27. import common from './static/utils/common.js'
  28. import channel from './static/utils/channel.js'
  29. // 全局注册加密工具,使用方法为:this.$md5
  30. import md5 from 'js-md5'
  31. //全局注册
  32. import SearchBar from 'search-bar-vue2'
  33. // 引入第三方字体
  34. import '@/assets/css/font.css'
  35. // 弹窗拖动
  36. import elDragDialog from './dialog'
  37. Vue.use(ElementUI, { locale })
  38. Vue.use(VueQuillEditor)
  39. Vue.use(Viewer, { defaultOptions: {
  40. zIndex: 9999
  41. }})
  42. Vue.prototype.$echarts = echarts
  43. Vue.prototype.$echartsGL = echartsGL // 引入组件(将echarts注册为全局)
  44. // 添加
  45. // const Vue = require('vue')
  46. // const ElementUI = require('element-ui')
  47. // const axios = require('axios')
  48. // const Qs = require('qs')
  49. Vue.config.productionTip = false
  50. Vue.prototype.$axios = axios
  51. Vue.prototype.$qs = Qs
  52. Vue.prototype.$constant = constant
  53. Vue.prototype.$common = common
  54. Vue.prototype.$channel = channel
  55. Vue.prototype.$md5 = md5
  56. Vue.use(SearchBar)
  57. /* 导入Excel组件*/
  58. // import XLSX from 'xlsx'
  59. const XLSX = require('xlsx')
  60. router.beforeEach((to, from, next) => {
  61. if (to.meta.title) {
  62. window.document.title = to.meta.title
  63. next()
  64. } else {
  65. //console.log(to)
  66. let name = '保障房管理系统'
  67. window.document.title = name
  68. next()
  69. }
  70. console.log(new Date())
  71. })
  72. router.afterEach((to, from, next) => {
  73. console.log('你來自哪裏',from.fullPath)
  74. if(from.fullPath=='/lifeline'||from.fullPath=='/lifeLine'||from.fullPath=='/lifeline/supervise'){
  75. // try{
  76. //
  77. // }catch (e) {
  78. //
  79. // }
  80. console.log('我来自/lifeline','请允许通行')
  81. // setTimeout(() => {
  82. // window.location.reload();
  83. //
  84. // }, 100)
  85. }
  86. })
  87. // 使用组件
  88. new Vue({
  89. el: '#app',
  90. router,
  91. store,
  92. render: h => h(App)
  93. })
  94. /* 日期时间格式化*/
  95. Date.prototype.Format = function(fmt) { // author: meizz
  96. var o = {
  97. 'M+': this.getMonth() + 1, // 月份
  98. 'd+': this.getDate(), // 日
  99. 'h+': this.getHours(), // 小时
  100. 'm+': this.getMinutes(), // 分
  101. 's+': this.getSeconds(), // 秒
  102. 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
  103. 'S': this.getMilliseconds() // 毫秒
  104. }
  105. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
  106. for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) }
  107. return fmt
  108. }
  109. /* 数字小数位格式化*/
  110. Number.prototype.FMoney = function(n) {
  111. n = n > 0 && n <= 20 ? n : 2
  112. var s = parseFloat((this + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
  113. var l = s.split('.')[0].split('').reverse()
  114. var r = s.split('.')[1]
  115. var t = ''
  116. for (var i = 0; i < l.length; i++) {
  117. t += l[i] + ((i + 1) % 3 === 0 && (i + 1) !== l.length ? ',' : '')
  118. }
  119. return t.split('').reverse().join('') + '.' + r
  120. }
  121. /* 计算字符串byte长度*/
  122. String.prototype.getByteLen = function() {
  123. var len = 0
  124. for (var i = 0; i < this.length; i++) {
  125. if ((this.charCodeAt(i) & 0xff00) !== 0) { len++ }
  126. len++
  127. }
  128. return len
  129. }
  130. /**
  131. * 导出数据报表xlsx文件
  132. * 已注入所有Vue实例,
  133. * template模板里调用 $$outputXlsxFile
  134. * 组件方法里调用 this.$outputXlsxFile
  135. * 例:this.$outputXlsxFile([['字段1', '字段2'], [1, 2]], [{wch: 10}, {wch: 50}], '测试导出') 得到 测试导出.xlsx 文件
  136. * 第一个参数是导出的数组对象,第二个参数是设置字段宽度,第三个参数是文件名
  137. */
  138. const outputXlsxFile = (data, wscols, xlsxName) => {
  139. /* convert state to workbook */
  140. const ws = XLSX.utils.aoa_to_sheet(data)
  141. ws['!cols'] = wscols
  142. const wb = XLSX.utils.book_new()
  143. XLSX.utils.book_append_sheet(wb, ws, xlsxName)
  144. /* generate file and send to client */
  145. XLSX.writeFile(wb, xlsxName + '.xlsx')
  146. }
  147. Vue.directive('el-drag-dialog', elDragDialog)// 添加标签事件绑定 可以放大移动弹窗
  148. // 弹窗默认点击遮罩改为不关闭 为了防止和拖拽冲突 ,这句需要放在use ElementUI之前(也可以不加这句,自己测试区别)
  149. // ElementUI.Dialog.props.closeOnClickModal.default = false
  150. Vue.prototype.$outputXlsxFile = outputXlsxFile