index.vue 4.3 KB

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