traxxx/assets/js/main.js

98 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-02-05 02:50:03 +00:00
import config from 'config';
import { createApp } from 'vue';
import dayjs from 'dayjs';
2020-12-27 03:21:10 +00:00
import mitt from 'mitt';
import router from './router';
import initStore from './store';
import initUiObservers from './ui/observers';
import { formatDate, formatDuration } from './format';
import '../css/style.scss';
import Container from '../components/container/container.vue';
import Icon from '../components/icon/icon.vue';
2020-08-15 17:04:33 +00:00
import Footer from '../components/footer/footer.vue';
import Tooltip from '../components/tooltip/tooltip.vue';
2021-01-03 21:53:51 +00:00
import Dialog from '../components/dialog/dialog.vue';
async function init() {
2021-01-03 21:53:51 +00:00
let uid = 0;
const store = initStore(router);
const app = createApp(Container);
2020-12-27 03:21:10 +00:00
const events = mitt();
function getPath(media, type, options) {
const path = (store.state.ui.sfw && media.assetPath)
|| (media.isS3 && config.media.s3Path)
|| (options?.local && config.media.assetPath)
|| config.media.mediaPath;
const filename = type && !options?.original ? media[type] : media.path;
return `${path}/${filename}`;
}
initUiObservers(store, router);
if (window.env.sfw) {
store.dispatch('setSfw', true);
}
app.use(store);
app.use(router);
await router.isReady();
app.mixin({
components: {
Icon,
2020-08-15 17:04:33 +00:00
Footer,
Tooltip,
'v-popover': Tooltip,
2021-01-03 21:53:51 +00:00
Dialog,
},
2020-12-27 03:21:10 +00:00
data() {
return {
events,
2021-02-05 02:50:03 +00:00
config,
2020-12-27 03:21:10 +00:00
};
},
watch: {
pageTitle(title) {
if (title) {
document.title = `traxxx - ${title}`;
return;
}
document.title = 'traxxx';
},
},
methods: {
formatDate,
formatDuration,
isAfter: (dateA, dateB) => dayjs(dateA).isAfter(dateB),
isBefore: (dateA, dateB) => dayjs(dateA).isBefore(dateB),
getPath,
getBgPath: (media, type) => `url(${getPath(media, type)})`,
},
2021-01-03 21:53:51 +00:00
beforeCreate() {
this.uid = uid;
uid += 1;
},
});
app.directive('tooltip', {
beforeMount(el, binding) {
// console.log(binding.modifiers);
el.title = binding.value; // eslint-disable-line no-param-reassign
},
});
app.mount('#container');
}
init();