currencyFn.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. console.log(3)
  14. type = 1
  15. str = str.replace(itemChild.columnName, itemChild.columnValue)
  16. } else if (itemChild.htmlType == "datetime") {
  17. console.log(4)
  18. type = 2
  19. if(getTime(itemChild.columnValue)){
  20. str = str.replace(itemChild.columnName, itemChild.columnValue)
  21. // str = itemChild.columnValue
  22. // console.log(itemChild.columnValue, itemChild.columnName,19)
  23. console.log(str)
  24. }else{
  25. is=true
  26. }
  27. }else if(itemChild.htmlType == "datetime-date") {
  28. console.log(5)
  29. type = 3
  30. if (getTime(itemChild.columnValue)) {
  31. str = str.replace(itemChild.columnName, getTime(itemChild.columnValue))
  32. console.log(str,29)
  33. } else {
  34. is = true
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. if (is) {
  42. return
  43. }
  44. if (type == 2) {
  45. // return setTimeH(evals(str))
  46. return str
  47. }
  48. if(type==3){
  49. return setTime(evals(str))
  50. }
  51. return evals(str)
  52. }
  53. function evals(code) {
  54. let fun = new Function(`return ${code}`)();
  55. return fun
  56. }
  57. // 时间戳转成天
  58. function setTime(val) {
  59. return Math.round(Number(val) / (1000 * 3600 * 24))
  60. }
  61. // 时间戳转成小时
  62. function setTimeH(val) {
  63. return Math.round(Number(val) / (1000 * 3600))
  64. }
  65. // 转化成时间戳
  66. function getTime(val) {
  67. var date = new Date(val);
  68. return date.getTime()
  69. }
  70. export function setDyn(col, arr, comp) {
  71. let str = comp
  72. for (let item of arr) {
  73. for (let itemChild of item.hrChildren) {
  74. for (let colItem of col) {
  75. if (colItem == itemChild.columnName) {
  76. str = str.replace(itemChild.columnName, itemChild.columnValue)
  77. }
  78. }
  79. }
  80. }
  81. return str
  82. }