SEmpty2.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const n = `<template>\r
  2. <div class="s-empty-common">\r
  3. <a-empty :image="image" :imageStyle="iconStyle">\r
  4. <template #description>\r
  5. <span class="description" v-if="$slots.default">\r
  6. <slot />\r
  7. </span>\r
  8. <span class="description" v-else>\r
  9. {{ description }}\r
  10. </span>\r
  11. </template>\r
  12. </a-empty>\r
  13. </div>\r
  14. </template>\r
  15. <script setup>\r
  16. import { onMounted, ref, getCurrentInstance } from 'vue'\r
  17. import { Empty } from 'ant-design-vue'\r
  18. const app = getCurrentInstance()\r
  19. const { $l } = app.appContext.config.globalProperties\r
  20. \r
  21. const props = defineProps({\r
  22. /**\r
  23. * icon类型\r
  24. * @type\r
  25. */\r
  26. type: {\r
  27. type: [String, Number],\r
  28. default: 1\r
  29. },\r
  30. /**\r
  31. * 提示信息\r
  32. * @icon\r
  33. */\r
  34. icon: {\r
  35. type: [String, Object],\r
  36. default: ''\r
  37. },\r
  38. /**\r
  39. * 描述信息\r
  40. * @desc\r
  41. */\r
  42. desc: {\r
  43. type: [String, Boolean],\r
  44. default() {\r
  45. return\r
  46. }\r
  47. },\r
  48. /**\r
  49. * 图片样式\r
  50. * @desc\r
  51. */\r
  52. iconStyle: {\r
  53. type: Object,\r
  54. default() {\r
  55. return {}\r
  56. }\r
  57. }\r
  58. })\r
  59. const image = ref('')\r
  60. const description = ref('')\r
  61. \r
  62. onMounted(() => {\r
  63. if (!props.icon) {\r
  64. if (parseInt(props.type) === 1) {\r
  65. image.value = Empty.PRESENTED_IMAGE_DEFAULT\r
  66. } else if (parseInt(props.type) === 2) {\r
  67. image.value = Empty.PRESENTED_IMAGE_SIMPLE\r
  68. } else {\r
  69. image.value = Empty.PRESENTED_IMAGE_DEFAULT\r
  70. console.warn(\r
  71. '内置type类型为:1 或者 2,如需其他类型,请使用icon属性,例如:icon="https://xxx.png'\r
  72. )\r
  73. }\r
  74. } else {\r
  75. image.value = props.icon\r
  76. }\r
  77. \r
  78. if (props.desc === undefined) {\r
  79. description.value = $l('暂无数据')\r
  80. } else {\r
  81. if (typeof props.desc === 'string') {\r
  82. description.value = props.desc.trim()\r
  83. } else {\r
  84. description.value = $l('暂无数据')\r
  85. }\r
  86. }\r
  87. })\r
  88. <\/script>\r
  89. <style lang="less" scoped>\r
  90. .description {\r
  91. color: var(--s-text-color-secondary);\r
  92. }\r
  93. </style>\r
  94. `;
  95. export {
  96. n as default
  97. };