// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
// import Vue from "vue/dist/vue.common.js";
import { API } from "../src/axios/api/index.js";
Vue.prototype.$API = API;
import App from "./App";
import router from "./router";
import utils from "./utils/util";
import filters from "./filters/index";
import directives from "./directives/index";
import store from "./store/index.js";
import wx from "weixin-js-sdk";
import Scroll from "vue-slim-better-scroll";
import Vant from "vant";
import "vant/lib/index.css";
import "vant/lib/index.less";
import "../src/styles/vantTheme.less";

import 'video.js/dist/video-js.min.css'

import clipboard from "clipboard";
Vue.prototype.clipboard = clipboard;
Vue.use(Scroll);
Vue.use(Vant);
import { MessageBox, Toast, Indicator } from "mint-ui";
//Vue.prototype.$message = Toast({duration:1000});

Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;

// 全局注册自定义组件
import VContent from "./components/common/content";
import VFooter from "./components/common/footer";
Vue.use(VContent);
Vue.use(VFooter);

Vue.use(wx);
import {
  ToastPlugin,
  XButton,
  XHeader,
  Cell,
  CellBox,
  Tab,
  TabItem,
  ViewBox,
  PopupRadio,
  Group,
  XTextarea,
  Panel,
  Scroller,
  XInput,
  Tabbar,
  TabbarItem,
  Sticky,
  XSwitch,
  Selector,
  Box,
  LoadingPlugin,
  FormPreview,
  DatetimeRange,
  ConfirmPlugin,
  Confirm,
  CheckIcon,
  Popup,
  Radio,
  PopupHeader,
  PopupPicker,
  XAddress,
  Datetime,
  Flow,
  FlowState,
  FlowLine,
  Popover,
  TransferDom,
  XDialog,
  Flexbox,
  FlexboxItem,
  Qrcode,
  Swiper,
  SwiperItem,
  Search,
  Marquee,
  MarqueeItem,
} from "vux";

import FastClick from "fastclick"; //使用 fastclick 解决移动端 300ms 点击延迟
FastClick.attach(document.body);
FastClick.prototype.focus = function (targetElement) {
  var length;

  var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
  var deviceIsIOS =
    /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
  //兼容处理:在iOS7中，有一些元素（如date、datetime、month等）在setSelectionRange会出现TypeError
  //这是因为这些元素并没有selectionStart和selectionEnd的整型数字属性，所以一旦引用就会报错，因此排除这些属性才使用setSelectionRange方法
  try {
    if (
      deviceIsIOS &&
      targetElement.setSelectionRange &&
      targetElement.type.indexOf("date") !== 0 &&
      targetElement.type !== "time" &&
      targetElement.type !== "month" &&
      targetElement.type !== "email"
    ) {
      length = targetElement.value.length;
      targetElement.setSelectionRange(length, length); //修复bug ios 11.3不弹出键盘，这里加上聚焦代码，让其强制聚焦弹出键盘
      targetElement.focus();
    } else {
      targetElement.focus();
    }
  } catch (error) {
    console.warn(error);
  }
};
if (/Android [4-6]/.test(navigator.appVersion)) {
  window.addEventListener("resize", function () {
    if (
      document.activeElement.tagName == "INPUT" ||
      document.activeElement.tagName == "TEXTAREA"
    ) {
      window.setTimeout(function () {
        document.activeElement.scrollIntoViewIfNeeded();
      }, 0);
    }
  });
}

Vue.component("x-button", XButton);
Vue.component("x-header", XHeader);
Vue.component("cell", Cell);
Vue.component("cell-box", CellBox);
Vue.component("tab", Tab);
Vue.component("tab-item", TabItem);
Vue.component("view-box", ViewBox);
Vue.component("popup-radio", PopupRadio);
Vue.component("group", Group);
Vue.component("x-textarea", XTextarea);
Vue.component("panel", Panel);
Vue.component("popup-picker", PopupPicker);
Vue.component("scroller", Scroller);
Vue.component("x-input", XInput);
Vue.component("tabbar", Tabbar);
Vue.component("tabbar-item", TabbarItem);
Vue.component("sticky", Sticky);
Vue.component("x-switch", XSwitch);
Vue.component("selector", Selector);
Vue.component("box", Box);
Vue.component("form-preview", FormPreview);
Vue.component("datetime-range", DatetimeRange);
Vue.component("confirm", Confirm);
Vue.component("check-icon", CheckIcon);
Vue.component("popup", Popup);
Vue.component("radio", Radio);
Vue.component("popup-header", PopupHeader);
Vue.component("x-address", XAddress);
Vue.component("datetime", Datetime);
Vue.component("flow", Flow);
Vue.component("flow-state", FlowState);
Vue.component("flow-line", FlowLine);
Vue.component("popover", Popover);
Vue.directive("transfer-dom", TransferDom);
Vue.component("x-dialog", XDialog);
Vue.component("flexbox", Flexbox);
Vue.component("flexbox-item", FlexboxItem);
Vue.component("qrcode", Qrcode);
Vue.component("swiper", Swiper);
Vue.component("SwiperItem", SwiperItem);
Vue.component("search", Search);
Vue.component("marquee", Marquee);
Vue.component("marquee-item", MarqueeItem);
Vue.config.productionTip = false;
Vue.use(utils);
Vue.use(filters);
Vue.use(directives);
Vue.use(LoadingPlugin);
Vue.use(ToastPlugin);
Vue.use(ConfirmPlugin);
import "mint-ui/lib/style.css";
import "./assets/css/my-mint.scss"; //全局修改mint-UI样式
import VueLazyload from "vue-lazyload";
Vue.use(VueLazyload);
new Vue({
  el: "#app",
  router,
  store,
  wx,
  render: (h) => h(App),
});
