index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area">
  6. <u-switch v-model="checked" :loading="loading"
  7. :size="size" @change="change"
  8. :active-color="activeColor"
  9. :disabled="disabled"
  10. :activeValue="100"
  11. :inactiveValue="1"
  12. ></u-switch>
  13. </view>
  14. </view>
  15. <view class="u-config-wrap">
  16. <view class="u-config-title u-border-bottom">
  17. 参数配置
  18. </view>
  19. <view class="u-config-item">
  20. <view class="u-item-title">状态</view>
  21. <u-subsection :list="['关闭', '打开']" @change="modelChange"></u-subsection>
  22. </view>
  23. <view class="u-config-item">
  24. <view class="u-item-title">颜色</view>
  25. <u-subsection :list="['primary', 'error', 'warning', 'success']" @change="colorChange"></u-subsection>
  26. </view>
  27. <view class="u-config-item">
  28. <view class="u-item-title">尺寸(单位rpx)</view>
  29. <u-subsection current="1" :list="['40', '60', '80']" @change="sizeChange"></u-subsection>
  30. </view>
  31. <view class="u-config-item">
  32. <view class="u-item-title">加载中</view>
  33. <u-subsection :list="['否', '是']" @change="loadingChange"></u-subsection>
  34. </view>
  35. <view class="u-config-item">
  36. <view class="u-item-title">禁用</view>
  37. <u-subsection current="1" :list="['是', '否']" @change="disabledChange"></u-subsection>
  38. </view>
  39. <view class="u-config-item">
  40. <view class="u-item-title">异步控制</view>
  41. <u-subsection :list="['关闭', '打开']" @change="asyncChange"></u-subsection>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. checked: false,
  51. activeColor: '#2979ff',
  52. size: 50,
  53. loading: false,
  54. disabled: false
  55. }
  56. },
  57. methods: {
  58. modelChange(index) {
  59. // 两个!!可以把0变成false,1变成true
  60. this.checked = !!index;
  61. },
  62. colorChange(index) {
  63. let color = index == 0 ? 'primary' : index == 1 ? 'error' : index == 2 ? 'warning' : 'success';
  64. this.activeColor = this.$u.color[color];
  65. },
  66. sizeChange(index) {
  67. this.size = index == 0 ? '40' : index == 1 ? '60' : '80';
  68. },
  69. loadingChange(index) {
  70. this.loading = !!index;
  71. },
  72. disabledChange(index) {
  73. this.disabled = index == 0 ? true : false;
  74. },
  75. asyncChange(index) {
  76. if(this.checked && index == 1) {
  77. this.$u.toast('请先关闭选择器');
  78. return;
  79. }
  80. if(!this.checked && index == 0) {
  81. this.$u.toast('请先打开选择器');
  82. return;
  83. }
  84. let str = index == 0 ? '是否要关闭?' : '是否要打开?';
  85. this.loading = true;
  86. let oldStatus = this.checked;
  87. this.checked = true;
  88. uni.showModal({
  89. title: '提示',
  90. content: str,
  91. complete: (res) => {
  92. this.loading = false;
  93. if(res.confirm) {
  94. if(oldStatus) this.checked = false;
  95. else this.checked = true;
  96. } else {
  97. if(!oldStatus) this.checked = false;
  98. else this.checked = true;
  99. }
  100. }
  101. })
  102. },
  103. change(value) {
  104. // console.log(value);
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped lang="scss">
  110. .u-demo {}
  111. </style>