currencyFn.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export function getDyn(col, arr, comp) {
  2. let str = comp
  3. let is = true
  4. let type = ''
  5. for (let item of arr) {
  6. for (let itemChild of item.hrChildren) {
  7. for (let colItem of col) {
  8. if (itemChild.columnValue) {
  9. is = false
  10. }
  11. if (colItem == itemChild.columnName) {
  12. if (itemChild.htmlType == "input") {
  13. type = 1
  14. str = str.replace(itemChild.columnName, itemChild.columnValue)
  15. } else if (itemChild.htmlType == "datetime") {
  16. type = 2
  17. if(getTime(itemChild.columnValue)){
  18. str = str.replace(itemChild.columnName, getTime(itemChild.columnValue))
  19. }else{
  20. is=true
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. if (is) {
  28. return
  29. }
  30. if (type == 2) {
  31. return setTime(evals(str))
  32. }
  33. return evals(str)
  34. }
  35. function evals(code) {
  36. let fun = new Function(`return ${code}`)();
  37. return fun
  38. }
  39. // 时间戳转成天
  40. function setTime(val) {
  41. return Number(val) / (1000 * 3600 * 24)
  42. }
  43. // 转化成时间戳
  44. function getTime(val) {
  45. var date = new Date(val);
  46. return date.getTime()
  47. }
  48. export function setDyn(col, arr, comp) {
  49. let str = comp
  50. for (let item of arr) {
  51. for (let itemChild of item.hrChildren) {
  52. for (let colItem of col) {
  53. if (colItem == itemChild.columnName) {
  54. str = str.replace(itemChild.columnName, itemChild.columnValue)
  55. }
  56. }
  57. }
  58. }
  59. return str
  60. }