您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

jade-checkbox.vue 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view>
  3. <checkbox-group @change="changeCb">
  4. <label class="cu-checked-group">
  5. <checkbox hidden color="#FFFFFF" value="2" />
  6. <view class="cu-checkbox" :class="checkType===1 ? 'check-not-full' : (checkType===2 ? 'check-full': 'check-not')">
  7. <view class="uni-checkbox-input"></view>
  8. </view>
  9. <text class="text" :class="checkType!==0 ? 'cu-checked' : ''">{{title}}</text>
  10. </label>
  11. </checkbox-group>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: "jade-checkbox",
  17. props: {
  18. // 绑定参数v-model
  19. value: {
  20. type: [Array, String, Number],
  21. default () {
  22. return ''
  23. }
  24. },
  25. // 数据源
  26. list: {
  27. type: Array,
  28. default () {
  29. return []
  30. }
  31. },
  32. // 文字
  33. title: String,
  34. // 对应关系
  35. map: {
  36. type: Object,
  37. default () {
  38. return {
  39. name: 'name',
  40. value: 'value'
  41. }
  42. }
  43. }
  44. },
  45. data() {
  46. return {
  47. checkType: 0,
  48. checkedData: []
  49. };
  50. },
  51. watch: {
  52. value(v) {
  53. this.checkedData = v
  54. },
  55. checkedData(v) {
  56. if (!this.checkedData.length) {
  57. this.checkType = 0
  58. } else if (this.checkedData.length == this.list.length) {
  59. this.checkType = 2
  60. } else {
  61. this.checkType = 1
  62. }
  63. this.$emit('change', this.checkedData)
  64. }
  65. },
  66. methods: {
  67. changeCb() {
  68. if (this.checkedData.length == this.list.length) {
  69. this.checkedData = []
  70. } else {
  71. this.checkedData = []
  72. this.list.forEach(item => {
  73. this.checkedData.push(item[this.map.value])
  74. })
  75. }
  76. },
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. .cu-checked-group {
  82. padding: 10px 0;
  83. display: flex;
  84. align-items: center;
  85. font-size: 14px;
  86. font-weight: 700;
  87. border-bottom: 1px #eee solid;
  88. .text{
  89. margin-left: 5px;
  90. }
  91. .cu-checked {
  92. color: #007aff;
  93. }
  94. }
  95. .cu-checkbox{
  96. position: relative;
  97. width: 16px;
  98. height: 16px;
  99. border: 1px solid #DCDFE6;
  100. border-radius: 2px;
  101. background-color: #fff;
  102. box-sizing: border-box;
  103. &.check-not {
  104. border: 1px solid #DCDFE6;
  105. background-color: #fff;
  106. }
  107. &.check-not-full {
  108. border-color: #007aff;
  109. background-color: #007aff;
  110. .uni-checkbox-input {
  111. position: absolute;
  112. /* #ifdef APP-NVUE */
  113. top: 2px;
  114. /* #endif */
  115. /* #ifndef APP-NVUE */
  116. top: 1px;
  117. /* #endif */
  118. left: 3px;
  119. height: 6px;
  120. width: 9px;
  121. border-bottom-width: 1px;
  122. border-bottom-color: #e7e7e7;
  123. border-bottom-style: solid;
  124. transform-origin: center;
  125. }
  126. }
  127. &.check-full {
  128. border-color: #007aff;
  129. background-color: #007aff;
  130. .uni-checkbox-input {
  131. position: absolute;
  132. /* #ifdef APP-NVUE */
  133. top: 2px;
  134. /* #endif */
  135. /* #ifndef APP-NVUE */
  136. top: 1px;
  137. /* #endif */
  138. left: 5px;
  139. height: 8px;
  140. width: 4px;
  141. border-right-width: 1px;
  142. border-right-color: #fff;
  143. border-right-style: solid;
  144. border-bottom-width: 1px;
  145. border-bottom-color: #fff;
  146. border-bottom-style: solid;
  147. transform-origin: center;
  148. transform: rotate(45deg);
  149. }
  150. }
  151. }
  152. </style>