-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
118 lines (102 loc) · 2.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import Vue from 'vue';
import Router from 'vue-router';
import lodash from 'async-dash';
import axios from 'axios';
import moment from 'moment';
import numeral from 'numeral';
import * as SocketIO from 'socket.io-client';
import globalData from './mixins/globalData';
import App from './components/App.vue';
import * as views from './views';
import initUiComponents from './uiComponents';
import initUiMixins from './uiMixins.js';
Vue.config.productionTip = false;
Vue.use(Router);
const _ = lodash;
/**
* @typedef {Object} RouteItem
* @property {string} path
* @property {string} name
* @property {Object} component
* @property {RouteItem[]} children
*/
/**
* @param params
* @param {RouteItem[]} params.routes
* @param {ComponentsConfig} params.componentsConfig
* @param {Object} params.store
*/
function main(uParams = {}) {
const params = {
extVue: {},
routerMode: 'history',
...uParams,
};
window._ = _;
window.axios = axios;
initUiComponents(Vue, {
componentsConfig: params.componentsConfig || {},
});
initUiMixins();
const router = new Router({
mode: params.routerMode,
base: process.env.BASE_URL,
routes: [
{
path: '/',
component: App,
children: [
...(params.routes || []),
{
path: '*',
name: 'Miss',
component: views.ErrorView,
},
],
},
],
});
new Vue({
router,
render: h => h(App),
store: params.store,
...params.extVue,
}).$mount('#app');
}
const G = globalData.methods.G;
const formatPrice = (value, format = '0,0.00') => numeral(value).format(format);
const formatDateTime = (value, format = 'YYYY-MM-DD HH:mm:ss') =>
moment(value).format(format);
const containsText = (text, keyword) => {
return (
String(text)
.toLowerCase()
.indexOf(
String(keyword || '')
.trim()
.toLowerCase(),
) !== -1
);
};
const flattenedValues = obj => {
if (typeof obj !== 'object') {
return obj;
}
return _.flattenDeep(_.map(obj, item => flattenedValues(item)));
};
export {
Vue,
_,
lodash,
axios,
moment,
numeral,
main,
views,
G,
SocketIO,
formatPrice,
formatDateTime,
containsText,
flattenedValues,
};