综合办公系统
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

uv-row.vue 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view
  3. class="uv-row"
  4. ref="uv-row"
  5. :style="[rowStyle]"
  6. @tap="clickHandler"
  7. >
  8. <slot />
  9. </view>
  10. </template>
  11. <script>
  12. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  13. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  14. // #ifdef APP-NVUE
  15. const dom = uni.requireNativePlugin('dom')
  16. // #endif
  17. import props from './props.js';
  18. /**
  19. * Row 栅格系统中的行
  20. * @description 通过基础的 12 分栏,迅速简便地创建布局
  21. * @tutorial https://www.uvui.cn/components/layout.html
  22. * @property {String | Number} gutter 栅格间隔,左右各为此值的一半,单位px (默认 0 )
  23. * @property {String} justify 水平排列方式(微信小程序暂不支持) 可选值为`start`(或`flex-start`)、`end`(或`flex-end`)、`center`、`around`(或`space-around`)、`between`(或`space-between`) (默认 'start' )
  24. * @property {String} align 垂直排列方式 (默认 'center' )
  25. * @property {Object} customStyle 定义需要用到的外部样式
  26. *
  27. * @event {Function} click row被点击
  28. * @example <uv-row justify="space-between" customStyle="margin-bottom: 10px"></uv-row>
  29. */
  30. export default {
  31. name: "uv-row",
  32. emits: ['click'],
  33. mixins: [mpMixin, mixin, props],
  34. data() {
  35. return {
  36. }
  37. },
  38. computed: {
  39. uJustify() {
  40. if (this.justify == 'end' || this.justify == 'start') return 'flex-' + this.justify
  41. else if (this.justify == 'around' || this.justify == 'between') return 'space-' + this.justify
  42. else return this.justify
  43. },
  44. uAlignItem() {
  45. if (this.align == 'top') return 'flex-start'
  46. if (this.align == 'bottom') return 'flex-end'
  47. else return this.align
  48. },
  49. rowStyle() {
  50. const style = {
  51. alignItems: this.uAlignItem,
  52. justifyContent: this.uJustify
  53. }
  54. // 通过给uv-row左右两边的负外边距,消除uv-col在有gutter时,第一个和最后一个元素的左内边距和右内边距造成的影响
  55. if(this.gutter) {
  56. style.marginLeft = this.$uv.addUnit(-Number(this.gutter)/2)
  57. style.marginRight = this.$uv.addUnit(-Number(this.gutter)/2)
  58. }
  59. return this.$uv.deepMerge(style, this.$uv.addStyle(this.customStyle))
  60. }
  61. },
  62. methods: {
  63. clickHandler(e) {
  64. this.$emit('click')
  65. },
  66. async getComponentWidth() {
  67. // 延时一定时间,以确保节点渲染完成
  68. await this.$uv.sleep()
  69. return new Promise(resolve => {
  70. // uvui封装的获取节点的方法,详见文档
  71. // #ifndef APP-NVUE
  72. this.$uvGetRect('.uv-row').then(res => {
  73. resolve(res.width)
  74. })
  75. // #endif
  76. // #ifdef APP-NVUE
  77. // nvue的dom模块用于获取节点
  78. dom.getComponentRect(this.$refs['uv-row'], (res) => {
  79. resolve(res.size.width)
  80. })
  81. // #endif
  82. })
  83. },
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. @import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
  89. .uv-row {
  90. @include flex;
  91. }
  92. </style>