New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@smt-ui/component

Package Overview
Dependencies
Maintainers
5
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smt-ui/component - npm Package Compare versions

Comparing version 1.2.18 to 1.2.20

4

package.json
{
"name": "@smt-ui/component",
"version": "1.2.18",
"version": "1.2.20",
"description": "extension base",

@@ -47,3 +47,3 @@ "author": "jialipeng <jialipeng@baidu.com>",

},
"gitHead": "037083b0351b7dd61ec637ee9293bab4062b9cb9"
"gitHead": "8ca4c2ae42a03578ca7be5b01926834424ad66d9"
}
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _px = require("../../common/utils/px");
var _index = require("../../common/utils/index");
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**
* @file 下拉刷新
* @author LipengJia (jialipeng@baidu.com)
* @date 2019-12-19
*/
var STATUS = {

@@ -108,3 +104,2 @@ IDLE: 0,

},
/**

@@ -116,6 +111,5 @@ * scrollView 滚动参数

var _this = this;
var detail = _ref.detail;
this.scrollTop = detail.scrollTop; // 如果是ios惯性,就禁掉回弹
this.scrollTop = detail.scrollTop;
// 如果是ios惯性,就禁掉回弹
if (this.data.pullToRefresh && this.scrollTop < 0 && this.data.enableScroll && this.offsetY === 0) {

@@ -130,6 +124,4 @@ this.setData({

}
this.triggerEvent('scroll', detail);
},
/**

@@ -151,3 +143,2 @@ * 阻尼值转换 * 四参方程有常数,便于转换屏幕比

var result = 0;
if (clientHeight > 400) {

@@ -160,3 +151,2 @@ // 系数 .65

}
return Math.round(result);

@@ -166,216 +156,167 @@ },

var _this2 = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var type, _ref2$touches, touches, _ref2$changedTouches, changedTouches, _ref2$manual, manual, disabled, _iterator, _step, touch, id, pageY, distance, _iterator2, _step2, _touch, _id, _pageY, offsetY, pullDown, circleInfo, setOffsetY, _iterator3, _step3, _touch2, _id2, _pageY2, shouldLoad, result;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
type = _ref2.type, _ref2$touches = _ref2.touches, touches = _ref2$touches === void 0 ? [] : _ref2$touches, _ref2$changedTouches = _ref2.changedTouches, changedTouches = _ref2$changedTouches === void 0 ? [] : _ref2$changedTouches, _ref2$manual = _ref2.manual, manual = _ref2$manual === void 0 ? false : _ref2$manual;
if (!(_this2.closing || _this2.data.disableTouch && !manual)) {
_context.next = 3;
break;
}
return _context.abrupt("return");
case 3:
// ue规定: 如果api调用下拉刷新,则不启用手势刷新
disabled = !_this2.data.pullToRefresh && !manual && _this2.data.status === STATUS.IDLE; // 禁用多点触控
_context.t0 = type;
_context.next = _context.t0 === 'touchstart' ? 7 : _context.t0 === 'touchmove' ? 28 : _context.t0 === 'touchend' ? 44 : 56;
while (1) switch (_context.prev = _context.next) {
case 0:
type = _ref2.type, _ref2$touches = _ref2.touches, touches = _ref2$touches === void 0 ? [] : _ref2$touches, _ref2$changedTouches = _ref2.changedTouches, changedTouches = _ref2$changedTouches === void 0 ? [] : _ref2$changedTouches, _ref2$manual = _ref2.manual, manual = _ref2$manual === void 0 ? false : _ref2$manual;
if (!(_this2.closing || _this2.data.disableTouch && !manual)) {
_context.next = 3;
break;
case 7:
_this2.touching = true;
_iterator = _createForOfIteratorHelper(touches);
_context.prev = 9;
_iterator.s();
case 11:
if ((_step = _iterator.n()).done) {
_context.next = 19;
break;
}
return _context.abrupt("return");
case 3:
// ue规定: 如果api调用下拉刷新,则不启用手势刷新
disabled = !_this2.data.pullToRefresh && !manual && _this2.data.status === STATUS.IDLE; // 禁用多点触控
_context.t0 = type;
_context.next = _context.t0 === 'touchstart' ? 7 : _context.t0 === 'touchmove' ? 28 : _context.t0 === 'touchend' ? 44 : 56;
break;
case 7:
_this2.touching = true;
_iterator = _createForOfIteratorHelper(touches);
_context.prev = 9;
_iterator.s();
case 11:
if ((_step = _iterator.n()).done) {
_context.next = 19;
break;
}
touch = _step.value;
id = touch.identifier, pageY = touch.pageY;
if (!(_this2.pos[id] == null)) {
_context.next = 17;
break;
}
_this2.pos[id] = pageY + _this2.scrollTop;
return _context.abrupt("break", 19);
case 17:
_context.next = 11;
break;
case 19:
_context.next = 24;
break;
case 21:
_context.prev = 21;
_context.t1 = _context["catch"](9);
_iterator.e(_context.t1);
case 24:
_context.prev = 24;
_iterator.f();
return _context.finish(24);
case 27:
return _context.abrupt("break", 56);
case 28:
distance = 0;
_iterator2 = _createForOfIteratorHelper(touches);
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
_touch = _step2.value;
_id = _touch.identifier, _pageY = _touch.pageY;
if (_this2.pos[_id]) {
distance += Math.round(_pageY - _this2.pos[_id]);
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
offsetY = _this2.offsetY = _this2.dumping(distance + _this2.lastOffsetY);
pullDown = distance > 0; // 没loading动画时下拉计算动画
if (_this2.data.status === STATUS.IDLE) {
circleInfo = (0, _index.calcCircle)(offsetY, _this2.data.loadingHeight);
circleInfo && _this2.setData(circleInfo);
}
touch = _step.value;
id = touch.identifier, pageY = touch.pageY;
if (!(_this2.pos[id] == null)) {
_context.next = 17;
break;
}
_this2.pos[id] = pageY + _this2.scrollTop;
return _context.abrupt("break", 19);
case 17:
_context.next = 11;
// 还未加载时,向上划要收起loading
if (!(!pullDown && _this2.data.status !== STATUS.IDLE && Math.abs(offsetY) > 20)) {
_context.next = 40;
break;
case 19:
_context.next = 24;
}
_this2.fadeCircle();
_this2.setData({
status: STATUS.IDLE,
offsetY: 0
});
_this2.triggerEvent('statuschange', STATUS.IDLE);
_this2.lastOffsetY = _this2.offsetY = 0;
return _context.abrupt("return");
case 40:
if (!disabled) {
_context.next = 42;
break;
case 21:
_context.prev = 21;
_context.t1 = _context["catch"](9);
_iterator.e(_context.t1);
case 24:
_context.prev = 24;
_iterator.f();
return _context.finish(24);
case 27:
return _context.abrupt("break", 56);
case 28:
distance = 0;
_iterator2 = _createForOfIteratorHelper(touches);
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
_touch = _step2.value;
_id = _touch.identifier, _pageY = _touch.pageY;
if (_this2.pos[_id]) {
distance += Math.round(_pageY - _this2.pos[_id]);
}
}
return _context.abrupt("return");
case 42:
// offsetY快,setData慢,可能造成向上划没到顶。
// 要注意 初始就向下划,过滤掉
if (offsetY > 0 || _this2.data.offsetY > 0) {
setOffsetY = function setOffsetY() {
return _this2.setData({
offsetY: offsetY
});
}; // 如果已经禁止滚动&&还往下拉,直接赋值
if (!_this2.data.enableScroll) {
setOffsetY();
} else {
_this2.setData({
// 该setData 不会多次执行
enableScroll: false
}, setOffsetY);
}
}
return _context.abrupt("break", 56);
case 44:
_iterator3 = _createForOfIteratorHelper(changedTouches);
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
_touch2 = _step3.value;
_id2 = _touch2.identifier, _pageY2 = _touch2.pageY;
if (_this2.pos[_id2]) {
_this2.lastOffsetY += _pageY2 - _this2.pos[_id2];
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
if (!(touches.length || disabled)) {
_context.next = 48;
break;
}
return _context.abrupt("return");
case 48:
_this2.touching = false;
_this2.pos = {};
offsetY = _this2.offsetY = _this2.dumping(distance + _this2.lastOffsetY);
pullDown = distance > 0; // 没loading动画时下拉计算动画
// 判断是否加载
shouldLoad = _this2.scrollTop <= 0 && _this2.offsetY >= _this2.data.loadingHeight;
result = 0;
if (shouldLoad) {
// 只有status === 0时,触发加载
if (_this2.data.status === STATUS.IDLE) {
circleInfo = (0, _index.calcCircle)(offsetY, _this2.data.loadingHeight);
circleInfo && _this2.setData(circleInfo);
} // 还未加载时,向上划要收起loading
if (!(!pullDown && _this2.data.status !== STATUS.IDLE && Math.abs(offsetY) > 20)) {
_context.next = 40;
break;
_this2.triggerEvent('refresh');
_this2.setData({
status: STATUS.LOADING
});
_this2.triggerEvent('statuschange', STATUS.LOADING);
}
_this2.startRefreshTime = Date.now();
result = _this2.data.loadingHeight;
} else {
_this2.fadeCircle();
}
_this2.setData({
enableScroll: true
}, function () {
_this2.setData({
status: STATUS.IDLE,
offsetY: 0
offsetY: result
});
_this2.triggerEvent('statuschange', STATUS.IDLE);
_this2.lastOffsetY = _this2.offsetY = 0;
return _context.abrupt("return");
case 40:
if (!disabled) {
_context.next = 42;
break;
}
return _context.abrupt("return");
case 42:
// offsetY快,setData慢,可能造成向上划没到顶。
// 要注意 初始就向下划,过滤掉
if (offsetY > 0 || _this2.data.offsetY > 0) {
setOffsetY = function setOffsetY() {
return _this2.setData({
offsetY: offsetY
});
}; // 如果已经禁止滚动&&还往下拉,直接赋值
if (!_this2.data.enableScroll) {
setOffsetY();
} else {
_this2.setData({
// 该setData 不会多次执行
enableScroll: false
}, setOffsetY);
}
}
return _context.abrupt("break", 56);
case 44:
_iterator3 = _createForOfIteratorHelper(changedTouches);
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
_touch2 = _step3.value;
_id2 = _touch2.identifier, _pageY2 = _touch2.pageY;
if (_this2.pos[_id2]) {
_this2.lastOffsetY += _pageY2 - _this2.pos[_id2];
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
if (!(touches.length || disabled)) {
_context.next = 48;
break;
}
return _context.abrupt("return");
case 48:
_this2.touching = false;
_this2.pos = {}; // 判断是否加载
shouldLoad = _this2.scrollTop <= 0 && _this2.offsetY >= _this2.data.loadingHeight;
result = 0;
if (shouldLoad) {
// 只有status === 0时,触发加载
if (_this2.data.status === STATUS.IDLE) {
_this2.triggerEvent('refresh');
_this2.setData({
status: STATUS.LOADING
});
_this2.triggerEvent('statuschange', STATUS.LOADING);
}
_this2.startRefreshTime = Date.now();
result = _this2.data.loadingHeight;
} else {
_this2.fadeCircle();
}
_this2.setData({
enableScroll: true
}, function () {
_this2.setData({
offsetY: result
});
});
_this2.lastOffsetY = _this2.offsetY = result;
return _context.abrupt("break", 56);
case 56:
case "end":
return _context.stop();
}
});
_this2.lastOffsetY = _this2.offsetY = result;
return _context.abrupt("break", 56);
case 56:
case "end":
return _context.stop();
}

@@ -385,3 +326,2 @@ }, _callee, null, [[9, 21, 24, 27]]);

},
/**

@@ -392,6 +332,4 @@ * circle渐隐

var _this3 = this;
return (0, _index.linearAccu)(function (y, callback) {
var circleInfo = (0, _index.calcCircle)(y, _this3.data.loadingHeight);
if (circleInfo) {

@@ -404,3 +342,2 @@ _this3.setData(circleInfo, callback);

},
/**

@@ -411,51 +348,39 @@ * 渐隐loadingbar

var _this4 = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
// 防止关闭后,touchend还在触发中
_this4.closing = true;
_this4.debCloseLoading.cancel();
if (_this4.data.enableScroll) {
_context2.next = 5;
break;
}
while (1) switch (_context2.prev = _context2.next) {
case 0:
// 防止关闭后,touchend还在触发中
_this4.closing = true;
_this4.debCloseLoading.cancel();
if (_this4.data.enableScroll) {
_context2.next = 5;
return (0, _index.syncSetData)(_this4, {
enableScroll: true
});
case 5:
_context2.next = 7;
return (0, _index.syncSetData)(_this4, {
offsetY: 0
});
case 7:
_context2.next = 9;
return new Promise(function (r) {
return setTimeout(r, 200);
});
case 9:
_context2.next = 11;
return (0, _index.syncSetData)(_this4, {
status: STATUS.IDLE
});
case 11:
_this4.triggerEvent('statuschange', STATUS.IDLE);
_this4.lastOffsetY = _this4.offsetY = 0;
_this4.closing = false;
case 14:
case "end":
return _context2.stop();
}
break;
}
_context2.next = 5;
return (0, _index.syncSetData)(_this4, {
enableScroll: true
});
case 5:
_context2.next = 7;
return (0, _index.syncSetData)(_this4, {
offsetY: 0
});
case 7:
_context2.next = 9;
return new Promise(function (r) {
return setTimeout(r, 200);
});
case 9:
_context2.next = 11;
return (0, _index.syncSetData)(_this4, {
status: STATUS.IDLE
});
case 11:
_this4.triggerEvent('statuschange', STATUS.IDLE);
_this4.lastOffsetY = _this4.offsetY = 0;
_this4.closing = false;
case 14:
case "end":
return _context2.stop();
}

@@ -465,3 +390,2 @@ }, _callee2);

},
/**

@@ -472,41 +396,31 @@ * 调用模拟下拉刷新

var _this5 = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
if (!(_this5.data.status !== STATUS.IDLE)) {
_context3.next = 4;
break;
while (1) switch (_context3.prev = _context3.next) {
case 0:
if (!(_this5.data.status !== STATUS.IDLE)) {
_context3.next = 4;
break;
}
_this5.debCloseLoading.cancel();
_context3.next = 4;
return _this5.closeLoading();
case 4:
_this5.setData({
enableScroll: false,
status: STATUS.LOADING
}, function () {
if (_this5.closing) {
return;
}
_this5.debCloseLoading.cancel();
_context3.next = 4;
return _this5.closeLoading();
case 4:
_this5.setData({
enableScroll: false,
status: STATUS.LOADING
}, function () {
if (_this5.closing) {
return;
}
_this5.offsetY = _this5.data.loadingHeight;
_this5.touchHdl({
type: 'touchend',
manual: true
});
_this5.offsetY = _this5.data.loadingHeight;
_this5.touchHdl({
type: 'touchend',
manual: true
});
_this5.triggerEvent('statuschange', STATUS.LOADING);
case 6:
case "end":
return _context3.stop();
}
});
_this5.triggerEvent('statuschange', STATUS.LOADING);
case 6:
case "end":
return _context3.stop();
}

@@ -516,3 +430,2 @@ }, _callee3);

},
/**

@@ -523,31 +436,24 @@ * 停止当前刷新

var _this6 = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
var time;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
// 用户下拉,至少保证小球转1圈
time = 500 - (Date.now() - _this6.startRefreshTime);
time = time > 0 ? time : 0;
_context4.next = 4;
return new Promise(function (r) {
return setTimeout(r, time);
});
case 4:
_this6.setData({
status: STATUS.SHOWTEXT
});
_this6.triggerEvent('statuschange', STATUS.SHOWTEXT);
_context4.next = 8;
return _this6.debCloseLoading();
case 8:
case "end":
return _context4.stop();
}
while (1) switch (_context4.prev = _context4.next) {
case 0:
// 用户下拉,至少保证小球转1圈
time = 500 - (Date.now() - _this6.startRefreshTime);
time = time > 0 ? time : 0;
_context4.next = 4;
return new Promise(function (r) {
return setTimeout(r, time);
});
case 4:
_this6.setData({
status: STATUS.SHOWTEXT
});
_this6.triggerEvent('statuschange', STATUS.SHOWTEXT);
_context4.next = 8;
return _this6.debCloseLoading();
case 8:
case "end":
return _context4.stop();
}

@@ -557,3 +463,2 @@ }, _callee4);

},
/**

@@ -575,19 +480,25 @@ * 滚动到底部时触发

var _this7 = this;
this.clipText(this.data.text);
// 记录用户下拉开始时间,到加载结束至少保证小球转3圈
this.startRefreshTime = 0;
this.clipText(this.data.text); // 记录用户下拉开始时间,到加载结束至少保证小球转3圈
// 滚动高度,用于计算是否触顶下拉
this.scrollTop = 0;
this.startRefreshTime = 0; // 滚动高度,用于计算是否触顶下拉
// 是否有手指在屏幕
this.touching = false;
this.scrollTop = 0; // 是否有手指在屏幕
// 多点触控位置,解决手指交叉切换问题
this.pos = {};
this.touching = false; // 多点触控位置,解决手指交叉切换问题
// 上次结束位置
this.lastOffsetY = 0;
this.pos = {}; // 上次结束位置
// 手指移动位置 * 用这个来判断是否手机离开屏幕
this.offsetY = 0;
this.lastOffsetY = 0; // 手指移动位置 * 用这个来判断是否手机离开屏幕
// 是否正在关闭
this.closing = false;
this.offsetY = 0; // 是否正在关闭
this.closing = false; // 循环检测是否要关闭loading
// 循环检测是否要关闭loading
this.debOffsetCheck = function () {

@@ -599,3 +510,2 @@ return new Promise(function (resolve) {

}
clearInterval(timer);

@@ -605,27 +515,22 @@ resolve();

});
}; // 关闭loading bar; text显示时长: 800ms
};
// 关闭loading bar; text显示时长: 800ms
this.debCloseLoading = (0, _index.promiseDebounce)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return _this7.debOffsetCheck();
case 2:
_context5.next = 4;
return new Promise(function (r) {
return setTimeout(r, _this7.data.textStayTime);
});
case 4:
_context5.next = 6;
return _this7.closeLoading();
case 6:
case "end":
return _context5.stop();
}
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return _this7.debOffsetCheck();
case 2:
_context5.next = 4;
return new Promise(function (r) {
return setTimeout(r, _this7.data.textStayTime);
});
case 4:
_context5.next = 6;
return _this7.closeLoading();
case 6:
case "end":
return _context5.stop();
}

@@ -637,3 +542,2 @@ }, _callee5);

var _this8 = this;
// 计算滑动区域高度,用于计算阻尼值

@@ -645,5 +549,3 @@ swan.createSelectorQuery()["in"](this).select('.smt-feed-wrap').boundingClientRect(function (res) {

}
var clientHeight = res.height;
_this8.setData({

@@ -650,0 +552,0 @@ clientHeight: clientHeight

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**

@@ -25,3 +18,2 @@ * @file index.js 图标组件

var md5Config = require('./icon-md5.json');
var iconHost = 'https://b.bdstatic.com/miniapp/assets/images/swan-ui/icon/';

@@ -54,53 +46,41 @@ var app = getApp();

var _this = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var _this$data, name, color, len, iconType, localIconType, hasRequested;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this$data = _this.data, name = _this$data.name, color = _this$data.color;
len = name.length; // 根据名字,获取icon的模式
while (1) switch (_context.prev = _context.next) {
case 0:
_this$data = _this.data, name = _this$data.name, color = _this$data.color;
len = name.length; // 根据名字,获取icon的模式
iconType = name.substr(len - 2, len - 1) === '-m' ? 'multiple' : 'single';
localIconType = "".concat(iconType, "_").concat(md5Config[iconType]);
_this.setData({
inited: true
});
iconType = name.substr(len - 2, len - 1) === '-m' ? 'multiple' : 'single';
localIconType = "".concat(iconType, "_").concat(md5Config[iconType]);
// 该类型,已经发起过请求:尝试获取缓存,不再发起相同请求
hasRequested = app["".concat(localIconType, "has_requested")];
if (!hasRequested) {
_context.next = 10;
break;
}
_this.getLocalThrottleCount = 0;
_this.getLocalDataThrottle({
localIconType: localIconType,
iconType: iconType,
color: color,
name: name
});
return _context.abrupt("return");
case 10:
// 该类型,未发起过请求:根据不同的icon模式发起对应的请求
_this.requestIconData({
iconType: iconType,
name: name
});
_this.setData({
inited: true
}); // 该类型,已经发起过请求:尝试获取缓存,不再发起相同请求
hasRequested = app["".concat(localIconType, "has_requested")];
if (!hasRequested) {
_context.next = 10;
break;
}
_this.getLocalThrottleCount = 0;
_this.getLocalDataThrottle({
localIconType: localIconType,
iconType: iconType,
color: color,
name: name
});
return _context.abrupt("return");
case 10:
// 该类型,未发起过请求:根据不同的icon模式发起对应的请求
_this.requestIconData({
iconType: iconType,
name: name
}); // 标识当前类型的请求,已发过
app["".concat(localIconType, "has_requested")] = true;
case 12:
case "end":
return _context.stop();
}
// 标识当前类型的请求,已发过
app["".concat(localIconType, "has_requested")] = true;
case 12:
case "end":
return _context.stop();
}

@@ -110,3 +90,2 @@ }, _callee);

},
/**

@@ -119,38 +98,31 @@ * 本地缓存因为有请求时机的diff,进行多次重试

var _this2 = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
var iconType, localIconType, color, name, localIconsData;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
iconType = options.iconType, localIconType = options.localIconType, color = options.color, name = options.name;
_context2.next = 3;
return _this2.getLocalData(localIconType);
case 3:
localIconsData = _context2.sent;
// 有缓存,从本地缓存读取数据
if (localIconsData) {
_this2.colorFormatAndSetIconData(color, localIconsData[name]);
} else if (_this2.getLocalThrottleCount < 20) {
// getLocalThrottleCount作用:防止特殊case时,无限递归,导致内存溢出
setTimeout(function () {
_this2.getLocalDataThrottle(options);
_this2.getLocalThrottleCount++;
}, 10);
} else {
// 重试20次,依旧没有读到缓存,则从新发起请求
_this2.requestIconData({
iconType: iconType,
name: name
});
}
case 5:
case "end":
return _context2.stop();
}
while (1) switch (_context2.prev = _context2.next) {
case 0:
iconType = options.iconType, localIconType = options.localIconType, color = options.color, name = options.name;
_context2.next = 3;
return _this2.getLocalData(localIconType);
case 3:
localIconsData = _context2.sent;
// 有缓存,从本地缓存读取数据
if (localIconsData) {
_this2.colorFormatAndSetIconData(color, localIconsData[name]);
} else if (_this2.getLocalThrottleCount < 20) {
// getLocalThrottleCount作用:防止特殊case时,无限递归,导致内存溢出
setTimeout(function () {
_this2.getLocalDataThrottle(options);
_this2.getLocalThrottleCount++;
}, 10);
} else {
// 重试20次,依旧没有读到缓存,则从新发起请求
_this2.requestIconData({
iconType: iconType,
name: name
});
}
case 5:
case "end":
return _context2.stop();
}

@@ -160,3 +132,2 @@ }, _callee2);

},
/**

@@ -171,5 +142,4 @@ * 根据icon的模式,请求对应的接口数据,并对数据进行持久化处理

var _this3 = this;
var iconType = _ref.iconType,
name = _ref.name;
name = _ref.name;
swan.request({

@@ -180,13 +150,11 @@ url: "".concat(iconHost).concat(iconType, "_").concat(md5Config[iconType]),

var statusCode = _ref2.statusCode,
data = _ref2.data;
data = _ref2.data;
if (statusCode === 200) {
var iconData = _this3.translateIconData(data[name]);
_this3.setData({
iconData: iconData,
inited: true
}); // 数据持久化
});
// 数据持久化
swan.setStorage({

@@ -212,3 +180,2 @@ key: "".concat(iconType, "_").concat(md5Config[iconType]),

},
/**

@@ -235,3 +202,2 @@ * 从本地获取缓存,减少请求次数

},
/**

@@ -245,6 +211,6 @@ * 对从server获取的动态数据,进行转译处理

var _this$data2 = this.data,
quot = _this$data2.quot,
size = _this$data2.size;
str = str.replace(/{{quot}}/g, quot).replace(/{{size}}/g, size); // 处理颜色的计算
quot = _this$data2.quot,
size = _this$data2.size;
str = str.replace(/{{quot}}/g, quot).replace(/{{size}}/g, size);
// 处理颜色的计算
var self = this;

@@ -257,3 +223,2 @@ str = str.replace(/fill=.*?}}/g, function ($1) {

},
/**

@@ -268,17 +233,13 @@ * 对于获取数据中的fill相关的动态字符,进行转译处理

var _this$data3 = this.data,
isStr = _this$data3.isStr,
rgbColor = _this$data3.rgbColor;
isStr = _this$data3.isStr,
rgbColor = _this$data3.rgbColor;
var _fillStr$split = fillStr.split('||'),
_fillStr$split2 = (0, _slicedToArray2["default"])(_fillStr$split, 2),
condition = _fillStr$split2[0],
execute = _fillStr$split2[1];
_fillStr$split2 = (0, _slicedToArray2["default"])(_fillStr$split, 2),
condition = _fillStr$split2[0],
execute = _fillStr$split2[1];
condition = condition.replace(/isStr/g, isStr).replace(/\(|\)/g, '').replace(/\s/g, '');
var _condition$split = condition.split('?'),
_condition$split2 = (0, _slicedToArray2["default"])(_condition$split, 2),
firstCondition = _condition$split2[0],
firstExecute = _condition$split2[1];
_condition$split2 = (0, _slicedToArray2["default"])(_condition$split, 2),
firstCondition = _condition$split2[0],
firstExecute = _condition$split2[1];
if (/true/.test(firstCondition) && rgbColor) {

@@ -292,3 +253,2 @@ firstExecute = firstExecute.split(':')[0].replace(/rgbColor/g, rgbColor);

lastExecute = 'fill=' + "'" + firstExecute;
if (!firstExecute) {

@@ -299,6 +259,4 @@ firstExecute = execute.slice(0, execute.length - 1);

}
return lastExecute;
},
/**

@@ -313,5 +271,3 @@ * 1. 对传入的color进行格式化处理

var _this4 = this;
var rgbColor = color || this.data.color;
var trans = function trans(hexColor) {

@@ -321,6 +277,4 @@ if (hexColor && hexColor.charAt(0) === '#') {

}
return hexColor;
};
if (typeof color === 'string') {

@@ -330,6 +284,4 @@ rgbColor = trans(color);

rgbColor = [];
var _iterator = _createForOfIteratorHelper(color),
_step;
_step;
try {

@@ -346,3 +298,2 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) {

}
this.setData({

@@ -355,7 +306,5 @@ isStr: typeof color === 'string',

return;
} // 对icon的初始数据进行转译
}
// 对icon的初始数据进行转译
var iconData = _this4.translateIconData(data);
_this4.setData({

@@ -362,0 +311,0 @@ iconData: iconData

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
/**

@@ -92,3 +88,2 @@ * @file notice-bar

var _this = this;
return new Promise(function (r) {

@@ -101,3 +96,2 @@ return _this.createSelectorQuery()["in"](_this).select(selector).boundingClientRect(function (_ref) {

},
/**

@@ -109,55 +103,43 @@ * 初始化函数

var _this2 = this;
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var _this2$data, scroll, speed, delay, _yield, _yield2, containerWidth, textWidth, duration;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this2$data = _this2.data, scroll = _this2$data.scroll, speed = _this2$data.speed, delay = _this2$data.delay; // 不开启滚动,则退出
if (scroll) {
_context.next = 3;
break;
while (1) switch (_context.prev = _context.next) {
case 0:
_this2$data = _this2.data, scroll = _this2$data.scroll, speed = _this2$data.speed, delay = _this2$data.delay; // 不开启滚动,则退出
if (scroll) {
_context.next = 3;
break;
}
return _context.abrupt("return");
case 3:
_context.next = 5;
return _this2.getWidths('.notice-bar .text-container');
case 5:
_context.t0 = _context.sent;
_context.next = 8;
return _this2.getWidths('.notice-bar .text-container .text');
case 8:
_context.t1 = _context.sent;
_context.next = 11;
return [_context.t0, _context.t1];
case 11:
_yield = _context.sent;
_yield2 = (0, _slicedToArray2["default"])(_yield, 2);
containerWidth = _yield2[0];
textWidth = _yield2[1];
duration = +(textWidth / speed * 1000).toFixed(2);
_this2.setData({
textWidth: textWidth,
containerWidth: containerWidth
}, function () {
if (textWidth > containerWidth) {
setTimeout(function () {
return _this2.genAnimate(duration, textWidth);
}, delay * 1000);
}
return _context.abrupt("return");
case 3:
_context.next = 5;
return _this2.getWidths('.notice-bar .text-container');
case 5:
_context.t0 = _context.sent;
_context.next = 8;
return _this2.getWidths('.notice-bar .text-container .text');
case 8:
_context.t1 = _context.sent;
_context.next = 11;
return [_context.t0, _context.t1];
case 11:
_yield = _context.sent;
_yield2 = (0, _slicedToArray2["default"])(_yield, 2);
containerWidth = _yield2[0];
textWidth = _yield2[1];
duration = +(textWidth / speed * 1000).toFixed(2);
_this2.setData({
textWidth: textWidth,
containerWidth: containerWidth
}, function () {
if (textWidth > containerWidth) {
setTimeout(function () {
return _this2.genAnimate(duration, textWidth);
}, delay * 1000);
}
});
case 17:
case "end":
return _context.stop();
}
});
case 17:
case "end":
return _context.stop();
}

@@ -167,3 +149,2 @@ }, _callee);

},
/**

@@ -177,3 +158,2 @@ * 生成动画

var _this3 = this;
// 须先复位

@@ -192,3 +172,2 @@ var animation = swan.createAnimation({

animation.translate3d("-".concat(distance, "px"), 0, 0).step();
_this3.setData({

@@ -199,3 +178,2 @@ animationData: animation["export"]()

},
/**

@@ -206,14 +184,11 @@ * 滚动动画结束回调函数

var _this4 = this;
var _this$data = this.data,
textWidth = _this$data.textWidth,
speed = _this$data.speed,
containerWidth = _this$data.containerWidth,
infinite = _this$data.infinite;
textWidth = _this$data.textWidth,
speed = _this$data.speed,
containerWidth = _this$data.containerWidth,
infinite = _this$data.infinite;
var duration = +((textWidth + containerWidth) / speed * 1000).toFixed(2);
var fn = function fn() {
return _this4.genAnimate(duration, textWidth + containerWidth);
};
if (!infinite) {

@@ -227,3 +202,2 @@ this.setData({

},
/**

@@ -230,0 +204,0 @@ * 删除事件

@@ -66,2 +66,8 @@ /**

value: false
},
// 文本截断字数设置
textClipNum: {
type: Object,
value: {}
}

@@ -86,7 +92,8 @@ },

'loadingTitle, title, desc, btnText'(loadingTitle, title, desc, btnText) {
const {title: titleClipNum, desc: descClipNum, btn: btnClipNum} = this.data.textClipNum;
this.setData({
clipLoadingTitle: loadingTitle.slice(0, PS_CLIP_NUM.TITLE),
clipTitle: title.slice(0, PS_CLIP_NUM.TITLE),
clipDesc: desc.slice(0, PS_CLIP_NUM.DESC),
clipBtnText: btnText.slice(0, PS_CLIP_NUM.BTN)
clipLoadingTitle: loadingTitle.slice(0, titleClipNum || PS_CLIP_NUM.TITLE),
clipTitle: title.slice(0, titleClipNum || PS_CLIP_NUM.TITLE),
clipDesc: desc.slice(0, descClipNum || PS_CLIP_NUM.DESC),
clipBtnText: btnText.slice(0, btnClipNum || PS_CLIP_NUM.BTN)
});

@@ -93,0 +100,0 @@ }

@@ -1,1 +0,1 @@

{"name":"component","label":"通用","type":"component","configPath":"./smart-design-config.json","version":"1.2.17"}
{"name":"component","label":"通用","type":"component","configPath":"./smart-design-config.json","version":"1.2.19"}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc