service-contact.js 808 B

123456789101112131415161718192021222324252627
  1. import { request, parseResponseJson } from '@/utils/request'
  2. /** 拉取运营在系统设置中配置的客服电话(需登录)。 */
  3. export async function fetchServicePhone() {
  4. try {
  5. const res = await request({ url: '/mini/common/service-contact', method: 'GET' })
  6. const body = parseResponseJson(res)
  7. if (body.code === 200 && body.data && body.data.servicePhone) {
  8. return String(body.data.servicePhone).trim()
  9. }
  10. } catch {
  11. // ignore
  12. }
  13. return ''
  14. }
  15. /** 一键拨号(号码中的空格在拨号前去掉)。 */
  16. export function dialServicePhone(phone) {
  17. const raw = String(phone || '')
  18. .trim()
  19. .replace(/\s/g, '')
  20. if (!raw) {
  21. uni.showToast({ title: '暂未配置客服电话', icon: 'none' })
  22. return
  23. }
  24. uni.makePhoneCall({ phoneNumber: raw })
  25. }