fs-text.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <text
  3. :class="[colorType,decoration,{block}]"
  4. :style="styleStr"
  5. @click="handleClick">
  6. {{formatText(text)}}
  7. </text>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'fs-text'
  12. }
  13. </script>
  14. <script setup>
  15. import { computed } from 'vue'
  16. const props = defineProps({
  17. text: String,
  18. mode: {
  19. type: String,
  20. validator(value) {
  21. return ['price', 'phone', 'name'].includes(value)
  22. }
  23. },
  24. colorType: {
  25. type: String,
  26. validator(value) {
  27. return ['primary', 'success', 'info', 'warning', 'danger'].includes(value)
  28. }
  29. },
  30. color: String,
  31. link: String,
  32. linkType: {
  33. type: String,
  34. default: 'navigateTo'
  35. },
  36. block: Boolean,
  37. decoration: {
  38. type: String,
  39. validator(value) {
  40. return ['underline', 'line-through'].includes(value)
  41. }
  42. }
  43. })
  44. const emits = defineEmits(['click'])
  45. const styleStr = computed(() => {
  46. return props.color ? `color: ${props.color};` : ''
  47. })
  48. const formatText = text => {
  49. if (props.mode === 'price') {
  50. return '¥' + text
  51. } else if (props.mode === 'name') {
  52. return text[0] + '*' + text[text.length - 1]
  53. }
  54. return text
  55. }
  56. const handleClick = () => {
  57. if (props.mode === 'phone') {
  58. uni.makePhoneCall({
  59. phoneNumber: props.text
  60. })
  61. } else if (props.link) {
  62. uni[props.linkType]({
  63. url: props.link
  64. })
  65. }
  66. emits('click')
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. </style>