dk-title.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * title字体大小(默认13px)
  38. */
  39. titleFontSize:{
  40. type:String,
  41. value:'13px'
  42. },
  43. /**
  44. * 缩进的宽度
  45. */
  46. indentWidth:{
  47. type:String,
  48. value:''
  49. }
  50. },
  51. options: {
  52. styleIsolation: 'shared',
  53. },
  54. /**
  55. * 组件的初始数据
  56. */
  57. data: {
  58. indent:0,
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. /**
  65. * 查询标题宽度
  66. */
  67. initWidth(){
  68. // 没有做设置才会执行
  69. let self = this
  70. var query = wx.createSelectorQuery().in(this);
  71. query.select('.vanTag').boundingClientRect()
  72. query.exec(function (res) {
  73. //res就是 所有标签为publicImg的元素的信息 的数组
  74. if(res && res.length > 0 && res[0]){
  75. self.setData({
  76. indent:res[0].width * 2 + 10
  77. })
  78. }
  79. })
  80. },
  81. },
  82. /**
  83. * 组件生命周期
  84. */
  85. lifetimes: {
  86. attached: function () {
  87. // 页面被展示
  88. this.initWidth();
  89. },
  90. },
  91. })