|
|
@@ -9,10 +9,9 @@
|
|
|
*/
|
|
|
|
|
|
/*
|
|
|
- * div之间的水平拖动,适应各种情况
|
|
|
- * module: 所属模块,防止不同页面相同id导致localstorage数据被覆盖
|
|
|
- * eleObj: resize, parent, left, right
|
|
|
- * limit: min, max
|
|
|
+ * 拖动相关公共接口
|
|
|
+ * 前台使用此接口时,注意在恢复系统默认设置时,
|
|
|
+ * 清除相关缓存数据: project_view.js--->$('#property_default').click(callback)
|
|
|
* */
|
|
|
|
|
|
const SlideResize = (function() {
|
|
|
@@ -20,9 +19,8 @@ const SlideResize = (function() {
|
|
|
//@param {Object dom}resize滚动条
|
|
|
function setResizeWidth (resize) {
|
|
|
const fixedWidth = 10;
|
|
|
- //跟滚动条同层的其他节点
|
|
|
- let bros = resize.parent().children();
|
|
|
//滚动条节点 及 同层非滚动条节点的索引
|
|
|
+ let bros = resize.parent().children();
|
|
|
let index = bros.index(resize),
|
|
|
otherIndex = index ? 0 : 1;
|
|
|
const other = resize.parent().children(`:eq(${otherIndex})`);
|
|
|
@@ -36,7 +34,14 @@ const SlideResize = (function() {
|
|
|
}
|
|
|
|
|
|
let mouseMoveCount = 0;
|
|
|
- function horizontalSlide(module, eleObj, limit, callback) {
|
|
|
+ /*
|
|
|
+ * div之间的水平拖动,适应各种情况
|
|
|
+ * @param {Object}eleObj: module所属模块,防止不同页面相同id导致localstorage数据被覆盖(放在对象里,因为可能有的地方要实时改这个module)
|
|
|
+ * resize, parent, left, right
|
|
|
+ * @param {Object}limit: min, max
|
|
|
+ * @param {Function}callback 回调
|
|
|
+ * */
|
|
|
+ function horizontalSlide(eleObj, limit, callback) {
|
|
|
const triggerCBSize = 5;
|
|
|
let drag = false,
|
|
|
startPoint = 0,
|
|
|
@@ -55,13 +60,14 @@ const SlideResize = (function() {
|
|
|
});
|
|
|
$('body').mousemove(function (e) {
|
|
|
if (drag) {
|
|
|
+ console.log('drag');
|
|
|
let moveSize = e.clientX - startPoint;
|
|
|
leftChange = leftWidth + moveSize;
|
|
|
leftChange = leftChange < limit.min ? limit.min : leftChange;
|
|
|
- leftChange = leftChange > limitMax ? limitMax - 3 : leftChange;
|
|
|
+ leftChange = leftChange > limitMax ? limitMax - 5 : leftChange;
|
|
|
rightChange = rightWidth - moveSize;
|
|
|
rightChange = rightChange < limit.min ? limit.min : rightChange;
|
|
|
- rightChange = rightChange > limitMax ? limitMax - 3 : rightChange;
|
|
|
+ rightChange = rightChange > limitMax ? limitMax - 5 : rightChange;
|
|
|
let leftPercentWidth = leftChange / eleObj.parent.width() * 100 + '%',
|
|
|
rightPercentWidth = rightChange / eleObj.parent.width() * 100 + '%';
|
|
|
eleObj.left.css('width', leftPercentWidth);
|
|
|
@@ -80,9 +86,9 @@ const SlideResize = (function() {
|
|
|
mouseMoveCount = 0;
|
|
|
//将宽度信息存储到localstorage
|
|
|
let leftWidthInfo = eleObj.left[0].style.width;
|
|
|
- setLocalCache(`${module}${eleObj.left.attr('id')}Width`, leftWidthInfo);
|
|
|
+ setLocalCache(`${eleObj.module}${eleObj.left.attr('id')}Width`, leftWidthInfo);
|
|
|
let rightWidthInfo = eleObj.right[0].style.width;
|
|
|
- setLocalCache(`${module}${eleObj.right.attr('id')}Width`, rightWidthInfo);
|
|
|
+ setLocalCache(`${eleObj.module}${eleObj.right.attr('id')}Width`, rightWidthInfo);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -105,11 +111,12 @@ const SlideResize = (function() {
|
|
|
|
|
|
/*
|
|
|
* div上下拖动
|
|
|
- * module: 所属模块,防止不同页面相同id导致localstorage数据被覆盖
|
|
|
- * eleObj: resize, top, topSpread, bottom, bottomSpread
|
|
|
- * limit: min, max, notTopSpread(上部分非spread部分的高度) notBottomSpread(下部分非spread部分的高度)
|
|
|
+ * @param {Object} eleObj: module所属模块,防止不同页面相同id导致localstorage数据被覆盖(放在对象里,因为可能有的地方要实时改这个module)
|
|
|
+ * resize, top, topSpread, bottom, bottomSpread
|
|
|
+ * @param {Object}limit: min, max, notTopSpread(上部分非spread部分的高度) notBottomSpread(下部分非spread部分的高度)
|
|
|
+ * @param {Function}callback 回调
|
|
|
* */
|
|
|
- function verticalSlide(module, eleObj, limit, callback) {
|
|
|
+ function verticalSlide(eleObj, limit, callback) {
|
|
|
const triggerCBSize = 5;
|
|
|
let drag = false,
|
|
|
startPoint = 0,
|
|
|
@@ -157,18 +164,19 @@ const SlideResize = (function() {
|
|
|
mouseMoveCount = 0;
|
|
|
//将高度信息存储到localstorage
|
|
|
let topHeightInfo = eleObj.top.height();
|
|
|
- setLocalCache(`${module}${eleObj.top.attr('id')}Height`, topHeightInfo);
|
|
|
+ setLocalCache(`${eleObj.module}${eleObj.top.attr('id')}Height`, topHeightInfo);
|
|
|
let bottomHeightInfo = eleObj.bottom.height();
|
|
|
- setLocalCache(`${module}${eleObj.bottom.attr('id')}Height`, bottomHeightInfo);
|
|
|
+ setLocalCache(`${eleObj.module}${eleObj.bottom.attr('id')}Height`, bottomHeightInfo);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 加载上下高度
|
|
|
- * module: 所属模块,防止不同页面相同id导致localstorage数据被覆盖
|
|
|
- * eleObj: top, topSpread, bottom, bottomSpread
|
|
|
- * limit: totalHeight(实时的上下部分总高度) notTopSpread(上部分非spread部分的高度) notBottomSpread(下部分非spread部分的高度)
|
|
|
+ * @param {String}module 所属模块,防止不同页面相同id导致localstorage数据被覆盖
|
|
|
+ * @param {Object}eleObj: module所属模块,防止不同页面相同id导致localstorage数据被覆盖(放在对象里,因为可能有的地方要实时改这个module) top, topSpread, bottom, bottomSpread
|
|
|
+ * @param {Object}limit: totalHeight(实时的上下部分总高度) notTopSpread(上部分非spread部分的高度) notBottomSpread(下部分非spread部分的高度)
|
|
|
+ * @param {Function}callback 回调
|
|
|
* */
|
|
|
|
|
|
function loadVerticalHeight(module, eleObj, limit, callback) {
|
|
|
@@ -196,5 +204,48 @@ const SlideResize = (function() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return {horizontalSlide, loadHorizonWidth, verticalSlide, loadVerticalHeight}
|
|
|
+ /*
|
|
|
+ * 包含多个上下结构的拖动(n>= 2,只包含上下结构的地方可以用loadVerticalHeight)
|
|
|
+ * 加载多个结构高度
|
|
|
+ * @param {String}module所属模块,防止不同页面相同id导致localstorage数据被覆盖
|
|
|
+ * @param {Array}eles 元素为结构对象 内部: {container: 外部div, spread: 该div的Spread, notSpread: 该div不含Spread的高度, defaultProportion: 默认高度比例0.6}
|
|
|
+ * @param {String}totalHeight 各个结构div总高度-可编译字符串
|
|
|
+ * @param {Function}callback 回调
|
|
|
+ * */
|
|
|
+ function loadMultiVerticalHeight(module, eles, totalHeight, callback) {
|
|
|
+ //当前窗口拖动区域总高度
|
|
|
+ totalHeight = eval(totalHeight);
|
|
|
+ let cacheHeight = 0,//缓存中设置了高度的div总高度
|
|
|
+ notCacheProportion = 0;//缓存中没设置高度的div占用的总高度比例(每个div都有默认的高度比例) (有了缓存高度的div就是被拖动过的,被拖动过的div,其默认高度比例就没用了)
|
|
|
+ //获取缓存的总高度、未被拖动过的所有div的默认比例之和notCacheProportion (1-notCacheProportion)就是缓存高度的占总的比例
|
|
|
+ for (let ele of eles) {
|
|
|
+ let eleHeight = getLocalCache(`${module}${ele.container.attr('id')}Height`);
|
|
|
+ if (eleHeight !== null) {
|
|
|
+ eleHeight = parseFloat(eleHeight);
|
|
|
+ cacheHeight += eleHeight;
|
|
|
+ } else {
|
|
|
+ notCacheProportion += ele.defaultProportion;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //缓存高度占总的比例
|
|
|
+ let cacheProportion = 1 - notCacheProportion;
|
|
|
+ for (let ele of eles) {
|
|
|
+ let eleHeight = getLocalCache(`${module}${ele.container.attr('id')}Height`),
|
|
|
+ curHeight = 0;
|
|
|
+ if (eleHeight !== null) {
|
|
|
+ eleHeight = parseFloat(eleHeight);
|
|
|
+ //ele在当前窗口大小中的高度
|
|
|
+ curHeight = eleHeight / cacheHeight * cacheProportion * totalHeight;
|
|
|
+ } else {
|
|
|
+ curHeight = ele.defaultProportion * totalHeight;
|
|
|
+ }
|
|
|
+ ele.container.height(curHeight);
|
|
|
+ ele.spread.height(curHeight - ele.notSpread);
|
|
|
+ }
|
|
|
+ if (callback) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {setResizeWidth, horizontalSlide, loadHorizonWidth, verticalSlide, loadVerticalHeight, loadMultiVerticalHeight}
|
|
|
})();
|