uni-popup-img.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="uni-popup-dialog">
  3. <view class="uni-popup-list">
  4. <view class="uni-popup-item">
  5. <view class="iconfont-im icon-shanchu uni-popup-item-info" @tap="confirm(1)"><text class="info">删除</text></view>
  6. <view class="iconfont-im icon-zhuanfa uni-popup-item-info" @tap="confirm(2)"><text class="info">转发</text></view>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. * PopUp 弹出层-对话框样式
  14. * @description 弹出层-对话框样式
  15. * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  16. * @property {String} value input 模式下的默认值
  17. * @property {String} placeholder input 模式下输入提示
  18. * @property {String} type = [success|warning|info|error] 主题样式
  19. * @value success 成功
  20. * @value warning 提示
  21. * @value info 消息
  22. * @value error 错误
  23. * @property {String} mode = [base|input] 模式、
  24. * @value base 基础对话框
  25. * @value input 可输入对话框
  26. * @property {String} content 对话框内容
  27. * @property {Boolean} beforeClose 是否拦截取消事件
  28. * @event {Function} confirm 点击确认按钮触发
  29. * @event {Function} close 点击取消按钮触发
  30. */
  31. export default {
  32. name: "uniPopupImg",
  33. props: {
  34. value: {
  35. type: [String, Number],
  36. default: ''
  37. },
  38. maxlength:{
  39. type: Number,
  40. default: 10
  41. },
  42. placeholder: {
  43. type: [String, Number],
  44. default: '请输入内容'
  45. },
  46. /**
  47. * 对话框主题 success/warning/info/error 默认 success
  48. */
  49. type: {
  50. type: String,
  51. default: 'error'
  52. },
  53. /**
  54. * 对话框模式 base/input
  55. */
  56. mode: {
  57. type: String,
  58. default: 'base'
  59. },
  60. /**
  61. * 对话框标题
  62. */
  63. title: {
  64. type: String,
  65. default: '提示'
  66. },
  67. /**
  68. * 对话框内容
  69. */
  70. content: {
  71. type: String,
  72. default: ''
  73. },
  74. /**
  75. * 拦截取消事件 ,如果拦截取消事件,必须监听close事件,执行 done()
  76. */
  77. beforeClose: {
  78. type: Boolean,
  79. default: false
  80. }
  81. },
  82. data() {
  83. return {
  84. dialogType: 'error',
  85. focus: false,
  86. val: ""
  87. }
  88. },
  89. inject: ['popup'],
  90. watch: {
  91. type(val) {
  92. this.dialogType = val
  93. },
  94. mode(val) {
  95. if (val === 'input') {
  96. this.dialogType = 'info'
  97. }
  98. },
  99. value(val) {
  100. this.val = val
  101. }
  102. },
  103. created() {
  104. // 对话框遮罩不可点击
  105. this.popup.mkclick = false
  106. if (this.mode === 'input') {
  107. this.dialogType = 'info'
  108. this.val = this.value
  109. } else {
  110. this.dialogType = this.type
  111. }
  112. },
  113. mounted() {
  114. this.focus = true
  115. },
  116. methods: {
  117. /**
  118. * 点击确认按钮
  119. */
  120. onOk() {
  121. this.$emit('confirm', () => {
  122. this.popup.close()
  123. if (this.mode === 'input') {
  124. this.val = this.value;
  125. return this.val;
  126. }
  127. }, this.mode === 'input' ? this.val : '')
  128. },
  129. confirm(val){
  130. this.$emit('confirm',{type:val})
  131. },
  132. /**
  133. * 点击取消按钮
  134. */
  135. close() {
  136. if (this.beforeClose) {
  137. this.$emit('close', () => {
  138. this.popup.close()
  139. })
  140. return
  141. }
  142. this.popup.close()
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .uni-popup-dialog {
  149. width: 550rpx;
  150. border-radius: 15px;
  151. background-color: #d8d8d8;
  152. padding-left: 25px;
  153. padding-top: 30px;
  154. padding-bottom: 30px;
  155. }
  156. .info{
  157. font-size: 16px;
  158. margin-left: 30rpx;
  159. }
  160. .uni-popup-item{
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: center;
  164. }
  165. .uni-popup-item-info{
  166. display: flex;
  167. align-items: center;
  168. }
  169. </style>