value.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. const uni_modules_uviewPlus_libs_function_index = require("../../libs/function/index.js");
  3. const uni_modules_uviewPlus_libs_function_test = require("../../libs/function/test.js");
  4. const value = {
  5. computed: {
  6. // 经处理后需要显示的值
  7. value() {
  8. const {
  9. text,
  10. mode,
  11. format,
  12. href
  13. } = this;
  14. if (mode === "price") {
  15. if (!/^\d+(\.\d+)?$/.test(text)) {
  16. uni_modules_uviewPlus_libs_function_index.error("金额模式下,text参数需要为金额格式");
  17. }
  18. if (uni_modules_uviewPlus_libs_function_test.test.func(format)) {
  19. return format(text);
  20. }
  21. return uni_modules_uviewPlus_libs_function_index.priceFormat(text, 2);
  22. }
  23. if (mode === "date") {
  24. !uni_modules_uviewPlus_libs_function_test.test.date(text) && uni_modules_uviewPlus_libs_function_index.error("日期模式下,text参数需要为日期或时间戳格式");
  25. if (uni_modules_uviewPlus_libs_function_test.test.func(format)) {
  26. return format(text);
  27. }
  28. if (format) {
  29. return uni_modules_uviewPlus_libs_function_index.timeFormat(text, format);
  30. }
  31. return uni_modules_uviewPlus_libs_function_index.timeFormat(text, "yyyy-mm-dd");
  32. }
  33. if (mode === "phone") {
  34. if (uni_modules_uviewPlus_libs_function_test.test.func(format)) {
  35. return format(text);
  36. }
  37. if (format === "encrypt") {
  38. return `${text.substr(0, 3)}****${text.substr(7)}`;
  39. }
  40. return text;
  41. }
  42. if (mode === "name") {
  43. !(typeof text === "string") && uni_modules_uviewPlus_libs_function_index.error("姓名模式下,text参数需要为字符串格式");
  44. if (uni_modules_uviewPlus_libs_function_test.test.func(format)) {
  45. return format(text);
  46. }
  47. if (format === "encrypt") {
  48. return this.formatName(text);
  49. }
  50. return text;
  51. }
  52. if (mode === "link") {
  53. !uni_modules_uviewPlus_libs_function_test.test.url(href) && uni_modules_uviewPlus_libs_function_index.error("超链接模式下,href参数需要为URL格式");
  54. return text;
  55. }
  56. return text;
  57. }
  58. },
  59. methods: {
  60. // 默认的姓名脱敏规则
  61. formatName(name) {
  62. let value2 = "";
  63. if (name.length === 2) {
  64. value2 = name.substr(0, 1) + "*";
  65. } else if (name.length > 2) {
  66. let char = "";
  67. for (let i = 0, len = name.length - 2; i < len; i++) {
  68. char += "*";
  69. }
  70. value2 = name.substr(0, 1) + char + name.substr(-1, 1);
  71. } else {
  72. value2 = name;
  73. }
  74. return value2;
  75. }
  76. }
  77. };
  78. exports.value = value;