util.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var utilsJs = {
  2. pxConversionMm(value) {
  3. /*px转换为mm*/
  4. var inch = value / this.conversion_getDPI()[0]
  5. var c_value = inch * 25.4
  6. return c_value
  7. },
  8. mmConversionPx(value) {
  9. /*mm转换为px*/
  10. //in 英尺单位 1in = 25.4 mm
  11. var inch = value / 25.4
  12. var c_value = inch * this.conversion_getDPI()[0]
  13. return c_value
  14. },
  15. indexToWords(index){
  16. let arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
  17. return arr[index];
  18. },
  19. sectionToChinese(section) {
  20. let chnNumChar = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九']
  21. let chnUnitChar = ['', '十', '百', '千']
  22. let strIns = '',chnStr = ''
  23. let unitPos = 0
  24. let zero = true
  25. let count = section
  26. while (section > 0) {
  27. var v = section % 10
  28. if (v === 0) {
  29. if (!zero) {
  30. zero = true
  31. chnStr = chnNumChar[v] + chnStr
  32. }
  33. } else {
  34. zero = false
  35. if(unitPos == 1 && parseInt(count/10) == 1){
  36. chnStr = chnUnitChar[unitPos] + chnNumChar[count%10]
  37. }else{
  38. strIns = chnNumChar[v]
  39. strIns += chnUnitChar[unitPos]
  40. chnStr = strIns + chnStr
  41. }
  42. }
  43. unitPos++
  44. section = Math.floor(section / 10)
  45. }
  46. return chnStr
  47. },
  48. }