修改 utils 文件路径

This commit is contained in:
yangchch6 2019-07-26 09:47:18 +08:00
parent acf9eb2ddb
commit 71021bd479
15 changed files with 329 additions and 341 deletions

View File

@ -26,7 +26,7 @@ var _TableHeader = require('./TableHeader');
var _TableHeader2 = _interopRequireDefault(_TableHeader); var _TableHeader2 = _interopRequireDefault(_TableHeader);
var _utils = require('./utils'); var _utils = require('./lib/utils');
var _shallowequal = require('shallowequal'); var _shallowequal = require('shallowequal');

View File

@ -20,7 +20,7 @@ var _propTypes2 = _interopRequireDefault(_propTypes);
var _throttleDebounce = require("throttle-debounce"); var _throttleDebounce = require("throttle-debounce");
var _utils = require("./utils"); var _utils = require("./lib/utils");
var _FilterType = require("./FilterType"); var _FilterType = require("./FilterType");

View File

@ -12,7 +12,7 @@ var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes); var _propTypes2 = _interopRequireDefault(_propTypes);
var _utils = require('./utils'); var _utils = require('./lib/utils');
var _TableCell = require('./TableCell'); var _TableCell = require('./TableCell');

View File

@ -12,7 +12,7 @@ var _react = require("react");
var _react2 = _interopRequireDefault(_react); var _react2 = _interopRequireDefault(_react);
var _utils = require("../utils"); var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

View File

@ -155,9 +155,9 @@ function removeClass(elm, className) {
}); });
} }
/** /**
* 简单数组数据对象拷贝 * 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象 * @param {*} obj 要拷贝的对象
*/ */
function ObjectAssign(obj) { function ObjectAssign(obj) {
var b = obj instanceof Array; var b = obj instanceof Array;
@ -174,8 +174,8 @@ function ObjectAssign(obj) {
} }
return tagObj; return tagObj;
} }
/** /**
* 获取某个父元素 * 获取某个父元素
* */ * */
function closest(ele, selector) { function closest(ele, selector) {
@ -289,8 +289,8 @@ var EventUtil = exports.EventUtil = {
} }
} }
/* /*
* 处理精度 * 处理精度
*/ */
};function DicimalFormater(value, precision) { };function DicimalFormater(value, precision) {
var value = value + '', var value = value + '',

View File

@ -47,10 +47,6 @@ const data23 = [
const DragColumnTable = dragColumn(Table); const DragColumnTable = dragColumn(Table);
const defaultProps23 = {
prefixCls: "bee-table"
};
class Demo23 extends Component { class Demo23 extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -69,7 +65,5 @@ class Demo23 extends Component {
/>; />;
} }
} }
Demo23.defaultProps = defaultProps23;
export default Demo23; export default Demo23;

File diff suppressed because one or more lines are too long

22
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "bee-table", "name": "bee-table",
"version": "2.1.7-beta.4", "version": "2.1.7-beta.5",
"description": "Table ui component for react", "description": "Table ui component for react",
"keywords": [ "keywords": [
"react", "react",

View File

@ -3,14 +3,14 @@ import PropTypes from 'prop-types';
import classes from 'component-classes'; import classes from 'component-classes';
import TableRow from './TableRow'; import TableRow from './TableRow';
import TableHeader from './TableHeader'; import TableHeader from './TableHeader';
import { measureScrollbar, debounce, warningOnce ,getMaxColChildrenLength} from './utils'; import { measureScrollbar, debounce, warningOnce ,getMaxColChildrenLength} from './lib/utils';
import shallowequal from 'shallowequal'; import shallowequal from 'shallowequal';
import addEventListener from 'tinper-bee-core/lib/addEventListener'; import addEventListener from 'tinper-bee-core/lib/addEventListener';
import ColumnManager from './ColumnManager'; import ColumnManager from './ColumnManager';
import createStore from './createStore'; import createStore from './createStore';
import Loading from 'bee-loading'; import Loading from 'bee-loading';
import Icon from 'bee-icon'; import Icon from 'bee-icon';
import { Event,EventUtil,closest} from "./utils"; import { Event,EventUtil,closest} from "./lib/utils";
import i18n from "./lib/i18n"; import i18n from "./lib/i18n";
import { getComponentLocale } from "bee-locale/build/tool"; import { getComponentLocale } from "bee-locale/build/tool";

View File

@ -2,7 +2,7 @@ import React, { Component } from "react";
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { debounce } from "throttle-debounce"; import { debounce } from "throttle-debounce";
import { Event,EventUtil} from "./utils"; import { Event,EventUtil} from "./lib/utils";
import FilterType from "./FilterType"; import FilterType from "./FilterType";
const propTypes = { const propTypes = {

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Event,EventUtil} from "./utils"; import { Event,EventUtil} from "./lib/utils";
import TableCell from './TableCell'; import TableCell from './TableCell';
import ExpandIcon from './ExpandIcon'; import ExpandIcon from './ExpandIcon';

View File

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import {DicimalFormater} from "../utils"; import {DicimalFormater} from "./utils";
export default function sum(Table) { export default function sum(Table) {
return class SumTable extends React.Component { return class SumTable extends React.Component {
//无状态 //无状态

View File

@ -1,303 +1,303 @@
import warning from 'warning'; import warning from 'warning';
import parseInt from 'lodash/parseInt'; import parseInt from 'lodash/parseInt';
let scrollbarSize; let scrollbarSize;
// Measure scrollbar width for padding body during modal show/hide // Measure scrollbar width for padding body during modal show/hide
const scrollbarMeasure = { const scrollbarMeasure = {
position: 'absolute', position: 'absolute',
top: '-9999px', top: '-9999px',
width: '50px', width: '50px',
height: '50px', height: '50px',
overflow: 'scroll', overflow: 'scroll',
}; };
export function measureScrollbar(direction = 'vertical') { export function measureScrollbar(direction = 'vertical') {
if (typeof document === 'undefined' || typeof window === 'undefined') { if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0; return 0;
} }
const tableDom =document.querySelector('.u-table'); const tableDom =document.querySelector('.u-table');
let currentDom = tableDom?tableDom:document.body; let currentDom = tableDom?tableDom:document.body;
if (scrollbarSize) { if (scrollbarSize) {
return scrollbarSize; return scrollbarSize;
} }
const scrollDiv = document.createElement('div'); const scrollDiv = document.createElement('div');
Object.keys(scrollbarMeasure).forEach(scrollProp => { Object.keys(scrollbarMeasure).forEach(scrollProp => {
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp]; scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
}); });
currentDom.appendChild(scrollDiv); currentDom.appendChild(scrollDiv);
let size = 0; let size = 0;
if (direction === 'vertical') { if (direction === 'vertical') {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth; size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
} else if (direction === 'horizontal') { } else if (direction === 'horizontal') {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight; size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
} }
currentDom.removeChild(scrollDiv); currentDom.removeChild(scrollDiv);
scrollbarSize = size; scrollbarSize = size;
return scrollbarSize; return scrollbarSize;
} }
export function debounce(func, wait, immediate) { export function debounce(func, wait, immediate) {
let timeout; let timeout;
return function debounceFunc() { return function debounceFunc() {
const context = this; const context = this;
const args = arguments; const args = arguments;
// https://fb.me/react-event-pooling // https://fb.me/react-event-pooling
if (args[0] && args[0].persist) { if (args[0] && args[0].persist) {
args[0].persist(); args[0].persist();
} }
const later = () => { const later = () => {
timeout = null; timeout = null;
if (!immediate) { if (!immediate) {
func.apply(context, args); func.apply(context, args);
} }
}; };
const callNow = immediate && !timeout; const callNow = immediate && !timeout;
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(later, wait); timeout = setTimeout(later, wait);
if (callNow) { if (callNow) {
func.apply(context, args); func.apply(context, args);
} }
}; };
} }
const warned = {}; const warned = {};
export function warningOnce(condition, format, args) { export function warningOnce(condition, format, args) {
if (!warned[format]) { if (!warned[format]) {
warning(condition, format, args); warning(condition, format, args);
warned[format] = true; warned[format] = true;
} }
} }
export function getOffset (Node, offset ) { export function getOffset (Node, offset ) {
if(!offset) { if(!offset) {
offset = {}; offset = {};
offset.top = 0; offset.top = 0;
offset.left = 0; offset.left = 0;
} }
if(Node == document.body) { if(Node == document.body) {
return offset; return offset;
} }
offset.top += Node.offsetTop; offset.top += Node.offsetTop;
offset.left += Node.offsetLeft; offset.left += Node.offsetLeft;
if(Node.offsetParent) if(Node.offsetParent)
return getOffset(Node.offsetParent, offset); return getOffset(Node.offsetParent, offset);
else else
return offset; return offset;
}; };
export const tryParseInt = (value, defaultValue = 0) => { export const tryParseInt = (value, defaultValue = 0) => {
const resultValue = parseInt(value); const resultValue = parseInt(value);
if (isNaN(resultValue)) { if (isNaN(resultValue)) {
return defaultValue; return defaultValue;
} }
return resultValue; return resultValue;
}; };
export function addClass(elm, className) { export function addClass(elm, className) {
if (!className) return; if (!className) return;
const els = Array.isArray(elm) ? elm : [elm]; const els = Array.isArray(elm) ? elm : [elm];
els.forEach((el) => { els.forEach((el) => {
if (el.classList) { if (el.classList) {
el.classList.add(className.split(' ')); el.classList.add(className.split(' '));
} else { } else {
el.className += ` ${className}`; el.className += ` ${className}`;
} }
}); });
} }
export function removeClass(elm, className) { export function removeClass(elm, className) {
if (!className) return; if (!className) return;
const els = Array.isArray(elm) ? elm : [elm]; const els = Array.isArray(elm) ? elm : [elm];
els.forEach((el) => { els.forEach((el) => {
if (el.classList) { if (el.classList) {
el.classList.remove(className.split(' ')); el.classList.remove(className.split(' '));
} else { } else {
el.className = el.className.replace(new RegExp(`(^|\\b)${className.split(' ').join('|')}(\\b|$)`, 'gi'), ' '); el.className = el.className.replace(new RegExp(`(^|\\b)${className.split(' ').join('|')}(\\b|$)`, 'gi'), ' ');
} }
}); });
} }
/** /**
* 简单数组数据对象拷贝 * 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象 * @param {*} obj 要拷贝的对象
*/ */
export function ObjectAssign(obj){ export function ObjectAssign(obj){
let b = obj instanceof Array; let b = obj instanceof Array;
let tagObj = b?[]:{}; let tagObj = b?[]:{};
if(b){//数组 if(b){//数组
obj.forEach(da => { obj.forEach(da => {
let _da = {}; let _da = {};
Object.assign(_da,da); Object.assign(_da,da);
tagObj.push(_da); tagObj.push(_da);
}); });
}else{ }else{
Object.assign(tagObj,obj); Object.assign(tagObj,obj);
} }
return tagObj; return tagObj;
} }
/** /**
* 获取某个父元素 * 获取某个父元素
* */ * */
export function closest(ele, selector) { export function closest(ele, selector) {
const matches = ele.matches || ele.webkitMatchesSelector || ele.mozMatchesSelector || ele.msMatchesSelector; const matches = ele.matches || ele.webkitMatchesSelector || ele.mozMatchesSelector || ele.msMatchesSelector;
if (matches) { if (matches) {
while (ele) { while (ele) {
if (matches.call(ele, selector)) { if (matches.call(ele, selector)) {
return ele; return ele;
} else { } else {
ele = ele.parentElement; ele = ele.parentElement;
} }
} }
} }
return null; return null;
} }
export function getMaxColChildrenLength(columns){ export function getMaxColChildrenLength(columns){
let arr=[]; let arr=[];
arr = columns.map((item,index)=>{ arr = columns.map((item,index)=>{
let chilrenLen = 0; let chilrenLen = 0;
if(item.children){ if(item.children){
chilrenLen = getColChildrenLength(item.children,chilrenLen+1) chilrenLen = getColChildrenLength(item.children,chilrenLen+1)
} }
return chilrenLen return chilrenLen
}) })
var max = Math.max.apply(null,arr); var max = Math.max.apply(null,arr);
return max; return max;
} }
export function getColChildrenLength(columns,chilrenLen){ export function getColChildrenLength(columns,chilrenLen){
columns.forEach((item,index)=>{ columns.forEach((item,index)=>{
if(item.children){ if(item.children){
chilrenLen = getColChildrenLength(item.children,chilrenLen+1); chilrenLen = getColChildrenLength(item.children,chilrenLen+1);
} }
}) })
return chilrenLen; return chilrenLen;
} }
function addHandler(element,type,handler){ function addHandler(element,type,handler){
let event = null; let event = null;
if(element.addEventListener){//检测是否为DOM2级方法 if(element.addEventListener){//检测是否为DOM2级方法
event = element.addEventListener(type, handler, false); event = element.addEventListener(type, handler, false);
}else if (element.attachEvent){//检测是否为IE级方法 }else if (element.attachEvent){//检测是否为IE级方法
event = element.attachEvent("on" + type, handler); event = element.attachEvent("on" + type, handler);
} else {//检测是否为DOM0级方法 } else {//检测是否为DOM0级方法
event = element["on" + type] = handler; event = element["on" + type] = handler;
} }
return event; return event;
} }
function removeHandler(element, type, handler){ function removeHandler(element, type, handler){
if (element&&element.removeEventListener){//element&& ie11报错兼容 if (element&&element.removeEventListener){//element&& ie11报错兼容
element.removeEventListener(type, handler, false); element.removeEventListener(type, handler, false);
} else if (element&&element.detachEvent){ } else if (element&&element.detachEvent){
element.detachEvent("on" + type, handler); element.detachEvent("on" + type, handler);
} else if(element) { } else if(element) {
element["on" + type] = null; element["on" + type] = null;
} }
} }
//获取事件对象的兼容性写法 //获取事件对象的兼容性写法
function getEvent(event){ function getEvent(event){
return event ? event : window.event; return event ? event : window.event;
} }
//获取事件对象目标的兼容性写法 //获取事件对象目标的兼容性写法
function getTarget(event){ function getTarget(event){
return event.target || event.srcElement; return event.target || event.srcElement;
} }
function preventDefault(event){ function preventDefault(event){
if (event.preventDefault){ if (event.preventDefault){
event.preventDefault(); event.preventDefault();
} else { } else {
event.returnValue = false; event.returnValue = false;
} }
} }
function stopPropagation(event){ function stopPropagation(event){
if (event.stopPropagation){ if (event.stopPropagation){
event.stopPropagation(); event.stopPropagation();
} else { } else {
event.cancelBubble = true; event.cancelBubble = true;
} }
} }
//用事件冒泡方式如果想兼容事件捕获只需要添加个bool参数 //用事件冒泡方式如果想兼容事件捕获只需要添加个bool参数
export const EventUtil = { export const EventUtil = {
addHandler: function(element,type,handler) { addHandler: function(element,type,handler) {
if (element.addEventListener) { if (element.addEventListener) {
element.addEventListener(type,handler,false); element.addEventListener(type,handler,false);
} }
else if (element.attachEvent) { else if (element.attachEvent) {
element.attachEvent('on'+type,handler); element.attachEvent('on'+type,handler);
} }
else { else {
element['on'+type] = handler; element['on'+type] = handler;
} }
}, },
removeHandler: function(element,type,handler) {//element&& ie11报错兼容 removeHandler: function(element,type,handler) {//element&& ie11报错兼容
if (element&&element.removeEventListener) if (element&&element.removeEventListener)
{ {
element.removeEventListener(type,handler,false); element.removeEventListener(type,handler,false);
} }
else if(element&&element.detachEvent) { else if(element&&element.detachEvent) {
element.detachEvent('on' +type,handler); element.detachEvent('on' +type,handler);
} }
else if(element){ else if(element){
element['on'+type] = null; element['on'+type] = null;
} }
} }
} }
/* /*
* 处理精度 * 处理精度
*/ */
export function DicimalFormater(value,precision) { export function DicimalFormater(value,precision) {
var value = value + '', var value = value + '',
precision = precision?precision:0; precision = precision?precision:0;
for (var i = 0; i < value.length; i++) { for (var i = 0; i < value.length; i++) {
if ("-0123456789.".indexOf(value.charAt(i)) == -1) if ("-0123456789.".indexOf(value.charAt(i)) == -1)
return ""; return "";
} }
return checkDicimalInvalid(value, precision); return checkDicimalInvalid(value, precision);
}; };
export function checkDicimalInvalid(value, precision) { export function checkDicimalInvalid(value, precision) {
if (value == null || isNaN(value)) if (value == null || isNaN(value))
return ""; return "";
// 浮点数总位数不能超过10位 // 浮点数总位数不能超过10位
var digit = parseFloat(value); var digit = parseFloat(value);
var result = (digit * Math.pow(10, precision) / Math.pow(10, precision)) var result = (digit * Math.pow(10, precision) / Math.pow(10, precision))
.toFixed(precision); .toFixed(precision);
if (result == "NaN") if (result == "NaN")
return ""; return "";
return result; return result;
}; };
export const Event = { export const Event = {
addHandler, addHandler,
removeHandler, removeHandler,
getEvent, getEvent,
getTarget, getTarget,
preventDefault, preventDefault,
stopPropagation stopPropagation
} }