card.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {isNumber} from "../utils/utils";
  2. import {cardTypes} from "./enum";
  3. const app = getApp();
  4. const miniRatio = 2;
  5. const pcRatio = 2;
  6. export default class LastMayday {
  7. palette(data, number = 'xx', startTime = "xxxx年x月x日", endTime = 'xxxx年x月x日',
  8. userName = 'xx', projectName = 'xx培训', isOnline = false) {
  9. projectName = projectName.trim();
  10. const config = JSON.parse(data.configs);
  11. const numberStyle = config.find(item => item.type == cardTypes.NUMBER_STYLE);
  12. // app.globalData.isPC = false;
  13. Object.keys(numberStyle).forEach(key => {
  14. if (isNumber(numberStyle[key])) {
  15. if (app.globalData.isPC) {
  16. numberStyle[key] = numberStyle[key] * pcRatio + "rpx"
  17. } else {
  18. numberStyle[key] = numberStyle[key] * miniRatio + "rpx"
  19. }
  20. }
  21. })
  22. const textStyle = config.find(item => item.type == cardTypes.TEXT_STYLE);
  23. Object.keys(textStyle).forEach(key => {
  24. if (isNumber(textStyle[key])) {
  25. if (app.globalData.isPC) {
  26. textStyle[key] = textStyle[key] * pcRatio + "rpx"
  27. } else {
  28. textStyle[key] = textStyle[key] * miniRatio + "rpx"
  29. }
  30. }
  31. })
  32. if (app.globalData.isPC) {
  33. return (
  34. {
  35. width: data.drawWidth * pcRatio + 'rpx',
  36. height: data.drawHeight * pcRatio + 'rpx',
  37. views: [
  38. {
  39. type: 'image',
  40. url: data.templatePicUrl,
  41. css: {
  42. width: data.drawWidth * pcRatio + 'rpx',
  43. height: data.drawHeight * pcRatio + 'rpx',
  44. },
  45. },
  46. {
  47. type: 'text',
  48. text: `编号:${number}`,
  49. css: numberStyle,
  50. },
  51. {
  52. type: 'text',
  53. text: ` ${userName}同志于${startTime}-${endTime}参加”${projectName}”${isOnline ? "线上培训" : "线下培训"},完成规定培训内容。准予结业,特发此证。`,
  54. css: textStyle,
  55. },
  56. ],
  57. }
  58. );
  59. } else {
  60. return (
  61. {
  62. width: data.drawWidth * miniRatio + 'rpx',
  63. height: data.drawHeight * miniRatio + 'rpx',
  64. views: [
  65. {
  66. type: 'image',
  67. url: data.templatePicUrl,
  68. css: {
  69. width: data.drawWidth * miniRatio + 'rpx',
  70. height: data.drawHeight * miniRatio + 'rpx',
  71. },
  72. },
  73. {
  74. type: 'text',
  75. text: `编号:${number}`,
  76. css: numberStyle,
  77. },
  78. {
  79. type: 'text',
  80. text: ` ${userName}同志于${startTime}-${endTime}参加”${projectName}”${isOnline ? "线上培训" : "线下培训"},完成规定培训内容。准予结业,特发此证。`,
  81. css: textStyle,
  82. },
  83. ],
  84. }
  85. );
  86. }
  87. }
  88. }