index.vue 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <uni-shadow-root class="vant-radio-index"><view :class="(utils.bem('radio', [direction]))+' custom-class'">
  3. <view v-if="labelPosition === 'left'" :class="(utils.bem('radio__label', [labelPosition, { disabled: disabled || parentDisabled }]))+' label-class'" @click="onClickLabel">
  4. <slot></slot>
  5. </view>
  6. <view class="van-radio__icon-wrap" :style="'font-size: '+(utils.addUnit(iconSize))" @click="onChange">
  7. <slot v-if="useIconSlot" name="icon"></slot>
  8. <van-icon v-else name="success" :class="utils.bem('radio__icon', [shape, { disabled: disabled || parentDisabled, checked: value === name }])" :style="computed.iconStyle({ iconSize, checkedColor, disabled, parentDisabled, value, name })" custom-class="icon-class" :custom-style="computed.iconCustomStyle({ iconSize })"></van-icon>
  9. </view>
  10. <view v-if="labelPosition === 'right'" :class="'label-class '+(utils.bem('radio__label', [labelPosition, { disabled: disabled || parentDisabled }]))" @click="onClickLabel">
  11. <slot></slot>
  12. </view>
  13. </view></uni-shadow-root>
  14. </template>
  15. <wxs src="../wxs/utils.wxs" module="utils"></wxs><wxs src="./index.wxs" module="computed"></wxs>
  16. <script>
  17. import VanIcon from '../icon/index.vue'
  18. global['__wxVueOptions'] = {components:{'van-icon': VanIcon}}
  19. global['__wxRoute'] = 'vant/radio/index'
  20. import { canIUseModel } from '../common/version';
  21. import { VantComponent } from '../common/component';
  22. import { useParent } from '../common/relation';
  23. VantComponent({
  24. field: true,
  25. relation: useParent('radio-group', function () {
  26. this.updateFromParent();
  27. }),
  28. classes: ['icon-class', 'label-class'],
  29. props: {
  30. name: null,
  31. value: null,
  32. disabled: Boolean,
  33. useIconSlot: Boolean,
  34. checkedColor: String,
  35. labelPosition: {
  36. type: String,
  37. value: 'right',
  38. },
  39. labelDisabled: Boolean,
  40. shape: {
  41. type: String,
  42. value: 'round',
  43. },
  44. iconSize: {
  45. type: null,
  46. value: 20,
  47. },
  48. },
  49. data: {
  50. direction: '',
  51. parentDisabled: false,
  52. },
  53. methods: {
  54. updateFromParent() {
  55. if (!this.parent) {
  56. return;
  57. }
  58. const { value, disabled: parentDisabled, direction } = this.parent.data;
  59. this.setData({
  60. value,
  61. direction,
  62. parentDisabled,
  63. });
  64. },
  65. emitChange(value) {
  66. const instance = this.parent || this;
  67. instance.$emit('input', value);
  68. instance.$emit('change', value);
  69. if (canIUseModel()) {
  70. instance.setData({ value });
  71. }
  72. },
  73. onChange() {
  74. if (!this.data.disabled && !this.data.parentDisabled) {
  75. this.emitChange(this.data.name);
  76. }
  77. },
  78. onClickLabel() {
  79. const { disabled, parentDisabled, labelDisabled, name } = this.data;
  80. if (!(disabled || parentDisabled) && !labelDisabled) {
  81. this.emitChange(name);
  82. }
  83. },
  84. },
  85. });
  86. export default global['__wxComponents']['vant/radio/index']
  87. </script>
  88. <style platform="mp-weixin">
  89. @import '../common/index.css';.van-radio{align-items:center;display:flex;overflow:hidden;-webkit-user-select:none;user-select:none}.van-radio__icon-wrap{flex:none}.van-radio--horizontal{margin-right:var(--padding-sm,12px)}.van-radio__icon{align-items:center;border:1px solid var(--radio-border-color,#c8c9cc);box-sizing:border-box;color:transparent;display:flex;font-size:var(--radio-size,20px);height:1em;justify-content:center;text-align:center;transition-duration:var(--radio-transition-duration,.2s);transition-property:color,border-color,background-color;width:1em}.van-radio__icon--round{border-radius:100%}.van-radio__icon--checked{background-color:var(--radio-checked-icon-color,#1989fa);border-color:var(--radio-checked-icon-color,#1989fa);color:#fff}.van-radio__icon--disabled{background-color:var(--radio-disabled-background-color,#ebedf0);border-color:var(--radio-disabled-icon-color,#c8c9cc)}.van-radio__icon--disabled.van-radio__icon--checked{color:var(--radio-disabled-icon-color,#c8c9cc)}.van-radio__label{word-wrap:break-word;color:var(--radio-label-color,#323233);line-height:var(--radio-size,20px);padding-left:var(--radio-label-margin,10px)}.van-radio__label--left{float:left;margin:0 var(--radio-label-margin,10px) 0 0}.van-radio__label--disabled{color:var(--radio-disabled-label-color,#c8c9cc)}.van-radio__label:empty{margin:0}
  90. </style>