index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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-toast :type="type" ref="uToast"></u-toast>
  7. <u-notice-bar :autoplay="autoplay" :playState="playState" :speed="speed" @getMore="getMore"
  8. :mode="mode" @end="end" @close="close" @click="click" :show="show" :type="type" :list="list"
  9. :moreIcon="moreIcon" :volumeIcon="volumeIcon" :duration="duration" :isCircular="isCircular"></u-notice-bar>
  10. </view>
  11. </view>
  12. <view class="u-config-wrap">
  13. <view class="u-config-title u-border-bottom">
  14. 参数配置
  15. </view>
  16. <view class="u-config-item">
  17. <view class="u-item-title">主题</view>
  18. <u-subsection :current="3" :list="['primary', 'success', 'error', 'warning', 'none']" @change="typeChange"></u-subsection>
  19. </view>
  20. <view class="u-config-item">
  21. <view class="u-item-title">滚动模式</view>
  22. <u-subsection :current="current" :list="['水平', '垂直']" @change="modeChange"></u-subsection>
  23. </view>
  24. <view class="u-config-item">
  25. <view class="u-item-title">是否衔接(水平模式有效)</view>
  26. <u-subsection :list="['是', '否']" @change="isCircularChange"></u-subsection>
  27. </view>
  28. <view class="u-config-item">
  29. <view class="u-item-title">状态</view>
  30. <u-subsection :list="['播放', '暂停']" @change="playStateChange"></u-subsection>
  31. </view>
  32. <view class="u-config-item">
  33. <view class="u-item-title">速度</view>
  34. <u-subsection :current="1" :list="['慢', '正常', '快']" @change="speedChange"></u-subsection>
  35. </view>
  36. <view class="u-config-item">
  37. <view class="u-item-title">图标</view>
  38. <u-subsection :list="['显示', '隐藏']" @change="iconChange"></u-subsection>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. show: true,
  48. autoplay: false,
  49. type: 'warning',
  50. list: [
  51. '锦瑟无端五十弦,一弦一柱思华年',
  52. '庄生晓梦迷蝴蝶,望帝春心托杜鹃',
  53. '沧海月明珠有泪,蓝田日暖玉生烟'
  54. ],
  55. mode: 'horizontal',
  56. playState: 'play',
  57. speed: 160,
  58. duration: 2000,
  59. moreIcon: true,
  60. volumeIcon: true,
  61. isCircular: true,
  62. current: 0
  63. }
  64. },
  65. onLoad() {
  66. },
  67. methods: {
  68. typeChange(index) {
  69. let type = ['primary', 'success', 'error', 'warning', 'none'];
  70. this.type = type[index];
  71. },
  72. modeChange(index) {
  73. this.current = index;
  74. this.mode = index == 0 ? 'horizontal' : 'vertical';
  75. },
  76. playStateChange(index) {
  77. this.playState = index == 0 ? 'play' : 'paused';
  78. },
  79. speedChange(index) {
  80. if(index == 0) {
  81. this.$nextTick(() => {
  82. this.speed = 50;
  83. this.duration = 6000;
  84. })
  85. } else if(index == 1) {
  86. this.$nextTick(() => {
  87. this.speed = 160;
  88. this.duration = 2000;
  89. })
  90. } else {
  91. this.$nextTick(() => {
  92. this.speed = 350;
  93. this.duration = 400;
  94. })
  95. }
  96. },
  97. iconChange(index) {
  98. if(index == 0) {
  99. this.moreIcon = true;
  100. this.volumeIcon = true;
  101. } else {
  102. this.moreIcon = false;
  103. this.volumeIcon = false;
  104. }
  105. },
  106. isCircularChange(index) {
  107. this.isCircular = index == 0 ? true : false;
  108. this.current = 0;
  109. this.mode = 'horizontal';
  110. },
  111. close() {
  112. this.toast(`点击了关闭图标`);
  113. },
  114. click(index) {
  115. if(this.mode == 'horizontal' && this.isCircular) {
  116. this.toast('此模式无法获取Index值');
  117. } else {
  118. this.toast(`点击了第${index + 1}条消息`);
  119. }
  120. },
  121. getMore() {
  122. this.toast(`点击了更多图标`);
  123. },
  124. toast(title) {
  125. this.$refs.uToast.show({
  126. title: title,
  127. type: 'warning'
  128. })
  129. },
  130. end() {
  131. // console.log('end');
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .item {
  138. margin-top: 30px;
  139. }
  140. </style>