arisu.js 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/arisu.js CHANGED
@@ -66,6 +66,7 @@ __webpack_require__.d(utils_namespaceObject, {
66
66
  HoverDir: () => (HoverDir),
67
67
  IAccordion: () => (IAccordion),
68
68
  IList: () => (IList),
69
+ ILoader: () => (ILoader),
69
70
  IPagination: () => (IPagination),
70
71
  ItemCount: () => (ItemCount),
71
72
  LineEffect: () => (LineEffect),
@@ -174,6 +175,8 @@ __webpack_require__.d(utils_namespaceObject, {
174
175
  b('.myElement').slideDown(500, function() { console.log('动画完成'); });
175
176
  // 标签打开关闭切换
176
177
  b('.myElement').slideToggle(500, function() { console.log('动画完成'); });
178
+ // 元素透明度逐渐递减变0,最后display设置为none
179
+ b('#id').fadeOut(1000, ()=>{ b.l('透明度为0后消失') })
177
180
 
178
181
  // 1.2 页面基础方法扩展
179
182
  // 全选全清,<input type="checkbox" class="myCheckbox"><input type="checkbox" class="test">
@@ -201,14 +204,14 @@ __webpack_require__.d(utils_namespaceObject, {
201
204
  if(b.isNull(变量)) {
202
205
  // 如果为空设置默认值
203
206
  b.setDefault(data.id, 0);
207
+ // 判断变量是否为对象
208
+ console.log(b.isObject(custom));
204
209
  // 获取两个数组中的相同值
205
210
  b.same([1,2], [7,9,4,2,5,6,1]) //[1, 2]
206
211
  // 获取两个数组中的不相同值
207
212
  b.different([1,2], [7,9,4,2,5,6,1]) //[7, 9, 4, 5, 6]
208
213
  // 判断字符串是否为html标签,如<li></li><div></div><img/>返回true
209
214
  console.log(b.isHtmlTag('<img />')); // true
210
- // 判断变量是否为对象
211
- console.log(b.isObject(custom));
212
215
  // 允许插件扩展plugin静态方法
213
216
  // 普通方法
214
217
  function test(p1, p2) { console.log(this, p1, p2) } //Base... 3 4
@@ -738,38 +741,74 @@ class Base {
738
741
  }
739
742
 
740
743
  // data属性绑定设置
744
+ // data( key, value ) {
745
+ // if ( key === undefined ) {
746
+ // throw new Error('读取的或设置的键值不能为空');
747
+ // }
748
+ //
749
+ // let cache,
750
+ // elem = this.elements[0],
751
+ // // 获取与元素关联的缓存对象
752
+ // id = Base.expando,
753
+ // isCache = id && Base.cache[ id ];
754
+ //
755
+ // if ( value !== undefined ) {
756
+ // // 如果尚未创建缓存对象,则创建它
757
+ // if ( !isCache ) {
758
+ // cache = {};
759
+ // // 生成唯一的缓存键
760
+ // elem[ Base.expando ] = cache[ Base.expando ] = id;
761
+ // // 将缓存对象存储在全局 Base.cache 中
762
+ // Base.cache[ id ] = isCache = cache;
763
+ // }
764
+ // // 存储数据到缓存对象中
765
+ // isCache[ Base.camelCase( key ) ] = value;
766
+ // return this;
767
+ // } else {
768
+ // // console.log(isCache)
769
+ // // console.log(elem)
770
+ // if (!isCache)
771
+ // return undefined;
772
+ // else
773
+ // return isCache[ Base.camelCase( key ) ] ? isCache[ Base.camelCase( key ) ] : Base.dataAttr( elem, Base.camelCase( key ) )
774
+ // }
775
+ // }
776
+
777
+ // 清除data属性绑定的值
778
+ // removeData( key ) {
779
+ // delete Base.cache[ Base.expando ][ key ];
780
+ // }
781
+
741
782
  data( key, value ) {
742
783
  if ( key === undefined ) {
743
784
  throw new Error('读取的或设置的键值不能为空');
744
785
  }
745
-
746
- let cache,
747
- elem = this.elements[0],
748
- // 获取与元素关联的缓存对象
749
- id = Base.expando,
750
- isCache = id && Base.cache[ id ];
751
-
786
+ let element = this.elements[0];
752
787
  if ( value !== undefined ) {
753
- // 如果尚未创建缓存对象,则创建它
754
- if ( !isCache ) {
755
- cache = {};
756
- // 生成唯一的缓存键
757
- elem[ Base.expando ] = cache[ Base.expando ] = id;
758
- // 将缓存对象存储在全局 Base.cache 中
759
- Base.cache[ id ] = isCache = cache;
788
+ // 获取与元素关联的数据映射,‌如果不存在则创建一个新的
789
+ let dataMap = Base.elementData.get( element );
790
+ if (!dataMap) {
791
+ dataMap = new Map(); // 使用Map来存储元素的数据
792
+ Base.elementData.set( element, dataMap );
760
793
  }
761
- // 存储数据到缓存对象中
762
- isCache[ Base.camelCase( key ) ] = value;
794
+
795
+ // 存储数据
796
+ dataMap.set( Base.camelCase( key ), value );
763
797
  return this;
764
798
  } else {
765
- if (!isCache) return undefined; else
766
- return isCache[ Base.camelCase( key ) ] ? isCache[ Base.camelCase( key ) ] : Base.dataAttr( elem, Base.camelCase( key ) )
799
+ const dataMap = Base.elementData.get(element);
800
+ // 如果数据映射存在且包含该key,‌则返回其值;‌否则返回undefined
801
+ return dataMap ? dataMap.get(Base.camelCase( key )) : Base.dataAttr( element, key );
767
802
  }
768
803
  }
769
804
 
770
805
  // 清除data属性绑定的值
771
806
  removeData( key ) {
772
- delete Base.cache[ Base.expando ][ key ];
807
+ let element = this.elements[0];
808
+ let dataMap = Base.elementData.get( element );
809
+ if (dataMap) {
810
+ dataMap.set( Base.camelCase( key ), undefined );
811
+ }
773
812
  }
774
813
 
775
814
  // attr 方法实现
@@ -1030,100 +1069,135 @@ class Base {
1030
1069
  // 标签消失高度变0的关闭动画,300MS刚刚好
1031
1070
  slideUp(duration, callback) {
1032
1071
  const options = b.extend({ duration: duration, callback: callback }, { duration: 300, callback: false })
1072
+ // return this.each((element) => {
1073
+ // const computedStyle = window.getComputedStyle(element),
1074
+ // height = element.offsetHeight;
1075
+ //
1076
+ // let paddingTop = computedStyle.getPropertyValue('padding-top'),
1077
+ // paddingBottom = computedStyle.getPropertyValue('padding-bottom'),
1078
+ // marginTop = computedStyle.getPropertyValue('margin-top'),
1079
+ // marginBottom = computedStyle.getPropertyValue('margin-bottom');
1080
+ // if (paddingTop && paddingTop.includes('px'))
1081
+ // paddingTop = paddingTop.replace(/px/g, '');
1082
+ // if (paddingBottom && paddingBottom.includes('px'))
1083
+ // paddingBottom = paddingBottom.replace(/px/g, '');
1084
+ // if (marginTop && marginTop.includes('px'))
1085
+ // marginTop = marginTop.replace(/px/g, '');
1086
+ // if (marginBottom && marginBottom.includes('px'))
1087
+ // marginBottom = marginBottom.replace(/px/g, '');
1088
+ //
1089
+ // // element.style.transition = 'height ' + options.duration + 'ms ease-in-out';
1090
+ // element.style.transition = 'none';
1091
+ // element.style.overflow = 'hidden'; // 隐藏超出元素的内容
1092
+ //
1093
+ // function step(startTime) {
1094
+ // const now = performance.now(),
1095
+ // timeElapsed = now - startTime,
1096
+ // newHeight = Math.max(0, height - (timeElapsed / options.duration) * height),// 计算当前应该设置的高度
1097
+ // newPaddingTop = Math.max(0, paddingTop - (timeElapsed / options.duration) * paddingTop),
1098
+ // newPaddingBottom = Math.max(0, paddingBottom - (timeElapsed / options.duration) * paddingBottom),
1099
+ // newMarginTop = Math.max(0, marginTop - (timeElapsed / options.duration) * marginTop),
1100
+ // newMarginBottom = Math.max(0, marginBottom - (timeElapsed / options.duration) * marginBottom);
1101
+ // element.style.height = newHeight + `px`;
1102
+ // element.style.paddingTop = newPaddingTop + `px`;
1103
+ // element.style.paddingBottom = newPaddingBottom + `px`;
1104
+ // element.style.marginTop = newMarginTop + `px`;
1105
+ // element.style.marginBottom = newMarginBottom + `px`;
1106
+ // // 如果还没到达目标高度,则继续下一帧
1107
+ // if (timeElapsed < options.duration) {
1108
+ // requestAnimationFrame(step.bind(null, startTime));
1109
+ // } else {
1110
+ // // 过渡完成后清除过渡效果,以便后续操作
1111
+ // element.style.transition = '';
1112
+ // element.style.height = '';
1113
+ // element.style.display = 'none';
1114
+ // options.callback && options.callback();
1115
+ // }
1116
+ // }
1117
+ // requestAnimationFrame(step);
1118
+ // });
1033
1119
  return this.each((element) => {
1034
- const computedStyle = window.getComputedStyle(element),
1035
- height = element.offsetHeight;
1036
-
1037
- let paddingTop = computedStyle.getPropertyValue('padding-top'),
1038
- paddingBottom = computedStyle.getPropertyValue('padding-bottom'),
1039
- marginTop = computedStyle.getPropertyValue('margin-top'),
1040
- marginBottom = computedStyle.getPropertyValue('margin-bottom');
1041
- if (paddingTop && paddingTop.includes('px'))
1042
- paddingTop = paddingTop.replace(/px/g, '');
1043
- if (paddingBottom && paddingBottom.includes('px'))
1044
- paddingBottom = paddingBottom.replace(/px/g, '');
1045
- if (marginTop && marginTop.includes('px'))
1046
- marginTop = marginTop.replace(/px/g, '');
1047
- if (marginBottom && marginBottom.includes('px'))
1048
- marginBottom = marginBottom.replace(/px/g, '');
1049
-
1050
- // element.style.transition = 'height ' + options.duration + 'ms ease-in-out';
1051
- element.style.transition = 'none';
1052
- element.style.overflow = 'hidden'; // 隐藏超出元素的内容
1053
-
1054
- function step(startTime) {
1055
- const now = performance.now(),
1056
- timeElapsed = now - startTime,
1057
- newHeight = Math.max(0, height - (timeElapsed / options.duration) * height),// 计算当前应该设置的高度
1058
- newPaddingTop = Math.max(0, paddingTop - (timeElapsed / options.duration) * paddingTop),
1059
- newPaddingBottom = Math.max(0, paddingBottom - (timeElapsed / options.duration) * paddingBottom),
1060
- newMarginTop = Math.max(0, marginTop - (timeElapsed / options.duration) * marginTop),
1061
- newMarginBottom = Math.max(0, marginBottom - (timeElapsed / options.duration) * marginBottom);
1062
- element.style.height = newHeight + `px`;
1063
- element.style.paddingTop = newPaddingTop + `px`;
1064
- element.style.paddingBottom = newPaddingBottom + `px`;
1065
- element.style.marginTop = newMarginTop + `px`;
1066
- element.style.marginBottom = newMarginBottom + `px`;
1067
- // 如果还没到达目标高度,则继续下一帧
1068
- if (timeElapsed < options.duration) {
1069
- requestAnimationFrame(step.bind(null, startTime));
1070
- } else {
1071
- // 过渡完成后清除过渡效果,以便后续操作
1072
- element.style.transition = '';
1073
- element.style.height = '';
1074
- element.style.display = 'none';
1075
- options.callback && options.callback();
1076
- }
1077
- }
1078
- requestAnimationFrame(step);
1120
+ element.style.height = element.scrollHeight + "px";
1121
+ element.style.overflow = 'hidden';
1122
+ element.style.transition = `height ${options.duration}ms ease-in-out`;
1123
+ setTimeout(() => {
1124
+ element.style.height = '0px';
1125
+ }, options.duration / 100);
1126
+ setTimeout(() => {
1127
+ element.style.display = 'none';
1128
+ element.style.overflow = '';
1129
+ element.style.transition = '';
1130
+ element.style.height = '';
1131
+ if (options.callback && typeof options.callback === 'function') options.callback(element);
1132
+ }, options.duration - options.duration / 100);
1079
1133
  });
1080
1134
  }
1081
1135
 
1082
1136
  // 标签显示高度变复原的打开动画
1083
1137
  slideDown(duration, callback) {
1084
1138
  const options = b.extend({ duration: duration, callback: callback }, { duration: 300, callback: false })
1139
+ // return this.each((element) => {
1140
+ // // 获取元素当前的高度和初始的 display 状态
1141
+ // let startHeight = element.offsetHeight,
1142
+ // display = element.style.display,
1143
+ // mainDuration = options.duration * 7 / 10,
1144
+ // pmDuration = options.duration * 3 / 10;
1145
+ // if (display === 'none') {
1146
+ // element.style.display = '';
1147
+ // startHeight = 0; // 如果元素是隐藏的,则从 0 开始
1148
+ // }
1149
+ //
1150
+ // let endHeight = element.scrollHeight, // 目标高度是元素的 scrollHeight
1151
+ // changeHeight = endHeight - startHeight,
1152
+ // startTime = null;
1153
+ //
1154
+ // // 动画函数
1155
+ // function step(timestamp) {
1156
+ // if (!startTime) startTime = timestamp;
1157
+ // let progress = timestamp - startTime;
1158
+ // if (progress > mainDuration) progress = mainDuration;
1159
+ // let newHeight = ease(progress, startHeight, changeHeight, mainDuration);
1160
+ // element.style.height = newHeight + 'px';
1161
+ //
1162
+ // if (progress < mainDuration) {
1163
+ // window.requestAnimationFrame(step);
1164
+ // } else {
1165
+ // element.style.transition = 'padding ' + pmDuration + 'ms ease, margin ' + pmDuration + 'ms ease';
1166
+ // // element.style.transition = 'all ' + pmDuration + 'ms ease';
1167
+ // element.style.margin = '';
1168
+ // element.style.padding = '';
1169
+ // element.style.height = '';
1170
+ // options.callback && options.callback();
1171
+ // }
1172
+ // }
1173
+ // // 线性缓动函数
1174
+ // function ease(t, b, c, d) {
1175
+ // t /= d / 2;
1176
+ // if (t < 1) return c / 2 * t * t + b;
1177
+ // t--;
1178
+ // return -c / 2 * (t * (t - 2) - 1) + b;
1179
+ // }
1180
+ // window.requestAnimationFrame(step);
1181
+ // });
1085
1182
  return this.each((element) => {
1086
1183
  // 获取元素当前的高度和初始的 display 状态
1087
1184
  let startHeight = element.offsetHeight,
1088
- display = element.style.display,
1089
- mainDuration = options.duration * 7 / 10,
1090
- pmDuration = options.duration * 3 / 10;
1185
+ display = element.style.display;
1091
1186
  if (display === 'none') {
1092
1187
  element.style.display = '';
1093
1188
  startHeight = 0; // 如果元素是隐藏的,则从 0 开始
1094
1189
  }
1095
-
1096
- let endHeight = element.scrollHeight, // 目标高度是元素的 scrollHeight
1097
- changeHeight = endHeight - startHeight,
1098
- startTime = null;
1099
-
1100
- // 动画函数
1101
- function step(timestamp) {
1102
- if (!startTime) startTime = timestamp;
1103
- let progress = timestamp - startTime;
1104
- if (progress > mainDuration) progress = mainDuration;
1105
- let newHeight = ease(progress, startHeight, changeHeight, mainDuration);
1106
- element.style.height = newHeight + 'px';
1107
-
1108
- if (progress < mainDuration) {
1109
- window.requestAnimationFrame(step);
1110
- } else {
1111
- element.style.transition = 'padding ' + pmDuration + 'ms ease, margin ' + pmDuration + 'ms ease';
1112
- // element.style.transition = 'all ' + pmDuration + 'ms ease';
1113
- element.style.margin = '';
1114
- element.style.padding = '';
1115
- element.style.height = '';
1116
- options.callback && options.callback();
1117
- }
1118
- }
1119
- // 线性缓动函数
1120
- function ease(t, b, c, d) {
1121
- t /= d / 2;
1122
- if (t < 1) return c / 2 * t * t + b;
1123
- t--;
1124
- return -c / 2 * (t * (t - 2) - 1) + b;
1125
- }
1126
- window.requestAnimationFrame(step);
1190
+ element.style.height = startHeight + "px";
1191
+ element.style.transition = `height ${options.duration}ms ease-in-out`;
1192
+ element.style.height = element.scrollHeight + "px";
1193
+ element.style.display = 'block';
1194
+ setTimeout(() => {
1195
+ element.style.overflow = '';
1196
+ element.style.transition = '';
1197
+ element.style.display = '';
1198
+ element.style.height = '';
1199
+ if (options.callback && typeof options.callback === 'function') options.callback(element);
1200
+ }, options.duration);
1127
1201
  });
1128
1202
  }
1129
1203
 
@@ -1144,6 +1218,39 @@ class Base {
1144
1218
  }
1145
1219
  }
1146
1220
 
1221
+ // 元素透明度逐渐递减变0,最后display设置为none
1222
+ fadeOut(duration, callback) {
1223
+ const options = b.extend({ duration: duration, callback: callback }, { duration: 300, callback: false })
1224
+ // let start = performance.now();
1225
+ // const step = (time, element) => {
1226
+ // let progress = (time - start) / options.duration;
1227
+ // if (progress >= 1) {
1228
+ // element.style.opacity = 0;
1229
+ // element.style.transition = 'none';
1230
+ // if (options.callback && typeof options.callback === 'function') options.callback();
1231
+ // return;
1232
+ // }
1233
+ // element.style.opacity = 1 - progress.toFixed(1);
1234
+ // window.requestAnimationFrame((time) => {
1235
+ // step(time, element)
1236
+ // });
1237
+ // };
1238
+ // return this.each((element) => {
1239
+ // element.style.transition = `opacity ${duration}ms ease-in-out`;
1240
+ // window.requestAnimationFrame((time) => {
1241
+ // step(time, element)
1242
+ // });
1243
+ // });
1244
+ return this.each((element) => {
1245
+ element.style.transition = `opacity ${options.duration}ms ease-in-out`;
1246
+ element.style.opacity = 0;
1247
+ setTimeout(() => {
1248
+ element.style.display = 'none';
1249
+ if (options.callback && typeof options.callback === 'function') options.callback(element);
1250
+ }, options.duration);
1251
+ });
1252
+ }
1253
+
1147
1254
  // 1.2 页面常用方法扩展
1148
1255
 
1149
1256
  // 全选全清
@@ -1164,8 +1271,8 @@ class Base {
1164
1271
  * 反选
1165
1272
  <pre>
1166
1273
  <a href="javascript:" id="be-reverse-check">反选</a>
1167
- <label><input type="checkbox" className="be-check" checked="checked"/>选项一</label>
1168
- <label><input type="checkbox" className="be-check"/>选项二</label>
1274
+ <label><input type="checkbox" class="be-check" checked="checked"/>选项一</label>
1275
+ <label><input type="checkbox" class="be-check"/>选项二</label>
1169
1276
 
1170
1277
  b('#be-reverse-check').checkReverse('.be-check')
1171
1278
  </pre>
@@ -1263,8 +1370,8 @@ class Base {
1263
1370
  /**
1264
1371
  * 点击切换激活项(添加active class),已经激活则取消(删除active class)
1265
1372
  <pre>
1266
- <button type="button" className="my-btn btn btn-success">我的按钮1</button>
1267
- <button type="button" className="my-btn btn btn-success">我的按钮2</button>
1373
+ <button type="button" class="my-btn btn btn-success">按钮1</button>
1374
+ <button type="button" class="my-btn btn btn-success">按钮2</button>
1268
1375
 
1269
1376
  b(".my-btn").setActive();
1270
1377
  </pre>
@@ -1283,7 +1390,7 @@ class Base {
1283
1390
  }
1284
1391
 
1285
1392
  /**
1286
- * 全屏loading,
1393
+ * 全屏loading
1287
1394
  <pre>
1288
1395
  import "istyle/src/css/loading/do-pr-loader.css";
1289
1396
  b('#c').click(() => {
@@ -1302,24 +1409,29 @@ class Base {
1302
1409
  }
1303
1410
  options = b.extend(options, {
1304
1411
  isFull: true,
1305
- loadingClass: '.do-preloader',
1306
- template: '<div class="do-preloader"><span class="do-pr-loader"><span class="do-pr-lr"></span></span></div>'
1412
+ loadingTarget: '#do-preloader',
1413
+ template: '<div id="do-preloader" class="do-preloader"><span class="do-pr-loader"><span class="do-pr-lr"></span></span></div>'
1307
1414
  });
1308
1415
 
1309
1416
  return this.each((element) => {
1310
1417
  if (isComplete) {
1311
1418
  b("> *", element).removeClass("be-blur-2");
1312
- b(options.loadingClass).addClass("oy-0");
1419
+ b(options.loadingTarget).addClass("oy-0");
1313
1420
  setTimeout(() => {
1314
1421
  b("> *", element).removeClass("be-ts");
1315
- b(options.loadingClass).remove();
1422
+ b(options.loadingTarget).remove();
1316
1423
  }, 300);
1317
1424
  } else {
1318
- b(element).prepend(options.template);
1319
- b("> *", element).addClass("be-ts").addClass("be-blur-2");
1320
- if (options.template) {
1321
- b(options.loadingClass).css('position', 'fixed').css('height', '100vh').css('width', '100vw')
1322
- }
1425
+ const myEle = b("> *", element);
1426
+ myEle.addClass("be-ts").addClass("be-blur-2");
1427
+ // setTimeout(() => { // 同时加入可能看不出效果
1428
+ // myEle.addClass("be-blur-2");
1429
+ b(element).prepend(options.template);
1430
+ const myLoadingTarget = b(options.loadingTarget);
1431
+ if (myLoadingTarget.length) {
1432
+ b(options.loadingTarget).css('position', 'fixed').css('height', '100vh').css('width', '100vw')
1433
+ }
1434
+ // }, 100);
1323
1435
  }
1324
1436
  });
1325
1437
  }
@@ -1351,11 +1463,15 @@ class Base {
1351
1463
  return custom;
1352
1464
  }
1353
1465
 
1354
- // 字符串装换为驼峰格式
1466
+ // 字符串连字符-或者. 转为驼峰格式
1355
1467
  static camelCase = function(str) {
1356
- return str.replace(/-([a-z])/g, function(all, letter) {
1357
- return letter.toUpperCase();
1468
+ let transformed = str.replace(/-([a-z])/, function(match, p1) {
1469
+ return p1.toUpperCase();
1358
1470
  });
1471
+ transformed = transformed.replace(/\.([a-z])/, function(match, p1) {
1472
+ return p1.toUpperCase();
1473
+ });
1474
+ return transformed;
1359
1475
  }
1360
1476
 
1361
1477
  // 打印简写
@@ -1386,6 +1502,11 @@ class Base {
1386
1502
  return target;
1387
1503
  }
1388
1504
 
1505
+ // 判断变量是否为对象
1506
+ static isObject(item) {
1507
+ return (item) ? (item && typeof item === 'object' && !Array.isArray( item ) && true) : false;
1508
+ }
1509
+
1389
1510
  // 获取两个数组中的相同值,eg: b.same([1,2], [7,9,4,2,5,6,1]) //[1, 2]
1390
1511
  static same = function(arr1, arr2) {
1391
1512
  return arr1.filter(function(v) {
@@ -1406,11 +1527,6 @@ class Base {
1406
1527
  return regex.test(str);
1407
1528
  }
1408
1529
 
1409
- // 判断变量是否为对象
1410
- static isObject(item) {
1411
- return (item) ? (item && typeof item === 'object' && !Array.isArray( item ) && true) : false;
1412
- }
1413
-
1414
1530
  // 允许插件扩展
1415
1531
  static plugin(pluginName, pluginFunction) {
1416
1532
  // Base.fn[pluginName] = pluginFunction;
@@ -1855,6 +1971,7 @@ class Base {
1855
1971
  // 2.4 静态属性
1856
1972
  // 生成缓存随机名称
1857
1973
  static expando = "base" + ("" + Math.random()).replace(/\D/g, "");
1974
+ static elementData = new Map();
1858
1975
  static cache = { };
1859
1976
 
1860
1977
  static build(selector, context) {
@@ -1987,6 +2104,7 @@ Array.prototype.unique = function () {
1987
2104
  10. 弹框搜索面板:new u.PopoverSearch('#ipopover', {
1988
2105
  11. 文字切换动画特效:new u.Flash("#ce-flash", {
1989
2106
  12. 绘制点线背景动画:new u.LineEffect("#canvas-warp", {
2107
+ 13. JS、CSS页面引入,多次引入只保留一个:const iloader = new u.ILoader();
1990
2108
 
1991
2109
  * ======================================================================== */
1992
2110
  /**
@@ -2093,6 +2211,7 @@ class SubmitFlag {
2093
2211
 
2094
2212
  init(element) {
2095
2213
  let myElems = base(element),
2214
+ /** @type {SubmitFlag<>} **/
2096
2215
  data = myElems.data("be.submitflag");
2097
2216
  myElems.data("text", myElems.text()).click((e) => {
2098
2217
  data.request(e.currentTarget);
@@ -2518,13 +2637,18 @@ class BtnEf {
2518
2637
  * ======================================================================== */
2519
2638
  class AeLoader {
2520
2639
  constructor(selector, custom) {
2521
- this.selector = selector;
2522
- this.options = base.extend( custom, this.options )
2640
+ this.selector = '';
2641
+ if(base.isObject(selector)) {
2642
+ this.options = base.extend( selector, this.options );
2643
+ } else {
2644
+ if(selector) this.selector = selector;
2645
+ this.options = base.extend( custom, this.options )
2646
+ }
2523
2647
  base("[data-ae-load]").addClass("ae-load");
2524
2648
  }
2525
2649
 
2526
2650
  options = {
2527
- target: '',
2651
+ // target: '',
2528
2652
  //默认1秒,修改需要同时也需要修改CSS动画
2529
2653
  time: 1000
2530
2654
  }
@@ -2552,8 +2676,8 @@ class AeLoader {
2552
2676
 
2553
2677
  base("[data-ae-load]").addClass("ae-load");
2554
2678
  base(target + "[data-ae-load]").each(function(currentTarget) {
2555
- let minWidth = base(currentTarget).data("al-mw");
2556
- let minHeight = base(currentTarget).data("al-mh");
2679
+ const minWidth = base(currentTarget).data("al-mw"),
2680
+ minHeight = base(currentTarget).data("al-mh");
2557
2681
  if (minWidth) base(currentTarget).css("min-width", minWidth);
2558
2682
  if (minHeight) base(currentTarget).css("min-height", minHeight);
2559
2683
 
@@ -2587,7 +2711,7 @@ class AeLoader {
2587
2711
  * 2024年6月29日 10:28:55
2588
2712
  * ========================================================================
2589
2713
  * <pre>
2590
- <div class="be-paging-warp">
2714
+ <div id="be-pw" class="be-paging-warp">
2591
2715
  <p></p>
2592
2716
  <nav>
2593
2717
  <ul id="ipagination" class="be-paging"></ul>
@@ -2626,10 +2750,10 @@ class IPagination {
2626
2750
  }
2627
2751
  // containerId, totalItems, itemsPerPage, visiblePages = 5
2628
2752
  options = {
2629
- targetWarp: '.be-paging-warp',
2753
+ targetWarp: '#be-pw', //不同分页区分
2630
2754
  totalItems: 0, //总条数
2631
2755
  itemsPerPage: 0, //一页几条数据
2632
- visiblePages: 5, //显示多少可见页
2756
+ visiblePages: 5, //多少按钮页可见
2633
2757
  prev: '上一页', //or: <i class="bi bi-chevron-left"></i>
2634
2758
  next: '下一页', //or: <i class="bi bi-chevron-right"></i>
2635
2759
  first: '首页', //or: <i class="bi bi-chevron-double-left"></i>
@@ -2731,7 +2855,7 @@ class IPagination {
2731
2855
  </div>
2732
2856
  <div class="be-list-nofound">查询不到相应数据!</div>
2733
2857
  <div class="be-list-page">
2734
- <div class="be-paging-warp">
2858
+ <div id="ilist-ip-warp" class="be-paging-warp">
2735
2859
  <p></p>
2736
2860
  <nav>
2737
2861
  <ul id="ipagination" class="be-paging"></ul>
@@ -2908,6 +3032,7 @@ class IList {
2908
3032
  template: "#tp-list",
2909
3033
  headerMap: { }, //{ 'Content-Type': 'application/json'}
2910
3034
  cache: 'default',
3035
+ ipWarp: '#ilist-ip-warp',
2911
3036
  prev: '上一页', //or: <i class="bi bi-chevron-left"></i>
2912
3037
  next: '下一页', //or: <i class="bi bi-chevron-right"></i>
2913
3038
  first: '首页', //or: <i class="bi bi-chevron-double-left"></i>
@@ -2944,7 +3069,8 @@ class IList {
2944
3069
 
2945
3070
  // 数据查询
2946
3071
  getData(element, options, param) {
2947
- let target = this;
3072
+ let target = this,
3073
+ myElement = base(element);
2948
3074
  base(".be-list-data-body", element).html("");
2949
3075
  base(".be-list-loading", element).addClass("opacity-100");
2950
3076
  base(".be-list-nofound", element).removeClass("opacity-100");
@@ -2979,11 +3105,29 @@ class IList {
2979
3105
 
2980
3106
  if (data.total) {
2981
3107
  target.page(element, options, param, data.total);//翻页
2982
- //全选/全清
3108
+
3109
+ // 全选/全清
2983
3110
  base(".ilist-check-all").checkAll('.ilist-check');
2984
3111
 
2985
- if (base(element).data("be.ilist.event")) {
2986
- base(element).data("be.ilist.event", false);
3112
+ //点击列选择单列/点击列取消选择单列
3113
+ base( "table > tbody tr", element ).click( e => {
3114
+ let target = base( e.target );
3115
+ if (!(target.is( "input" ) || target.is( "i" ) || target.is( "a" ))) {
3116
+ base( ".ilist-check", e.currentTarget ).click();
3117
+ }
3118
+ } )
3119
+
3120
+ // 全选列/全清列
3121
+ // b( ".ilist-check-all", element ).change( e => {
3122
+ // let isChecked = b( e.currentTarget ).is( ":checked" );
3123
+ // if (isChecked)
3124
+ // b( ".ilist-check" ).addClass( "active" ).trigger("change");
3125
+ // else
3126
+ // b( ".ilist-check" ).removeClass( "active" ).trigger("change");
3127
+ // } );
3128
+
3129
+ if (myElement.data("be.ilist.event")) {
3130
+ myElement.data("be.ilist.event", false);
2987
3131
 
2988
3132
  //选择单列/取消选择单列
2989
3133
  base( ".ilist-check", element ).change( e => {
@@ -2994,27 +3138,14 @@ class IList {
2994
3138
  base(e.currentTarget).parents("tr").removeClass("active");
2995
3139
  } );
2996
3140
 
2997
- //全选列/全清列
2998
- base( ".ilist-check-all", element ).change( e => {
2999
- let isChecked = base( e.currentTarget ).is( ":checked" );
3000
- if (isChecked)
3001
- base( ".ilist-check" ).addClass( "active" ).trigger("change");
3002
- else
3003
- base( ".ilist-check" ).removeClass( "active" ).trigger("change");
3004
- } );
3005
-
3006
- //点击列选择单列/点击列取消选择单列
3007
- base( "table > tbody tr", element ).click( e => {
3008
- let target = base( e.target );
3009
- if (!(target.is( "input" ) || target.is( "i" ) || target.is( "a" ))) {
3010
- base( ".ilist-check", e.currentTarget ).click();
3011
- }
3012
- } )
3013
-
3014
3141
  //排序,<td data-sortname="a.title" data-is-sort="true"
3015
3142
  base( "table > thead tr td", element ).click( e => {
3016
3143
  const sortname = base( e.currentTarget ).data( "sortname" );
3017
3144
  if (sortname) {
3145
+ const reloadParam = myElement.data("be.ilist.param");
3146
+ if (reloadParam) {
3147
+ param = base.extend(reloadParam, param);
3148
+ }
3018
3149
  param.sortname = sortname;
3019
3150
  if (!base( e.currentTarget ).hasClass( "is-check" ) && param.sortname) {
3020
3151
  let sortorder = base( e.currentTarget ).attr( "data-sort-order" );
@@ -3035,7 +3166,7 @@ class IList {
3035
3166
  param.sortorder = "desc";
3036
3167
  }
3037
3168
 
3038
- base( element ).data( "be.ilist.flag", true );
3169
+ myElement.data("be.ilist.flag", true );
3039
3170
  param.page = "1";
3040
3171
  options.isInit = false;
3041
3172
  target.getData( element, options, param );
@@ -3063,8 +3194,9 @@ class IList {
3063
3194
  page(element, options, param, total) {
3064
3195
  let target = this,
3065
3196
  myElement = base(element);
3066
- if (myElement.data("be.ilist.flag")) {
3197
+ if (myElement.data("be.ilist.flag")) { //每次都重新生成一次分页
3067
3198
  new IPagination('#ipagination', {
3199
+ targetWarp: options.ipWarp,
3068
3200
  totalItems: total,
3069
3201
  itemsPerPage: options.rp,
3070
3202
  visiblePages: options.visiblePages,
@@ -3085,12 +3217,15 @@ class IList {
3085
3217
 
3086
3218
  // 设置参数重新搜索
3087
3219
  reload(param) {
3088
- let target = base(this),
3089
- data = target.data("be.ilist"),
3220
+ let myElement = base(this.selector),
3221
+ /** @type {IList<>} **/
3222
+ data = myElement.data("be.ilist"),
3090
3223
  newParam = base.extend(param,
3091
3224
  { page: 1, rp: data.options.rp, sortname: data.options.sortname, sortorder: data.options.sortorder });
3092
3225
  data.options.isInit = false;
3093
- target.data("be.ilist.flag", true);
3226
+ myElement.data("be.ilist.flag", true);
3227
+ myElement.data("be.ilist.param", newParam);
3228
+ base('table > thead tr td', myElement).attr('data-sort-order', '');
3094
3229
  data["getData"](data['selector'], data.options, newParam);
3095
3230
  }
3096
3231
  }
@@ -3547,7 +3682,6 @@ class PopoverSearch {
3547
3682
  // 获取参数
3548
3683
  getParam() {
3549
3684
  const params = {};
3550
- base.l(base(".popover-form-item"))
3551
3685
  base(".popover-form-item").each(function(e) {
3552
3686
  const myEle = base(e),
3553
3687
  name = myEle.attr("name"),
@@ -3895,38 +4029,52 @@ class LineEffect {
3895
4029
  // 监听事件,移动鼠标, 滚动, 改变屏幕大小
3896
4030
  addListeners(options, xy, canvas) {
3897
4031
  const target = this;
3898
- if(!('ontouchstart' in window)) {
3899
- window.addEventListener("mousemove", (e) => {
3900
- target.mouseMove(e, xy);
3901
- });
3902
- }
3903
- window.addEventListener("scroll", () => {
4032
+ const mousemove = (e) => {
4033
+ target.mouseMove(e, xy);
4034
+ };
4035
+ const scroll = () => {
3904
4036
  target.scrollCheck(options);
3905
- });
3906
- window.addEventListener("resize", () => {
4037
+ };
4038
+ const resize = () => {
3907
4039
  target.resize(options, canvas);
3908
- });
4040
+ };
4041
+
4042
+ if (document.getElementById(target.options.canvasId)) {
4043
+ if(!('ontouchstart' in window)) {
4044
+ window.addEventListener("mousemove", mousemove);
4045
+ }
4046
+ window.addEventListener("scroll", scroll);
4047
+ window.addEventListener("resize", resize);
4048
+ } else {
4049
+ if(!('ontouchstart' in window)) {
4050
+ window.removeEventListener("mousemove", mousemove);
4051
+ }
4052
+ window.removeEventListener("scroll", scroll);
4053
+ window.removeEventListener("resize", resize);
4054
+ }
3909
4055
  }
3910
4056
 
3911
4057
  mouseMove(e, xy) {
3912
- const canvas = document.getElementById(this.options.canvasId),
3913
- rect = canvas.getBoundingClientRect(),
3914
- scrollTop = window.pageYOffset || document.documentElement.scrollTop,
3915
- scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
3916
- offsetTop = rect.top + scrollTop,
3917
- offsetLeft = rect.left + scrollLeft;
3918
-
3919
- let posx = 0,
3920
- posy = 0;
3921
- if (e.pageX || e.pageY) {
3922
- posx = e.pageX;
3923
- posy = e.pageY;
3924
- } else if (e.clientX || e.clientY) {
3925
- posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
3926
- posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
4058
+ const canvas = document.getElementById(this.options.canvasId);
4059
+ if (canvas) {
4060
+ const rect = canvas.getBoundingClientRect(),
4061
+ scrollTop = window.pageYOffset || document.documentElement.scrollTop,
4062
+ scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
4063
+ offsetTop = rect.top + scrollTop,
4064
+ offsetLeft = rect.left + scrollLeft;
4065
+
4066
+ let posx = 0,
4067
+ posy = 0;
4068
+ if (e.pageX || e.pageY) {
4069
+ posx = e.pageX;
4070
+ posy = e.pageY;
4071
+ } else if (e.clientX || e.clientY) {
4072
+ posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
4073
+ posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
4074
+ }
4075
+ xy.x = posx - offsetLeft;
4076
+ xy.y = posy - offsetTop;
3927
4077
  }
3928
- xy.x = posx - offsetLeft;
3929
- xy.y = posy - offsetTop;
3930
4078
  }
3931
4079
 
3932
4080
  scrollCheck(options) {
@@ -3940,7 +4088,6 @@ class LineEffect {
3940
4088
  }
3941
4089
 
3942
4090
 
3943
-
3944
4091
  /* ========================================================================
3945
4092
  * 12. 鼠标上下左右划入监听实现对应动画
3946
4093
  * 2022年7月28日 10:50:06
@@ -4070,6 +4217,169 @@ class HoverDir {
4070
4217
  }
4071
4218
 
4072
4219
 
4220
+ /* ========================================================================
4221
+ * 13. JS、CSS页面引入,多次引入只保留一个
4222
+ * 2024年9月15日 09:19:37
4223
+ * ========================================================================
4224
+ * <pre>
4225
+ const iloader = new u.ILoader();
4226
+ Promise.all([
4227
+ iloader.loadStyle('https://arisu.cn/te/WEB/css/animate.v4.css'),
4228
+ iloader.loadScript('https://arisu.cn/te/WEB/js/handlebars-v4.0.5.js'),
4229
+ iloader.loadScript('https://arisu.cn/te/WEB/js/imagesloaded.pkgd.min.js'),
4230
+ ]).then(() => {
4231
+ console.log('All scripts、style loaded');
4232
+ }).catch(error => {
4233
+ console.error('Error loading scripts、style', error);
4234
+ });
4235
+ * </pre>
4236
+ * ======================================================================== */
4237
+ class ILoader {
4238
+ constructor(custom) {
4239
+ /** @type {Array<{script: HTMLElement, url: string, isLoaded: boolean}>} **/
4240
+ this.jsLoaded = [];
4241
+ this.cssLoaded = [];
4242
+ this.options = base.extend( custom, this.options );
4243
+ }
4244
+ options = {
4245
+ // 脚本加载失败,重新尝试次数和每次使用时间(毫秒)
4246
+ times: 20,
4247
+ time: 1000
4248
+ }
4249
+
4250
+ /** 定义一个加载并执行外部 JS 文件的函数
4251
+ const iloader = new u.ILoader();
4252
+ Promise.all([
4253
+ iloader.loadScript('https://arisu.cn/te/WEB/js/handlebars-v4.0.5.js'),
4254
+ iloader.loadScript('https://arisu.cn/te/WEB/js/imagesloaded.pkgd.min.js')
4255
+ ]).then(() => {
4256
+ console.log('All scripts loaded');
4257
+ }).catch(error => {
4258
+ console.error('Error loading scripts', error);
4259
+ });
4260
+ * @param url
4261
+ * @returns {Promise<unknown>}
4262
+ */
4263
+ loadScript(url) {
4264
+ const target = this;
4265
+
4266
+ return new Promise((resolve, reject) => {
4267
+ // 检查是否已经加载过该脚本
4268
+ const existingScript = target.jsLoaded.find(script => script.url === url);
4269
+ if (!existingScript) {
4270
+ // 页面上未引入
4271
+ let script = document.createElement('script'),
4272
+ isOnload = false,
4273
+ count = 0;
4274
+
4275
+ target.jsLoaded = [...target.jsLoaded, { script: script, url: url, isLoaded: false, count: 0 }];
4276
+
4277
+ script.src = url;
4278
+ // script.async = 'true';
4279
+ script.onload = () => {
4280
+ target.jsLoaded = target.jsLoaded.map(item =>
4281
+ item.url === url ? { ...item, isLoaded: true } : item
4282
+ );
4283
+ isOnload = true;
4284
+ resolve(script);
4285
+ };
4286
+ script.onerror = () => {
4287
+ target.jsLoaded = target.jsLoaded.filter(item => item.url !== url);
4288
+ reject(new Error('Script load error for ' + url));
4289
+ }
4290
+ document.body.append(script);
4291
+ const intervalId = setInterval(() => {
4292
+ if (isOnload) {
4293
+ // b.l('载入成功!: ', url)
4294
+ clearInterval(intervalId);
4295
+ return;
4296
+ } else {
4297
+ if (count > target.options.times) {
4298
+ // console.log('载入失败!: ', url)
4299
+ if (script.parentNode === document.body) document.body.removeChild(script);
4300
+ clearInterval(intervalId);
4301
+ return;
4302
+ }
4303
+ }
4304
+ count++;
4305
+ }, 100);
4306
+ } else {
4307
+ // 页面上已经引入,但是还未调用
4308
+ let count = 0, scriptItem;
4309
+ const intervalId = setInterval(() => {
4310
+ scriptItem = target.jsLoaded.find(item => item.url === url);
4311
+ base.l('尝试加载中: ', url, count)
4312
+ try {
4313
+ if (!scriptItem.isLoaded && count > target.options.times) {
4314
+ // b.l('删除了URL: ', scriptItem.url);
4315
+ target.jsLoaded = target.jsLoaded.filter(item => item.url !== url);
4316
+ if (scriptItem.script.parentNode === document.body) document.body.removeChild(scriptItem.script);
4317
+ clearInterval(intervalId);
4318
+ return;
4319
+ }
4320
+
4321
+ if (scriptItem.isLoaded) {
4322
+ // b.l('载入成功 ');
4323
+ clearInterval(intervalId);
4324
+ resolve();
4325
+ return;
4326
+ }
4327
+ count++;
4328
+ } catch(e) { console.error(e) }
4329
+ }, target.options.time);
4330
+ }
4331
+ })
4332
+ }
4333
+
4334
+ /** 定义一个加载并执行外部 JS 文件的函数
4335
+ Promise.all([
4336
+ loadScript('https://arisu.cn/te/WEB/css/buttons-plus.css'),
4337
+ loadStyle('https://arisu.cn/te/WEB/css/animate.v4.css')
4338
+ ]).then(() => {
4339
+ console.log('All scripts/style loaded');
4340
+ }).catch(error => {
4341
+ console.error('Error loading', error);
4342
+ });
4343
+ * @param href 样式地址
4344
+ * @returns {Promise<unknown>}
4345
+ */
4346
+ loadStyle(href) {
4347
+ const target = this;
4348
+ return new Promise((resolve, reject) => {
4349
+ // 检查是否已经加载了CSS文件
4350
+ const links = document.getElementsByTagName("link");
4351
+ for (let i = 0; i < links.length; i++) {
4352
+ if (links[i].getAttribute("href") === href) {
4353
+ resolve();
4354
+ return true;
4355
+ }
4356
+ }
4357
+
4358
+ let style = document.createElement('link');
4359
+ style.href = href;
4360
+ style.rel = 'stylesheet';
4361
+ style.type = 'text/css';
4362
+ style.onload = () => resolve(style);
4363
+ style.onerror = () => reject(new Error('Style load error for ' + href));
4364
+ document.head.append(style);
4365
+ target.cssLoaded.push(style);
4366
+ });
4367
+ }
4368
+
4369
+ // 删除所有引入脚本、样式
4370
+ destroy() {
4371
+ this.jsLoaded.forEach((item)=>{
4372
+ if (item.script && item.script.parentNode === document.body) document.body.removeChild(item.script);
4373
+ })
4374
+ this.cssLoaded.forEach((item)=>{
4375
+ if (item.parentNode === document.head) document.head.removeChild(item);
4376
+ })
4377
+ this.jsLoaded = [];
4378
+ this.cssLoaded = [];
4379
+ }
4380
+ }
4381
+
4382
+
4073
4383
 
4074
4384
 
4075
4385
  /* harmony default export */ const utils = (base);
@@ -4225,7 +4535,12 @@ function owl($target, options) {
4225
4535
  utils['owl'] = owl;
4226
4536
 
4227
4537
 
4228
- // 消息框参数设置
4538
+ /**
4539
+ * 消息框参数设置:messageInit('info', 1, 2)
4540
+ * @param type info / error / success
4541
+ * @param classes 消息位置(2:顶部 / 6:左下下) ,按顺时针显示
4542
+ * @param theme 样式(2:黑色), 1:flat、2:future、3:block、4:air、5:ice
4543
+ **/
4229
4544
  function messageInit(type, classes, theme) {
4230
4545
  // 弹框样式,需要导入对应CSS
4231
4546
  if (theme === 1) {
@@ -4639,6 +4954,7 @@ utils['niceScroll'] = niceScroll;
4639
4954
  function validationEngine($target, options) {
4640
4955
  options = utils.extend(options, {
4641
4956
  focusFirstField : false,
4957
+ validationEventTrigger: "click",
4642
4958
  promptPosition: "topRight"
4643
4959
  });
4644
4960
  $target.validationEngine(options);
@@ -4649,13 +4965,14 @@ utils['validationEngine'] = validationEngine;
4649
4965
  * 14. validationEngine表单验证,确认是否验证通过
4650
4966
  * @param $target jQuery选择器
4651
4967
  * @param command 字符串方法名
4968
+ * @param options 新参数
4652
4969
  <pre>
4653
4970
  const isSuccessed = b.validate($("#form-2"));
4654
4971
  </pre>
4655
4972
  **/
4656
- function validate($target, command) {
4657
- const options = utils.extend( { command: command }, { command: "validate" });
4658
- return $target.validationEngine(options.command);
4973
+ function validate($target, command, options) {
4974
+ const os = utils.extend( { command: command }, { command: "validate", options });
4975
+ return $target.validationEngine(os.command, os.options);
4659
4976
  }
4660
4977
  utils['validate'] = validate;
4661
4978