uni-popup-dialog.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="uni-popup-dialog">
  3. <view class="uni-dialog-title">
  4. <text class="uni-dialog-title-text" :class="['uni-popup__'+dialogType]">{{title}}</text>
  5. </view>
  6. <view v-if="mode === 'base'" class="uni-dialog-content">
  7. <slot>
  8. <text class="uni-dialog-content-text">{{content}}</text>
  9. </slot>
  10. </view>
  11. <view v-else class="uni-dialog-content">
  12. <slot>
  13. <input class="uni-dialog-input" v-model="val" type="text" :placeholder="placeholder" :focus="focus" >
  14. </slot>
  15. </view>
  16. <view class="uni-dialog-button-group">
  17. <view class="uni-dialog-button" @click="closeDialog">
  18. <text class="uni-dialog-button-text">取消</text>
  19. </view>
  20. <view class="uni-dialog-button uni-border-left" @click="onOk">
  21. <text class="uni-dialog-button-text uni-button-color">确定</text>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import popup from '../uni-popup/popup.js'
  28. /**
  29. * PopUp 弹出层-对话框样式
  30. * @description 弹出层-对话框样式
  31. * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  32. * @property {String} value input 模式下的默认值
  33. * @property {String} placeholder input 模式下输入提示
  34. * @property {String} type = [success|warning|info|error] 主题样式
  35. * @value success 成功
  36. * @value warning 提示
  37. * @value info 消息
  38. * @value error 错误
  39. * @property {String} mode = [base|input] 模式、
  40. * @value base 基础对话框
  41. * @value input 可输入对话框
  42. * @property {String} content 对话框内容
  43. * @property {Boolean} beforeClose 是否拦截取消事件
  44. * @event {Function} confirm 点击确认按钮触发
  45. * @event {Function} close 点击取消按钮触发
  46. */
  47. export default {
  48. name: "uniPopupDialog",
  49. mixins: [popup],
  50. emits:['confirm','close'],
  51. props: {
  52. value: {
  53. type: [String, Number],
  54. default: ''
  55. },
  56. placeholder: {
  57. type: [String, Number],
  58. default: '请输入内容'
  59. },
  60. type: {
  61. type: String,
  62. default: 'error'
  63. },
  64. mode: {
  65. type: String,
  66. default: 'base'
  67. },
  68. title: {
  69. type: String,
  70. default: '提示'
  71. },
  72. content: {
  73. type: String,
  74. default: ''
  75. },
  76. beforeClose: {
  77. type: Boolean,
  78. default: false
  79. }
  80. },
  81. data() {
  82. return {
  83. dialogType: 'error',
  84. focus: false,
  85. val: ""
  86. }
  87. },
  88. watch: {
  89. type(val) {
  90. this.dialogType = val
  91. },
  92. mode(val) {
  93. if (val === 'input') {
  94. this.dialogType = 'info'
  95. }
  96. },
  97. value(val) {
  98. this.val = val
  99. }
  100. },
  101. created() {
  102. // 对话框遮罩不可点击
  103. this.popup.disableMask()
  104. // this.popup.closeMask()
  105. if (this.mode === 'input') {
  106. this.dialogType = 'info'
  107. this.val = this.value
  108. } else {
  109. this.dialogType = this.type
  110. }
  111. },
  112. mounted() {
  113. this.focus = true
  114. },
  115. methods: {
  116. /**
  117. * 点击确认按钮
  118. */
  119. onOk() {
  120. if (this.mode === 'input'){
  121. this.$emit('confirm', this.val)
  122. }else{
  123. this.$emit('confirm')
  124. }
  125. if(this.beforeClose) return
  126. this.popup.close()
  127. },
  128. /**
  129. * 点击取消按钮
  130. */
  131. closeDialog() {
  132. this.$emit('close')
  133. if(this.beforeClose) return
  134. this.popup.close()
  135. },
  136. close(){
  137. this.popup.close()
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .uni-popup-dialog {
  144. width: 300px;
  145. border-radius: 15px;
  146. background-color: #fff;
  147. }
  148. .uni-dialog-title {
  149. /* #ifndef APP-NVUE */
  150. display: flex;
  151. /* #endif */
  152. flex-direction: row;
  153. justify-content: center;
  154. padding-top: 15px;
  155. padding-bottom: 5px;
  156. }
  157. .uni-dialog-title-text {
  158. font-size: 16px;
  159. font-weight: 500;
  160. }
  161. .uni-dialog-content {
  162. /* #ifndef APP-NVUE */
  163. display: flex;
  164. /* #endif */
  165. flex-direction: row;
  166. justify-content: center;
  167. align-items: center;
  168. padding: 5px 15px 15px 15px;
  169. }
  170. .uni-dialog-content-text {
  171. font-size: 14px;
  172. color: #6e6e6e;
  173. }
  174. .uni-dialog-button-group {
  175. /* #ifndef APP-NVUE */
  176. display: flex;
  177. /* #endif */
  178. flex-direction: row;
  179. border-top-color: #f5f5f5;
  180. border-top-style: solid;
  181. border-top-width: 1px;
  182. }
  183. .uni-dialog-button {
  184. /* #ifndef APP-NVUE */
  185. display: flex;
  186. /* #endif */
  187. flex: 1;
  188. flex-direction: row;
  189. justify-content: center;
  190. align-items: center;
  191. height: 45px;
  192. }
  193. .uni-border-left {
  194. border-left-color: #f0f0f0;
  195. border-left-style: solid;
  196. border-left-width: 1px;
  197. }
  198. .uni-dialog-button-text {
  199. font-size: 14px;
  200. }
  201. .uni-button-color {
  202. color: #007aff;
  203. }
  204. .uni-dialog-input {
  205. flex: 1;
  206. font-size: 14px;
  207. border: 1px #eee solid;
  208. height: 40px;
  209. padding: 0 10px;
  210. border-radius: 5px;
  211. color: #555;
  212. }
  213. .uni-popup__success {
  214. color: #4cd964;
  215. }
  216. .uni-popup__warn {
  217. color: #f0ad4e;
  218. }
  219. .uni-popup__error {
  220. color: #dd524d;
  221. }
  222. .uni-popup__info {
  223. color: #909399;
  224. }
  225. </style>