text-props.uvue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1">
  4. <!-- #endif -->
  5. <view>
  6. <page-head :title="title"></page-head>
  7. <view class="uni-padding-wrap uni-common-mt">
  8. <view class="uni-title">
  9. <text class="uni-title-text">text相关属性示例</text>
  10. </view>
  11. <view class="uni-title">
  12. <text class="uni-subtitle-text">根据宽度自动折行</text>
  13. </view>
  14. <view class="text-box">
  15. <text>{{ multiLineText }}</text>
  16. </view>
  17. <view class="uni-title">
  18. <text class="uni-subtitle-text">\\n换行</text>
  19. </view>
  20. <view class="text-box">
  21. <text>\n 换行</text>
  22. <text>\\n 换行</text>
  23. <text>\\\n 换行</text>
  24. <text>\n 换行 \\n 换行 \\\n 换行 \\\\n 换行 \\\\\n 换行</text>
  25. <text space="nbsp">HBuilderX,轻巧、极速,极客编辑器;\nuni-app x,终极跨平台方案;</text>
  26. </view>
  27. <view class="uni-title">
  28. <text class="uni-subtitle-text">截断(clip)</text>
  29. </view>
  30. <view class="text-box">
  31. <text class="uni-flex-item" style="width: 100%;text-overflow: clip;white-space: nowrap;">{{
  32. multiLineText
  33. }}</text>
  34. </view>
  35. <view class="uni-title">
  36. <text class="uni-subtitle-text">截断(ellipsis)</text>
  37. </view>
  38. <view class="text-box">
  39. <text class="uni-flex-item" style="width: 100%;text-overflow: ellipsis;white-space: nowrap;">{{
  40. multiLineText
  41. }}</text>
  42. </view>
  43. <view class="uni-title">
  44. <text class="uni-subtitle-text">selectable</text>
  45. </view>
  46. <view class="text-box">
  47. <text :selectable="true">{{ singleLineText }}</text>
  48. </view>
  49. <view class="uni-title">
  50. <text class="uni-subtitle-text">space</text>
  51. <text class="uni-subtitle-text">依次为nbsp ensp emsp效果</text>
  52. </view>
  53. <view class="text-box">
  54. <text space="nbsp">{{ singleLineText }}</text>
  55. <text space="ensp">{{ singleLineText }}</text>
  56. <text space="emsp">{{ singleLineText }}</text>
  57. </view>
  58. <view class="uni-title">
  59. <text class="uni-subtitle-text">decode</text>
  60. <text class="uni-subtitle-text">依次为lt gt amp apos nbsp ensp emsp效果</text>
  61. </view>
  62. <view class="text-box">
  63. <text :decode="true">{{ decodeStr }}</text>
  64. <text :decode="true">uni-app&nbsp;x,终极跨平台方案</text>
  65. <text :decode="true">uni-app&ensp;x,终极跨平台方案</text>
  66. <text :decode="true">uni-app&emsp;x,终极跨平台方案</text>
  67. </view>
  68. <view class="uni-title">
  69. <text class="uni-subtitle-text">嵌套1</text>
  70. </view>
  71. <view class="text-box">
  72. <text @tap="nestedText1Tap">一级节点黑色
  73. <text style="color: red;background-color: yellow;" @tap="nestedText2Tap">二级节点红色且背景色黄色
  74. <text style="text-decoration-line:underline;color:blue;" @tap="nestedText3Tap">App三级节点不继承二级的颜色</text>
  75. </text>
  76. <text style="font-size: 50px">二级节点大字体</text>
  77. </text>
  78. </view>
  79. <view class="uni-title">
  80. <text class="uni-subtitle-text">嵌套2</text>
  81. </view>
  82. <view class="text-box">
  83. <text>
  84. <text>文字应居中显示</text>
  85. </text>
  86. </view>
  87. <view class="uni-title">
  88. <text class="uni-subtitle-text">padding和border</text>
  89. </view>
  90. <view class="text-box">
  91. <text class="text-padding-border">hello uni-app x</text>
  92. <text class="text-padding-border" style="width: 200px;">hello uni-app x</text>
  93. <text class="text-padding-border" style="height: 100px;">hello uni-app x</text>
  94. <text class="text-padding-border" style="width: 200px;height: 100px;">hello uni-app x</text>
  95. </view>
  96. <view class="uni-title">
  97. <text class="uni-subtitle-text">含换行符的多行文本(3行),但不自动换行,可横向滚动</text>
  98. </view>
  99. <scroll-view class="text-container" direction="horizontal">
  100. <text style="white-space: nowrap;align-self: flex-start;">HBuilderX,轻巧、极速,极客编辑器;\nuni-app x,是下一代 uni-app,是一个跨平台应用开发引擎。uni-app x 是一个庞大的工程,它包括uts语言、uvue渲染引擎、uni的组件和API、以及扩展机制。\nuts是一门类ts的、跨平台的、新语言。</text>
  101. </scroll-view>
  102. <!-- #ifdef APP -->
  103. <view class="uni-title">
  104. <text class="uni-subtitle-text">点击事件测试</text>
  105. </view>
  106. <view class="text-box" style="flex-direction: row;">
  107. <text class="text-icon" style="background-color: aqua;" @tap="iconTap">{{String.fromCharCode(parseInt('E650',16))}}</text>
  108. <text class="text-icon" style="background-color: yellow;" @tap="iconTap2">{{String.fromCharCode(parseInt('EA08',16))}}</text>
  109. </view>
  110. <!-- #endif -->
  111. <view v-if="autoTest">
  112. <view class="uni-row">
  113. <text id="empty-text"></text>
  114. </view>
  115. <view class="uni-row">
  116. <text id="empty-text2">{{emptyText}}</text>
  117. </view>
  118. <view class="uni-row">
  119. <text id="empty-text3" style="width: 100px;height: 100px;">{{emptyText}}</text>
  120. </view>
  121. <text>一级节点文本
  122. <text>二级节点文本
  123. <text id="nested-text">{{nestedText}}</text>
  124. </text>
  125. </text>
  126. <text id="height-text" style="height: 50px;">{{heightText}}</text>
  127. <text style="position: fixed;" id="nested-text2" @tap="nestedText1TapForTest">1
  128. <text @tap="nestedText2TapForTest">2
  129. <text>3</text>
  130. </text>
  131. </text>
  132. </view>
  133. </view>
  134. </view>
  135. <!-- #ifdef APP -->
  136. </scroll-view>
  137. <!-- #endif -->
  138. </template>
  139. <script>
  140. export default {
  141. data() {
  142. return {
  143. decodeStr: '&lt; &gt; &amp; &apos;',
  144. title: 'text-props',
  145. multiLineText:
  146. 'HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言;HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言',
  147. singleLineText: 'uni-app x,终极跨平台方案',
  148. // 自动化测试
  149. autoTest: false,
  150. nestedText: '三级节点文本',
  151. emptyText: '空文本',
  152. heightText: '设置高度文本',
  153. isNestedText1TapTriggered: false,
  154. isNestedText2TapTriggered: false
  155. }
  156. },
  157. methods: {
  158. nestedText1Tap() {
  159. uni.showModal({
  160. title: '点击了',
  161. content: '一级节点黑色',
  162. showCancel: false
  163. });
  164. },
  165. nestedText2Tap(e : UniPointerEvent) {
  166. e.stopPropagation();
  167. uni.showModal({
  168. title: '点击了',
  169. content: '二级节点红色且背景色黄色',
  170. showCancel: false
  171. });
  172. },
  173. nestedText3Tap(e : UniPointerEvent) {
  174. e.stopPropagation();
  175. uni.showModal({
  176. title: '点击了',
  177. content: 'App三级节点不继承二级的颜色',
  178. showCancel: false
  179. });
  180. },
  181. iconTap() {
  182. uni.showModal({
  183. title: '点击了',
  184. content: '字体图标1',
  185. showCancel: false
  186. });
  187. },
  188. iconTap2() {
  189. uni.showModal({
  190. title: '点击了',
  191. content: '字体图标2',
  192. showCancel: false
  193. });
  194. },
  195. // 自动化测试
  196. setNestedText() {
  197. this.nestedText = "修改三级节点文本";
  198. },
  199. setEmptyText() {
  200. this.emptyText = "";
  201. },
  202. setHeightText() {
  203. this.heightText = "修改设置高度文本";
  204. },
  205. getBoundingClientRectForTest() : DOMRect | null {
  206. return uni.getElementById('nested-text2')?.getBoundingClientRect();
  207. },
  208. nestedText1TapForTest() {
  209. this.isNestedText1TapTriggered = true;
  210. },
  211. nestedText2TapForTest() {
  212. this.isNestedText2TapTriggered = true;
  213. }
  214. }
  215. }
  216. </script>
  217. <style>
  218. .text-box {
  219. margin-bottom: 20px;
  220. padding: 20px 0;
  221. background-color: #ffffff;
  222. justify-content: center;
  223. align-items: center;
  224. }
  225. .text-container {
  226. width: 100%;
  227. background-color: #ffffff;
  228. padding: 10px;
  229. }
  230. .text {
  231. font-size: 15px;
  232. color: #353535;
  233. line-height: 27px;
  234. text-align: center;
  235. }
  236. .text-padding-border {
  237. margin-top: 5px;
  238. padding: 20px;
  239. border: 5px solid red;
  240. text-align: center;
  241. }
  242. .text-icon {
  243. font-family: uni-icon;
  244. font-size: 100px;
  245. }
  246. </style>