2022-05-29 22:27:43 +08:00

185 lines
5.4 KiB
JavaScript
Vendored

const isElectron = window && window.process && window.process.type;
const isEEUiApp = window && window.navigator && /eeui/i.test(window.navigator.userAgent);
import './functions/common'
import './functions/eeui'
import './functions/web'
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App.vue'
import routes from './routes'
import VueRouter from 'vue-router'
import VueClipboard from 'vue-clipboard2'
import ViewUI from 'view-design-hi';
import Language from './language/index'
import store from './store/index'
Vue.use(Vuex);
Vue.use(ViewUI, {
modal: {
checkEscClose: true
}
});
Vue.use(VueClipboard);
Vue.use(VueRouter);
Vue.use(Language);
import PageTitle from './components/PageTitle.vue'
import Loading from './components/Loading.vue'
import AutoTip from './components/AutoTip.vue'
import TagInput from './components/TagInput.vue'
import TableAction from './components/TableAction.vue'
import QuickEdit from './components/QuickEdit.vue'
import UserAvatar from './components/UserAvatar.vue'
import ImgView from './components/ImgView.vue'
Vue.component('PageTitle', PageTitle);
Vue.component('Loading', Loading);
Vue.component('AutoTip', AutoTip);
Vue.component('TagInput', TagInput)
Vue.component('TableAction', TableAction);
Vue.component('QuickEdit', QuickEdit);
Vue.component('UserAvatar', UserAvatar);
Vue.component('ImgView', ImgView);
import {
Avatar,
Tooltip,
Popover,
Dropdown,
DropdownMenu,
DropdownItem,
} from 'element-ui';
Vue.component('EAvatar', Avatar);
Vue.component('ETooltip', Tooltip);
Vue.component('EPopover', Popover);
Vue.component('EDropdown', Dropdown);
Vue.component('EDropdownMenu', DropdownMenu);
Vue.component('EDropdownItem', DropdownItem);
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
mode: isElectron || isEEUiApp ? 'hash' : 'history',
routes
});
// 进度条配置
if (!isElectron && !isEEUiApp) {
ViewUI.LoadingBar.config({
color: '#3fcc25',
failedColor: '#ff0000'
});
router.beforeEach((to, from, next) => {
ViewUI.LoadingBar._timer && clearTimeout(ViewUI.LoadingBar._timer)
ViewUI.LoadingBar._timer = setTimeout(_ => {
ViewUI.LoadingBar._load = true;
ViewUI.LoadingBar.start();
}, 300)
next();
});
router.afterEach(() => {
ViewUI.LoadingBar._timer && clearTimeout(ViewUI.LoadingBar._timer)
if (ViewUI.LoadingBar._load === true) {
ViewUI.LoadingBar._load = false;
ViewUI.LoadingBar.finish();
}
});
}
// 加载路由
Vue.prototype.goForward = function(location, isReplace) {
if (typeof location === 'string') {
location = {name: location};
}
if (app.$store.state.routeHistorys.length === 0) {
app.$store.state.routeHistorys.push(app.$route)
}
if (isReplace === true) {
app.$router.replace(location).then(to => {
app.$store.state.routeHistorys.pop();
app.$store.state.routeHistorys.push(to);
}).catch(_ => {});
} else {
app.$router.push(location).then(to => {
const length = app.$store.state.routeHistorys.push(to)
length > 120 && app.$store.state.routeHistorys.splice(length - 100)
app.$store.state.routeHistoryLast = length >= 2 ? app.$store.state.routeHistorys[length - 2] : {};
}).catch(_ => {});
}
};
// 返回路由
Vue.prototype.goBack = function () {
if (app.$store.state.routeHistorys.length > 1) {
app.$router.back();
//
app.$store.state.routeHistorys.pop();
const length = app.$store.state.routeHistorys.length;
app.$store.state.routeHistoryLast = length >= 2 ? app.$store.state.routeHistorys[length - 2] : {};
} else {
app.$router.replace({path: '/'}).catch(_ => {});
app.$store.state.routeHistorys = [];
app.$store.state.routeHistoryLast = {};
}
};
// 全局对象/变量
$A.Electron = null;
$A.Platform = "web";
$A.isMainElectron = false;
$A.isSubElectron = false;
$A.isEEUiApp = isEEUiApp;
$A.isDesktop = $A.isDesktop();
$A.openLog = $A.getStorageString("log::open") === "open";
if (isElectron) {
$A.Electron = electron;
$A.Platform = /macintosh|mac os x/i.test(navigator.userAgent) ? "mac" : "win";
$A.isMainElectron = /\s+MainTaskWindow\//.test(window.navigator.userAgent);
$A.isSubElectron = /\s+SubTaskWindow\//.test(window.navigator.userAgent);
}
Vue.prototype.$A = $A;
Vue.prototype.$Electron = $A.Electron;
Vue.prototype.$Platform = $A.Platform;
Vue.prototype.$isMainElectron = $A.isMainElectron;
Vue.prototype.$isSubElectron = $A.isSubElectron;
Vue.prototype.$isEEUiApp = $A.isEEUiApp;
Vue.prototype.$isDesktop = $A.isDesktop;
Vue.prototype.$openLog = $A.openLog;
Vue.config.productionTip = false;
const app = new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
});
$A.goForward = app.goForward;
$A.goBack = app.goBack;
$A.getLanguage = app.getLanguage;
$A.Message = app.$Message;
$A.Notice = app.$Notice;
$A.Modal = app.$Modal;
$A.store = app.$store;
$A.L = app.$L;
$A.execMainDispatch = (action, data) => {
if ($A.isSubElectron) {
$A.Electron.sendMessage('sendForwardMain', {
channel: 'dispatch',
data: {action, data},
});
}
};