12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- const qs = require('qs');
- const $ = require("jquery");
- var Utils = require('./rePromise');
- //重写assign方法
- if (typeof Object.assign != 'function') {
- Object.assign = function (target) {
- 'use strict';
- if (target == null) {
- throw new TypeError('Cannot convert undefined or null to object');
- }
- target = Object(target);
- for (var index = 1; index < arguments.length; index++) {
- var source = arguments[index];
- if (source != null) {
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- }
- }
- return target;
- };
- }
- window.console = window.console || (function () {
- var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
- = c.clear = c.exception = c.trace = c.assert = function () { };
- return c;
- })();
- const config = {
- }
- const getUrlArgObject = function getQueryString(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
- var r = window.location.search.substr(1).match(reg);
- var q = window.location.pathname.substr(1).match(reg_rewrite);
- if (r != null) {
- return decodeURIComponent(r[2]);
- } else if (q != null) {
- return decodeURIComponent(q[2]);
- } else {
- return null;
- }
- }
- const post = function (url, data) {
- return new Utils((resolve, reject) => {
- $.ajax({
- method: 'post',
- url: url,
- data: JSON.stringify(data),
- contentType: "application/json; charset=UTF-8",
- beforeSend: function (xmlHttp) {
- xmlHttp.setRequestHeader("If-Modified-Since", "0");
- xmlHttp.setRequestHeader("Cache-Control", "no-cache");
- },
- success: function (res) {
- resolve({ data: res });
- },
- error: function (error) {
- reject(error);
- },
- });
- });
- }
- //判断浏览器是否为Ie8
- const isIe8 = function () {
- var DEFAULT_VERSION = 8.0;
- var ua = navigator.userAgent.toLowerCase();
- var isIE = ua.indexOf("msie") > -1;
- var safariVersion;
- if (isIE) {
- safariVersion = ua.match(/msie ([\d.]+)/)[1];
- }
- if (safariVersion <= DEFAULT_VERSION) {
- return true
- }
- }
- module.exports = {
- config,
- post,
- getUrlArgObject,
- isIe8
- };
|