quanwei
2025-11-05 0368a9e52986b67493f10b7e21e8b6536a25fa6a
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
<template>
  <view class="prompt-box" v-if="visible" @touchmove="true">
    <view class="prompt">
      <view class="prompt-top">
        <text class="prompt-title">{{title}}</text>
        <input class="prompt-input" type="text" :placeholder="placeholder" v-model="value">
      </view>
      <slot></slot>
      <view class="prompt-buttons" :style="'background:' + mainColor">
        <button class="prompt-cancle" :style="'color:' + mainColor" @click="close">取消</button>
        <button @click="$emit('confirm', value)">确定</button>
      </view>
    </view>
  </view>
</template>
 
<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
      required: true,
    },
    title: {
      type: String,
      default: '提示',
    },
    placeholder: {
      type: String,
      default: '请输入内容',
    },
    mainColor: {
      type: String,
      default: '#e74a39',
    },
    defaultValue: {
      type: String,
    }
  },
  data() {
    return {
      value: '',
    }
  },
  mounted() {
    this.value = this.defaultValue
  },
  methods: {
    close() {
      this.$emit('update:visible', false)
    }
  }
}
</script>
 
<style scoped>
  view, button, input {
    box-sizing: border-box;
  }
  
  .prompt-box {
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, .2);
    transition: opacity .2s linear;
  }
  .prompt {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 600upx;
    min-height: 300upx;
    background: white;
    border-radius: 20upx;
    overflow: hidden;
  }
  .prompt-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
  }
  .prompt-title {
    margin: 20upx 0;
    color: #333;
  }
  .prompt-input {
    width: 520upx;
        height: 80upx;
    font-size: 28upx;
    border-radius: 8upx;
        border: 1px solid #ccc;
        padding: 5upx 10upx;
  }
  .prompt-buttons {
    display: flex;
    width: 100%;
    box-shadow: 0 0 2upx 2upx #eee;
  }
  button {
    width: 50%;
    border-radius: 0;
  }
  .prompt-cancle {
    background: white;
  }
</style>