index.sjs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var getWidth = function getWidth(rightWidth, leftWidth, inertiaWidth) {
  2. var num = (rightWidth || leftWidth) * 2 + inertiaWidth;
  3. var width = rightWidth > leftWidth ? rightWidth : leftWidth;
  4. return rightWidth && leftWidth ? "calc(100% + ".concat(width + inertiaWidth, "px)") : "calc(100% + ".concat(num / 2, "px)");
  5. };
  6. var getMarginLeft = function getMarginLeft(rightWidth, leftWidth, inertiaWidth) {
  7. var width = rightWidth > leftWidth ? rightWidth : leftWidth;
  8. return "calc(-".concat((width + inertiaWidth) / 2, "px)");
  9. };
  10. var getSlotWidthStyle = function getSlotWidthStyle(rightWidth, leftWidth) {
  11. var left = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  12. var right = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  13. var inertiaWidth = arguments.length > 4 ? arguments[4] : undefined;
  14. // 右
  15. if (right.length > 0 && left.length === 0) {
  16. return "calc(100% - ".concat((1 + inertiaWidth) / 2, "px)");
  17. }
  18. // 左
  19. if (left.length > 0 && right.length === 0) {
  20. return "width: calc(100% - ".concat(leftWidth / 2, "px); margin-left: ").concat((leftWidth + inertiaWidth) / 2, "px;");
  21. }
  22. if (left.length > 0 && right.length > 0) {
  23. return "width: 100%;margin-left: 0;";
  24. }
  25. };
  26. var getLeft = function getLeft(tapType, idx, right, isLeft) {
  27. var tip = !isLeft ? 'L-' : 'R-';
  28. if (right.length === 1) {
  29. return tapType && tapType === "".concat(tip).concat(idx) ? 'text-move-midd' : '';
  30. }
  31. if (right.length === 3 && idx === 1) {
  32. return tapType && tapType === "".concat(tip).concat(idx) ? 'text-move-midd' : '';
  33. }
  34. var cls = '';
  35. if (idx === 0) {
  36. cls = isLeft ? 'text-move-left' : 'text-move-right';
  37. } else {
  38. cls = isLeft ? 'text-move-right' : 'text-move-left';
  39. }
  40. return tapType && tapType === "".concat(tip).concat(idx) ? cls : '';
  41. };
  42. var getWidth2 = function getWidth2(rightWidth, leftWidth, inertiaWidth) {
  43. var width = rightWidth > leftWidth ? rightWidth : leftWidth;
  44. return rightWidth && leftWidth ? "calc(100% - ".concat(width + inertiaWidth, "px)") : "calc(100% - ".concat((width + inertiaWidth) / 2, "px)");
  45. };
  46. var getMarginLeft2 = function getMarginLeft2(rightWidth, leftWidth, inertiaWidth) {
  47. var num = rightWidth > 0 ? inertiaWidth : 0;
  48. var width = rightWidth > leftWidth ? rightWidth : leftWidth;
  49. return leftWidth && rightWidth ? "".concat((width + num) / 2, "px") : leftWidth > 0 ? 0 : "".concat((width + inertiaWidth) / 2, "px");
  50. };
  51. var getMarginLeft3 = function getMarginLeft3(rightWidth, leftWidth, inertiaWidth) {
  52. var width = rightWidth > leftWidth ? rightWidth : leftWidth;
  53. return leftWidth && rightWidth ? "calc(100% - ".concat((width + inertiaWidth) / 2, "px)") : "calc(100% - ".concat(rightWidth / 2 - 1, "px)");
  54. };
  55. var getMoveX = function getMoveX(rightButtons, idx) {
  56. var arr = rightButtons.slice(idx, rightButtons.length);
  57. return arr.reduce(function (tolal, cur) {
  58. return parseFloat(tolal) + cur.width;
  59. }, 0);
  60. };
  61. var getMovableContentRightStyle = function getMovableContentRightStyle(item, tapTypeR, idx, rightWidth, inTouch, inertiaWidth, myStyle) {
  62. var isTapTypeR = tapTypeR && tapTypeR === "R-".concat(idx);
  63. var myStyleString = isTapTypeR ? styleObjectToString(myStyle) : '';
  64. return "\n font-size: ".concat((item.fontSize || 28) / 2, "px;\n color: ").concat(item.color, ";\n background: ").concat(item.bgColor, ";\n height: calc(100% + 2px);\n ").concat(isTapTypeR ? "width: ".concat((rightWidth + 1 + (item.confirmType === 'move' && inTouch ? inertiaWidth : 0)) / 2, "px;") : "width: ".concat(item.width / 2, "px;"), "\n ").concat(myStyleString);
  65. };
  66. var styleKeyMap = {
  67. 'marginRight': 'margin-right',
  68. 'marginLeft': 'margin-left',
  69. 'fontSize': 'font-size',
  70. zIndex: 'z-index'
  71. };
  72. function styleObjectToString(myStyle) {
  73. var styleKeys = keys(myStyle);
  74. var res = '';
  75. for (var i = 0; i < styleKeys.length; i++) {
  76. var key = styleKeys[i];
  77. res = res + "".concat(styleKeyMap[key] || key, ": ").concat(myStyle[key], "; ");
  78. }
  79. return res;
  80. }
  81. var getMovableContentLeftStyle = function getMovableContentLeftStyle(itemL, tapTypeL, idx, leftWidth, inTouch, inertiaWidth, myStyle) {
  82. var isTapTypeL = tapTypeL && tapTypeL === "L-".concat(idx);
  83. var myStyleString = isTapTypeL ? styleObjectToString(myStyle) : '';
  84. return "\n background: ".concat(itemL.bgColor, ";\n height: calc(100% + 2px);\n font-size: ").concat((itemL.fontSize || 28) / 2, "px;\n color: ").concat(itemL.color, ";\n ").concat(isTapTypeL ? "width: ".concat((leftWidth + 1 + (itemL.confirmType === 'move' && inTouch ? inertiaWidth : 0)) / 2, "px;") : "width: ".concat(itemL.width / 2, "px;"), "\n ").concat(myStyleString);
  85. };
  86. var getLeftSlotName = function getLeftSlotName(tapTypeL, idx, itemL) {
  87. if (!itemL.slotName) {
  88. return '';
  89. }
  90. return tapTypeL && tapTypeL === "L-".concat(idx) ? "".concat(itemL.slotName, "-confirm") : itemL.slotName;
  91. };
  92. var getRightSlotName = function getRightSlotName(tapTypeR, idx, item) {
  93. if (!item.slotName) {
  94. return '';
  95. }
  96. return tapTypeR && tapTypeR === "R-".concat(idx) ? "".concat(item.slotName, "-confirm") : item.slotName;
  97. };
  98. var getLeftText = function getLeftText(tapTypeL, idx, itemL) {
  99. return tapTypeL && tapTypeL === "L-".concat(idx) ? itemL.confirmText || itemL.text : itemL.text;
  100. };
  101. var getRightText = function getRightText(tapTypeR, idx, item) {
  102. return tapTypeR && tapTypeR === "R-".concat(idx) ? item.confirmText || item.text : item.text;
  103. };
  104. var getRightMovableContentStyle = function getRightMovableContentStyle(tapTypeR, idx, rightWidth, leftWidth, inertiaWidth) {
  105. return styleObjectToString({
  106. zIndex: tapTypeR === "R-".concat(idx) ? 1 : 0,
  107. marginLeft: getMarginLeft3(rightWidth, leftWidth, inertiaWidth),
  108. width: (rightWidth - 0.1) / 2 + 'px'
  109. });
  110. };
  111. var getLeftMovableContentStyle = function getLeftMovableContentStyle(tapTypeL, idx, leftWidth, inertiaWidth) {
  112. return styleObjectToString({
  113. zIndex: tapTypeL === "L-".concat(idx) ? 1 : 0,
  114. marginLeft: "".concat(inertiaWidth / 2, "px"),
  115. width: (leftWidth - 1) / 2 + 'px'
  116. });
  117. };
  118. var axmlObj = function axmlObj(obj) {
  119. return obj;
  120. };
  121. export default {
  122. axmlObj: axmlObj,
  123. getWidth2: getWidth2,
  124. getMarginLeft2: getMarginLeft2,
  125. getMarginLeft3: getMarginLeft3,
  126. getRightMovableContentStyle: getRightMovableContentStyle,
  127. getLeftMovableContentStyle: getLeftMovableContentStyle,
  128. getLeft: getLeft,
  129. getWidth: getWidth,
  130. getSlotWidthStyle: getSlotWidthStyle,
  131. getMarginLeft: getMarginLeft,
  132. getMoveX: getMoveX,
  133. getMovableContentRightStyle: getMovableContentRightStyle,
  134. getMovableContentLeftStyle: getMovableContentLeftStyle,
  135. getRightText: getRightText,
  136. getLeftText: getLeftText,
  137. getLeftSlotName: getLeftSlotName,
  138. getRightSlotName: getRightSlotName
  139. };
  140. function keys(obj) {
  141. if (typeof Object.keys === 'function') {
  142. return Object.keys(obj);
  143. }
  144. }