zhgdyun/src/pages/index/index.js
2024-02-29 19:28:07 +08:00

358 lines
9.7 KiB
JavaScript

import Vue from 'vue'
import App from './index.vue'
import router from '@/router/index'
import VueMatomo from 'vue-matomo'
import store from '@/store'
import '@/plugins/element.js'
import vuescroll from 'vuescroll'
import uploader from 'vue-simple-uploader'
import i18n from '@/assets/i18n/i18n'
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import * as filters from '@/filters/index.js'
import '@/assets/iconfont/iconfont.css'
import '@/assets/style/layout.less'
import '@/assets/style/button.less'
import '@/assets/style/table.less'
import '@/assets/style/dialog.less'
import '@/assets/style/pagination.less'
import axios from 'axios'
import { Message } from 'element-ui'
import Pagination from '@/components/Pagination'
import { resetForm } from '@/util'
import { autoLogin } from '@/assets/js/api/autoLogin-xingXuan'
import { decode, encode } from 'js-base64'
import {
loginApi,
companyLoginApi,
projectLoginApi,
} from '@/assets/js/api/loginSign'
import SlideVerify from 'vue-monoplasty-slide-verify' //滑动验证
import VueAwesomeSwiper from 'vue-awesome-swiper'
import scroll from 'vue-seamless-scroll'
Vue.use(scroll)
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
const hls = require('videojs-contrib-hls')
Vue.use(hls)
Vue.use(VueQuillEditor) // 注册富文本编辑器
Vue.use(SlideVerify)
Vue.use(VueAwesomeSwiper)
// 全局组件挂载
Vue.component('Pagination', Pagination)
// 全局方法挂载
Vue.prototype.resetForm = resetForm
if (COMPANY == 'xingxuan') {
if (window.location.href.indexOf('?project_id=') != -1) {
const projectId = window.location.href
.split('?project_id=')[1]
.split('&')[0]
login(projectId)
}
function login(projectNumber) {
autoLogin({ projectNumber }).then((res) => {
if (res.code != 200) return
parseLoginData(res.result)
})
}
function parseLoginData(data) {
window._paq.push(['trackEvent', '点击', '登录', '登录账号'])
axios.defaults.headers.common['Authorization'] = 'Bearer' + ' ' + data.token
axios.defaults.headers.common['operateId'] = data.userId
store.commit('setUserInfo', data)
var moduleList = data.menuAuthority.moduleList
? data.menuAuthority.moduleList
: []
var companyModule = []
var projectModule = []
if (moduleList.length == 0 && data.accountType != 1) {
Message.warning('当前账号还没分配权限')
return false
}
moduleList.forEach((element) => {
if (element.moduleType == 1) {
companyModule.push(element)
}
if (element.moduleType == 5) {
projectModule.push(element)
}
})
var menu2 = [
{
menuName: '企业管理',
id: 9199,
path: '/registerAudit',
},
{
menuName: '模块菜单管理',
id: 9299,
path: '/moduleMenuManage',
},
{
menuName: 'app版本管理',
id: 9297,
path: '/operateManage',
},
{
menuName: '字典管理',
id: 9298,
path: '/dictionaryManaged'
},
{
menuName: '塔吊模型管理',
id: 9299,
path: '/brand'
}
]
switch (data.accountType) {
case 1:
store.commit('setMenuList', menu2)
store.commit('setProjectManageMenuList', menu2)
store.commit('setIsShowBackIndex', false)
router.push('/registerAudit')
break
case 2:
case 3:
case 4:
case 7:
store.commit('setMenuList', companyModule)
store.commit('setProjectManageMenuList', companyModule)
store.commit('setIsShowBackIndex', false)
console.log('跳转路由', companyModule[0].modulePath)
router.push(companyModule[0].modulePath)
break
case 5:
store.commit('setMenuList', projectModule)
store.commit('setProjectManageMenuList', projectModule)
store.commit('setIsShowBackIndex', false)
store.commit('setProjectSn', data.sn)
router.push(projectModule[0].modulePath)
break
case 6:
store.commit('setProjectSn', data.sn)
break
}
}
}
function handler(data, sn) {
console.log(data + sn, 'dllmhjc')
console.log(sn, 'dllmhjc -- sn')
window._paq.push(['trackEvent', '点击', '登录', '登录账号'])
axios.defaults.headers.common['Authorization'] = 'Bearer' + ' ' + data.token
axios.defaults.headers.common['operateId'] = data.userId
store.commit('setProjectSn', sn)
store.commit('setUserInfo', data)
var moduleList = data.menuAuthority.moduleList
? data.menuAuthority.moduleList
: []
var companyModule = []
var projectModule = []
if (moduleList.length == 0 && data.accountType != 1) {
return false
}
moduleList.forEach((element) => {
if (element.moduleType == 1) {
companyModule.push(element)
}
if (element.moduleType == 5) {
projectModule.push(element)
}
})
var 菜单 = [
{ menuName: '企业管理', id: 9199, path: '/registerAudit' },
{ menuName: '模块菜单管理', id: 9299, path: '/moduleMenuManage' },
{ menuName: 'app版本管理', id: 9297, path: '/operateManage' },
{ menuName: '塔吊模型管理', id: 9298, path: '/brand' },
]
switch (data.accountType) {
case 1:
store.commit('setMenuList', 菜单)
store.commit('setProjectManageMenuList', 菜单)
store.commit('setIsShowBackIndex', false)
router.push('/registerAudit')
break
case 2:
case 3:
case 4:
case 7:
store.commit('setMenuList', companyModule)
store.commit('setProjectManageMenuList', companyModule)
store.commit('setIsShowBackIndex', false)
router.push(companyModule[0].modulePath)
store.commit('setProjectSn', sn)
break
case 5:
case 6:
store.commit('setMenuList', projectModule)
store.commit('setProjectManageMenuList', projectModule)
store.commit('setIsShowBackIndex', false)
if (PROJECT_TYPE != 'zjsj') {
//看看项目看板内有没有菜单
let arr = data.menuAuthority.moduleList
let arr2 = []
arr.forEach((element) => {
if (element.moduleType == 4) {
arr2.push(element)
return
}
})
console.log('arr2', arr2)
// 如果数组为空表示该用户没有权限访问
if (!arr2.length) {
router.push('/projectIndex')
} else {
router.push(arr2[0].modulePath)
}
} else {
if ((data.styleType != 2 && data.styleType != 3) || !data.styleType) {
router.push('/projectIndex')
} else if (data.styleType == 2) {
router.push('/projectV2/taskList')
} else {
router.push('/projectV3/taskList')
}
store.commit('setProjectSn', data.sn)
break
}
}
// this.selectMp3FileList()
}
let url = ''
console.log(COMPANY)
if (COMPANY == 'longguang') {
url = 'http://matomo.logan.com.cn'
}
Vue.use(VueMatomo, {
// url http://matomo-sit.logan.com.cn/index.php测试地址
host: 'http://matomo.logan.com.cn', //生产
// host:'http://matomo-sit.logan.com.cn', //测试
// host:url,
siteId: 47,
router: router,
requireConsent: false,
enbleLinkTracking: true,
trackInitialView: true,
disableCookies: false,
requireCookieConsent: false,
enableHeartBeatTimer: true,
heartBeatTimerInterval: 15,
userId: '',
trackerFileName: 'matomo',
trackerUrl: undefined,
trackerScriptUrl: undefined,
debug: true,
})
Vue.use(preview)
Vue.use(uploader)
Vue.prototype.$EventBus = new Vue()
Object.keys(filters).forEach((key) => {
Vue.filter(key, filters[key])
})
Vue.config.productionTip = false
Vue.use(vuescroll, {
ops: {
bar: {
background: 'rgba(166, 166, 167, 0.6)',
onlyShowBarOnScroll: false,
size: '5px',
minSize: 0.2,
},
},
})
// 加载缩略图
Vue.prototype.downloadImgMin = function(row) {
let fileUrl = store.state.FILEURL + row.fileUrl
return fileUrl
}
//获取文件下载路径
Vue.prototype.getDownloadFilePath = function(row) {
let fileUrl = store.state.FILEURL + row.fileUrl
return fileUrl
}
//文件查看大图
Vue.prototype.getViewFilePath = function(row) {
let fileUrl = store.state.FILEURL + row.fileUrl
return fileUrl
}
//路由监听
router.beforeEach((to, form, next) => {
const whitepage = [
'/authentication',
'/test',
'/videoLearning',
'/pages/projectEnd/safetyEducation/authentication',
'/companyAdmin/docManage',
]
console.log('白名单跳转生效了嘛==============11111111111 :', to)
if (whitepage.includes(to.path)) {
console.log('白名单跳转生效了嘛==============')
return next()
}
const direction = to.query.direction
console.log('跳转', direction)
if (direction) {
const info = JSON.parse(decode(direction))
const account = { account: info.acount, password: info.pwd }
const tentative = (res) => {
console.log('res-----', res)
handler(res.result, info.projectSn)
return next({ path: to.path })
}
if (LOGINTYPE == 1) {
loginApi(account).then(tentative)
} else if (LOGINTYPE == 2) {
companyLoginApi(account).then(tentative)
} else if (LOGINTYPE == 3) {
projectLoginApi(account).then(tentative)
}
} else {
if (COMPANY == 'xingxuan') return next()
if (store.state.userInfo) {
next()
} else if (
!store.state.userInfo &&
to.path != '/login' &&
to.path != '/' &&
to.path != '/sign' &&
!isDockingToWoer &&
to.path != '/authorization'
) {
next({ path: '/' })
} else {
next()
}
}
})
// Vue.prototype.$EventBus = new Vue()
new Vue({
router,
store,
i18n,
render: (h) => h(App),
}).$mount('#app')