import config from './config.js';
import VueI18n from 'vue-i18n';
let VueTouch = require('vue-touch');
Vue.use(VueTouch);

import ugenComponents from 'ugen-components';
let uComponents = ugenComponents.uComponents;
import projectComponents from './manage';

const iot = new UIOT({
    lang: ['zh', 'en'],
    vue: Vue,
    i18n: VueI18n,
    appId: '10003',
    wx: {
        appId: ''
    },
    cloud: {
        url: 'http://192.168.2.97:20007'
    },
    plugin: {
        log: {
            url: 'http://192.168.2.213:3302/log'
        }
    }
});

let uPublic = {};
uPublic.console = function (res) {
    console.log(res)
};
// 设置页面字体
uPublic.recalc = function () {
    let docEl = document.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            let clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = clientWidth / 10 + 'px';
        };
    window.addEventListener(resizeEvt, recalc, false);
    recalc();
};
// 注册组件
uPublic.componentsInit = function (array) {
    array.forEach(function (item, index) {
        Vue.component(item, ugenComponents.manage[item]);
    });
};
// 加载项目自定义组件
uPublic.componentsExtend = function (array) {
    array.forEach(function (item, index) {
        Vue.component(item, projectComponents[item]);
    });
};

iot.ready(() => {
    uPublic.recalc();
});
export {iot, uPublic, uComponents}