| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <template>
- <view class="custom-toast" v-if="show" id="CustomToast">
- <view class="toast-content">
- <image class="imgbox" src="/static/image/new/icon_warning.svg"></image>
- <text class="toast-text">{{ text }}</text>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'CustomToast',
- data() {
- return {
- show: false,
- text: '',
- duration: 1500, // 默认时间
- timer: null
- };
- },
- methods: {
- // 显示提示
- showToast(options) {
- // 清除之前的定时器
- if (this.timer) clearTimeout(this.timer);
-
- this.text = options.title || '';
- this.duration = options.duration || 1500;
- this.show = true;
-
- // 自动隐藏
- this.timer = setTimeout(() => {
- this.show = false;
- }, this.duration);
- },
- // 手动隐藏
- hideToast() {
- this.show = false;
- if (this.timer) clearTimeout(this.timer);
- }
- },
- beforeDestroy() {
- if (this.timer) clearTimeout(this.timer);
- }
- };
- </script>
- <style scoped>
- .custom-toast {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- pointer-events: none; /* 不阻挡底层点击 */
- z-index: 99999;
- }
- .toast-content {
- background: rgba(0, 0, 0, 0.7);
- color: #fff;
- padding: 28px 38px;
- border-radius: 20px;
- max-width: 70%;
- text-align: center;
- display: flex;
- align-items: center;
- }
- .imgbox{
- margin-right: 40px;
- width: 56px;
- height: 56px;
- }
- /* 核心:自定义文字大小(按需调整) */
- .toast-text {
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28px;
- color: #FFFFFF;
- line-height: 42px;
- }
- </style>
|