main.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import Vue from 'vue'
  2. import axios from 'axios'
  3. import NP from 'number-precision'
  4. import ElementUI from 'element-ui'
  5. import '@/assets/css/index.css'
  6. import '@/styles/element-ui.scss'
  7. /*
  8. import '@/styles/index.scss'
  9. */
  10. import '@/styles/theme.scss'
  11. import elementUIVerify from '@/utils/elementUIVerify'
  12. import ECharts from 'vue-echarts/components/ECharts.vue'
  13. import 'echarts/lib/chart/bar'
  14. import 'echarts/lib/chart/pie'
  15. import 'echarts/lib/chart/line'
  16. import 'echarts/lib/component/tooltip'
  17. import 'echarts/lib/component/toolbox'
  18. import 'echarts/lib/component/polar'
  19. import 'echarts/lib/component/geo'
  20. import 'echarts/lib/component/legend'
  21. import 'echarts/lib/component/title'
  22. import 'echarts/lib/component/visualMap'
  23. import 'echarts/lib/component/dataset'
  24. import 'echarts/lib/component/axis'
  25. import VueQriously from 'vue-qriously'
  26. import Print from '@/utils/print'
  27. import Clipboard from 'v-clipboard'
  28. import '@/icons' // icon
  29. import App from './App'
  30. import router from './router'
  31. import store from './store'
  32. import * as filters from './filters' // global filters
  33. import '@/permission' // permission control
  34. import printPage from '@/utils/printPage'
  35. import VueScrollTo from 'vue-scrollto'
  36. import GlobalComponents from '@/components/GlobalComponents'
  37. // string 原型方法修改
  38. import '@/utils/posUtils/string'
  39. import VueKonva from 'vue-konva'
  40. import agencyName from '@/utils/agencyName'
  41. // 红色雷锋侧边栏
  42. if (process.env.VUE_APP_PROJECT === 'leifengjinianguan') {
  43. import('@/styles/project/leifeng/index.scss')
  44. } else {
  45. import('@/styles/index.scss')
  46. }
  47. Vue.use(VueKonva)
  48. // import * as faceapi from 'face-api.js'
  49. faceapi.env.monkeyPatch({
  50. Canvas: HTMLCanvasElement,
  51. Image: HTMLImageElement,
  52. ImageData: ImageData,
  53. Video: HTMLVideoElement,
  54. createCanvasElement: () => document.createElement('canvas'),
  55. createImageElement: () => document.createElement('img')
  56. })
  57. Vue.use(GlobalComponents)
  58. Vue.use(VueScrollTo)
  59. Vue.http = Vue.prototype.$http = axios
  60. Vue.NP = Vue.prototype.$NP = NP
  61. Vue.config.productionTip = false
  62. Vue.use(ElementUI, { size: 'small' })
  63. Vue.use(elementUIVerify)
  64. Vue.use(Clipboard)
  65. Vue.component('v-chart', ECharts)
  66. const log = require('electron-log')
  67. log.transports.console.level = 'silly'
  68. log.transports.file.maxSize = 15 * 1024 * 1024
  69. const Store = require('electron-store')
  70. const localStore = new Store()
  71. // 避免在配置页无法打开配置文件
  72. localStore.set('init', true)
  73. console.log(localStore.get('appName'), process.env.VUE_APP_PROJECT_NAME)
  74. document.title = localStore.get('appName') || process.env.VUE_APP_PROJECT_NAME
  75. // 本地存储
  76. Vue.localStore = Vue.prototype.$localStore = localStore
  77. // 日志收集
  78. Vue.log = Vue.prototype.$log = log
  79. // 与旧版本本地存储做兼容,防止数据丢失
  80. setLocalStoreFromlocalStorage()
  81. // 打印
  82. Vue.use(Print)
  83. // 二维码
  84. Vue.use(VueQriously)
  85. // Vue.component('v-chart', ECharts)
  86. // register global utility filters.
  87. Object.keys(filters).forEach(key => {
  88. Vue.filter(key, filters[key])
  89. })
  90. // 是否存在定制logo
  91. const fs = require('fs')
  92. const userDataFolder = require('electron').remote.app.getPath('userData')
  93. const logoPath = require('path').join(userDataFolder, 'logo.png')
  94. fs.stat(logoPath, (err, stats) => {
  95. if (err) {
  96. console.log(err)
  97. return
  98. }
  99. store.commit('SET_CUSTOM_LOGO', 'file://' + logoPath)
  100. })
  101. Vue.mixin({
  102. data () {
  103. return {
  104. colorPalette: [
  105. '#74a275', '#3b5069', '#b39a57', '#2987db', '#f49e43',
  106. '#785012', '#805ebe', '#204e55', '#c0c21f', '#9f3d3f', '#cf7d39', '#d7c0c3', '#06315b', '#97b3a1', '#f8e71c', '#d4578a', '#72ce84', '#e93d35'
  107. ]
  108. }
  109. },
  110. computed: {
  111. // 售票电脑ip、mac信息
  112. sellerDevice () {
  113. return this.$store.state.app.sellerDevice
  114. },
  115. pagePermission () {
  116. return this.$route.meta.permissionList
  117. },
  118. printType () {
  119. return this.$store.state.app.localConfig && this.$store.state.app.localConfig.printType
  120. },
  121. transformUrl () {
  122. const value = this.$store.state.app.systemConfig.find(i => i.config_key === 'reportfile_url_serverip_replace').config_value
  123. console.log('reportfile_url_serverip_replace', value, typeof value)
  124. return value === '1'
  125. }
  126. },
  127. methods: {
  128. agencyName,
  129. checkPermission (type) {
  130. return this.pagePermission.indexOf(type) !== -1 || this.pagePermission.indexOf('all') !== -1
  131. },
  132. goToDownload () {
  133. this.$confirm('报表已导出,是否跳转到报表下载页?', '提示', {
  134. confirmButtonText: '确定',
  135. cancelButtonText: '取消',
  136. type: 'warning'
  137. }).then(() => {
  138. this.$router.push('/queryReport/reportExport')
  139. }).catch(() => {
  140. })
  141. },
  142. // 下载excel
  143. downloadFile (url) {
  144. return axios.get(url, {
  145. responseType: 'arraybuffer'
  146. }).then(res => {
  147. const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
  148. const link = document.createElement('a')
  149. link.href = window.URL.createObjectURL(blob)
  150. link.download = url.split('/').pop()
  151. link.click()
  152. }).catch(e => {
  153. this.$message.error(`${url}下载失败:${e}`)
  154. })
  155. },
  156. downloadExport (data) {
  157. if (!data.download_url) {
  158. this.$message.error('暂无下载地址')
  159. return
  160. }
  161. let url = ''
  162. if (this.transformUrl) {
  163. const urlObj = new URL(data.download_url)
  164. const localObj = new URL(this.$localStore.get('serverUrl'))
  165. // const localObj = new URL('http://pdev.cleartv.cn:12')
  166. console.log(localObj)
  167. // 主机地址一样,则不进行替换
  168. if (urlObj.hostname === localObj.hostname) {
  169. url = data.download_url
  170. } else {
  171. urlObj.hostname = localObj.hostname
  172. urlObj.protocol = localObj.protocol
  173. urlObj.port = localObj.port || '80'
  174. url = urlObj.href
  175. }
  176. } else {
  177. url = data.download_url
  178. }
  179. console.log('下载地址', url)
  180. this.downloadFile(url)
  181. },
  182. printPage
  183. }
  184. })
  185. const { ipcRenderer } = require('electron')
  186. ipcRenderer.removeAllListeners('message')
  187. ipcRenderer.on('message', (event, { message, data }) => {
  188. switch (message) {
  189. case 'downloadProgress':
  190. // console.log('下载进度', data)
  191. store.dispatch('updateApp', {
  192. status: 0,
  193. process: Math.floor(data.percent)
  194. })
  195. break
  196. case 'update-available':
  197. console.log('有可用更新')
  198. break
  199. case 'update-not-available':
  200. console.log('无可用更新')
  201. store.dispatch('updateApp', {
  202. status: 1,
  203. process: 0
  204. })
  205. break
  206. case 'isUpdateNow':
  207. store.dispatch('updateApp', {
  208. status: 2,
  209. process: 0
  210. })
  211. break
  212. default:
  213. // console.log(message, data)
  214. break
  215. }
  216. })
  217. new Vue({
  218. router,
  219. store,
  220. render: h => h(App)
  221. }).$mount('#app')
  222. // 兼容处理
  223. function setLocalStoreFromlocalStorage () {
  224. let { serverUrl, updateUrl, defaultPrinter, defaultTemplate, autoPrint } = localStorage
  225. serverUrl && localStore.set('serverUrl', serverUrl)
  226. updateUrl && localStore.set('updateUrl', updateUrl)
  227. defaultPrinter && localStore.set('defaultPrinter', defaultPrinter)
  228. defaultTemplate && localStore.set('defaultTemplate', defaultTemplate - 0)
  229. autoPrint && localStore.set('autoPrint', !!(autoPrint - 0))
  230. // 清除原纪录,切换到config.json来保存数据
  231. localStorage.clear()
  232. }