import Vue from "vue";
import browser from "@/utils/browser.js";
import rollName from "@/components/rollName";
import clickoutside from "./v-clickoutside";
import clickwindow from "./v-clickwindow";
import errorimg from "./v-errorimg";


let g_CDN = process.env.VUE_APP_STATIC_DIR
let fdkk_CDN = process.env.VUE_APP_CDN



Vue.mixin({
  components: { rollName },
  data() {
    return {
      g_isMobile: browser.mobile,
      g_CDN,
      fdkk_CDN
    };
  },
  directives: {
    clickoutside: clickoutside,
    clickwindow: clickwindow,
    errorimg: errorimg
  },
  methods: {
    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;
    },
    getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      }
      return false;
    },
  },
});
