common.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import dayjs from "dayjs";
  2. import {
  3. chineseToPinYin
  4. } from '@/utils/pinyin.js'
  5. import {
  6. selectDictLabel,
  7. toast
  8. } from "@/utils/util.js";
  9. import store from '@/store';
  10. export const callFunction = function(action, data) {
  11. store.dispatch("app/getIsUseCallSystem", action).then(() => {
  12. if (data) {
  13. const {
  14. join,
  15. ...params
  16. } = data;
  17. const keys = Object.keys(params);
  18. const strParams = keys.reduce((acc, cur) => {
  19. const str = `${cur} : "${params[cur]}"`;
  20. return acc ? acc + "," + str : str;
  21. }, "");
  22. if (join) {
  23. const joinkeys = Object.keys(join);
  24. const joinstr = joinkeys.reduce((acc, cur) => {
  25. const str = `${cur} : "${join[cur]}"`;
  26. return acc ? acc + "," + str : str;
  27. }, "");
  28. store.state.app.callSystem.evalJS(`window.$join={${joinstr}}`);
  29. };
  30. store.state.app.callSystem.evalJS(`${action}({${strParams}})`);
  31. } else {
  32. store.state.app.callSystem.evalJS(`${action}()`);
  33. }
  34. })
  35. };
  36. const common = {
  37. install(app) {
  38. const gp = app.config.globalProperties
  39. gp.$formatMoney = (val, zero = "") => {
  40. if (!val && val !== 0) return zero;
  41. let num = Math.abs(val).toString();
  42. let decimals = '';
  43. const symbolStr = Number(val) < 0 ? "-" : "";
  44. if (num.indexOf('.') > -1) {
  45. decimals = num.split('.')[1]
  46. num = num.split('.')[0]
  47. }
  48. let temp = ''
  49. let len = num.length
  50. if (len <= 3) {
  51. decimals ? temp = '.' + decimals : temp;
  52. return symbolStr + num + temp
  53. } else {
  54. let remainder = len % 3
  55. decimals ? temp = '.' + decimals : temp
  56. if (remainder > 0) {
  57. return symbolStr + num.slice(0, remainder) + ',' + num.slice(remainder, len).match(/\d{3}/g)
  58. .join(',') + temp
  59. } else {
  60. return symbolStr + num.slice(0, len).match(/\d{3}/g).join(',') + temp
  61. }
  62. }
  63. }
  64. gp.$avatar = (url) => {
  65. // ESM 环境无 require,使用静态路径或传入的 url
  66. if (url) return url;
  67. return '/static/case/icon-avatar.png';
  68. }
  69. gp.$chineseToPinYin = chineseToPinYin;
  70. gp.$dayjs = dayjs;
  71. gp.$selectDictLabel = (dictType, value) => {
  72. return selectDictLabel(store.state.dict[dictType], value);
  73. }
  74. gp.$makePhoneCall = (params) => {
  75. uni.makePhoneCall(params);
  76. }
  77. gp.$toast = toast;
  78. gp.$callFunction = callFunction;
  79. gp.$showReal = function(type, telephone) {
  80. if(type == 1){
  81. if (telephone == null) {
  82. return "";
  83. }
  84. if (telephone.length < 7) {
  85. const phone = telephone.substring(1, telephone.length - 1)
  86. return telephone.replace(phone, '****')
  87. }
  88. const phone = telephone.substring(3, telephone.length - 4)
  89. const normal = telephone.replace(phone, '****');
  90. return normal;
  91. }else{
  92. return telephone;
  93. }
  94. }
  95. }
  96. }
  97. export default common;