uni-popup-dialog.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. props: {
  51. value: {
  52. type: [String, Number],
  53. default: ''
  54. },
  55. placeholder: {
  56. type: [String, Number],
  57. default: '请输入内容'
  58. },
  59. type: {
  60. type: String,
  61. default: 'error'
  62. },
  63. mode: {
  64. type: String,
  65. default: 'base'
  66. },
  67. title: {
  68. type: String,
  69. default: '提示'
  70. },
  71. content: {
  72. type: String,
  73. default: ''
  74. },
  75. beforeClose: {
  76. type: Boolean,
  77. default: false
  78. }
  79. },
  80. data() {
  81. return {
  82. dialogType: 'error',
  83. focus: false,
  84. val: ""
  85. }
  86. },
  87. watch: {
  88. type(val) {
  89. this.dialogType = val
  90. },
  91. mode(val) {
  92. if (val === 'input') {
  93. this.dialogType = 'info'
  94. }
  95. },
  96. value(val) {
  97. this.val = val
  98. }
  99. },
  100. created() {
  101. // 对话框遮罩不可点击
  102. this.popup.disableMask()
  103. // this.popup.closeMask()
  104. if (this.mode === 'input') {
  105. this.dialogType = 'info'
  106. this.val = this.value
  107. } else {
  108. this.dialogType = this.type
  109. }
  110. },
  111. mounted() {
  112. this.focus = true
  113. },
  114. methods: {
  115. /**
  116. * 点击确认按钮
  117. */
  118. onOk() {
  119. if (this.mode === 'input'){
  120. this.$emit('confirm', this.val)
  121. }else{
  122. this.$emit('confirm')
  123. }
  124. if(this.beforeClose) return
  125. this.popup.close()
  126. },
  127. /**
  128. * 点击取消按钮
  129. */
  130. closeDialog() {
  131. this.$emit('close')
  132. if(this.beforeClose) return
  133. this.popup.close()
  134. },
  135. close(){
  136. this.popup.close()
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .uni-popup-dialog {
  143. width: 300px;
  144. border-radius: 15px;
  145. background-color: #fff;
  146. }
  147. .uni-dialog-title {
  148. /* #ifndef APP-NVUE */
  149. display: flex;
  150. /* #endif */
  151. flex-direction: row;
  152. justify-content: center;
  153. padding-top: 15px;
  154. padding-bottom: 5px;
  155. }
  156. .uni-dialog-title-text {
  157. font-size: 16px;
  158. font-weight: 500;
  159. }
  160. .uni-dialog-content {
  161. /* #ifndef APP-NVUE */
  162. display: flex;
  163. /* #endif */
  164. flex-direction: row;
  165. justify-content: center;
  166. align-items: center;
  167. padding: 5px 15px 15px 15px;
  168. }
  169. .uni-dialog-content-text {
  170. font-size: 14px;
  171. color: #6e6e6e;
  172. }
  173. .uni-dialog-button-group {
  174. /* #ifndef APP-NVUE */
  175. display: flex;
  176. /* #endif */
  177. flex-direction: row;
  178. border-top-color: #f5f5f5;
  179. border-top-style: solid;
  180. border-top-width: 1px;
  181. }
  182. .uni-dialog-button {
  183. /* #ifndef APP-NVUE */
  184. display: flex;
  185. /* #endif */
  186. flex: 1;
  187. flex-direction: row;
  188. justify-content: center;
  189. align-items: center;
  190. height: 45px;
  191. }
  192. .uni-border-left {
  193. border-left-color: #f0f0f0;
  194. border-left-style: solid;
  195. border-left-width: 1px;
  196. }
  197. .uni-dialog-button-text {
  198. font-size: 14px;
  199. }
  200. .uni-button-color {
  201. color: #007aff;
  202. }
  203. .uni-dialog-input {
  204. flex: 1;
  205. font-size: 14px;
  206. border: 1px #eee solid;
  207. height: 40px;
  208. padding: 0 10px;
  209. border-radius: 5px;
  210. color: #555;
  211. }
  212. .uni-popup__success {
  213. color: #4cd964;
  214. }
  215. .uni-popup__warn {
  216. color: #f0ad4e;
  217. }
  218. .uni-popup__error {
  219. color: #dd524d;
  220. }
  221. .uni-popup__info {
  222. color: #909399;
  223. }
  224. </style>