DialogBox.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 class="content" v-if="options.DialogType == 'input'">
  7. <input type="text" v-model="options.value" :placeholder="options.placeholder">
  8. <text class="iconfont icon-clear" @click.stop="onClear"></text>
  9. </view>
  10. <view class="inquiry" v-else-if="options.DialogType == 'inquiry'">
  11. <text>{{options.content}}</text>
  12. </view>
  13. <view class="operation-btn">
  14. <view class="btn" @click="onCancel">
  15. <text>{{options.btn1}}</text>
  16. <text class="tag"></text>
  17. </view>
  18. <view class="btn" @click="onConfirm">
  19. <text class="activity">{{options.btn2}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. AClass: [
  31. ['a-fadein', 'a-fadeout'],
  32. ['a-bouncein', 'a-bounceout'],
  33. ],
  34. AnIndex: 0,
  35. AnIdx: 0,
  36. isShow: false,
  37. SetTime: null,
  38. value: '',
  39. // parmoise
  40. resolve: '',
  41. reject: '',
  42. promise: '',
  43. // 配置
  44. options: {
  45. // 提示标题
  46. title: '',
  47. // 内容
  48. content: '',
  49. btn1: '',
  50. btn2: '',
  51. // 提示内容
  52. placeholder: '请输入内容',
  53. // 提示框类型
  54. DialogType: 'input',
  55. // 动画类型
  56. animation: 0,
  57. },
  58. };
  59. },
  60. props: {
  61. // 提示标题
  62. title: {
  63. type: String,
  64. default: '提示',
  65. },
  66. // 内容
  67. content: {
  68. type: String,
  69. default: '',
  70. },
  71. // 提示内容
  72. placeholder: {
  73. type: String,
  74. default: '请输入内容',
  75. },
  76. // 提示框类型
  77. DialogType: {
  78. type: String,
  79. default: 'input'
  80. },
  81. // 动画类型
  82. animation: {
  83. type: Number,
  84. default: 0
  85. }
  86. },
  87. methods: {
  88. // 询问框
  89. confirm(options) {
  90. this.AnIndex = options.animation || 0;
  91. this.AnIdx = options.animation || 0;
  92. this.options = {
  93. // 提示标题
  94. title: options.title || '',
  95. // 内容
  96. content: options.content || '',
  97. btn1: options.btn1 || '',
  98. btn2: options.btn2 || '',
  99. // 提示内容
  100. placeholder: options.placeholder || '请输入内容',
  101. // 提示框类型
  102. DialogType: options.DialogType || 'input',
  103. // 动画类型
  104. animation: options.animation || 0,
  105. // input输入的值
  106. value: options.value || '',
  107. };
  108. this.show();
  109. this.promise = new Promise((resolve, reject) => {
  110. this.resolve = resolve;
  111. this.reject = reject;
  112. });
  113. return this.promise; //返回promise对象,给父级组件调用
  114. },
  115. /**
  116. * 显示
  117. */
  118. show(callback) {
  119. this.isShow = true;
  120. },
  121. /**
  122. * 隐藏
  123. */
  124. hide() {
  125. this.AnIdx = 1;
  126. this.SetTime = setTimeout(() => {
  127. this.isShow = false;
  128. }, 300);
  129. },
  130. /**
  131. * 清除输入值
  132. */
  133. onClear() {
  134. this.options.value = '';
  135. },
  136. /**
  137. * 取消点击
  138. */
  139. onCancel() {
  140. this.hide();
  141. this.reject({
  142. value: this.options.value,
  143. isConfirm: true,
  144. });
  145. },
  146. /**
  147. * 确定点击
  148. */
  149. onConfirm() {
  150. this.hide();
  151. this.resolve({
  152. value: this.options.value,
  153. isConfirm: true,
  154. });
  155. },
  156. },
  157. }
  158. </script>
  159. <style scoped lang="scss">
  160. @import 'DialogBox.scss'
  161. </style>