main.js
6.9 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import Vue from "vue";
import App from "./App.vue";
import router from "./router/index";
//ElementUI 地址:https://element.eleme.io/#/zh-CN/guide/design
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);
import HHVideo from './components/HHVideo.vue';
Vue.component('HhVideo', HHVideo);
import { Message } from 'element-ui'
// 挂载到$message上 Message.error(txt)
Vue.prototype.$message = Message
// http://momentjs.cn/ 日期处理组件 获取当前月初、月末、时间区间段 等
import moment from "moment"
Vue.prototype.$moment = moment;
//ajax 实现异步请求的技术
import axios from "axios";
// 挂载到vue的全局(原型上),在每个组件都可以使用 ,prototype是固定的,$axios是自定义的
Vue.prototype.$axios = axios;
//dataV 地址:http://datav.jiaminghi.com/
import dataV from "@jiaminghi/data-view";
Vue.use(dataV);
//vue-seamless-scroll简单无缝滚动组件 目前基本上使用少,使用datav轮播居多
//https://chenxuan0000.github.io/vue-seamless-scroll/zh/guide/01-basic.html
import scroll from "vue-seamless-scroll";
Vue.use(scroll);
//echarts 地址:https://echarts.apache.org/zh/index.html this.$echarts(opt)
import echarts from "echarts";
Vue.prototype.$echarts = echarts;
//【线下地址 根据业务修改 电视机上调试需要使用自身电脑真实IP】
Vue.prototype.baseUrlOff = "http://127.0.0.1:6001/";
//【根据实际需求 项目可能有多个不同的接口地址、默认值不要改】
Vue.prototype.baseUrlOnLine = window.appConfig.baseUrlOnLine;
Vue.prototype.baseUrlOnLine2 = window.appConfig.baseUrlOnLine2;
Vue.prototype.baseUrlOnLine3 = window.appConfig.baseUrlOnLine3;
Vue.prototype.baseUrlOnLine4 = window.appConfig.baseUrlOnLine4;
Vue.prototype.baseUrlOnLine5 = window.appConfig.baseUrlOnLine5;
Vue.prototype.baseUrlOnLine6 = window.appConfig.baseUrlOnLine6;
// 更新头部时间并刷新页面
let eleHeadTime = null;
String.prototype.ajaxSuccessActionLoad = function (res) {
let timestamp = res.data["timestamp"]
if (!timestamp) {
Message.error({
message: "接口API 不存在【timestamp】字段属性,请核实接口字段信息",
duration: 5000
});
return;
}
let nowDateVal = moment(timestamp).format("YYYY-MM-DD")
if (nowDateVal.indexOf("1970") > -1) nowDateVal = moment.unix(timestamp).format("YYYY-MM-DD")
if (eleHeadTime == null) {
eleHeadTime = document.querySelector('#head_time')
}
let val = eleHeadTime.innerText;
if (val != nowDateVal && val != '') {
window.location.reload()
}
eleHeadTime.innerText = nowDateVal
};
//ajax 数据返回判断
String.prototype.ajaxSuccessBefore = function (result, logTitle) {
"".Log(result, logTitle)
let isOk = false;
let txt = "";
if (typeof result.data.code != "undefined" && result.data.code == 401) {
txt = `Tokens失效请重新登入<br>地址:【${result.config.url}】`;
isOk = true;
} else if (typeof result.data.code != "undefined" && result.status != 200 || result.status == 500) {
txt = `本页数据请求成功之后存在错误 :【${JSON.stringify(result.data)}】
<br>地址【${result.config.url}】
<br>请求方式【${result.config.method}】
<br>参数【${JSON.stringify(result.config.data || {})}】
<br>httpCode【${result.status}】
<br><br>服务器api接口请求数据出现异常,点击任意空白处继续或刷新浏览器,问题频繁出现请联系管理员!`;
isOk = true;
}
if (isOk) {
Message.error({
message: txt,
dangerouslyUseHTMLString: true,// 允许使用 HTML
duration: 5000
});
}
return isOk;
};
//ajax 错误提示 ElementUI
//其他页面使用案例: this.$alert(msg, "提示", { dangerouslyUseHTMLString: true })
String.prototype.ajaxError = function (result, url) {
try {
var msg = result.toString();
if (msg.indexOf("SyntaxError") > -1) {
let txt = `本页中存在JavaScript语法错误,请开发者仔细核实!
<br><br>错误信息【${msg}】
<br><br>URL【${url}】`;
Message.error({
message: txt,
dangerouslyUseHTMLString: true,
duration: 5000
});
return false;
}
} catch (error) { }
var types = typeof result.code;
const status = types == "undefined" ? 501 : result.response.status;
var txt = `本页中存在错误
<br>URL【${url}】
<br>httpCode【${status},${result.message}】
<br><br>您访问的接口资源可能不存在,或者不支持跨域,请检查Url地址是否正确, 使用postman核实一下,反复出现请联系接口管理员! <br>`;
if (typeof result.message != "undefined") {
"".Log(result, "JS内部方法异常")
"".Log(txt, "JS错误信息")
if (status == 501) {
txt += "<h2 style='color: red;>【JS内部错误!】</h2>";
}
Message.error({
message: txt,
dangerouslyUseHTMLString: true,// 允许使用 HTML
duration: 5000
});
return false;
}
"".Log(result, "ajaxError")
switch (status) {
case 404:
txt += "<h2 style='color: red;'>【您访问的接口资源不存在,请检查Url地址是否正确!】</h2>";
break;
case 500:
txt += "<h2 style='color: red;>【服务器内存API出现异常,反复出现请联系接口管理员!】</h2>";
break;
case 0:
txt +=
"<h2 style='color: red;'>【您访问的接口不支持跨域或者接口资源不存在,请联系接口管理员!】</h2>";
break;
default:
txt +=
"<h2 style='color: red;>【您访问的接口资源可能不存在,或者不支持跨域,请检查Url地址是否正确,反复出现请联系接口管理员!】</h2>";
break;
}
if (status != 501) {
if (result.code == "ECONNABORTED" && result.message.indexOf("timeout") != -1) {
txt +=
"<h2 style='color: red;>【服务器响应超时,反复出现请联系接口管理员优化接口响应时间!】</h2>";
}
}
if (status == 501) {
txt += "<h2 style='color: red;>【JS内部错误!】</h2>";
}
"".Log(txt, "ajaxError")
Message.error({
message: txt,
dangerouslyUseHTMLString: true,// 允许使用 HTML
duration: 5000
});
};
//【发布】 编译的时候改成 false
Vue.config.productionTip = false;
//【baseOnLineOrOff true 线上 false 线上】
window.baseOnLineOrOff = true
if (process.env.NODE_ENV === "development") window.baseOnLineOrOff = false
new Vue({
router,
render: h => h(App),
}).$mount("#app");