pc_add.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * 生成PC端的录入组件代码
  3. * @author eden
  4. * @datetime 2021-02-02 03:20:00
  5. */
  6. impls.pc.add = {
  7. /**
  8. * 获取代码
  9. * @param {*} dbObject 对象信息
  10. * @param {*} columns 对象字段列表
  11. * @param {*} template 组件模板
  12. */
  13. getCode: function (dbObject, columns, template) {
  14. // 获取服务名
  15. var serviceName = serviceUtil.getServiceCode(dbObject, "add")[1];
  16. var action = `@service{name: \`${serviceName}\`, page: \`toTips\` }@`
  17. // 对象数组
  18. var objects = getUIObject();
  19. // 录入框HTML代码
  20. var code = "";
  21. for (let index = 0; index < columns.length; index++) {
  22. const element = columns[index];
  23. var result = impls.utils.getUICode(element, objects);
  24. if (!result) {
  25. result = `
  26. <p>未获取到${element.column_comment}(${element.column_uiName})的代码<p>
  27. `;
  28. }
  29. code += result;
  30. }
  31. // 底部操作按钮HTML代码
  32. var btn = `
  33. <el-button type="primary" icon="el-icon-circle-check" :loading="loading" onclick="space.forms.submit();">保存</el-button>
  34. <el-button icon="el-icon-circle-close" onclick="space.allFunction.closeDialog();">关闭</el-button>
  35. `;
  36. var codes = objectToCode(objects);
  37. // HTML代码替换模板的占位符
  38. template = template.replace('<code name="fields" />', code);
  39. template = template.replace('<code name="buttons" />', btn);
  40. template = template.replace('<code name="service" />', action);
  41. template = template.replace('<code name="obj" />', codes.obj);
  42. template = template.replace('<code name="appRules" />', codes.rules);
  43. template = template.replace('<code name="methods" />', codes.methods);
  44. template = template.replace('<code name="sources" />', codes.sources);
  45. template = template.replace('<code name="mounted" />', codes.mounted);
  46. return template;
  47. }
  48. }