uni-events-helper-wx
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
6.2 KiB

3 years ago
  1. <template>
  2. <view
  3. class="u-text"
  4. :class="[]"
  5. v-if="show"
  6. :style="{
  7. margin: margin
  8. }"
  9. @tap="clickHandler"
  10. >
  11. <text
  12. class="u-text__price"
  13. v-if="mode === 'price'"
  14. :style="[valueStyle]"
  15. ></text>
  16. <view
  17. class="u-text__prefix-icon"
  18. v-if="prefixIcon"
  19. >
  20. <u-icon
  21. :name="prefixIcon"
  22. :customStyle="$u.addStyle(iconStyle)"
  23. ></u-icon>
  24. </view>
  25. <u-link
  26. v-if="mode === 'link'"
  27. :text="value"
  28. :href="href"
  29. underLine
  30. ></u-link>
  31. <template v-else-if="openType && isMp">
  32. <button
  33. class="u-reset-button u-text__value"
  34. :style="[valueStyle]"
  35. :data-index="index"
  36. :openType="openType"
  37. @getuserinfo="onGetUserInfo"
  38. @contact="onContact"
  39. @getphonenumber="onGetPhoneNumber"
  40. @error="onError"
  41. @launchapp="onLaunchApp"
  42. @opensetting="onOpenSetting"
  43. :lang="lang"
  44. :session-from="sessionFrom"
  45. :send-message-title="sendMessageTitle"
  46. :send-message-path="sendMessagePath"
  47. :send-message-img="sendMessageImg"
  48. :show-message-card="showMessageCard"
  49. :app-parameter="appParameter"
  50. >{{ value }}</button>
  51. </template>
  52. <text
  53. v-else
  54. class="u-text__value"
  55. :style="[valueStyle]"
  56. :class="[type && `u-text__value--${type}`, lines && `u-line-${lines}`]"
  57. >{{ value }}</text>
  58. <view
  59. class="u-text__suffix-icon"
  60. v-if="suffixIcon"
  61. >
  62. <u-icon
  63. :name="suffixIcon"
  64. :customStyle="$u.addStyle(iconStyle)"
  65. ></u-icon>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import value from './value.js'
  71. import button from '../../libs/mixin/button.js'
  72. import openType from '../../libs/mixin/openType.js'
  73. import props from './props.js';
  74. /**
  75. * Text 文本
  76. * @description 此组件集成了文本类在项目中的常用功能包括状态拨打电话格式化日期*替换超链接...等功能 您大可不必在使用特殊文本时自己定义text组件几乎涵盖您能使用的大部分场景
  77. * @tutorial https://www.uviewui.com/components/loading.html
  78. * @property {String} type 主题颜色
  79. * @property {Boolean} show 是否显示默认 true
  80. * @property {String | Number} text 显示的值
  81. * @property {String} prefixIcon 前置图标
  82. * @property {String} suffixIcon 后置图标
  83. * @property {String} mode 文本处理的匹配模式 text-普通文本price-价格phone-手机号name-姓名date-日期link-超链接
  84. * @property {String} href mode=link下配置的链接
  85. * @property {String | Function} format 格式化规则
  86. * @property {Boolean} call mode=phone时点击文本是否拨打电话默认 false
  87. * @property {Boolean} encrypt 是否对mode=phone|name类型文本进行脱敏*号替换部分文本默认 false
  88. * @property {String} openType 小程序的打开方式
  89. * @property {Boolean} bold 是否粗体默认normal默认 false
  90. * @property {Boolean} block 是否块状默认 false
  91. * @property {String | Number} lines 文本显示的行数如果设置超出此行数将会显示省略号
  92. * @property {String} color 文本颜色默认 '#303133'
  93. * @property {String | Number} size 字体大小默认 15
  94. * @property {Object | String} iconStyle 图标的样式 默认 {fontSize: '15px'}
  95. * @property {Boolean} precision 是否显示金额的千分位mode=price时有效默认 true
  96. * @property {String} decoration 是否显示金额的千分位mode=price时有效默认 'none'
  97. * @property {Object | String | Number} margin 外边距对象字符串数值形式均可默认 0
  98. * @property {String | Number} lineHeight 文本行高
  99. * @property {String} align 文本对齐方式可选值left|center|right默认 'left'
  100. * @property {String} wordWrap 文字换行可选值break-word|normal|anywhere默认 'normal'
  101. * @event {Function} click 点击触发事件
  102. * @example <u--text text="我用十年青春,赴你最后之约"></u--text>
  103. */
  104. export default {
  105. name: 'u--text',
  106. // #ifdef MP
  107. mixins: [uni.$u.mpMixin, uni.$u.mixin, value, button, openType, props],
  108. // #endif
  109. // #ifndef MP
  110. mixins: [uni.$u.mpMixin, uni.$u.mixin, value, props],
  111. // #endif
  112. computed: {
  113. valueStyle() {
  114. const style = {
  115. textDecoration: this.decoration,
  116. fontWeight: this.bold ? 'bold' : 'normal',
  117. textAlign: this.align,
  118. wordWrap: this.wordWrap,
  119. fontSize: uni.$u.addUnit(this.size)
  120. }
  121. !this.type && (style.color = this.color)
  122. this.isNvue && this.lines && (style.lines = this.lines)
  123. this.lineHeight && (style.lineHeight = uni.$u.addUnit(this.lineHeight))
  124. !this.isNvue && this.block && (style.display = 'block')
  125. return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))
  126. },
  127. isNvue() {
  128. let nvue = false
  129. // #ifdef APP-NVUE
  130. nvue = true
  131. // #endif
  132. return nvue
  133. },
  134. isMp() {
  135. let mp = false
  136. // #ifdef MP
  137. mp = true
  138. // #endif
  139. return mp
  140. }
  141. },
  142. data() {
  143. return {
  144. }
  145. },
  146. methods: {
  147. clickHandler() {
  148. // 如果为手机号模式,拨打电话
  149. if (this.mode === 'phone' && uni.$u.test.mobile(this.text)) {
  150. uni.makePhoneCall({
  151. phoneNumber: this.text
  152. });
  153. }
  154. this.$emit('click')
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. @import "../../libs/css/components.scss";
  161. .u-text {
  162. @include flex(row);
  163. align-items: center;
  164. flex-wrap: wrap;
  165. flex: 1;
  166. &__price {
  167. font-size: 14px;
  168. color: $u-content-color;
  169. }
  170. &__value {
  171. font-size: 14px;
  172. @include flex;
  173. color: $u-content-color;
  174. flex-wrap: wrap;
  175. flex: 1;
  176. text-overflow: ellipsis;
  177. align-items: center;
  178. &--primary {
  179. color: $u-primary;
  180. }
  181. &--warning {
  182. color: $u-warning;
  183. }
  184. &--success {
  185. color: $u-success;
  186. }
  187. &--info {
  188. color: $u-info;
  189. }
  190. &--error {
  191. color: $u-error;
  192. }
  193. &--main {
  194. color: $u-main-color;
  195. }
  196. &--content {
  197. color: $u-content-color;
  198. }
  199. &--tips {
  200. color: $u-tips-color;
  201. }
  202. &--light {
  203. color: $u-light-color;
  204. }
  205. }
  206. }
  207. </style>