card.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {isNumber} from "../utils/utils";
  2. const app = getApp();
  3. export default class LastMayday {
  4. palette(data) {
  5. const config = JSON.parse(data.configs);
  6. let ratio = 0;
  7. if (app.globalData.isPC) {
  8. ratio = 2;
  9. } else {
  10. ratio = 2;
  11. }
  12. let viewsConfigs = config.map(configItem => {
  13. let viewText = '';
  14. let textIndent = configItem.textIndent;
  15. let padEmptyStr = '';
  16. if (textIndent > 0) {
  17. padEmptyStr = new Array(textIndent).fill('').join(' ');
  18. }
  19. viewText = padEmptyStr + configItem.content;
  20. Object.keys(configItem).forEach(key => {
  21. if (isNumber(configItem[key])) {
  22. configItem[key] = configItem[key] * ratio + "rpx"
  23. }
  24. });
  25. return {
  26. type: 'text',
  27. text: viewText,
  28. css: configItem
  29. };
  30. });
  31. return (
  32. {
  33. width: data.drawWidth * ratio + 'rpx',
  34. height: data.drawHeight * ratio + 'rpx',
  35. views: [
  36. {
  37. type: 'image',
  38. url: data.templatePicUrl,
  39. css: {
  40. width: data.drawWidth * ratio + 'rpx',
  41. height: data.drawHeight * ratio + 'rpx',
  42. },
  43. },
  44. ...viewsConfigs
  45. ],
  46. }
  47. );
  48. }
  49. }