zhangxiaoxu123456
2021-12-06 f32f7d699607bb159d25dcf441942370aba2c968
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
  <view class="min-action" :class="{'min-action-show': show}" @touchmove.stop.prevent="()=>{}">
    <view class="min-action-mask" @click="handleMaskClick"></view>
    <view class="min-action-main" :class="{'min-action-main-show': show}">
      <view class="min-action-header min-action-line"><slot></slot></view>
      <view class="min-action-btn min-action-flex min-action-line"
        v-for="(item, index) in actions" :key="index"
        :style="[item.color ? {color: item.color} : '']"
        @click="handleClick(index)"
      >
        <view class="min-action-loading min-action-icon" v-if="item.loading === 1"></view>
        <image class="min-action-icon" :src="item.image" v-if="item.image"></image>
        <view class="min-action-icon" :class="item.icon" v-if="item.icon"></view>
        <view>{{item.name}}</view>
      </view>
      <view class="min-action-cancel" v-if="showCancel">
        <view class="min-action-flex min-action-btn" @click="handleClick(-1)">{{cancelText}}</view>
      </view>
    </view>
  </view>
</template>
 
<script>
export default {
  name: 'min-action-sheet',
  data () {
    return {
      show: false,
      asID: 'as',
      showCancel: true,
      cancelText: '取消',
      maskClose: true,
      actions: [],
      success: () => {},
      isClick: true
    }
  },
  methods: {
    handleShow ({showCancel = true, cancelText = '取消',
      maskClose = true, actions = [], asID = 'as',
      success = () => {}}) {
      this.show = true
      this.asID = asID
      this.showCancel = showCancel
      this.cancelText = cancelText
      this.maskClose = maskClose
      this.actions = actions
      this.success = success
    },
    handleHide () {
      this.show = false
      this.asID = 'as'
      this.showCancel = true
      this.cancelText = '取消'
      this.maskClose = true
      this.actions = []
      this.success = () => {}
      this.isClick = true
    },
    handleMaskClick () {
      if (!this.isClick) return
      this.maskClose && this.handleHide()
    },
    handleClick (id) {
      if (!this.isClick) return
      if (this.actions[id]) {
        if (this.actions[id].loading === 0) {
          this.actions[id].loading = 1
          this.success({asID: this.asID, id, handleHide: this.handleHide})
          this.isClick = false
          return
        }
      }
      this.success({asID: this.asID, id})
      this.handleHide()
    }
  }
}
</script>
 
<style scoped>
.min-action-flex {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
}
.min-action-line::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  transform: scale(.5);
  transform-origin: 0 0;
  pointer-events: none;
  box-sizing: border-box;
  border-bottom: 1px solid #e9eaec;
}
.min-action-loading {
  background: transparent;
  border-radius: 50%;
  border: 2px solid #e5e5e5;
  border-left-color: #aaaaaa;
  animation: loading 1s linear infinite;
}
.min-action,
.min-action-mask {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.min-action {
  z-index: 1000;
  visibility: hidden;
}
.min-action-show {
  visibility: visible;
}
.min-action-mask {
  background: rgba(0, 0, 0, 0.5);
}
.min-action-main {
  position: absolute;
  width: 100%;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  transform: translate3d(0, 100%, 0);
  transform-origin: center;
  visibility: hidden;
  transition: all 0.3s;
}
.min-action-main-show {
  transform: translate3d(0, 0, 0);
  visibility: visible;
}
.min-action-header {
  background: #ffffff;
  text-align: center;
  position: relative;
  font-size: 28rpx;
  color: #1c2438;
}
.min-action-icon {
  margin-right: 12rpx;
  width: 28rpx;
  height: 28rpx;
}
.min-action-cancel {
  padding-top: 12rpx;
  background: #f7f7f7;
}
.min-action-btn {
  position: relative;
  height: 96rpx;
  font-size: 28rpx;
  background: #ffffff;
  color: #1c2438;
}
@keyframes loading {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>