main.js
3.08 KB
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
119
120
121
122
123
124
125
126
127
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import './assets/js/api'
import './assets/js/common'
import './util/enum'
import 'lodash'
import Vue from 'vue'
import app from './app'
import router from './router'
import moment from 'moment'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
Vue.filter('parseImageSrc', function (value) {
var result = ''
if (value) {
var image = JSON.parse(value)[0]
result = image.file
}
return result
})
Vue.filter('parseImageList', function (value) {
var result = ''
if (value) {
result = JSON.parse(value)
}
return result
})
Vue.filter('enumToDescription', function (value, enumList) {
if (!value) return ''
return _.get(enumList, value)
})
Vue.filter('formatDate', function (value, format) {
if (!value) return ''
if (!format) format = 'YYYY-MM-DD HH:mm:ss'
value = parseInt(value)
return moment(value).format(format)
})
function ajaxFunction(url, type, data, callback) {
$.ajax({
url: url,
type: type,
data: data,
success: callback,
statusCode: {
401: function () {
router.push('/passport/login')
}
}
})
}
Vue.prototype.turnDate = function (time) {
if (time != '' && time != null) {
var d = new Date(time);
var dateTime = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
return dateTime;
} else {
return '';
}
}
//时间控件 选择范围时间
Vue.prototype.formatDate = function (value, format) {
if (!value) return ''
if (!format) format = 'YYYY-MM-DD HH:mm:ss';
return moment(value).format(format);
}
Vue.prototype.ajax = function (obj) {
obj.data = getData(obj.data)
ajaxFunction(obj.url, obj.type, obj.data, obj.success)
}
Vue.prototype.get = function (url, data, callback) {
if (typeof data == 'function') {
callback = data
}
data = getData(data)
ajaxFunction(url, 'GET', data, callback)
}
Vue.prototype.getJSON = function (url, data, callback) {
if (typeof data == 'function') {
callback = data
}
data = getData(data)
ajaxFunction(url, 'GET', data, callback)
}
Vue.prototype.post = function (url, data, callback) {
if (typeof data == 'function') {
callback = data
}
data = getData(data)
ajaxFunction(url, 'POST', data, callback)
}
function getData(data) {
if (window.localStorage.userContext == undefined) return data;
var userContext = JSON.parse(window.localStorage.userContext)
if (data == undefined) {
data = {}
}
if (typeof data == 'string') {
data = data + '&token=' + userContext.token + '&username=' + userContext.adminModel.userName
} else {
data.token = userContext.token
data.username = userContext.adminModel.userName
}
return data
}
/* eslint-disable no-new */
new Vue({
el: '#dk-app',
router,
template: '<app/>',
components: {
app
}
})
import './assets/css/dookayui.min.css'
import './assets/css/common.css'
import './assets/css/ddtv.css'