message.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import $ from 'jquery'
  2. import _ from 'lodash'
  3. /**
  4. * 显示错误异常信息
  5. * @param msg 错误内容
  6. * @param sender 发送者按钮(可以为空)
  7. */
  8. export function showErrorDialog(msg, sender?) {
  9. Ext.MessageBox.show({
  10. title: '错误',
  11. msg: msg,
  12. buttons: Ext.MessageBox.OK,
  13. animateTarget: sender,
  14. icon: 'error',
  15. cls: 'show-icon-messagebox',
  16. });
  17. }
  18. /**
  19. * 中间灰底白字提示
  20. */
  21. export function msg(message: string): void {
  22. const $body = $('body')
  23. $body.find('[xtype=tooltip]').remove()
  24. const $w = $(
  25. '<div xtype="tooltip" class="yvan-msg yvan-anim yvan-anim-00">' +
  26. ' <div class="yvan-msg-content">' +
  27. _.escape(message) +
  28. '</div></div>'
  29. )
  30. $body.append($w)
  31. const iframeWidth = $w.parent().width() as number
  32. const iframeHeight = $w.parent().height() as number
  33. const windowWidth = $w.width() as number
  34. const windowHeight = $w.height() as number
  35. let setWidth = (iframeWidth - windowWidth) / 2
  36. let setHeight = (iframeHeight - windowHeight) / 2
  37. if (iframeHeight < windowHeight || setHeight < 0) {
  38. setHeight = 0
  39. }
  40. if (iframeWidth < windowWidth || setWidth < 0) {
  41. setWidth = 0
  42. }
  43. $w.css({left: setWidth, top: setHeight})
  44. setTimeout(() => {
  45. $w.remove()
  46. }, 3000)
  47. }