wd-status-tip.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!--
  2. * @Author: weisheng
  3. * @Date: 2023-06-12 10:04:19
  4. * @LastEditTime: 2024-09-20 10:23:38
  5. * @LastEditors: jiaoxueyan
  6. * @Description:
  7. * @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-status-tip\wd-status-tip.vue
  8. * 记得注释
  9. -->
  10. <template>
  11. <view :class="`wd-status-tip ${customClass}`" :style="customStyle">
  12. <slot name="image" v-if="$slots.image"></slot>
  13. <wd-img v-else-if="imgUrl" :mode="imageMode" :src="imgUrl" custom-class="wd-status-tip__image" :custom-style="imgStyle"></wd-img>
  14. <view v-if="tip" class="wd-status-tip__text">{{ tip }}</view>
  15. </view>
  16. </template>
  17. <script lang="ts">
  18. export default {
  19. name: 'wd-status-tip',
  20. options: {
  21. addGlobalClass: true,
  22. virtualHost: true,
  23. styleIsolation: 'shared'
  24. }
  25. }
  26. </script>
  27. <script lang="ts" setup>
  28. import wdImg from '../wd-img/wd-img.vue'
  29. import { computed, type CSSProperties } from 'vue'
  30. import { addUnit, isDef, isObj, objToStyle } from '../common/util'
  31. import { statusTipProps } from './types'
  32. const props = defineProps(statusTipProps)
  33. // 图片地址
  34. const imgUrl = computed(() => {
  35. // 改用网络地址,避免小程序打包的时候统一打包进去导致包过大问题
  36. let img: string = ''
  37. if (['search', 'network', 'content', 'collect', 'comment', 'halo', 'message'].includes(props.image)) {
  38. img = `${props.urlPrefix}${props.image}.png`
  39. } else {
  40. img = props.image
  41. }
  42. return img
  43. })
  44. /**
  45. * 图片样式
  46. */
  47. const imgStyle = computed(() => {
  48. let style: CSSProperties = {}
  49. if (props.imageSize) {
  50. if (isObj(props.imageSize)) {
  51. isDef(props.imageSize.height) && (style.height = addUnit(props.imageSize.height))
  52. isDef(props.imageSize.width) && (style.width = addUnit(props.imageSize.width))
  53. } else {
  54. style = {
  55. height: addUnit(props.imageSize),
  56. width: addUnit(props.imageSize)
  57. }
  58. }
  59. }
  60. return `${objToStyle(style)}`
  61. })
  62. </script>
  63. <style lang="scss" scoped>
  64. @import './index.scss';
  65. </style>