pigeon.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * @Description: 消息系统
  3. * @Author: sql
  4. * @Date: 2018-11-26 11:06:55
  5. * @LastEditTime: 2018-11-30 11:25:43
  6. */
  7. import { ElMessage, ElMessageBox } from 'element-plus'
  8. const base = {
  9. placement: 'top-right',
  10. }
  11. export default class Pigeon {
  12. /**
  13. * 系统提醒
  14. * @param {string} msg 提醒信息
  15. * @param {int} type 0 信息, 1 成功, 2警告, 3 错误
  16. */
  17. message(msg, type = 0) {
  18. if (msg == '' || msg == null) {
  19. ElMessage.error('msg不能为空!!!')
  20. return false
  21. }
  22. switch (type) {
  23. case 0:
  24. ElMessage({ customClass: 'crm_message crm_msg_info', message: msg })
  25. break
  26. case 1:
  27. ElMessage.success({ customClass: 'crm_message crm_msg_suc', message: msg })
  28. break
  29. case 2:
  30. ElMessage.warning({
  31. customClass: 'crm_message crm_msg_war',
  32. message: msg,
  33. })
  34. break
  35. case 3:
  36. ElMessage.error({ customClass: 'crm_message crm_msg_err', message: msg })
  37. break
  38. default:
  39. ElMessage({ customClass: 'crm_message crm_msg_info', message: msg })
  40. break
  41. }
  42. }
  43. /**
  44. * 成功的系统提醒
  45. * @param {string} msg
  46. */
  47. MessageOK(msg) {
  48. this.message(msg, 1)
  49. }
  50. /**
  51. * 成功的系统提醒
  52. * @param {string} msg
  53. */
  54. success(msg) {
  55. this.message(msg, 1)
  56. }
  57. /**
  58. * 错误的系统提醒
  59. * @param {string} msg
  60. */
  61. MessageError(msg) {
  62. this.message(msg, 3)
  63. }
  64. /**
  65. * 错误的系统提醒
  66. * @param {string} msg
  67. */
  68. error(msg) {
  69. this.message(msg, 3)
  70. }
  71. /**
  72. * 警告的系统提醒
  73. * @param {string} msg
  74. */
  75. MessageWarning(msg) {
  76. this.message(msg, 2)
  77. }
  78. /**
  79. * 警告的系统提醒
  80. * @param {string} msg
  81. */
  82. warning(msg) {
  83. this.message(msg, 2)
  84. }
  85. /**
  86. * 普通的系统提醒
  87. * @param {string} msg
  88. */
  89. MessageInfo(msg) {
  90. this.message(msg, 0)
  91. }
  92. /**
  93. * 普通的系统提醒
  94. * @param {string} msg
  95. */
  96. info(msg) {
  97. this.message(msg, 0)
  98. }
  99. /**
  100. * 确认消息
  101. * @param {string} msg 提示信息
  102. * @param {string} title 头部
  103. * @param {function} confirmHandle 确认回调函数
  104. * @param {function} cancelHandle 取消回调函数
  105. * @param {string} confirmText 确认按钮文字
  106. * @param {string} cancelText 取消按钮文字
  107. * @param {string} settings 其他配置项
  108. */
  109. static MessageConfirm(
  110. msg,
  111. title,
  112. confirmText,
  113. cancelText,
  114. confirmHandle,
  115. cancelHandle,
  116. settings = {}
  117. ) {
  118. ElMessageBox.confirm(msg, title, {
  119. confirmButtonText: confirmText,
  120. cancelButtonText: cancelText,
  121. customClass: 'crm_message_box',
  122. ...settings,
  123. })
  124. .then(({ value }) => {
  125. confirmHandle(value)
  126. })
  127. .catch(() => {
  128. cancelHandle()
  129. })
  130. }
  131. /**
  132. * 提交内容
  133. * @param {string} msg 提示信息
  134. * @param {function} confirmHandle 确认回调函数
  135. * @param {function} cancelHandle 取消回调函数
  136. * @param settings
  137. */
  138. static MessagePrompt(
  139. msg,
  140. confirmHandle,
  141. cancelHandle,
  142. settings = {
  143. inputType: 'text',
  144. inputPattern: null,
  145. inputErrorMessage: null,
  146. }
  147. ) {
  148. ElMessageBox.prompt(msg, '系统提示', {
  149. confirmButtonText: settings.confirmButtonText || '确定',
  150. cancelButtonText: settings.cancelButtonText || '取消',
  151. ...settings,
  152. beforeClose: (action, instance, done) => {
  153. if (action === 'confirm') {
  154. instance.confirmButtonLoading = true
  155. instance.confirmButtonText = '执行中...'
  156. setTimeout(() => {
  157. done()
  158. setTimeout(() => {
  159. instance.confirmButtonLoading = false
  160. }, 100)
  161. }, 500)
  162. } else {
  163. instance.cancelButtonLoading = true
  164. instance.cancelButtonText = '执行中...'
  165. setTimeout(() => {
  166. done()
  167. setTimeout(() => {
  168. instance.cancelButtonLoading = false
  169. }, 100)
  170. }, 500)
  171. }
  172. },
  173. })
  174. .then(({ value }) => {
  175. confirmHandle(value)
  176. })
  177. .catch(() => {
  178. cancelHandle()
  179. })
  180. }
  181. }