common.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * 工具函数(从 common.wxs 转换而来)
  3. */
  4. /**
  5. * 只展示月和日
  6. */
  7. export const lengthFormat = function (str: string): string | undefined {
  8. if (str) {
  9. return str.substring(5);
  10. }
  11. };
  12. /**
  13. * 转中字
  14. */
  15. export const numToCn = function (num: number): string | undefined {
  16. var str: string | undefined;
  17. switch (num) {
  18. case 1:
  19. str = "一";
  20. break;
  21. case 2:
  22. str = "二";
  23. break;
  24. case 3:
  25. str = "三";
  26. break;
  27. case 4:
  28. str = "四";
  29. break;
  30. case 5:
  31. str = "五";
  32. break;
  33. case 6:
  34. str = "六";
  35. break;
  36. case 7:
  37. str = "七";
  38. break;
  39. case 8:
  40. str = "八";
  41. break;
  42. case 9:
  43. str = "九";
  44. break;
  45. case 10:
  46. str = "十";
  47. break;
  48. }
  49. return str;
  50. };
  51. /**
  52. * 日期格式化 日 月
  53. */
  54. export const dateFormat = function (str: string): string {
  55. if (!str) {
  56. return "";
  57. }
  58. return str.substring(5, 7) + "." + str.substring(8, 10);
  59. };
  60. /**
  61. * 是否含有
  62. */
  63. export const isHas = function (val: any, arr: any[]): boolean {
  64. if (!arr) {
  65. return false;
  66. }
  67. for (var i = 0; i < arr.length; i++) {
  68. if (arr[i] == val) {
  69. return true;
  70. }
  71. }
  72. return false;
  73. };
  74. /**
  75. * 消息是否选中
  76. */
  77. export const msgSelected = function (item: any, list: any[]): boolean {
  78. for (var i = 0; i < list.length; i++) {
  79. if (item.Ids == list[i].Ids) {
  80. return true;
  81. }
  82. }
  83. return false;
  84. };
  85. /**
  86. * 处方是否选中
  87. */
  88. export const presSelected = function (item: any, list: any[]): boolean {
  89. for (var i = 0; i < list.length; i++) {
  90. if (item.PrescNo == list[i].PrescNo) {
  91. return true;
  92. }
  93. }
  94. return false;
  95. };
  96. /**
  97. * 是否包含字段
  98. */
  99. export const isIndexOf = function (str: string, val: string): boolean {
  100. return str.indexOf(val) != -1;
  101. };