UNPKG

mp-colorui

Version:

MP ColorUI 是一款基于 Taro 框架并且联合 Color-UI CSS 库开发的多端 UI 组件库(支持小程序端和H5端)

428 lines (353 loc) 24.4 kB
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([["components/swiperAction/index"],{ /***/ "./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/swiperAction/index.tsx?taro&type=script&parse=COMPONENT&": /*!******************************************************************************************************************************************************************!*\ !*** ./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./src/components/swiperAction/index.tsx?taro&type=script&parse=COMPONENT& ***! \******************************************************************************************************************************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var _taroWeapp = __webpack_require__(/*! @tarojs/taro-weapp */ "./node_modules/@tarojs/taro-weapp/index.js"); var _taroWeapp2 = _interopRequireDefault(_taroWeapp); __webpack_require__(/*! ./index.scss */ "./src/components/swiperAction/index.scss"); var _model = __webpack_require__(/*! ../../lib/model */ "./src/lib/model.ts"); var _index = __webpack_require__(/*! ../../lib/index */ "./src/lib/index.ts"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var ClSwiperAction = function (_Taro$Component) { _inherits(ClSwiperAction, _Taro$Component); function ClSwiperAction() { var _ref; var _temp, _this, _ret; _classCallCheck(this, ClSwiperAction); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ClSwiperAction.__proto__ || Object.getPrototypeOf(ClSwiperAction)).call.apply(_ref, [this].concat(args))), _this), _this.$usedState = ["anonymousState__temp3", "anonymousState__temp4", "anonymousState__temp5", "anonymousState__temp6", "anonymousState__temp7", "loopArray72", "BG_COLOR_LIST", "initOptions", "isH5", "contentId", "children"], _this.anonymousFunc0Map = {}, _this.customComponents = ["ClLayout"], _temp), _possibleConstructorReturn(_this, _ret); } _createClass(ClSwiperAction, [{ key: "_constructor", value: function _constructor(props) { _get(ClSwiperAction.prototype.__proto__ || Object.getPrototypeOf(ClSwiperAction.prototype), "_constructor", this).call(this, props); this.$$refs = new _taroWeapp2.default.RefsArray(); } }, { key: "_createData", value: function _createData() { var _this2 = this; this.__state = arguments[0] || this.state || {}; this.__props = arguments[1] || this.props || {}; var __isRunloopRef = arguments[2]; var __prefix = this.$prefix; ; var props = this.__props; var _useState = (0, _taroWeapp.useState)(props.options || []), _useState2 = _slicedToArray(_useState, 2), initOptions = _useState2[0], setInitOptions = _useState2[1]; var _useState3 = (0, _taroWeapp.useState)((0, _index.generateId)()), _useState4 = _slicedToArray(_useState3, 2), contentId = _useState4[0], setContentId = _useState4[1]; var _useState5 = (0, _taroWeapp.useState)(), _useState6 = _slicedToArray(_useState5, 2), actionWidth = _useState6[0], setActionWidth = _useState6[1]; var _useState7 = (0, _taroWeapp.useState)(0), _useState8 = _slicedToArray(_useState7, 2), lastPoint = _useState8[0], setLastPoint = _useState8[1]; var _useState9 = (0, _taroWeapp.useState)(0), _useState10 = _slicedToArray(_useState9, 2), translateX = _useState10[0], setTranslateX = _useState10[1]; var _useState11 = (0, _taroWeapp.useState)(0), _useState12 = _slicedToArray(_useState11, 2), lastTranslateX = _useState12[0], setLastTranslateX = _useState12[1]; var _useState13 = (0, _taroWeapp.useState)(0), _useState14 = _slicedToArray(_useState13, 2), showAnimation = _useState14[0], setShowAnimation = _useState14[1]; var _useState15 = (0, _taroWeapp.useState)(0), _useState16 = _slicedToArray(_useState15, 2), beforeMove = _useState16[0], setBeforeMove = _useState16[1]; var _useState17 = (0, _taroWeapp.useState)(false), _useState18 = _slicedToArray(_useState17, 2), show = _useState18[0], setShow = _useState18[1]; var _useState19 = (0, _taroWeapp.useState)(false), _useState20 = _slicedToArray(_useState19, 2), init = _useState20[0], setInit = _useState20[1]; (0, _taroWeapp.useEffect)(function () { var list = props.options || []; var newOprions = list.map(function (item) { item.cu_index_id = (0, _index.generateId)(); return item; }); setInitOptions(newOprions); if (_index.isH5) { var query = document.querySelector("#" + contentId); if (query) { var width = query.clientWidth; setActionWidth(width); } } else { var _query = _taroWeapp2.default.createSelectorQuery().in(_this2.$scope); _this2.componentDidMount = function () { setTimeout(function () { var view = _query.select("#contentId"); try { view.boundingClientRect().exec(function (rect) { var res = rect[0]; var width = res.width; setActionWidth(width); setInit(true); }); } catch (e) { throw e; } }, 500); }; } }, [props.options]); (0, _taroWeapp.useEffect)(function () { setShow(false); if (translateX === 0) { setShow(false); props.onClose && props.onClose(); } else if (Math.abs(translateX) === actionWidth) { setTimeout(function () { setShow(true); }, 300); props.onOpened && props.onOpened(); } }, [translateX]); (0, _taroWeapp.useEffect)(function () { setShow(!!props.show); if (props.show) { if (props.direction === "left") { setTranslateX(actionWidth); } else { setTranslateX(-actionWidth); } } }, [props.show, actionWidth]); var anonymousState__temp3 = (0, _index.classNames)("cl-swiper-action", props.className); var anonymousState__temp4 = (0, _taroWeapp.internal_inline_style)(Object.assign({}, props.style)); this.anonymousFunc1 = function (e) { e.stopPropagation(); }; this.anonymousFunc2 = function (e) { if (props.disabled) { return; }setLastPoint(e.touches[0].clientX); setBeforeMove(e.touches[0].clientX); setLastTranslateX(translateX); setShowAnimation(0); }; this.anonymousFunc3 = function (e) { if (props.disabled) { return; }var nowPoint = e.touches[0].clientX; // 为正则右,为负则左 var distance = nowPoint - lastPoint; if (props.direction === "right") { distance = Math.abs(lastTranslateX) === actionWidth ? distance < 0 ? 0 : distance : lastTranslateX === 0 ? distance > 0 ? 0 : distance : distance; } if (props.direction === "left") { distance = Math.abs(lastTranslateX) === actionWidth ? distance > 0 ? 0 : distance : lastTranslateX === 0 ? distance < 0 ? 0 : distance : distance; } setTranslateX(lastTranslateX + distance * _index.screenPercent); }; this.anonymousFunc4 = function (e) { if (props.disabled) { return; }setShowAnimation(0.3); var touches = e.changedTouches[0]; var nowClientX = touches.clientX; var move = beforeMove - nowClientX; var isRight = props.direction === "right"; // 向左滑动一定距离 if (move > 20) { setTranslateX(isRight ? -actionWidth : 0); setLastTranslateX(isRight ? -actionWidth : 0); // 向右滑动一定距离 } else if (move < -20) { setTranslateX(isRight ? 0 : actionWidth); setLastTranslateX(isRight ? 0 : actionWidth); } else { setLastTranslateX(lastTranslateX); setTranslateX(lastTranslateX); } }; var anonymousState__temp5 = (0, _taroWeapp.internal_inline_style)({ transform: "translateX(" + (0, _taroWeapp.pxTransform)(translateX / _index.screenPercent) + ")", transition: "all 0.3s ease-in", position: "relative" }); var anonymousState__temp6 = _index.isH5 ? (0, _taroWeapp.internal_inline_style)({ right: "" + (props.direction === "right" ? (0, _taroWeapp.pxTransform)(-actionWidth / _index.screenPercent) : "auto"), left: "" + (props.direction === "left" ? (0, _taroWeapp.pxTransform)(-actionWidth / _index.screenPercent) : "auto"), zIndex: init ? 1 : -1 }) : null; var anonymousState__temp7 = (0, _taroWeapp.internal_inline_style)({ right: "" + (props.direction === "right" ? (0, _taroWeapp.pxTransform)(-actionWidth / _index.screenPercent) : "auto"), left: "" + (props.direction === "left" ? (0, _taroWeapp.pxTransform)(-actionWidth / _index.screenPercent) : "auto"), zIndex: init ? 1 : -1 }); var loopArray72 = initOptions.map(function (item, index) { item = { $original: (0, _taroWeapp.internal_get_original)(item) }; var $loopState__temp2 = (0, _taroWeapp.internal_inline_style)({ height: "100%" }); var _$indexKey = "bhczz" + index; _this2.anonymousFunc0Map[_$indexKey] = function () { props.onClick && props.onClick(index); if (props.autoClose) { setTranslateX(0); } }; var _genCompid = (0, _taroWeapp.genCompid)(__prefix + "bhdzzzzzzz" + index, true), _genCompid2 = _slicedToArray(_genCompid, 2), $prevCompid__864 = _genCompid2[0], $compid__864 = _genCompid2[1]; _taroWeapp.propsManager.set({ "padding": "small", "paddingDirection": "horizontal" }, $compid__864, $prevCompid__864); return { $loopState__temp2: $loopState__temp2, _$indexKey: _$indexKey, $compid__864: $compid__864, $original: item.$original }; }); Object.assign(this.__state, { anonymousState__temp3: anonymousState__temp3, anonymousState__temp4: anonymousState__temp4, anonymousState__temp5: anonymousState__temp5, anonymousState__temp6: anonymousState__temp6, anonymousState__temp7: anonymousState__temp7, loopArray72: loopArray72, BG_COLOR_LIST: _model.BG_COLOR_LIST, initOptions: initOptions, isH5: _index.isH5, contentId: contentId }); return this.__state; } }, { key: "anonymousFunc0", value: function anonymousFunc0(_$indexKey) { var _anonymousFunc0Map; ; for (var _len2 = arguments.length, e = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { e[_key2 - 1] = arguments[_key2]; } return this.anonymousFunc0Map[_$indexKey] && (_anonymousFunc0Map = this.anonymousFunc0Map)[_$indexKey].apply(_anonymousFunc0Map, e); } }, { key: "anonymousFunc1", value: function anonymousFunc1(e) { e.stopPropagation(); } }, { key: "anonymousFunc2", value: function anonymousFunc2(e) { ; } }, { key: "anonymousFunc3", value: function anonymousFunc3(e) { ; } }, { key: "anonymousFunc4", value: function anonymousFunc4(e) { ; } }]); return ClSwiperAction; }(_taroWeapp2.default.Component); ClSwiperAction.$$events = ["anonymousFunc0", "anonymousFunc1", "anonymousFunc2", "anonymousFunc3", "anonymousFunc4"]; ClSwiperAction.$$componentPath = "components/swiperAction/index"; ClSwiperAction.options = { addGlobalClass: true }; ClSwiperAction.defaultProps = { show: false, disabled: false, autoClose: false, options: [], direction: "right", onClick: function onClick() {}, onClose: function onClose() {}, onOpened: function onOpened() {} }; exports.default = ClSwiperAction; Component(__webpack_require__(/*! @tarojs/taro-weapp */ "./node_modules/@tarojs/taro-weapp/index.js").default.createComponent(ClSwiperAction)); /***/ }), /***/ "./node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!./node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/swiperAction/index.tsx?taro&type=template&parse=COMPONENT&": /*!*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\ !*** ./node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!./node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./src/components/swiperAction/index.tsx?taro&type=template&parse=COMPONENT& ***! \*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__.p + "components/swiperAction/index.wxml"; /***/ }), /***/ "./src/components/swiperAction/index.scss": /*!************************************************!*\ !*** ./src/components/swiperAction/index.scss ***! \************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { // extracted by mini-css-extract-plugin /***/ }), /***/ "./src/components/swiperAction/index.tsx": /*!***********************************************!*\ !*** ./src/components/swiperAction/index.tsx ***! \***********************************************/ /*! no static exports found */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.tsx?taro&type=template&parse=COMPONENT& */ "./src/components/swiperAction/index.tsx?taro&type=template&parse=COMPONENT&"); /* harmony import */ var _index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./index.tsx?taro&type=script&parse=COMPONENT& */ "./src/components/swiperAction/index.tsx?taro&type=script&parse=COMPONENT&"); /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_1__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_1__[key]; }) }(__WEBPACK_IMPORT_KEY__)); /***/ }), /***/ "./src/components/swiperAction/index.tsx?taro&type=script&parse=COMPONENT&": /*!*********************************************************************************!*\ !*** ./src/components/swiperAction/index.tsx?taro&type=script&parse=COMPONENT& ***! \*********************************************************************************/ /*! no static exports found */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./index.tsx?taro&type=script&parse=COMPONENT& */ "./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/swiperAction/index.tsx?taro&type=script&parse=COMPONENT&"); /* harmony import */ var _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__); /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__[key]; }) }(__WEBPACK_IMPORT_KEY__)); /* harmony default export */ __webpack_exports__["default"] = (_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0___default.a); /***/ }), /***/ "./src/components/swiperAction/index.tsx?taro&type=template&parse=COMPONENT&": /*!***********************************************************************************!*\ !*** ./src/components/swiperAction/index.tsx?taro&type=template&parse=COMPONENT& ***! \***********************************************************************************/ /*! no static exports found */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!../../../node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!../../../node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./index.tsx?taro&type=template&parse=COMPONENT& */ "./node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!./node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/swiperAction/index.tsx?taro&type=template&parse=COMPONENT&"); /* harmony import */ var _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__); /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__[key]; }) }(__WEBPACK_IMPORT_KEY__)); /***/ }) },[["./src/components/swiperAction/index.tsx","runtime","taro","vendors","common"]]]);