vueFilters.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import Vue from "vue";
  2. import * as constant from "../constant";
  3. import numeral from "numeral";
  4. import dayjs from "dayjs";
  5. // 乐团状态
  6. Vue.filter("bandStatus", (value) => {
  7. let templateStatus = {
  8. APPLY: "报名中",
  9. PAY: "缴费中",
  10. PREPARE: "筹备中",
  11. UNDERWAY: "进行中",
  12. CANCELED: "取消",
  13. };
  14. return templateStatus[value];
  15. });
  16. // 商品类型
  17. Vue.filter("shopType", (value) => {
  18. let template = {
  19. INSTRUMENT: "乐器",
  20. ACCESSORIES: "辅件",
  21. TEACHING: "教材",
  22. STAFF: "教谱",
  23. OTHER: "其它",
  24. };
  25. return template[value];
  26. });
  27. // 金额格式化
  28. Vue.filter("moneyFormat", (value) => {
  29. return numeral(value).format("0,0.00");
  30. });
  31. // 金额格式化,不要多余的0
  32. Vue.filter("moneyFormat2", (value) => {
  33. const str = numeral(value).format("0,0.00");
  34. const nums = str.split(".");
  35. const result = [nums[0]];
  36. const subfix = parseFloat("." + nums[1]);
  37. if (subfix > 0) {
  38. result.push(("" + subfix).replace("0.", ""));
  39. }
  40. return result.join(".");
  41. });
  42. Vue.filter("numberFormat", (value) => {
  43. return numeral(value).format("0,0");
  44. });
  45. // 课程类型
  46. Vue.filter("coursesType", (val) => constant.courseType[val]);
  47. // 合并数组
  48. Vue.filter("joinArray", (value, type) => {
  49. if (!type) {
  50. type = " ";
  51. }
  52. if (typeof value == "object" && value != null) {
  53. return value.join(type);
  54. } else {
  55. return value;
  56. }
  57. });
  58. // 数据类型
  59. Vue.filter("dataStatusCN", (value) => {
  60. let templateStatus = {
  61. 到课: "",
  62. 请假: "truant",
  63. 旷课: "leave",
  64. };
  65. return templateStatus[value];
  66. });
  67. // 考勤类型
  68. Vue.filter("clockingIn", (value) => {
  69. let templateStatus = {
  70. NORMAL: "正常",
  71. TRUANT: "旷课",
  72. LEAVE: "请假",
  73. QUIT_SCHOOL: "休学",
  74. DROP_OUT: "退学",
  75. LATE: "迟到",
  76. };
  77. return templateStatus[value];
  78. });
  79. // 课程类型
  80. Vue.filter("teachModeStatus", (value) => {
  81. let templateStatus = {
  82. ONLINE: "线上课",
  83. OFFLINE: "线下课",
  84. };
  85. return templateStatus[value];
  86. });
  87. // 消耗类型
  88. Vue.filter("periodRecordStatus", (value) => {
  89. let templateStatus = {
  90. NOT_START: "未开始",
  91. APPLYING: "报名中",
  92. NORMAL: "正常",
  93. LOCK: "锁定",
  94. FINISH: "结束",
  95. CANCEL: "取消",
  96. };
  97. return templateStatus[value];
  98. });
  99. // 计算分钟数
  100. Vue.filter("calcMinute", (minute) => {
  101. if (minute <= 0) {
  102. return "0分钟";
  103. }
  104. let minutes = minute % 60; // 算出分钟
  105. let hours = 0; // 小时
  106. if (minute >= 60) {
  107. hours = (minute - minutes) / 60;
  108. }
  109. let text = "";
  110. if (hours) {
  111. text = hours + "小时";
  112. }
  113. if (minutes) {
  114. text += minutes + "分钟";
  115. }
  116. return text;
  117. });
  118. Vue.filter("formatDate", (value) => {
  119. let d = new Date(value.replace(/-/gi, "/"));
  120. let hour = d.getHours() >= 10 ? d.getHours() : "0" + d.getHours();
  121. let minute = d.getMinutes() >= 10 ? d.getMinutes() : "0" + d.getMinutes();
  122. return hour + ":" + minute;
  123. });
  124. Vue.filter("formatDateExtend", (value, format = "YYYY-MM-DD") => {
  125. return dayjs(value).format(format);
  126. });
  127. Vue.filter("formatTimer", (value) => {
  128. if (value) {
  129. return value.split(" ")[0];
  130. } else {
  131. return value;
  132. }
  133. });
  134. // 格式化单位
  135. Vue.filter("formatUnit", (value) => {
  136. const template = {
  137. 1: "元",
  138. 2: "%",
  139. };
  140. return template[value];
  141. });
  142. Vue.filter("coupontypeDetailType", (val) => constant.coupontypeDetail[val]);
  143. // 乐团学员状态
  144. Vue.filter("musicGroupStudentType", (value) => {
  145. let template = {
  146. NORMAL: "在读",
  147. LEAVE: "请假",
  148. QUIT: "退团",
  149. APPLY: "报名",
  150. };
  151. return template[value];
  152. });
  153. Vue.filter("coursesType", (val) => constant.courseType[val]);