index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/libs/classNames'
  3. import { $wuxBackdrop } from '../index'
  4. import { defaults } from './utils'
  5. baseComponent({
  6. useFunc: true,
  7. data: defaults,
  8. computed: {
  9. classes: ['prefixCls', function(prefixCls) {
  10. const wrap = classNames(prefixCls)
  11. const content = classNames(`${prefixCls}__content`, {
  12. [`${prefixCls}__content--has-icon`]: true,
  13. })
  14. const icon = classNames(`${prefixCls}__icon`, {
  15. [`${prefixCls}__icon--loading`]: true,
  16. })
  17. const text = `${prefixCls}__text`
  18. return {
  19. wrap,
  20. content,
  21. icon,
  22. text,
  23. }
  24. }],
  25. },
  26. methods: {
  27. /**
  28. * 隐藏
  29. */
  30. hide() {
  31. this.$$setData({ in: false })
  32. this.$wuxBackdrop && this.$wuxBackdrop.release()
  33. },
  34. /**
  35. * 显示
  36. */
  37. show(opts = {}) {
  38. const options = this.$$mergeOptionsAndBindMethods(Object.assign({}, defaults, opts))
  39. this.$$setData({ in: true, ...options })
  40. this.$wuxBackdrop && this.$wuxBackdrop.retain()
  41. },
  42. },
  43. created() {
  44. if (this.data.mask) {
  45. this.$wuxBackdrop = $wuxBackdrop('#wux-backdrop', this)
  46. }
  47. },
  48. })