客服电话换接口获取
This commit is contained in:
parent
e89470df68
commit
126e236cc2
|
|
@ -26,71 +26,85 @@
|
||||||
<script>
|
<script>
|
||||||
import permissionUtils from "@/utils/per";
|
import permissionUtils from "@/utils/per";
|
||||||
import locationService from "@/utils/locationService";
|
import locationService from "@/utils/locationService";
|
||||||
export default {
|
import request from "@/utils/request";
|
||||||
data() {
|
|
||||||
return {
|
export default {
|
||||||
isShowPer: false, // 控制电话权限说明视图显示
|
data() {
|
||||||
phone: '19950079687'
|
return {
|
||||||
|
isShowPer: false, // 控制电话权限说明视图显示
|
||||||
|
phone: '19950079687' // 默认号码,接口失败时使用
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLoad(options) {
|
||||||
|
// 调用接口获取客服电话
|
||||||
|
this.getCustomerService();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 获取客服电话
|
||||||
|
async getCustomerService() {
|
||||||
|
try {
|
||||||
|
const res = await request.post('/sj/poster/getCustomerService');
|
||||||
|
if (res.code === 200 && res.data && res.data.phone) {
|
||||||
|
this.phone = res.data.phone;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取客服电话失败', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
// 拨打电话
|
||||||
this.phone = options.phone || '19950079687'
|
async callPhone() {
|
||||||
},
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
methods: {
|
if (systemInfo.platform === "ios") {
|
||||||
// 拨打电话
|
uni.makePhoneCall({ phoneNumber: this.phone });
|
||||||
async callPhone() {
|
} else {
|
||||||
const systemInfo = uni.getSystemInfoSync();
|
let permission = "android.permission.CALL_PHONE";
|
||||||
if (systemInfo.platform === "ios") {
|
this.isShowPer = true;
|
||||||
uni.makePhoneCall({ phoneNumber: this.phone });
|
|
||||||
} else {
|
|
||||||
let permission = "android.permission.CALL_PHONE";
|
|
||||||
this.isShowPer = true;
|
|
||||||
|
|
||||||
// 1. 检查权限
|
// 1. 检查权限
|
||||||
const { granted } = await permissionUtils.checkPermission(
|
const { granted } = await permissionUtils.checkPermission(
|
||||||
"phone",
|
"phone",
|
||||||
"需要拨打电话权限,方便您联系客服"
|
"需要拨打电话权限,方便您联系客服"
|
||||||
);
|
);
|
||||||
if (granted) {
|
if (granted) {
|
||||||
this.isShowPer = false;
|
this.isShowPer = false;
|
||||||
uni.makePhoneCall({ phoneNumber: this.phone });
|
uni.makePhoneCall({ phoneNumber: this.phone });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isShowPer = false;
|
this.isShowPer = false;
|
||||||
// 2. 显示权限说明弹窗
|
// 2. 显示权限说明弹窗
|
||||||
const confirm = await this.showPermissionDialog(
|
const confirm = await this.showPermissionDialog(
|
||||||
"拨打电话权限申请",
|
"拨打电话权限申请",
|
||||||
"我们需要拨打电话权限,方便您联系客服"
|
"我们需要拨打电话权限,方便您联系客服"
|
||||||
);
|
);
|
||||||
if (!confirm) return;
|
if (!confirm) return;
|
||||||
|
|
||||||
// 3. 请求权限
|
// 3. 请求权限
|
||||||
const result = await permissionUtils.requestPermission(
|
const result = await permissionUtils.requestPermission(
|
||||||
"phone",
|
"phone",
|
||||||
"需要拨打电话权限,方便您联系客服"
|
"需要拨打电话权限,方便您联系客服"
|
||||||
);
|
);
|
||||||
if (result) {
|
if (result) {
|
||||||
uni.makePhoneCall({ phoneNumber: this.phone });
|
uni.makePhoneCall({ phoneNumber: this.phone });
|
||||||
} else {
|
} else {
|
||||||
locationService.openAppSettings();
|
locationService.openAppSettings();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
showPermissionDialog(title, content) {
|
},
|
||||||
|
showPermissionDialog(title, content) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
confirmText: "去开启",
|
confirmText: "去开启",
|
||||||
success(res) {
|
success(res) {
|
||||||
resolve(res.confirm);
|
resolve(res.confirm);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue