cl-row.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view
  3. :class="[classList]"
  4. :style="{
  5. height: parseRpx(height),
  6. width: parseRpx(width),
  7. padding: parseRpx(padding),
  8. margin: margin2,
  9. borderRadius: parseRpx(borderRadius),
  10. border,
  11. backgroundColor,
  12. }"
  13. @tap="onTap"
  14. >
  15. <slot></slot>
  16. </view>
  17. </template>
  18. <script>
  19. import { isArray, isNumber, parseRpx } from "../../utils";
  20. /**
  21. * row 行
  22. * @description 布局组件
  23. * @tutorial https://docs.cool-js.com/uni/components/layout/flex.html
  24. * @property {Object} type 类型
  25. * @property {Object} wrap 是否换行
  26. * @example <cl-col :span="12"></cl-col>
  27. */
  28. export default {
  29. name: "cl-row",
  30. componentName: "ClRow",
  31. props: {
  32. type: String,
  33. wrap: Boolean,
  34. backgroundColor: String,
  35. border: String,
  36. gutter: [Number, String],
  37. justify: {
  38. type: String,
  39. default: "start",
  40. },
  41. align: {
  42. type: String,
  43. default: "top",
  44. },
  45. height: [String, Number],
  46. width: [String, Number],
  47. padding: [String, Number, Array],
  48. margin: [String, Number, Array],
  49. borderRadius: [String, Number],
  50. },
  51. computed: {
  52. margin2() {
  53. return this.margin ? parseRpx(this.margin) : `0 -${this.gutter / 2}rpx`;
  54. },
  55. classList() {
  56. let list = ["cl-row"];
  57. if (this.type) {
  58. list.push(`cl-row--${this.type}`);
  59. }
  60. if (this.justify) {
  61. list.push(`is-justify-${this.justify}`);
  62. }
  63. if (this.align) {
  64. list.push(`is-align-${this.align}`);
  65. }
  66. if (this.wrap) {
  67. list.push("is-wrap");
  68. }
  69. return list.join(" ");
  70. },
  71. },
  72. methods: {
  73. parseRpx,
  74. onTap(e) {
  75. this.$emit("click", e);
  76. this.$emit("tap", e);
  77. },
  78. },
  79. };
  80. </script>