index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 ref="uToast"></u-toast>
  7. <u-swipe-action
  8. bg-color="rgb(250, 250, 250)"
  9. @open="open"
  10. :disabled="disabled"
  11. :index="index"
  12. v-for="(item, index) in list"
  13. :key="item.id"
  14. :show="item.show"
  15. @click="click"
  16. :btn-width="btnWidth"
  17. @close="close"
  18. :options="options"
  19. @content-click="contentClick"
  20. >
  21. <view class="item u-border-bottom">
  22. <image mode="aspectFill" :src="item.images" />
  23. <!-- 此层wrap在此为必写的,否则可能会出现标题定位错误 -->
  24. <view class="title-wrap">
  25. <text class="title u-line-2">{{ item.title }}</text>
  26. </view>
  27. </view>
  28. </u-swipe-action>
  29. </view>
  30. </view>
  31. <view class="u-config-wrap">
  32. <view class="u-config-title u-border-bottom">参数配置</view>
  33. <view class="u-config-item">
  34. <view class="u-item-title">状态(操作第一个)</view>
  35. <u-subsection :current="1" :list="['打开', '关闭']" @change="showChange"></u-subsection>
  36. </view>
  37. <view class="u-config-item">
  38. <view class="u-item-title">禁止滑动</view>
  39. <u-subsection :current="1" :list="['是', '否']" @change="disabledChange"></u-subsection>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. list1: [
  49. {
  50. id: 1,
  51. title: '长安回望绣成堆,山顶千门次第开,一骑红尘妃子笑,无人知是荔枝来',
  52. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  53. show: false
  54. },
  55. {
  56. id: 2,
  57. title: '新丰绿树起黄埃,数骑渔阳探使回,霓裳一曲千峰上,舞破中原始下来',
  58. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  59. show: false
  60. },
  61. {
  62. id: 3,
  63. title: '登临送目,正故国晚秋,天气初肃。千里澄江似练,翠峰如簇',
  64. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  65. show: false,
  66. }
  67. ],
  68. list: [],
  69. disabled: false,
  70. btnWidth: 180,
  71. show: false,
  72. options: [
  73. {
  74. text: '收藏',
  75. style: {
  76. backgroundColor: '#007aff'
  77. }
  78. },
  79. {
  80. text: '删除',
  81. style: {
  82. backgroundColor: '#dd524d'
  83. }
  84. }
  85. ]
  86. };
  87. },
  88. onLoad() {
  89. setTimeout(() => {
  90. this.list = this.list1;
  91. }, 0)
  92. },
  93. methods: {
  94. disabledChange(index) {
  95. this.disabled = index == 0 ? true : false;
  96. },
  97. showChange(index) {
  98. if (index == 0) {
  99. this.list.map((val, ids) => {
  100. if (ids != 0) val.show = false;
  101. else val.show = true;
  102. });
  103. } else {
  104. this.list[0].show = false;
  105. }
  106. },
  107. click(index, index1) {
  108. if(index1 == 1) {
  109. this.list.splice(index, 1);
  110. this.$u.toast(`删除了第${index}个cell`);
  111. } else {
  112. this.list[index].show = false;
  113. this.$u.toast(`收藏成功`);
  114. }
  115. },
  116. open(index) {
  117. this.list[index].show = true;
  118. this.list.map((val, idx) => {
  119. if (index != idx) this.list[idx].show = false;
  120. });
  121. },
  122. close(index) {
  123. this.list[index].show = false;
  124. },
  125. contentClick(index) {
  126. // console.log(index);
  127. }
  128. }
  129. };
  130. </script>
  131. <style lang="scss" scoped>
  132. .item {
  133. display: flex;
  134. padding: 20rpx;
  135. }
  136. image {
  137. width: 120rpx;
  138. flex: 0 0 120rpx;
  139. height: 120rpx;
  140. margin-right: 20rpx;
  141. border-radius: 12rpx;
  142. }
  143. .title {
  144. text-align: left;
  145. font-size: 28rpx;
  146. color: $u-content-color;
  147. margin-top: 20rpx;
  148. }
  149. </style>