78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
/**
|
||
* 显示消息提示框
|
||
* @param content 提示的标题
|
||
*/
|
||
export function toast(content) {
|
||
uni.showToast({
|
||
icon: 'none',
|
||
title: content
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 显示模态弹窗
|
||
* @param content 提示的标题
|
||
*/
|
||
export function showConfirm(content) {
|
||
return new Promise((resolve, reject) => {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: content,
|
||
cancelText: '取消',
|
||
confirmText: '确定',
|
||
success: function(res) {
|
||
resolve(res)
|
||
}
|
||
})
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 参数处理
|
||
* @param params 参数
|
||
*/
|
||
export function tansParams(params) {
|
||
let result = ''
|
||
for (const propName of Object.keys(params)) {
|
||
const value = params[propName]
|
||
var part = encodeURIComponent(propName) + "="
|
||
if (value !== null && value !== "" && typeof (value) !== "undefined") {
|
||
if (typeof value === 'object') {
|
||
for (const key of Object.keys(value)) {
|
||
if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
|
||
let params = propName + '[' + key + ']'
|
||
var subPart = encodeURIComponent(params) + "="
|
||
result += subPart + encodeURIComponent(value[key]) + "&"
|
||
}
|
||
}
|
||
} else {
|
||
result += part + encodeURIComponent(value) + "&"
|
||
}
|
||
}
|
||
}
|
||
return result
|
||
}
|
||
|
||
// 获取设备类型(安卓/苹果)
|
||
export function getDeviceType() {
|
||
try {
|
||
// 同步获取系统信息(uniapp核心API,支持多端)
|
||
const systemInfo = uni.getSystemInfoSync();
|
||
// platform字段返回值:android / ios / devtools(微信开发者工具) / windows / mac 等
|
||
const { platform } = systemInfo;
|
||
|
||
// 精准判断设备类型
|
||
if (platform === 'android') {
|
||
return 'android'; // 安卓设备
|
||
} else if (platform === 'ios') {
|
||
return 'ios'; // 苹果设备
|
||
} else {
|
||
// 非安卓/苹果的情况(如小程序开发者工具、Windows、Mac、鸿蒙等)
|
||
return 'unknown';
|
||
}
|
||
} catch (error) {
|
||
// 捕获获取系统信息失败的异常(极低概率,如权限问题)
|
||
console.error('获取设备类型失败:', error);
|
||
return 'unknown';
|
||
}
|
||
} |