gaoluyang
3 天以前 92230c9a97dc9ce9df3313d11d26999c04bb6b26
src/utils/common.ts
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,54 @@
/**
* æ˜¾ç¤ºæ¶ˆæ¯æç¤ºæ¡†
* @param content æç¤ºçš„æ ‡é¢˜
*/
export function toast(content:string) {
  uni.showToast({
    icon: 'none',
    title: content
  })
}
/**
* æ˜¾ç¤ºæ¨¡æ€å¼¹çª—
* @param content æç¤ºçš„æ ‡é¢˜
*/
export function showConfirm(content:string):Promise<any> {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title: '提示',
      content: content,
      cancelText: '取消',
      confirmText: '确定',
      success: function(res) {
        resolve(res)
      }
    })
  })
}
/**
* å‚数处理
* @param params å‚æ•°
*/
export function tansParams(params:any) {
  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
}