QS-picker.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. function dateObj (props) {
  2. this.startYear = props.startYear || new Date().getFullYear() - 5;
  3. this.endYear = props.endYear || new Date().getFullYear() + 5;
  4. this.defaultValue = props.defaultValue?new Date(props.defaultValue):new Date();
  5. this.dateMode = props.dateMode || 3;
  6. this.dateFormatArray = props.dateFormatArray || ['/', '/', ' ', ':', ':'];
  7. }
  8. function customObj (props) {
  9. this.itemArray = props.itemArray || [];
  10. this.linkage = props.linkage || false;
  11. this.linkageNum = props.linkageNum || 2;
  12. this.defaultValue = props.defaultValue || null;
  13. this.steps = props.steps || {};
  14. }
  15. function custom2Obj (props) {
  16. this.itemArray = props.itemArray || [];
  17. this.itemObject = props.itemObject || {};
  18. this.linkage = props.linkage || false;
  19. this.linkageNum = props.linkageNum || 2;
  20. this.defaultValue = props.defaultValue || null;
  21. this.steps = props.steps || {};
  22. }
  23. function cityObj (props) {
  24. this.defaultValue = props.defaultValue || [0, 0, 0];
  25. }
  26. const _app = {
  27. num2Array(num) {
  28. const arr = [];
  29. if(typeof num === 'number') {
  30. for(let i = 1; i <= num; i++) {
  31. arr.push(i);
  32. }
  33. }
  34. return arr;
  35. },
  36. showToast(msg) {
  37. uni.showToast({
  38. title: msg,
  39. icon: 'none'
  40. })
  41. },
  42. showLoading(msg, ifmask) {
  43. uni.showLoading({
  44. title: msg,
  45. mask: ifmask || false
  46. })
  47. },
  48. hideLoading() {
  49. uni.hideLoading();
  50. },
  51. //date
  52. countDays(Y, val) {
  53. let days = new Date(Y,(val[1]+1),0).getDate();
  54. if (val) {
  55. val[2] = val[2] < days - 1? val[2] : days - 1;
  56. }
  57. days = this.num2Array(days);
  58. return {
  59. days,
  60. val
  61. };
  62. },
  63. countYears(sy, ey) {
  64. let _this = this;
  65. let y = [];
  66. let c = ey - sy;
  67. for (let i = 0; i <= c; i++) {
  68. y.push(sy + i);
  69. }
  70. return y;
  71. },
  72. creatDateObj(props) {
  73. return new dateObj(props || {});
  74. },
  75. creatCustomObj(props) {
  76. return new customObj(props || {});
  77. },
  78. creatCustom2Obj(props) {
  79. return new custom2Obj(props || {});
  80. }
  81. }
  82. export default _app;