space.nvue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="container">
  3. <uni-card :is-shadow="false" is-full>
  4. <view class="header">
  5. <text class="uni-h6">使用间距辅助类对元素快速应用</text> <text class="uni-primary uni-px-3 uni-h6">margin</text><text
  6. class="uni-h6"> 或 </text><text class="uni-primary uni-px-3 uni-h6">padding</text> <text
  7. class="uni-h6">样式, 范围是从 0 到 16。</text>
  8. </view>
  9. <view class="header uni-mt-5"><text class="uni-h6">规则为</text> <text
  10. class="uni-primary uni-pl-3 uni-h6">uni-${property}${direction}-${size}</text>
  11. </view>
  12. <view class="uni-mt-5"><text class="uni-h6">各值的含义请参考文档</text></view>
  13. </uni-card>
  14. <uni-section title="效果展示" type="line">
  15. <view class="margin">
  16. <view class="margin-item uni-border-4-bg" :class="[paddingClass,marginClass]">
  17. <view class="box uni-primary-bg">
  18. <text class="uni-white uni-body">通过下面的选项控制边距</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="actions uni-mt-10">
  23. <text class="action-label">外边距</text>
  24. <uni-data-checkbox v-model="formData.margin" multiple :localdata="directionData"
  25. @change="change($event,1)"></uni-data-checkbox>
  26. </view>
  27. <view class="actions uni-mt-3 uni-mb-10">
  28. <text class="action-label">外边距大小</text>
  29. <uni-data-checkbox v-model="formData.marginSize" :localdata="sizeData" @change="change($event,1)">
  30. </uni-data-checkbox>
  31. </view>
  32. <view class="actions">
  33. <text class="action-label">内边距</text>
  34. <uni-data-checkbox v-model="formData.padding" multiple :localdata="directionData"
  35. @change="change($event,2)"></uni-data-checkbox>
  36. </view>
  37. <view class="actions uni-mt-3 uni-mb-10">
  38. <text class="action-label">内边距大小</text>
  39. <uni-data-checkbox v-model="formData.paddingSize" :localdata="sizeData" @change="change($event,3)">
  40. </uni-data-checkbox>
  41. </view>
  42. </uni-section>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. paddingClass: 'uni-pa-5',
  50. marginClass: 'uni-ma-5',
  51. formData: {
  52. margin: ['t', 'r', 'l', 'b'],
  53. marginSize: '5',
  54. padding: ['t', 'r', 'l', 'b'],
  55. paddingSize: '5',
  56. },
  57. directionData: [{
  58. value: 't',
  59. text: '上'
  60. }, {
  61. value: 'r',
  62. text: '右'
  63. }, {
  64. value: 'b',
  65. text: '下'
  66. }, {
  67. value: 'l',
  68. text: '左'
  69. }],
  70. sizeData: [{
  71. value: '0',
  72. text: '0'
  73. }, {
  74. value: '2',
  75. text: '4px'
  76. }, {
  77. value: '5',
  78. text: '10px'
  79. }, {
  80. value: '10',
  81. text: '20px'
  82. }]
  83. }
  84. },
  85. onLoad() {},
  86. methods: {
  87. change(e, type) {
  88. let {
  89. margin,
  90. marginSize,
  91. padding,
  92. paddingSize
  93. } = this.formData
  94. this.marginClass = ''
  95. this.paddingClass = ''
  96. margin.forEach(v => {
  97. this.marginClass += `uni-m${v}-${marginSize} `
  98. })
  99. padding.forEach(v => {
  100. this.marginClass += `uni-p${v}-${paddingSize} `
  101. })
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss">
  107. .header {
  108. display: flex;
  109. flex-direction: row;
  110. flex-wrap: wrap;
  111. }
  112. .margin {
  113. display: flex;
  114. height: 200px;
  115. margin: 10px;
  116. overflow: hidden;
  117. border-radius: 5px;
  118. border: 1px #eee solid;
  119. /* #ifndef APP-NVUE */
  120. box-sizing: border-box;
  121. /* #endif */
  122. }
  123. .margin-item {
  124. display: flex;
  125. flex: 1;
  126. }
  127. .box {
  128. display: flex;
  129. align-items: center;
  130. justify-content: center;
  131. flex: 1;
  132. }
  133. .actions {
  134. display: flex;
  135. flex-direction: row;
  136. align-items: center;
  137. }
  138. .action-label {
  139. /* #ifndef APP-NVUE */
  140. flex-shrink: 0;
  141. /* #endif */
  142. width: 70px;
  143. margin-left: 10px;
  144. margin-right: 10px;
  145. font-size: 12px;
  146. }
  147. </style>