common.js 2.8 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(Vue) {
  38. Vue.prototype.$formatMoney = (val, zero = "") => {
  39. if (!val && val !== 0) return zero;
  40. // 统一用正数处理
  41. let num = Math.abs(val).toString();
  42. let decimals = '';
  43. const symbolStr = Number(val) < 0 ? "-" : "";
  44. // 判断是否有小数
  45. if (num.indexOf('.') > -1) {
  46. decimals = num.split('.')[1]
  47. num = num.split('.')[0]
  48. }
  49. let temp = ''
  50. let len = num.length
  51. if (len <= 3) {
  52. decimals ? temp = '.' + decimals : temp;
  53. return symbolStr + num + temp
  54. } else {
  55. let remainder = len % 3
  56. decimals ? temp = '.' + decimals : temp
  57. if (remainder > 0) { // 不是3的整数倍
  58. return symbolStr + num.slice(0, remainder) + ',' + num.slice(remainder, len).match(/\d{3}/g)
  59. .join(',') + temp
  60. } else { // 是3的整数倍
  61. return symbolStr + num.slice(0, len).match(/\d{3}/g).join(',') + temp
  62. }
  63. }
  64. }
  65. Vue.prototype.$avatar = (url) => {
  66. return require("@/static/case/icon-avatar.png")
  67. // return url ? url : require("@/static/case/icon-avatar.png")
  68. }
  69. Vue.prototype.$chineseToPinYin = chineseToPinYin;
  70. Vue.prototype.$dayjs = dayjs;
  71. Vue.prototype.$selectDictLabel = (dictType, value) => {
  72. return selectDictLabel(store.state.dict[dictType], value);
  73. }
  74. Vue.prototype.$makePhoneCall = (params) => {
  75. uni.makePhoneCall(params);
  76. }
  77. Vue.prototype.$toast = toast;
  78. Vue.prototype.$callFunction = callFunction;
  79. Vue.prototype.$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;