UNPKG

lixin-web

Version:

vue and bootstrap

300 lines (257 loc) 8.83 kB
import 'style-loader/lib/addStyles' import 'style-loader/lib/urls' //lement-ui\lib\utils\popper.js Object.defineProperty(Object, 'assign' // !isDevEnv && require('core-js/fn/object/assign') import Vue from 'vue' import * as filters from '../filters' //ensure System import not contains this code import {round} from 'lodash' export {debounce, camelCase,zipObject } from 'lodash' //webpack will _union as union import {union} from 'lodash' import {format,addDays,addYears} from 'date-fns' export {format,addYears,addDays} window.addDays = addDays window.addYears = addYears window.dateFnsFormat = format !isDevEnv && require('core-js/fn/array/from') !isDevEnv && require('core-js/fn/array/fill') !isDevEnv && require('core-js/fn/array/find') !isDevEnv && require('core-js/modules/es6.string.repeat') !isDevEnv && require('core-js/modules/es6.string.includes') // !isDevEnv && require('core-js/modules/es7.array.includes') !isDevEnv && require('core-js/modules/es7.object.values') window._union = union; // import notify, { error, success, fixCloseAnimation } from '../plugins/notify' // export { fixCloseAnimation} import sweetalert2,{success,error,confirm} from '../plugins/sweetalert2' import { Loading,Button, RadioGroup,RadioButton, Form,FormItem,Input,Checkbox, Scrollbar } from 'element-ui' import modal from '../../component/modal' import Affix from 'iview/src/components/affix' import AsyncCompLoading from '../../component/util/Loading' import 'element-ui/lib/tooltip' Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) }) //direct Vue.use(Tooltip) will get a conflict at admin.js.. Vue.use(Button) Vue.use(RadioGroup) Vue.use(RadioButton) Vue.use(Input) Vue.use(Form) Vue.use(FormItem) Vue.use(Checkbox) Vue.use(Loading.directive) Vue.use(Scrollbar) Vue.prototype.$loading = Loading.service Vue.component(Affix.name, Affix) Vue.use(modal) import 'element-ui/lib/transitions/collapse-transition' import 'vue-mixins/datepicker' import 'vue-mixins/dataTables' import 'vue-mixins/lottoBalTip' import 'vue-mixins/agentable' var cancelButton = { label: '取消', // icon: 'glyphicon glyphicon-remove', cssClass: 'btn-default', autospin: true, action: function (dialog) { dialog.close(); } }; var callbacks = []; function addHashChange(callback) { callbacks.push(callback); if ($.isFunction(callback)) callback(); if (!window.onhashchange) { var change = function () { $.each(callbacks, function () { if ($.isFunction(this)) this(); }); }; window.onhashchange = change; } } import {ajax} from "./axios"; export {ajax} var successRes = function (successCallback, errorCallback) { return function (response) { // App.unblockUI(); if ((typeof (response.error) == "undefined")) { //没有error,code,message的返回情况 if ($.isFunction(successCallback)) successCallback(response); return; } if (response.error != 0) { if (response.code == '0-1' || response.code == '0-4') { if (window.location.pathname == rootIndex || window.location.pathname == rootIndex + 'index.html') return; error(response.message, function () { //预加载 登录页背景 preloadImage('login_bg', !isMobileScreen) sessionStorage.pathState = location.pathname + location.hash // location.href = '/' }); } else if (response.code == "105-03") { Will.info('您还没有设置密保,请立即设定!', PopBindSecurity) } else { if ($.isFunction(errorCallback)) return errorCallback(response.data, response); if (response.message == '你还未进行Google绑定') return; error(response.message) } } if (response.error == 0) { if ($.isFunction(successCallback)) successCallback(response.data, response); } } } export {store} from './store' import {hasWebP,preloadImage} from './imgTool' export {hasWebP,preloadImage} export const blockUI = () => {} export const unblockUI = () => {} //todo use https://github.com/mzabriskie/axios var _ajax = function (data, url, successCallback, errorCallback, isAsync, { beforeSend = () => { }, complete = () => { }, loading = false } = {}) { var asyncc = isAsync === 0 ? false : true if (loading) { beforeSend = blockUI complete = unblockUI } return $.ajax({ type: 'post', beforeSend, url, data, timeout: 10000, dataType: 'json', async: asyncc, success: successRes(successCallback, errorCallback), complete }); } export const async$VM = (path, selector,option = {}) => { return import(`../../component/${path}.vue`) .then(component => { let opt = { ...option,render: h => h(component.default) } if (selector) opt.el = selector; return new Vue(opt) }) .catch(err => { console.error(err); }); } export const deferCompo = (path, condition = true) => { return (component) => { return (resolve) => { condition && import(`../../component/${path}/${component}.vue`).then(component => resolve(component)) } } } export const AsyncComp = (dir,component) => { return () => ({ // The component to load. Should be a Promise component: import(`../../component/${dir}/${component}.vue`), // A component to use while the async component is loading loading: AsyncCompLoading, // A component to use if the load fails // error: ErrorComp, // Delay before showing the loading component. Default: 200ms. delay: 200, // The error component will be displayed if a timeout is // provided and exceeded. Default: Infinity. timeout: 3000 }) } export const validation = (context, fields, callback, { valid = 'fa fa-check', invalid = 'fa fa-remove' } = {}) => { context.validation = $(context.$el).bootstrapValidator({ icon: { valid, invalid, validating: 'fa fa-refresh' }, fields }).data('bootstrapValidator') context.isValid = () => context.validation.validate().isValid() if (callback === 'preventFormSubmit' && context.$el.nodeType === 1) { $(context.$el.tagName == 'FORM' ? context.$el : context.$el.querySelector('form')).on('submit', e => e.preventDefault()) } typeof callback == 'function' && callback() } export const validModal = ( context, option = {}, callback, eventType = "hide" ) => context.$modal = $(context.$el) .modal(option) .on( `${eventType}.bs.modal`, () => (callback ? callback() : context.validation.resetForm(true)) ); export const isNumeric = value => !isNaN(parseFloat(value)) && isFinite(value); export {_getPw,compositionPw,elementPwtoText} from './Pw2Text' // https://github.com/ElemeFE/element/issues/4165 export const validNumber = (msg,int) => { return { validator: (rule, value, callback) => { if(!isNumeric(value)) { callback(new Error(msg)) } else if(int && !(value == Math.round(value))){ callback(new Error(int)) } else{ callback() } } // , trigger: 'blur,change' } } const redirect = (vm,path,query = {}) => { vm.$router.push({ path, query }) } export const checkPw = (vm,{path = '/',text = '密码保护',query = 'setPwPro'} = {}) => { confirm( `您尚未设置${text}`, () => redirect(vm,path,query ? {[query]:true} : {}), '去设置','取消', () => query !== false && (typeof query === 'function' ? query() : redirect(vm,'/')) ) } export const isMobileScreen = screen.width <= 480 export const isTabletScreen = screen.width > 480 && screen.width <= 768 export const isDesktopScreen = screen.width > 768 export const isTouchDevice = 'ontouchstart' in window // works on most browsers || navigator.maxTouchPoints // works on IE10/11 and Surface export const clipboard = (target,cb = () => {}) => { import('clipboard') .then(Clipboard => { var clipboard = new Clipboard(target); clipboard.on('success',cb); }) } export {UA,isIE,isEdge} from './UA' export const getPath = () => location.pathname.slice(1) || '/' const Will = { ajax: _ajax, axios: ajax, blockUI, unblockUI, addHashChange: addHashChange, // blockUI:function(){ // // App.blockUI({boxed:1}); // App.blockUI(); // }, // unblockUI:function(){ // App.unblockUI(); // }, cancelButton: cancelButton, successRes: successRes, isMobileScreen, isTabletScreen, isDesktopScreen, isTouchDevice, } Object.assign(Will, sweetalert2) export default Will window.Will = Will