my-popup-dialog.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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]">{{titleText}}</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-input">
  12. <slot>
  13. <input class="uni-dialog-input" v-model="val" :type="inputType" :placeholder="placeholderText" :focus="focus" >
  14. </slot>
  15. <slot>
  16. <input v-if="popmode==1" class="uni-dialog-input" style="margin-top: 16rpx;" v-model="val2" :type="inputType" :placeholder="placeholderText2" @input="input2">
  17. <radio-group v-if="popmode==2" style="margin-top: 16rpx;" @change="radioChange">
  18. <label class="radio"><radio value="1" checked="true"/>{{$t('comp.danxuan')}}</label>
  19. <label class="radio" style="margin-left: 8rpx;"><radio value="2"/>{{$t('comp.duoxuan')}}</label>
  20. </radio-group>
  21. <radio-group v-if="popmode==2" style="margin-top: 16rpx;" @change="radioChange2">
  22. <label class="radio"><radio value="1" checked="true"/>{{$t('comp.bixuan')}}</label>
  23. <label class="radio" style="margin-left: 8rpx;"><radio value="2"/>{{$t('comp.kexuan')}}</label>
  24. </radio-group>
  25. </slot>
  26. </view>
  27. <view class="uni-dialog-button-group">
  28. <view class="uni-dialog-button" @click="closeDialog">
  29. <text class="uni-dialog-button-text">{{closeText}}</text>
  30. </view>
  31. <view class="uni-dialog-button uni-border-left" @click="onOk">
  32. <text class="uni-dialog-button-text uni-button-color">{{okText}}</text>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import popup from '../uni-popup/popup.js'
  39. import {
  40. initVueI18n
  41. } from '@dcloudio/uni-i18n'
  42. import messages from '../uni-popup/i18n/index.js'
  43. const { t } = initVueI18n(messages)
  44. /**
  45. * PopUp 弹出层-对话框样式
  46. * @description 弹出层-对话框样式
  47. * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  48. * @property {String} value input 模式下的默认值
  49. * @property {String} placeholder input 模式下输入提示
  50. * * @property {String} placeholder2 2input 模式下输入提示
  51. * @property {String} type = [success|warning|info|error] 主题样式
  52. * @value success 成功
  53. * @value warning 提示
  54. * @value info 消息
  55. * @value error 错误
  56. * @property {String} mode = [base|input] 模式、
  57. * @value base 基础对话框
  58. * @value input 可输入对话框
  59. * @property {String} content 对话框内容
  60. * @property {Boolean} beforeClose 是否拦截取消事件
  61. * @event {Function} confirm 点击确认按钮触发
  62. * @event {Function} close 点击取消按钮触发
  63. */
  64. export default {
  65. name: "myPopupDialog",
  66. mixins: [popup],
  67. emits:['confirm','close'],
  68. props: {
  69. inputType:{
  70. type: String,
  71. default: 'text'
  72. },
  73. value: {
  74. type: [String, Number],
  75. default: ''
  76. },
  77. placeholder: {
  78. type: [String, Number],
  79. default: ''
  80. },
  81. placeholder2: {
  82. type: [String, Number],
  83. default: ''
  84. },
  85. type: {
  86. type: String,
  87. default: 'error'
  88. },
  89. mode: {
  90. type: String,
  91. default: 'base'
  92. },
  93. popmode: {
  94. type: Number,
  95. default: 2
  96. },
  97. title: {
  98. type: String,
  99. default: ''
  100. },
  101. content: {
  102. type: String,
  103. default: ''
  104. },
  105. beforeClose: {
  106. type: Boolean,
  107. default: false
  108. },
  109. cancelText:{
  110. type: String,
  111. default: ''
  112. },
  113. confirmText:{
  114. type: String,
  115. default: ''
  116. }
  117. },
  118. data() {
  119. return {
  120. dialogType: 'error',
  121. focus: false,
  122. val: "",
  123. val2: "",
  124. radioV:'1',
  125. radioV2:'1'
  126. }
  127. },
  128. computed: {
  129. okText() {
  130. return this.confirmText || t("uni-popup.ok")
  131. },
  132. closeText() {
  133. return this.cancelText || t("uni-popup.cancel")
  134. },
  135. placeholderText() {
  136. return this.placeholder || t("uni-popup.placeholder")
  137. },
  138. placeholderText2() {
  139. return this.placeholder2 || t("uni-popup.placeholder")
  140. },
  141. titleText() {
  142. return this.title || t("uni-popup.title")
  143. }
  144. },
  145. watch: {
  146. type(val) {
  147. this.dialogType = val
  148. },
  149. mode(val) {
  150. if (val === 'input') {
  151. this.dialogType = 'info'
  152. }
  153. }
  154. // value(val) {
  155. // this.val = val
  156. // }
  157. },
  158. created() {
  159. // 对话框遮罩不可点击
  160. this.popup.disableMask()
  161. // this.popup.closeMask()
  162. if (this.mode === 'input') {
  163. this.dialogType = 'info'
  164. //this.val = this.value
  165. } else {
  166. this.dialogType = this.type
  167. }
  168. },
  169. mounted() {
  170. this.focus = true
  171. },
  172. methods: {
  173. radioChange(evt){
  174. this.radioV = evt.detail.value
  175. },
  176. radioChange2(evt){
  177. this.radioV2 = evt.detail.value
  178. },
  179. input2(event){
  180. this.val2 = event.target.value;
  181. },
  182. input(event){
  183. this.val = event.target.value;
  184. },
  185. /**
  186. * 点击确认按钮
  187. */
  188. onOk() {
  189. if (this.mode === 'input'){
  190. this.$emit('confirm', this.val,this.val2,this.radioV,this.radioV2)
  191. }else{
  192. this.$emit('confirm')
  193. }
  194. if(this.beforeClose) return
  195. this.popup.close()
  196. },
  197. /**
  198. * 点击取消按钮
  199. */
  200. closeDialog() {
  201. this.$emit('close')
  202. if(this.beforeClose) return
  203. this.popup.close()
  204. },
  205. close(){
  206. this.popup.close()
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" >
  212. .uni-popup-dialog {
  213. width: 300px;
  214. border-radius: 11px;
  215. background-color: #fff;
  216. }
  217. .uni-dialog-title {
  218. /* #ifndef APP-NVUE */
  219. display: flex;
  220. /* #endif */
  221. flex-direction: row;
  222. justify-content: center;
  223. padding-top: 25px;
  224. }
  225. .uni-dialog-title-text {
  226. font-size: 16px;
  227. font-weight: 500;
  228. }
  229. .uni-dialog-content {
  230. /* #ifndef APP-NVUE */
  231. display: flex;
  232. /* #endif */
  233. flex-direction: row;
  234. justify-content: center;
  235. align-items: center;
  236. padding: 20px;
  237. }
  238. .uni-dialog-content-input {
  239. /* #ifndef APP-NVUE */
  240. display: flex;
  241. /* #endif */
  242. flex-direction: column;
  243. justify-content: center;
  244. align-items: center;
  245. padding: 20px;
  246. }
  247. .uni-dialog-content-text {
  248. font-size: 14px;
  249. color: #6C6C6C;
  250. }
  251. .uni-dialog-button-group {
  252. /* #ifndef APP-NVUE */
  253. display: flex;
  254. /* #endif */
  255. flex-direction: row;
  256. border-top-color: #f5f5f5;
  257. border-top-style: solid;
  258. border-top-width: 1px;
  259. }
  260. .uni-dialog-button {
  261. /* #ifndef APP-NVUE */
  262. display: flex;
  263. /* #endif */
  264. flex: 1;
  265. flex-direction: row;
  266. justify-content: center;
  267. align-items: center;
  268. height: 45px;
  269. }
  270. .uni-border-left {
  271. border-left-color: #f0f0f0;
  272. border-left-style: solid;
  273. border-left-width: 1px;
  274. }
  275. .uni-dialog-button-text {
  276. font-size: 16px;
  277. color: #333;
  278. }
  279. .uni-button-color {
  280. color: #007aff;
  281. }
  282. .uni-dialog-input {
  283. flex: 1;
  284. font-size: 14px;
  285. border: 1px #eee solid;
  286. height: 40px;
  287. padding: 0 10px;
  288. border-radius: 5px;
  289. color: #555;
  290. }
  291. .uni-popup__success {
  292. color: #4cd964;
  293. }
  294. .uni-popup__warn {
  295. color: #f0ad4e;
  296. }
  297. .uni-popup__error {
  298. color: #dd524d;
  299. }
  300. .uni-popup__info {
  301. color: #909399;
  302. }
  303. </style>