index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { addUnit, createNamespace } from '../utils';
  2. import Network from './Network';
  3. var _createNamespace = createNamespace('empty'),
  4. createComponent = _createNamespace[0],
  5. bem = _createNamespace[1];
  6. var PRESETS = ['error', 'search', 'default'];
  7. export default createComponent({
  8. props: {
  9. imageSize: [Number, String],
  10. description: String,
  11. image: {
  12. type: String,
  13. default: 'default'
  14. }
  15. },
  16. methods: {
  17. genImageContent: function genImageContent() {
  18. var h = this.$createElement;
  19. var slots = this.slots('image');
  20. if (slots) {
  21. return slots;
  22. }
  23. if (this.image === 'network') {
  24. return h(Network);
  25. }
  26. var image = this.image;
  27. if (PRESETS.indexOf(image) !== -1) {
  28. image = "https://img01.yzcdn.cn/vant/empty-image-" + image + ".png";
  29. }
  30. return h("img", {
  31. "attrs": {
  32. "src": image
  33. }
  34. });
  35. },
  36. genImage: function genImage() {
  37. var h = this.$createElement;
  38. var imageStyle = {
  39. width: addUnit(this.imageSize),
  40. height: addUnit(this.imageSize)
  41. };
  42. return h("div", {
  43. "class": bem('image'),
  44. "style": imageStyle
  45. }, [this.genImageContent()]);
  46. },
  47. genDescription: function genDescription() {
  48. var h = this.$createElement;
  49. var description = this.slots('description') || this.description;
  50. if (description) {
  51. return h("p", {
  52. "class": bem('description')
  53. }, [description]);
  54. }
  55. },
  56. genBottom: function genBottom() {
  57. var h = this.$createElement;
  58. var slot = this.slots();
  59. if (slot) {
  60. return h("div", {
  61. "class": bem('bottom')
  62. }, [slot]);
  63. }
  64. }
  65. },
  66. render: function render() {
  67. var h = arguments[0];
  68. return h("div", {
  69. "class": bem()
  70. }, [this.genImage(), this.genDescription(), this.genBottom()]);
  71. }
  72. });