uni-popup-form.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="uni-popup-dialog">
  3. <view class="uni-dialog-content">
  4. <view class="uni-content-ceil">
  5. <view class="uni-content-ceil-title">
  6. <text>帐号:</text>
  7. </view>
  8. <input type="text" :value="userinfo.username" @input="username" placeholder="请输入帐号" class="uni-content-ceil-input" />
  9. </view>
  10. <view class="uni-content-ceil">
  11. <view class="uni-content-ceil-title">
  12. <text>昵称:</text>
  13. </view>
  14. <input type="text" :value="userinfo.nickname" @input="nickname" placeholder="请输入昵称" class="uni-content-ceil-input" />
  15. </view>
  16. <view class="uni-content-ceil">
  17. <view class="uni-content-ceil-title">
  18. <text>密码:</text>
  19. </view>
  20. <input type="text" :value="userinfo.password" maxlength="11" @input="password" placeholder="请输入密码" class="uni-content-ceil-input" />
  21. </view>
  22. </view>
  23. <view class="uni-dialog-button-group">
  24. <button type="primary" @tap="onOk" style="width: 80%;border-radius: 30px;">确认</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. /**
  30. * PopUp 弹出层-对话框样式
  31. * @description 弹出层-对话框样式
  32. * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  33. * @property {String} value input 模式下的默认值
  34. * @property {String} placeholder input 模式下输入提示
  35. * @property {String} type = [success|warning|info|error] 主题样式
  36. * @value success 成功
  37. * @value warning 提示
  38. * @value info 消息
  39. * @value error 错误
  40. * @property {String} mode = [base|input] 模式、
  41. * @value base 基础对话框
  42. * @value input 可输入对话框
  43. * @property {String} content 对话框内容
  44. * @property {Boolean} beforeClose 是否拦截取消事件
  45. * @event {Function} confirm 点击确认按钮触发
  46. * @event {Function} close 点击取消按钮触发
  47. */
  48. export default {
  49. name: "uniPopupForm",
  50. props: {
  51. value: {
  52. type: [String, Number],
  53. default: ''
  54. },
  55. maxlength:{
  56. type: Number,
  57. default: 10
  58. },
  59. placeholder: {
  60. type: [String, Number],
  61. default: '请输入内容'
  62. },
  63. /**
  64. * 对话框主题 success/warning/info/error 默认 success
  65. */
  66. type: {
  67. type: String,
  68. default: 'error'
  69. },
  70. /**
  71. * 对话框模式 base/input
  72. */
  73. mode: {
  74. type: String,
  75. default: 'base'
  76. },
  77. /**
  78. * 对话框标题
  79. */
  80. title: {
  81. type: String,
  82. default: '提示'
  83. },
  84. /**
  85. * 对话框内容
  86. */
  87. content: {
  88. type: String,
  89. default: ''
  90. },
  91. /**
  92. * 拦截取消事件 ,如果拦截取消事件,必须监听close事件,执行 done()
  93. */
  94. beforeClose: {
  95. type: Boolean,
  96. default: false
  97. },
  98. userinfo:{
  99. type:Object,
  100. default:()=>{
  101. return {
  102. username: '',
  103. password: '',
  104. nickname: ''
  105. }
  106. }
  107. }
  108. },
  109. data() {
  110. return {
  111. dialogType: 'error',
  112. focus: false,
  113. val: ""
  114. }
  115. },
  116. components:{
  117. },
  118. inject: ['popup'],
  119. watch: {
  120. type(val) {
  121. this.dialogType = val
  122. },
  123. mode(val) {
  124. if (val === 'input') {
  125. this.dialogType = 'info'
  126. }
  127. },
  128. value(val) {
  129. this.val = val
  130. }
  131. },
  132. created() {
  133. // 对话框遮罩不可点击
  134. this.popup.mkclick = false
  135. if (this.mode === 'input') {
  136. this.dialogType = 'info'
  137. this.val = this.value
  138. } else {
  139. this.dialogType = this.type
  140. }
  141. },
  142. mounted() {
  143. this.focus = true
  144. },
  145. methods: {
  146. username(e){
  147. console.log(e.detail.value)
  148. return this.userinfo.username = e.detail.value;
  149. },
  150. nickname(e){
  151. console.log(e.detail.value)
  152. return this.userinfo.nickname = e.detail.value;
  153. },
  154. password(e){
  155. return this.userinfo.password = e.detail.value;
  156. },
  157. onOk() {
  158. //判断手机号
  159. if(this.userinfo.username == '')return uni.showToast({title:"请输入帐号",icon:'none'});
  160. if(this.userinfo.nickname == '')return uni.showToast({title:"请输入昵称",icon:'none'});
  161. if(this.userinfo.password == '')return uni.showToast({title:"请输入密码",icon:'none'});
  162. this.$emit('confirm',this.userinfo)
  163. },
  164. /**
  165. * 点击取消按钮
  166. */
  167. close() {
  168. if (this.beforeClose) {
  169. this.$emit('close', () => {
  170. this.popup.close()
  171. })
  172. return
  173. }
  174. this.popup.close()
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .uni-popup-dialog {
  181. background-color: #fff;
  182. padding: 20px;
  183. border-radius: 5px;
  184. }
  185. .uni-popup-dialog button{
  186. line-height: unset;
  187. }
  188. .fix-icon-title{
  189. position: relative;
  190. }
  191. .uni-dialog-title {
  192. /* #ifndef APP-NVUE */
  193. display: flex;
  194. /* #endif */
  195. flex-direction: row;
  196. justify-content: flex-start;
  197. padding: 20px 20px;
  198. }
  199. .icon-close:before{
  200. content: "\e620";
  201. position: absolute;
  202. display:block;
  203. width: 0;
  204. height: 0;
  205. left: 360rpx;
  206. top: -20rpx;
  207. }
  208. .uni-popup-image{
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. }
  213. .uni-popup-info {
  214. display: flex;
  215. flex-direction: column;
  216. margin-left: 20px;
  217. }
  218. .uni-dialog-content {
  219. /* #ifndef APP-NVUE */
  220. display: flex;
  221. /* #endif */
  222. flex-direction: column;
  223. justify-content: center;
  224. align-items: center;
  225. }
  226. .uni-dialog-content-text {
  227. font-size: 14px;
  228. color: #6e6e6e;
  229. }
  230. .uni-dialog-button-group {
  231. /* #ifndef APP-NVUE */
  232. display: flex;
  233. /* #endif */
  234. flex-direction: row;
  235. padding: 10px 0;
  236. }
  237. .uni-dialog-input {
  238. flex: 1;
  239. font-size: 14px;
  240. overflow: visible !important;
  241. line-height :1.9rem !important;
  242. height:1.9rem !important;
  243. border-radius: 10px;
  244. padding-left:2px;
  245. background-color: #eeeeee;
  246. }
  247. .uni-popup__success {
  248. color: $uni-color-success;
  249. }
  250. .uni-popup__warn {
  251. color: $uni-color-warning;
  252. }
  253. .uni-popup__error {
  254. color: $uni-color-error;
  255. }
  256. .uni-popup__info {
  257. color: #909399;
  258. },
  259. .uni-content-ceil{
  260. display: flex;
  261. flex-direction: row;
  262. justify-content: center;
  263. width: 100%;
  264. padding: 8px 0;
  265. }
  266. .uni-content-ceil-title{
  267. font-size: 16px;
  268. margin-right: 10upx;
  269. }
  270. .uni-content-ceil-input{
  271. border-bottom: 1upx solid #A9A9A9;
  272. padding: 0 50rpx;
  273. justify-content:space-around;
  274. }
  275. </style>