cheetah-framework
Version:
Cheetah Framework JS used in all our applications
117 lines (90 loc) • 2.53 kB
JavaScript
import Vue from 'vue'
import './bootstrap'
/** Axios */
import './bootstrap/axios'
/** Echo */
import './bootstrap/echo'
/** Vue Router **/
import router from './bootstrap/vueRouter'
/** Vue-i18n **/
import i18n from './i18n'
/** Vuex store **/
import store from './bootstrap/cheetahStore'
/** Load cheetah components */
import './components/bootstrap'
import App from './layouts/App'
import { translatedValue } from './utils/translatedValue'
import Currency from './utils/Currency'
const contentLanguages = _.get(window, 'Cheetah.contentLanguages', [_.get(window, 'Cheetah.locale', 'en')])
const systemLanguages = _.get(window, 'Cheetah.systemLanguages', [_.get(window, 'Cheetah.locale', 'en')])
Vue.prototype.$contentLanguages = contentLanguages
Vue.prototype.$systemLanguages = systemLanguages
Vue.prototype.$translatedValue = translatedValue
Vue.prototype.$formatCurrency = Currency.format
Vue.prototype.$appUrl = _.get(window, 'Cheetah.appUrl', '')
store.commit('Auth/SET_USER', window.Cheetah.user)
import frMessages from 'devextreme/localization/messages/fr.json'
import { locale as DxLocale, loadMessages } from 'devextreme/localization'
loadMessages(frMessages)
const vueConfig = {
i18n,
store,
router,
data () {
return {
windowWidth: window.innerWidth,
windowHeight: window.innerHeight,
locale: _.get(this, 'user.locale', _.get(window, 'Cheetah.locale', 'en'))
}
},
computed: {
logged () {
return this.user !== null
},
user () {
return this.$store.state.Auth.user
}
},
methods: {
updateLocale (lang) {
window.Cheetah.locale = lang
this.locale = lang
i18n.locale = lang
window.moment.locale(lang)
DxLocale(lang)
forceUpdateRecursively(this)
}
},
created () {
window.Cheetah.urlPrefix = _.trimEnd('/' + _.trimStart(window.Cheetah.urlPrefix, '/'), '/')
this.$nextTick(() => {
window.addEventListener('resize', e => {
this.windowWidth = window.innerWidth
this.windowHeight = window.innerHeight
})
})
this.updateLocale(this.locale)
},
render: h => h(App)
}
function forceUpdateRecursively (vm) {
if (vm.$forceUpdate) {
vm.$forceUpdate()
_.map(vm.$children, forceUpdateRecursively)
}
}
class CheetahApp {
static init (vueConfig) {
window.cheetahApp = new Vue(vueConfig)
return window.cheetahApp
}
}
export {
vueConfig,
CheetahApp,
i18n,
router,
translatedValue,
contentLanguages,
systemLanguages
}