tools.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * 拨打电话
  3. *
  4. */
  5. export const MakePhoneCall = (tel) => {
  6. if (!tel) {
  7. uni.showToast({
  8. title: '暂未设置电话号码',
  9. icon: 'none'
  10. });
  11. return;
  12. }
  13. uni.makePhoneCall({
  14. phoneNumber: tel,
  15. fail: () => {
  16. // uni.showToast({
  17. // title: '暂未设置电话号码',
  18. // icon: false
  19. // });
  20. }
  21. });
  22. };
  23. /**
  24. * 地图导航
  25. * location:商家位置
  26. * provinceName:所属省名
  27. * cityName:所属市名
  28. * areaName:所属区名
  29. * address:详细地址
  30. * latitude:纬度
  31. * longitude:经度
  32. */
  33. export const MapNavigation = (vo) => {
  34. const {
  35. location,
  36. provinceName,
  37. cityName,
  38. areaName,
  39. address,
  40. latitude,
  41. longitude
  42. } = vo;
  43. // console.log('MapNavigation', vo);
  44. // uni.showToast({
  45. // title: '开发中',
  46. // icon: 'none'
  47. // });
  48. uni.openLocation({
  49. latitude: latitude * 1,
  50. longitude: longitude * 1,
  51. name: address,
  52. success: function () {
  53. // console.log('success');
  54. }
  55. });
  56. }
  57. // 获取今天时间
  58. type FormatTs = 'YYYYMMDD' | 'YYYYMMDDhhmmss' | 'YYYYMMDDhhmm';
  59. const Zero = (num) => {
  60. return num >= 10 ? num : `0${num}`
  61. }
  62. interface TimeTs {
  63. time?: any
  64. format?: 'YYYYMMDD' | 'YYYYMMDDhhmmss' | 'YYYYMMDDhhmm' | 'MMDD',
  65. joint?: '/' | '-'
  66. }
  67. export const oneDay = 60 * 60 * 24 * 1000; // 一天的时间
  68. export const getTimeVal = (params: TimeTs = {}) => {
  69. const { time, format, joint = '-' } = params || {}
  70. // console.log("time, format, joint = ", params)
  71. // { format: FormatTs, joint = '/' }
  72. const Time_ = time ? new Date(time) : new Date();
  73. let Time_Str: any = '';
  74. if (format) {
  75. const Y = Time_.getFullYear();
  76. const M = Zero(Time_.getMonth() + 1);
  77. const D = Zero(Time_.getDate());
  78. const h = Zero(Time_.getHours());
  79. const m = Zero(Time_.getMinutes());
  80. const s = Zero(Time_.getSeconds());
  81. // console.log('Y ===== ', Y, M)
  82. switch (format) {
  83. case 'MMDD':
  84. Time_Str = `${M}${joint}${D}`;
  85. break;
  86. case 'YYYYMMDD':
  87. Time_Str = `${Y}${joint}${M}${joint}${D}`;
  88. break;
  89. case 'YYYYMMDDhhmm':
  90. Time_Str = `${Y}${joint}${M}${joint}${D} ${h}:${m}`;
  91. break;
  92. case 'YYYYMMDDhhmmss':
  93. Time_Str = `${Y}${joint}${M}${joint}${D} ${h}:${m}:${s}`;
  94. break;
  95. default:
  96. Time_Str = Time_.getTime()
  97. }
  98. } else {
  99. Time_Str = Time_.getTime()
  100. };
  101. // console.log('Time_Str = ', Time_Str)
  102. return Time_Str
  103. }
  104. export const copyData = (text) => {
  105. if (!text) {
  106. uni.showToast({
  107. title: "复制内容不能为空",
  108. icon: 'none'
  109. })
  110. } else {
  111. uni.setClipboardData({
  112. data: text,
  113. success: () => {
  114. uni.showToast({
  115. title: "复制成功",
  116. icon: 'none'
  117. })
  118. },
  119. fail: () => {
  120. uni.showToast({
  121. title: "复制失败",
  122. icon: 'none'
  123. })
  124. }
  125. });
  126. }
  127. }