import { getApp } from '@/app'
export default {
    deepExtend: function e(t) {
        t = t || {}
        for (var i = 1; i < arguments.length; i++) {
            var n = arguments[i]
            if (n) for (var r in n) n.hasOwnProperty(r) && ('object' == typeof n[r] ? (t[r] = e(t[r], n[r])) : (t[r] = n[r]))
        }
        return t
    },
    changeUrl(name) {
        if (name.indexOf('http') != -1) {
            return name
        } else {
            if ((typeof name === 'string' && name.substring(0, 4) == 'blob') || (typeof name === 'string' && name.substring(0, 10) == 'data:image')) {
                return name
            } else {
                return getApp().resource.getUserResourceURL(name)
            }
        }
    },
    getRandomSid() {
        //5-7位随机字符串 + 6位时间    为热点准备
        var pre = this.randomWord(true, 5, 7)
        var post = new Date().getTime() + ''
        var len = post.length
        post = post.substring(len - 8, len - 5) + post.substring(len - 3, len) //其实还是有可能重复的....
        return pre + post
    },
    randomWord(randomFlag, min, max) {
        //随机字符串
        var str = '',
            range = min,
            arr = [
                '0',
                '1',
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8',
                '9',
                'a',
                'b',
                'c',
                'd',
                'e',
                'f',
                'g',
                'h',
                'i',
                'j',
                'k',
                'l',
                'm',
                'n',
                'o',
                'p',
                'q',
                'r',
                's',
                't',
                'u',
                'v',
                'w',
                'x',
                'y',
                'z',
                'A',
                'B',
                'C',
                'D',
                'E',
                'F',
                'G',
                'H',
                'I',
                'J',
                'K',
                'L',
                'M',
                'N',
                'O',
                'P',
                'Q',
                'R',
                'S',
                'T',
                'U',
                'V',
                'W',
                'X',
                'Y',
                'Z',
            ]

        if (randomFlag) {
            // 随机长度
            range = Math.round(Math.random() * (max - min)) + min
        }
        for (var i = 0; i < range; i++) {
            var pos = Math.round(Math.random() * (arr.length - 1))
            str += arr[pos]
        }
        return str
    },
    uuid(len, radix) {

        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
    
        var uuid = [], i;
    
        radix = radix || chars.length;
    
     
    
        if (len) {
    
          // Compact form
    
          for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
    
        } else {
    
          // rfc4122, version 4 form
    
          var r;
    
     
    
          // rfc4122 requires these characters
    
          uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    
          uuid[14] = '4';
    
     
    
          // Fill in random data.  At i==19 set the high bits of clock sequence as
    
          // per rfc4122, sec. 4.1.5
    
          for (i = 0; i < 36; i++) {
    
            if (!uuid[i]) {
    
              r = 0 | Math.random()*16;
    
              uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
    
            }
    
          }
    
        }
        return uuid.join('');
    
    }
}
