89 lines
2.0 KiB
JavaScript
89 lines
2.0 KiB
JavaScript
/**
|
||
* 将常用的Uniapp提供的函数,存放到这里,按需引用
|
||
*/
|
||
|
||
|
||
/**
|
||
* 显示错误信息
|
||
* @param {Exception} err
|
||
*/
|
||
const showError = (err) => {
|
||
uni.showToast({
|
||
title: err?.message || err?.errMsg || err?.toString(),
|
||
icon: 'none',
|
||
duration: 2000
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 打电话
|
||
* @param {string} mobile 电话号码
|
||
*/
|
||
export const makePhoneCall = (mobile) => {
|
||
try {
|
||
uni.makePhoneCall({
|
||
phoneNumber: `${mobile}`,
|
||
success(e) {
|
||
console.log(e);
|
||
}
|
||
});
|
||
} catch (err) {
|
||
showError(err);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 拷贝文本
|
||
* @param {*} text
|
||
* @param {*} options
|
||
*/
|
||
export const copyText = (text, { copySuccess = '', copyFailed = '' } = {}) => {
|
||
try {
|
||
console.log('copyText');
|
||
uni.setClipboardData({
|
||
data: `${text}`,
|
||
success: () => {
|
||
console.error('复制成功');
|
||
try {
|
||
uni.showToast({
|
||
title: copySuccess,
|
||
icon: 'success',
|
||
duration: 2000
|
||
});
|
||
} catch (e) {
|
||
showError(e);
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
console.error('复制失败:', err);
|
||
try {
|
||
uni.showToast({
|
||
title: err.message || err.errMsg || copyFailed,
|
||
icon: 'none',
|
||
duration: 2000
|
||
});
|
||
} catch (e) {
|
||
showError(e);
|
||
}
|
||
}
|
||
});
|
||
} catch (err) {
|
||
showError(err);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 打开定位
|
||
* @param {Object} options
|
||
*/
|
||
export const openLocation = ({ latitude, longitude, name } = {}) => {
|
||
try {
|
||
uni.openLocation({
|
||
latitude,
|
||
longitude,
|
||
name,
|
||
});
|
||
} catch (err) {
|
||
showError(err);
|
||
}
|
||
} |