ToastW3.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="page-total" v-if="isShow">
  3. <view class="box" :class="AClass[AnIndex][AnIdx]">
  4. <view class="dialog-box">
  5. <view class="title">{{options.title}}</view>
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. AClass: [
  15. ['a-fadein', 'a-fadeout'],
  16. ['a-bouncein', 'a-bounceout'],
  17. ],
  18. AnIndex: 0,
  19. AnIdx: 0,
  20. isShow: false,
  21. SetTime: null,
  22. value: '',
  23. promise: '',
  24. // 配置
  25. options: {
  26. // 提示标题
  27. title: '',
  28. // 动画类型
  29. animation: 0,
  30. },
  31. };
  32. },
  33. props: {
  34. // 提示标题
  35. title: {
  36. type: String,
  37. default: '提示',
  38. },
  39. // 动画类型
  40. animation: {
  41. type: Number,
  42. default: 0
  43. }
  44. },
  45. methods: {
  46. // 询问框
  47. showToast(options) {
  48. this.AnIndex = options.animation || 0;
  49. this.AnIdx = options.animation || 0;
  50. this.options = {
  51. // 提示标题
  52. title: options.title || '',
  53. // 动画类型
  54. animation: options.animation || 0,
  55. };
  56. this.show();
  57. let that = this;
  58. setTimeout(function() {
  59. that.hide();
  60. },
  61. 2000);
  62. this.promise = new Promise((resolve, reject) => {
  63. this.resolve = resolve;
  64. this.reject = reject;
  65. });
  66. return this.promise; //返回promise对象,给父级组件调用
  67. },
  68. /**
  69. * 显示
  70. */
  71. show(callback) {
  72. this.isShow = true;
  73. },
  74. /**
  75. * 隐藏
  76. */
  77. hide() {
  78. this.AnIdx = 1;
  79. this.SetTime = setTimeout(() => {
  80. this.isShow = false;
  81. }, 300);
  82. },
  83. /**
  84. * 清除输入值
  85. */
  86. onClear() {
  87. this.options.value = '';
  88. },
  89. /**
  90. * 取消点击
  91. */
  92. onCancel() {
  93. this.hide();
  94. },
  95. /**
  96. * 确定点击
  97. */
  98. onConfirm() {
  99. this.hide();
  100. },
  101. },
  102. }
  103. </script>
  104. <style scoped lang="scss">
  105. @import 'ToastW3.scss'
  106. </style>