empty.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="empty-view">
  3. <image
  4. src="../static/images/empty.png"
  5. mode="scaleToFill"
  6. :style="{ width: size, height: heightSize }"
  7. />
  8. <text v-if="showText" class="tip" :style="{ color }">{{ text }}</text>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "EmptyView",
  14. props: {
  15. text: { type: String, default: "暂无数据" },
  16. showText: { type: Boolean, default: true },
  17. size: { type: String, default: "200rpx" },
  18. color: { type: String, default: "#b4c7f9" },
  19. },
  20. computed: {
  21. heightSize() {
  22. const s = this.size;
  23. if (typeof s === "number") {
  24. const v = s * (100 / 132);
  25. return v + "rpx";
  26. }
  27. const str = String(s || "").trim();
  28. const m = str.match(/^([0-9]+(?:\.[0-9]+)?)\s*(\D+)?$/);
  29. if (!m) return str;
  30. const num = parseFloat(m[1]);
  31. const unit = m[2] || "rpx";
  32. const v = num * (100 / 132);
  33. return v + unit;
  34. },
  35. },
  36. };
  37. </script>
  38. <style scoped>
  39. .empty-view {
  40. display: flex;
  41. align-items: center;
  42. justify-content: center;
  43. flex-direction: column;
  44. padding: 40rpx 0;
  45. }
  46. .tip {
  47. margin-top: 16rpx;
  48. font-size: 28rpx;
  49. }
  50. </style>