Vue.config.devtools = 'development'; var MyPlugin = {}; MyPlugin['filters'] = { 9999: function (result) { layer.msg(result.msg, { icon: 0, time: 2e3 }); }, '-1': function (result) { top.window.location.href = fsConfig['global']['loginUrl']; } }; MyPlugin['global'] = { token: sessionStorage.getItem('token'), appId: sessionStorage.getItem('appId'), result: { statusName: 'code', msgName: 'msg', successNo: '0000', dataName: 'data' }, page: { request: { pageName: 'current', limitName: 'size' }, response: { countName: 'data.total', dataNamePage: 'data.records' }, limit: 10, limits: [10, 20, 30, 50, 100] } }; MyPlugin.install = function (Vue, options) { Vue.myGlobalMethod = function () {}; Vue.isEmpty = function (value) { if (value === null || value == undefined || value === '') { return true; } return false; }; Vue.result = function (object, path, defaultValue) { var value = ''; if (!$.isEmpty(object) && $.isObject(object) && !Vue.isEmpty(path)) { var paths = path.split('.'); var length = paths.length; $.each(paths, function (i, v) { object = object[v]; if (length - 1 == i) { value = object; } if (!$.isObject(object)) { return false; } }); } if (Vue.isEmpty(value) && !Vue.isEmpty(defaultValue)) { value = defaultValue; } return value; }; Vue.getQueryString = function (name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; }; Vue.formatDate = function (date, fmt) { if (arguments.length < 2) { fmt = 'yyyy-MM-dd HH:mm:ss'; } var _this = date; var o = { 'M+': _this.getMonth() + 1, 'd+': _this.getDate(), 'h+': _this.getHours() % 12 == 0 ? 12 : _this.getHours() % 12, 'H+': _this.getHours(), 'm+': _this.getMinutes(), 's+': _this.getSeconds(), 'q+': Math.floor((_this.getMonth() + 3) / 3), S: _this.getMilliseconds() }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (_this.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)); } } return fmt; }; Vue.directive('my-directive', {}); Vue.mixin({ created: function () {} }); Vue.prototype.getQueryString = Vue.getQueryString; Vue.prototype.formatDate = Vue.formatDate; Vue.prototype.clickRange = function (value) { var _this = this; _this.query.searchDateType = value; var endDate = new Date(); var beginDate = new Date(); if ('today' == value) { beginDate = new Date(new Date().setDate(new Date().getDate())); } if ('yesterday' == value) { beginDate = new Date(new Date().setDate(new Date().getDate() - 1)); endDate = new Date(new Date().setDate(new Date().getDate() - 1)); } if ('week' == value) { beginDate = new Date(new Date().setDate(new Date().getDate() - 7)); } if ('month' == value) { beginDate = new Date(new Date().setMonth(new Date().getMonth() - 1)); } if ('year' == value) { beginDate = new Date(new Date().setFullYear(new Date().getFullYear() - 1)); } _this.query.beginDate = this.formatDate(beginDate, 'yyyy-MM-dd'); _this.query.endDate = this.formatDate(endDate, 'yyyy-MM-dd'); _this.reload(); }; Vue.prototype.invoke = function (url, param, callBackFunc, method, async) { if (!Vue.isEmpty(url)) { url = Vue.result(MyPlugin, 'global.servletUrl') + url; } if (Vue.isEmpty(async)) { async = true; } if (Vue.isEmpty(method)) { method = 'post'; } var token = sessionStorage.getItem('token'); var appId = sessionStorage.getItem('appId'); $.ajaxSetup({ beforeSend: function (request, settings) { if (token) { request.setRequestHeader('Authorization', token); } if (appId) { request.setRequestHeader('appId', appId); } request.setRequestHeader('resolutionRatio', window.screen.width + '*' + window.screen.height); } }); $.ajax({ url: url, type: method, async: async, timeout: 1e4, data: param, dataType: 'json', success: function (result) { if (result[statusName] != successNo) { var filters = MyPlugin['filters']; if (!Vue.isEmpty(filters)) { var otherFunction = filters[result[statusName]]; if ($.isFunction(otherFunction)) { otherFunction(result); return; } } } callBackFunc(result); }, error: function (XMLHttpRequest, textStatus, errorThrown) { var status = XMLHttpRequest.status; if (status == 404) { fsCommon.errorMsg('请求地址出错!'); } else if (status == 302) { fsCommon.errorMsg('连接网页出错!'); } else if (textStatus == 'timeout') { fsCommon.errorMsg('请求超时!'); } else { fsCommon.errorMsg('请求异常!'); } }, complete: function (XMLHttpRequest, textStatus) {} }); }; }; Vue.use(MyPlugin); var owner = '1581564523'; var token = 'preview'; $.ajaxSetup({ beforeSend: function (request, settings) { request.setRequestHeader('Authorization', token); request.setRequestHeader('owner', owner); } });