uni-popup-dialog.vue 6.2 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. 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 = false
  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. margin: 25% auto;
  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>