fs-text.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. encrypt: Boolean,
  38. decoration: {
  39. type: String,
  40. validator(value) {
  41. return ['underline', 'line-through'].includes(value)
  42. }
  43. }
  44. })
  45. const emits = defineEmits(['click'])
  46. const styleStr = computed(() => {
  47. return props.color ? `color: ${props.color};` : ''
  48. })
  49. const formatText = text => {
  50. if (props.mode === 'price') {
  51. return '¥' + text
  52. } else if (props.mode === 'name') {
  53. return text[0] + '**'
  54. } else if (props.mode === 'phone' && props.encrypt) {
  55. return text.slice(0, 3) + '****' + text.slice(-4)
  56. }
  57. return text
  58. }
  59. const handleClick = () => {
  60. if (props.mode === 'phone') {
  61. uni.makePhoneCall({
  62. phoneNumber: props.text
  63. })
  64. } else if (props.link) {
  65. uni[props.linkType]({
  66. url: props.link
  67. })
  68. }
  69. emits('click')
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. </style>