/* export function setData(dataset) {
|
for (let field in dataset) {
|
// 通过正则表达式 查找路径数据
|
const regex = /([\w$]+)|\[(:\d)\]/g
|
const patten = field.match(regex)
|
let result = this // 指向调用的数据 如data
|
// 遍历路径 逐级查找 最后一级用于直接赋值
|
for (let i = 0; i < patten.length - 1; i++) {
|
const key = patten[i]
|
result = result[key]
|
}
|
result[patten[patten.length - 1]] = dataset[field]
|
}
|
}
|
*/
|
//import WXBizDataCrypt from "./WXBizDataCrypt.js"
|
//var WXBizDataCrypt = require('./WXBizDataCrypt')
|
export function showModal(message, title = '提示', iscancel = true) {
|
return new Promise((resolve) => {
|
uni.showModal({
|
title: title,
|
content: message,
|
showCancel: iscancel,
|
success: function(res) {
|
if (res.confirm) {
|
resolve(true)
|
} else if (res.cancel) {
|
resolve(false)
|
}
|
}
|
});
|
})
|
}
|
|
export function showToast(title,duration="short") {
|
// uni.showToast({
|
// title: title,
|
// icon: icon?icon:'none'
|
// })
|
plus.nativeUI.toast(title, {duration});
|
}
|
export function showLoading(title) {
|
|
// #ifdef MP-WEIXIN
|
uni.showLoading({
|
title: title,
|
mask: true
|
})
|
// #endif
|
// #ifndef MP-WEIXIN
|
uni.showLoading({
|
title: title
|
})
|
// #endif
|
}
|
|
export function hideLoading() {
|
|
uni.hideLoading()
|
}
|
|
|
//根据field获取数据
|
export function getData(thiz, field) {
|
// 通过正则表达式 查找路径数据
|
const regex = /([\w$]+)|\[(:\d)\]/g
|
const patten = field.match(regex)
|
let result = thiz // 指向调用的数据 如data
|
// 遍历路径 逐级查找 最后一级用于直接赋值
|
for (let i = 0; i < patten.length - 1; i++) {
|
let key = patten[i]
|
result = result[key]
|
}
|
return result[patten[patten.length - 1]]
|
}
|
//页面点击时对参数进行了转义,要进行反转义
|
export function getOption(option) {
|
if (option !== null && typeof option === 'object') {
|
for (let key in option) {
|
option[key] = decodeURIComponent(option[key])
|
}
|
}
|
return option
|
}
|
|
export function showInfo(ex){
|
if( !ex)
|
return
|
let tip =ex
|
console.log(ex);
|
if( typeof ex !== "string" )
|
{
|
let exStr = JSON.stringify(ex)
|
if (exStr == "{}")
|
exStr = ex
|
tip = typeof ex.errMsg == "string" ? ex.errMsg :typeof ex.message == "string" ? ex.message: exStr
|
}
|
plus.nativeUI.toast(`<div>${tip}</div>` , {verticalAlign:"center",type:"richtext",duration:"short"});
|
}
|
|
export function showError(ex,title=""){
|
if( !ex)
|
return
|
let tip =ex
|
console.log(ex);
|
if( typeof ex !== "string" )
|
{
|
let exStr = JSON.stringify(ex)
|
if (exStr == "{}")
|
exStr = ex
|
tip = typeof ex.errMsg == "string" ? ex.errMsg :typeof ex.message == "string" ? ex.message: exStr
|
}
|
plus.nativeUI.alert(tip,title);
|
// uni.showModal({
|
// title: title ||"",
|
// content: tip,,
|
// showCancel: false
|
// });
|
}
|