zuojincheng
2024-10-22 d3e02569fdef4d270e896bea2f9894f83c4503f9
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<template>
  <div class="alertModal" ref="alert">
    <!--social post弹框-->
    <transition name="maskAnimate">
      <div v-show="modelFlag" class="alertbox">
        <transition name="zoomAnimate">
          <div v-show="modelFlag" class="alert-dialog">
            <div class="alert-content">
              <div class="alert-header">
                <span class="alert-close" @click="close">×</span>
                <span class="alert-title">
                  {{ modelTitle }}
                </span>
              </div>
              <div class="alert-body">
                {{ modelContent }}
              </div>
              <div class="alert-footer">
                <button class="close link" @click="cancle">{{ modelClose }}</button>
                <button class="submit link" @click="submit">{{ modelSave }}</button>
              </div>
            </div>
          </div>
        </transition>
      </div>
    </transition>
  </div>
</template>
 
<script>
 
export default {
  name: "Alert",
  data() {
    return {
      modelFlag: false,//0为消失,1为显示
      modelTitle: 'Alert',//弹窗标题
      modelClose: '取消',//取消按钮文字
      modelContent: '',//弹窗内容
      modelSave: '确定',//确定按钮文字
      callBack: null, //确定回调函数
      cancleBack: null, //取消回调函数
    }
  },
  methods: {
    //成功回调函数
    doCallBack() {
      if (typeof this.callBack == 'function') {
        this.callBack()
        this.callBack = null;
      }
    },
    doCancleBack() {
      if (typeof this.cancleBack == 'function') {
        this.cancleBack()
        this.cancleBack = null;
      }
    },
    //关闭弹窗,数据重置
    close() {
      this.modelFlag = false;
      this.modelTitle = '';
      this.modelClose = '取消';
      this.modelContent = '';
      this.modelSave = '确定';
      this.callBack = null;
      this.cancleBack = null;
    },
    //点击确定按钮弹窗消失
    submit() {
      this.doCallBack()
      this.close()
    },
    //点击取消按钮弹窗消失
    cancle() {
      this.doCancleBack()
      this.close()
    },
    //显示弹窗,记性复制
    show(options) {
      if (this.modelFlag == true) { return };
      this.modelTitle = options.modelTitle || this.modelTitle;
      this.modelContent = options.modelContent;
      this.modelFlag = true;
      this.modelSave = options.modelSave || this.modelSave;
      this.modelClose = options.modelClose || this.modelClose;
      if (options.callBack) {
        this.callBack = options.callBack;
      }
      if (options.cancleBack) {
        this.cancleBack = options.cancleBack;
      }
 
      this.$bus.$off('scanResult')
      this.$bus.$on('scanResult', (val) => {
        console.log('[alert] show 接收状态 =>', val)
        this.handleScanVal(val)
      })
 
    },
    // 对扫码结果进行处理
    handleScanVal: function (val) {
      console.log('[alert] 事件总线接收 =>', val)
 
      if (!this.modelFlag) {
        console.log('[alert] 屏蔽处理')
        return
      }
      if (val == '102001') {
        this.submit()
      } else if (val == '102002') {
        this.cancle()
      } else {
        this.$notify({
          title: '扫描的二维码无效',
          message: `请扫描确认或取消二维码,或通过触摸屏操作。`,
          type: 'error'
        })
      }
    }
  },
  watch: {
    // 通过事件总线发送弹窗状态
    modelFlag: function (newVal) {
      this.$bus.$emit('isAlert', newVal)
    }
  },
  mounted() {
  },
  destroyed() {
    this.$bus.$off('scanResult')
  }
}
</script>
 
<style lang="less" scoped>
.alertbox {
  position: fixed;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background-color: rgba(0, 0, 0, .5);
  display: flex;
  justify-content: center;
  align-items: center;
 
  .alert-dialog {
    width: 400px;
    height: 300px;
    overflow: hidden;
    border-radius: 10px;
    background-color: #002244;
    color: #fff;
    font-size: 24px;
 
    .alert-content {
      width: 100%;
      height: 100%;
      text-align: center;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
 
    .alert-header {
      width: 100%;
      height: 70px;
      line-height: 70px;
      text-align: center;
      font-size: 24px;
      position: relative;
 
 
      .alert-title {
        font-weight: 700;
      }
 
      .alert-close {
        width: 70px;
        height: 70px;
        line-height: 70px;
        text-align: center;
        position: absolute;
        right: 0;
        top: 0;
        color: #002244;
        cursor: pointer;
      }
    }
 
    .alert-body {
      flex-grow: 1;
      padding: 30px;
    }
 
    .alert-footer {
      width: 100%;
      height: 70px;
 
      .close,
      .submit {
        width: 50%;
        height: 70px;
        font-size: 20px;
        text-align: center;
        font-weight: 500;
        cursor: pointer;
        border: none;
        border-top: 2px solid #002244;
        background-color: #003366;
      }
 
      .close {
        font-weight: 500;
        border-right: 2px solid #002244;
        box-sizing: border-box;
        color: #fff;
      }
 
      .submit {
        color: #00ca6c;
        font-weight: 700;
      }
    }
  }
}
 
.zoomAnimate-enter-active {
  animation: bounceIn 0.5s;
}
 
.zoomAnimate-leave-active {
  animation: bounceOut 0.2s;
}
 
.maskAnimate-enter-active {
  animation: fadeIn 0.5s;
}
 
.maskAnimate-leave-active {
  animation: fadeOut 0.2s;
}
</style>