index.js 2.1 KB

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