index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Component({
  2. /**
  3. * 组件的属性列表
  4. */
  5. externalClasses: [
  6. 'l-class',
  7. 'l-title-class',
  8. 'l-avatar-class',
  9. 'l-row-class'
  10. ],
  11. properties: {
  12. loading: {
  13. type: Boolean,
  14. value: true
  15. },
  16. title: {
  17. type: Boolean,
  18. value: true
  19. },
  20. paragraph: {
  21. type: Boolean,
  22. value: true
  23. },
  24. active: {
  25. type: Boolean,
  26. value: true
  27. },
  28. avatar: Boolean,
  29. titleWidth: String,
  30. avatarSize: String,
  31. avatarShape: {
  32. type: String,
  33. value: 'circle'
  34. },
  35. rowsWidth: {
  36. type: Array,
  37. optionalTypes: [Array, String],
  38. value: '60%'
  39. },
  40. rowsHeight: {
  41. type: Array,
  42. optionalTypes: [Array, String],
  43. value: '34rpx'
  44. },
  45. rows: Number
  46. },
  47. observers: {
  48. 'rows,rowsWidth,rowsHeight': function(rows, rowsWidth, rowsHeight) {
  49. this._getResult(rows, rowsWidth, 'rowsW', '100%');
  50. this._getResult(rows, rowsHeight, 'rowsH', '34rpx');
  51. this._toRows(rows);
  52. }
  53. },
  54. /**
  55. * 组件的初始数据
  56. */
  57. data: {
  58. },
  59. /**
  60. * 组件的方法列表
  61. */
  62. methods: {
  63. _arrRepeat(target, n) {
  64. const r = [];
  65. for (let i = 0; i < n-1; i++) {
  66. r.push(target);
  67. }
  68. return r;
  69. },
  70. _getResult(rows, rowsPro, key, target) {
  71. if (Array.isArray(rowsPro)) {
  72. this.data[key] = rowsPro;
  73. } else {
  74. const r = this._arrRepeat(target, rows);
  75. r.push(rowsPro);
  76. this.data[key] = r;
  77. }
  78. },
  79. _toRows(rows) {
  80. let r = [];
  81. for (let i = 0; i < rows; i++) {
  82. r.push({
  83. width: this.data.rowsW[i],
  84. height: this.data.rowsH[i]
  85. });
  86. }
  87. this.setData({
  88. r
  89. });
  90. }
  91. }
  92. });