UNPKG

icx-meum-vue-common-module

Version:

icx-meum-vue-common-module

103 lines (96 loc) 2.93 kB
/** * Created by wangbagang on 2017/8/15. */ import IcxCard from './components/IcxCard.vue' import IcxCard2 from './components/IcxCard2.vue' import IcxLineProgress from './components/IcxLineProgress.vue' import IcxScroller from './components/IcxScroller.vue' import IcxSteps from './components/IcxSteps.vue' import * as CONST from './icx/const' import * as icxUtils from './icx/utils' import wechat from './config/wechat' import request from './config/http' import Logger from './config/Logger' import './config/rem' import JsBridge from './config/js-bridge' import './config/vds' // 此处是插件 const install = function (Vue, options) { Vue.mixin({ methods: { /** * 设置页面标题 * @param title */ setPageTitle (title = CONST.STRING_APP_NAME) { let $body = document.body document.title = title let $iframe = document.createElement('iframe') $iframe.src = 'static/favicon.ico' $iframe.addEventListener('load', function () { setTimeout(function () { $iframe.removeEventListener('load', null) $body.removeChild($iframe) }, 0) }) $body.appendChild($iframe) }, /** * 请求是否需要登录 * @param response * @returns {boolean} */ isApiToLogin (response) { return response.errorCode === CONST.INT_LOGIN_STRONG || response.errorCode === CONST.INT_LOGIN_WEAK }, /** * 请求是否成功 * @param response * @returns {*|boolean} */ isApiResponseOk (response) { return response && response.errorCode === CONST.INT_REQUEST_OK }, /** * 如果当前页面可能会在app中使用的话,请使用此方法打开新页面或者超链接 * @param location */ openWebViewWithBack (location) { if (typeof location === 'string' && location.indexOf('http') !== -1) { if (icxUtils.isMeumApp()) { window.WebViewJavascriptBridge.callHandler(CONST.APP_METHOD_START_WEBVIEW_ACTIVITY_WITH_BACK, location, function (response) {}) } else { window.location.href = location } } else if (typeof location === 'object') { if (icxUtils.isMeumApp()) { var url = this.$router.resolve(location) window.WebViewJavascriptBridge.callHandler(CONST.APP_METHOD_START_WEBVIEW_ACTIVITY_WITH_BACK, icxUtils.getBaseUrl(`${window.document.location.host}${url.href}`), function (response) {}) } else { this.$router.push(location) } } } } }) } // auto install if (typeof window !== 'undefined' && window.Vue) { install(window.Vue) } export default { install } export { IcxCard, IcxCard2, IcxLineProgress, IcxScroller, IcxSteps, wechat, request, icxUtils, Logger, JsBridge }