123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- Array.prototype.indexOf = function (val, property) {
- for (var i = 0; i < this.length; i++) {
- if (!property && this[i] == val) {
- return i;
- } else if (property && this[i][property] == val) {
- return i;
- }
- }
- return -1;
- };
- Array.prototype.remove = function (val, property) {
- if(!(this instanceof Array)){
- return;
- }
- var index = this.indexOf(val, property);
- if (index > -1) {
- this.splice(index, 1);
- }
- };
- Array.prototype.unique = function (arr2) {
- if(!(this instanceof Array)){
- return;
- }
- for (var i = 0; i < this.length; i++) {
- for (var j = 0; j < arr2.length; j++) {
- if (this[i] === arr2[j]) {
- this.splice(i, 1); //利用splice函数删除元素,从第i个位置,截取长度为1的元素
- }
- }
- }
- //alert(arr1.length)
- for (var i = 0; i < arr2.length; i++) {
- this.push(arr2[i]);
- }
- return arr1;
- };
- Array.prototype.array2Obj = function(key, value){
- var obj = {};
- if(this instanceof Array){
- for(var i = 0; i < this.length; i++){
- obj[this[i][key]] = value ? this[i][value] : this[i];
- }
- }
- return obj;
- }
- String.prototype.trim = function() {
- return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
- }
- if (typeof String.prototype.startsWith != 'function') {
- String.prototype.startsWith = function (prefix){
- return this.slice(0, prefix.length) === prefix;
- };
- }
- String.prototype.endWith = function(str){
- if(str == null || str == "" || this.length == 0 || str.length > this.length){
- return false;
- }
- if(this.substring(this.length - str.length) == str){
- return true;
- } else {
- return false;
- }
- return true;
- }
- String.prototype.replaceAll = function(s1, s2){
- return this.replace(new RegExp(s1, "gm"), s2);
- }
- loading = function(type) {
-
- }
- closeLoading = function() {
-
- }
- function shuffle(arr) {
- var length = arr.length, randomIndex, temp;
- while (length) {
- randomIndex = Math.floor(Math.random() * (length--));
- temp = arr[randomIndex];
- arr[randomIndex] = arr[length];
- arr[length] = temp
- }
- return arr;
- }
- function addNum(number1, number2) {
- var n1, n2, m;
- try {
- n1 = number1.toString().split(".")[1].length;
- } catch(e) {
- n1 = 0;
- }
- try {
- n2 = number2.toString().split(".")[1].length;
- } catch(e) {
- n2 = 0;
- }
- m = Math.pow(100, Math.max(n1, n2));
- return (number1 * m + number2 * m) / m;
- }
- function randomNumBoth(min, max){
- var range = max - min;
- var rand = Math.random();
- var num = min + Math.round(rand * range); //四舍五入
- return num;
- }
- const _w = () => {
- return (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth);
- }
- const _h = () => {
- return (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
- }
- const dictsConcatAfterOrder = (arr1 = [], arr2 = [], orderProperty = 'order') => {
- let arr = [].concat(arr2);
- arr1.forEach(item => {
- let index = arr.indexOf(item.value, 'value');
- if (index != -1) {
- arr.splice(index, 1);
- }
- });
- arr = arr1.concat(arr);
-
- if (orderProperty) {
- arr.sort((a, b) => {
- return a[orderProperty] - b[orderProperty];
- })
- } else {
- arr.sort((a, b) => {
- return a - b;
- })
- }
- return arr;
- }
- const getQuery = 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;
- }
|