as-popup-dialog.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <view class="as-popup-dialog">
  3. <view class="as-dialog-title">
  4. <text class="as-dialog-title-text" :class="['as-popup__'+type]">{{title}}</text>
  5. </view>
  6. <view v-if="mode === 'base'" class="as-dialog-content">
  7. <slot>
  8. <text class="as-dialog-content-text">{{content}}</text>
  9. </slot>
  10. </view>
  11. <view v-else class="as-dialog-content">
  12. <slot>
  13. <input class="as-dialog-input" v-model="val" :type="inputType" :placeholder="placeholderText" :focus="focus" >
  14. </slot>
  15. </view>
  16. <view class="as-dialog-button-group">
  17. <view class="as-dialog-button" @click="closeDialog">
  18. <text class="as-dialog-button-text">{{cancelText}}</text>
  19. </view>
  20. <view class="as-dialog-button as-border-left" @click="onOk">
  21. <text class="as-dialog-button-text as-button-color">{{confirmText}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default{
  28. name: "AsPopupDialog",
  29. emits:['confirm','close'],
  30. props: {
  31. inputType:{
  32. type: String,
  33. default: 'text'
  34. },
  35. value: {
  36. type: [String, Number],
  37. default: ''
  38. },
  39. placeholder: {
  40. type: [String, Number],
  41. default: ''
  42. },
  43. type: {
  44. type: String,
  45. default: 'info'
  46. },
  47. mode: {
  48. type: String,
  49. default: 'base'
  50. },
  51. title: {
  52. type: String,
  53. default: ''
  54. },
  55. content: {
  56. type: String,
  57. default: ''
  58. },
  59. beforeClose: {
  60. type: Boolean,
  61. default: false
  62. },
  63. cancelText:{
  64. type: String,
  65. default: '取消'
  66. },
  67. confirmText:{
  68. type: String,
  69. default: '确定'
  70. }
  71. },
  72. data(){
  73. return {
  74. popup: null,
  75. focus: false,
  76. val: ""
  77. }
  78. },
  79. methods: {
  80. /**
  81. * 获取父元素实例
  82. */
  83. getParent() {
  84. let name = 'AsPopup';
  85. let parent = this.$parent;
  86. let parentName = parent.$options.name;
  87. while (parentName !== name) {
  88. parent = parent.$parent;
  89. if (!parent) return false
  90. parentName = parent.$options.name;
  91. console.log(parentName);
  92. }
  93. return parent;
  94. },
  95. /**
  96. * 点击确认按钮
  97. */
  98. onOk() {
  99. if (this.mode === 'input'){
  100. this.$emit('confirm', this.val)
  101. }else{
  102. this.$emit('confirm')
  103. }
  104. if(this.beforeClose) return
  105. this.popup.close()
  106. },
  107. /**
  108. * 点击取消按钮
  109. */
  110. closeDialog() {
  111. this.$emit('close')
  112. if(this.beforeClose) return
  113. this.popup.close()
  114. },
  115. close(){
  116. this.popup.close()
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" >
  122. .as-popup-dialog {
  123. width: 300px;
  124. border-radius: 11px;
  125. background-color: #fff;
  126. }
  127. .as-dialog-title {
  128. /* #ifndef APP-NVUE */
  129. display: flex;
  130. /* #endif */
  131. flex-direction: row;
  132. justify-content: center;
  133. padding-top: 25px;
  134. }
  135. .as-dialog-title-text {
  136. font-size: 16px;
  137. font-weight: 500;
  138. }
  139. .as-dialog-content {
  140. /* #ifndef APP-NVUE */
  141. display: flex;
  142. /* #endif */
  143. flex-direction: row;
  144. justify-content: center;
  145. align-items: center;
  146. padding: 20px;
  147. }
  148. .as-dialog-content-text {
  149. font-size: 14px;
  150. color: #6C6C6C;
  151. }
  152. .as-dialog-button-group {
  153. /* #ifndef APP-NVUE */
  154. display: flex;
  155. /* #endif */
  156. flex-direction: row;
  157. border-top-color: #f5f5f5;
  158. border-top-style: solid;
  159. border-top-width: 1px;
  160. }
  161. .as-dialog-button {
  162. /* #ifndef APP-NVUE */
  163. display: flex;
  164. /* #endif */
  165. flex: 1;
  166. flex-direction: row;
  167. justify-content: center;
  168. align-items: center;
  169. height: 45px;
  170. }
  171. .as-border-left {
  172. border-left-color: #f0f0f0;
  173. border-left-style: solid;
  174. border-left-width: 1px;
  175. }
  176. .as-dialog-button-text {
  177. font-size: 16px;
  178. color: #333;
  179. }
  180. .as-button-color {
  181. color: #007aff;
  182. }
  183. .as-dialog-input {
  184. flex: 1;
  185. font-size: 14px;
  186. border: 1px #eee solid;
  187. height: 40px;
  188. padding: 0 10px;
  189. border-radius: 5px;
  190. color: #555;
  191. }
  192. .as-popup__success {
  193. color: #4cd964;
  194. }
  195. .as-popup__warn {
  196. color: #f0ad4e;
  197. }
  198. .as-popup__error {
  199. color: #dd524d;
  200. }
  201. .as-popup__info {
  202. color: #333;
  203. }
  204. </style>