tm-dialog.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view
  3. @click.stop="overCloseCHange"
  4. v-if="show"
  5. class="tm-dialog fixed flex-center"
  6. :style="{
  7. height: sysinfo + 'px'
  8. }"
  9. >
  10. <view @click.stop="" :class="[show ? 'success' : '']">
  11. <view :class="[clickOverlay ? 'clickover' : '']">
  12. <tm-sheet :black="black_tmeme" :padding="[0, 0]" classname="overflow" :width="600" :round="round" shadow="10">
  13. <view class="text-size-g flex-center text-weight-b px-32 pt-32 " :class="[black_tmeme ? 'bk' : '', bottomBorder ? 'border-b-1' : '']">
  14. <slot name="title">{{ title }}</slot>
  15. </view>
  16. <view class="px-50 py-n12 text-size-n text-align-center" style="max-height:700rpx;overflow-y: auto;">
  17. <slot name="default">
  18. <view >
  19. <text :class="[black_tmeme ? 'text-white' : 'text-grey-darken-3']">{{ content }}</text>
  20. <view v-if="model == 'confirm'" class="pt-24">
  21. <tm-input bg-color="grey-lighten-5" @input="suren" :black="black_tmeme" v-model="inputVala" :border-bottom="false" :flat="true"></tm-input>
  22. </view>
  23. </view>
  24. </slot>
  25. </view>
  26. <slot name="button">
  27. <view v-if="theme == 'merge'" class="py-0 flex-between">
  28. <tm-button
  29. :fllowTheme="fllowTheme"
  30. :height="80"
  31. text
  32. :black="black_tmeme"
  33. @click="concelClick"
  34. v-if="showCancel"
  35. :theme="black_tmeme ? 'grey-darken-4' : color_tmeme"
  36. round="0"
  37. shadow="0"
  38. style="width: 50%;"
  39. block
  40. >
  41. {{ cancelText }}
  42. </tm-button>
  43. <tm-button
  44. :fllowTheme="fllowTheme"
  45. :height="80"
  46. :black="black_tmeme"
  47. @click="confirmClick"
  48. :theme="color_tmeme"
  49. round="0"
  50. shadow="0"
  51. :style="{
  52. width: showCancel ? '50%' : '100%'
  53. }"
  54. block
  55. >
  56. {{ confirmText }}
  57. </tm-button>
  58. </view>
  59. <view v-if="theme == 'split'" class="px-40 pb-40 flex-between">
  60. <tm-button
  61. :fllowTheme="fllowTheme"
  62. text
  63. :height="72"
  64. :black="black_tmeme"
  65. @click="concelClick"
  66. v-if="showCancel"
  67. :theme="black_tmeme ? 'grey-darken-4' : color_tmeme"
  68. round="24"
  69. font-size="30"
  70. shadow="0"
  71. style="width: 46%;"
  72. block
  73. >
  74. {{ cancelText }}
  75. </tm-button>
  76. <tm-button
  77. :fllowTheme="fllowTheme"
  78. :height="72"
  79. :black="black_tmeme"
  80. @click="confirmClick"
  81. :theme="color_tmeme"
  82. round="24"
  83. font-size="30"
  84. shadow="0"
  85. :style="{
  86. width: showCancel ? '46%' : '100%'
  87. }"
  88. block
  89. >
  90. {{ confirmText }}
  91. </tm-button>
  92. </view>
  93. </slot>
  94. </tm-sheet>
  95. </view>
  96. </view>
  97. </view>
  98. </template>
  99. <script>
  100. /**
  101. * 对话框
  102. * @property {Boolean} value = [] 显示对话框,推荐使用value.sync或者v-model
  103. * @property {Boolean} black = [] 暗黑模式。
  104. * @property {Boolean} bottom-border = [] true,是否显示标题正文的边线。
  105. * @property {String} confirmColor = [] 默认:primary,确认按钮的主题颜色
  106. * @property {String} confirmText = [] 默认:确认,确认按钮的文字
  107. * @property {Boolean} showCancel = [] 默认:true,是否显示取消按钮。
  108. * @property {Boolean} disabled = [] 默认:false,禁用后,点击哪都关闭不了,只能通过手动设置v-model来关闭窗体。
  109. * @property {String} cancelColor = [] 默认:primary,取消按钮的主题色。
  110. * @property {String} cancelText = [] 默认:取消,取消按钮显示的文字。
  111. * @property {String} title = [] 默认:提示,标题。
  112. * @property {String} content = [] 默认:'',内容文字
  113. * @property {String} theme = [merge|split] 默认:'merge',merge合并按钮,split分割按钮
  114. * @property {String} model = [dialog|confirm] 默认:'dialog',对话框类型.dialog|confirm
  115. * @property {Number|String} round = [] 默认:'4',圆角
  116. * @property {String} input-val = [] 默认:'',model=confirm,显示的输入框内容。confirm
  117. * @property {Boolean} over-close = [] 默认:true,点击遮罩是否关闭窗体。
  118. * @property {Function} confirm 确认按钮时触发,注意:如果类型为confirm则返回 的参数包含输入框的内容。
  119. * @property {Function} cancel 点击取消按钮时触发。
  120. * @example <tm-dialog v-model="show" content="这是测试的内容"></tm-dialog>
  121. */
  122. import tmSheet from '@/tm-vuetify/components/tm-sheet/tm-sheet.vue';
  123. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  124. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  125. export default {
  126. components: { tmSheet, tmButton, tmInput },
  127. name: 'tm-dialog',
  128. model: {
  129. prop: 'value',
  130. event: 'input'
  131. },
  132. props: {
  133. value: {
  134. type: Boolean,
  135. default: false
  136. },
  137. bottomBorder: {
  138. type: Boolean,
  139. default: false
  140. },
  141. black: {
  142. type: Boolean | String,
  143. default: null
  144. },
  145. confirmColor: {
  146. type: String,
  147. default: 'primary'
  148. },
  149. confirmText: {
  150. type: String,
  151. default: '确认'
  152. },
  153. showCancel: {
  154. type: Boolean,
  155. default: true
  156. },
  157. cancelColor: {
  158. type: String,
  159. default: 'primary'
  160. },
  161. cancelText: {
  162. type: String,
  163. default: '取消'
  164. },
  165. title: {
  166. type: String,
  167. default: '消息提示'
  168. },
  169. content: {
  170. type: String,
  171. default: ''
  172. },
  173. inputVala:{
  174. type: String,
  175. default: ''
  176. },
  177. // 样式。
  178. theme: {
  179. type: String,
  180. default: 'merge' //merge|split merge合并按钮,split分割按钮
  181. },
  182. // 对话框类型.dialog|confirm
  183. model: {
  184. type: String,
  185. default: 'dialog' // dialog|confirm
  186. },
  187. round: {
  188. type: Number | String,
  189. default: 8
  190. },
  191. inputVal: {
  192. type: String,
  193. default: ''
  194. },
  195. // 跟随主题色的改变而改变。
  196. fllowTheme: {
  197. type: Boolean | String,
  198. default: true
  199. },
  200. overClose: {
  201. type: Boolean | String,
  202. default: false
  203. },
  204. //如果为true,需要你手动关闭。点按钮关闭不了。
  205. disabled: {
  206. type: Boolean | String,
  207. default: false
  208. }
  209. },
  210. computed: {
  211. show: {
  212. get: function() {
  213. return this.value;
  214. },
  215. set: async function(val) {
  216. this.$emit('input', val);
  217. this.$emit('update:value', val);
  218. }
  219. },
  220. black_tmeme: function() {
  221. if (this.black !== null) return this.black;
  222. return this.$tm.vx.state().tmVuetify.black;
  223. },
  224. color_tmeme: function() {
  225. if (this.$tm.vx.state().tmVuetify.color !== null && this.$tm.vx.state().tmVuetify.color && this.fllowTheme) {
  226. return this.$tm.vx.state().tmVuetify.color;
  227. }
  228. return this.confirmColor;
  229. }
  230. },
  231. data() {
  232. return {
  233. sysinfo: 0,
  234. clickOverlay: false
  235. };
  236. },
  237. created() {
  238. let sysinfo = uni.getSystemInfoSync();
  239. // #ifdef APP || MP
  240. if (sysinfo.windowHeight == sysinfo.screenHeight) {
  241. this.sysinfo = sysinfo.screenHeight;
  242. } else if (sysinfo.windowHeight < sysinfo.screenHeight) {
  243. this.sysinfo = sysinfo.windowHeight;
  244. }
  245. // #endif
  246. // #ifdef H5
  247. if(sysinfo.screenHeight>=sysinfo.windowHeight){
  248. this.sysinfo = sysinfo.windowHeight;
  249. }else{
  250. this.sysinfo = sysinfo.screenHeight;
  251. }
  252. // #endif
  253. this.show = this.value;
  254. },
  255. methods: {
  256. overCloseCHange() {
  257. if (this.overClose) {
  258. this.concelClick();
  259. } else {
  260. this.anifeed();
  261. }
  262. },
  263. anifeed() {
  264. let t = this;
  265. if (this.clickOverlay) this.clickOverlay = !this.clickOverlay;
  266. this.clickOverlay = true;
  267. uni.$tm.sleep(100).then(() => {
  268. t.clickOverlay = false;
  269. });
  270. },
  271. confirmClick() {
  272. if (this.model == 'confirm') {
  273. if (!this.inputVala) {
  274. uni.$tm.toast('请输入内容');
  275. this.anifeed();
  276. return;
  277. }
  278. this.$emit('confirm', this.inputVala);
  279. } else {
  280. this.$emit('confirm');
  281. }
  282. if (this.disabled == false) {
  283. this.show = false;
  284. }
  285. },
  286. suren(e) {
  287. this.$emit('update:inputVal', this.inputVala);
  288. },
  289. concelClick() {
  290. this.$emit('concel');//错误的拼写兼容
  291. this.$emit('cancel');//正常的拼写
  292. if (this.disabled == false) {
  293. this.show = false;
  294. }
  295. }
  296. }
  297. };
  298. </script>
  299. <style lang="scss">
  300. .tm-dialog {
  301. width: 100%;
  302. z-index: 600;
  303. background-color: rgba(0, 0, 0, 0.35);
  304. left: 0;
  305. top: 0;
  306. backdrop-filter: blur(10px);
  307. transition: all 0.35s;
  308. .success {
  309. animation: success 0.35s linear;
  310. // transform: scale(1);
  311. }
  312. .clickover {
  313. animation: clickover 0.35s linear;
  314. }
  315. }
  316. @keyframes clickover {
  317. 0% {
  318. transform: scale(0.95);
  319. }
  320. 50% {
  321. transform: scale(1.05);
  322. }
  323. 100% {
  324. transform: scale(1);
  325. }
  326. }
  327. @keyframes success {
  328. 0% {
  329. transform: scale(0.75);
  330. opacity: 0;
  331. }
  332. 75% {
  333. transform: scale(1.05);
  334. }
  335. 100% {
  336. transform: scale(1);
  337. opacity: 1;
  338. }
  339. }
  340. </style>