dk-title.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:带tag标题文本显示组件,解决因为tag现在造成文本换行的问题
  5. * 2.功能描述:dkTitle组件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * admin 2021-7-11 1.00 新建
  9. *******************************************************************************/
  10. Component({
  11. /**
  12. * 组件的属性列表
  13. */
  14. properties: {
  15. /**
  16. * 标题内容
  17. */
  18. title:{
  19. type: String,
  20. value: ' ',
  21. },
  22. /**
  23. * 标题标签内容
  24. */
  25. titleTag:{
  26. type: String,
  27. value: '',
  28. },
  29. /**
  30. * 字体大小(默认10px)
  31. */
  32. fontSize:{
  33. type:Number,
  34. value:10
  35. },
  36. /**
  37. * )
  38. */
  39. indent:{
  40. type:Number,
  41. value:1
  42. },
  43. /**
  44. * title字体大小(默认13px)
  45. */
  46. titleFontSize:{
  47. type:String,
  48. value:'13px'
  49. },
  50. /**
  51. * 缩进的宽度
  52. */
  53. indentWidth:{
  54. type:String,
  55. value:''
  56. }
  57. },
  58. options: {
  59. styleIsolation: 'shared',
  60. },
  61. /**
  62. * 组件的初始数据
  63. */
  64. data: {
  65. indent:0,
  66. },
  67. /**
  68. * 组件的方法列表
  69. */
  70. methods: {
  71. /**
  72. * 查询标题宽度
  73. */
  74. initWidth(){
  75. // 没有做设置才会执行
  76. let self = this
  77. var query = wx.createSelectorQuery().in(this);
  78. query.select('.vanTag').boundingClientRect()
  79. query.exec(function (res) {
  80. //res就是 所有标签为publicImg的元素的信息 的数组
  81. if(res && res.length > 0 && res[0]){
  82. self.setData({
  83. indent:res[0].width * 2 + 10
  84. })
  85. }
  86. })
  87. },
  88. },
  89. /**
  90. * 组件生命周期
  91. */
  92. lifetimes: {
  93. attached: function () {
  94. // 页面被展示
  95. this.initWidth();
  96. },
  97. },
  98. })