# 网页端公用方法

# 1、axios 接口请求

/**
 * get请求方法
 * @param {String} url 接口
 * @param {Object} param  请求参数
 * @param {function} data 成功回调
 * @param {function} error 失败回调
 */
this.$get( url, param, data => {}, error => {})
/**
 * post请求方法
 * @param {String} url 接口
 * @param {Object} param  请求参数
 * @param {function} data 成功回调
 * @param {function} error 失败回调
 */
this.$post( url, param, data => {}, error => {})

# 2、axios 接口同步请求

/**
 * post请求方法
 * @param {String} url 接口
 * @param {Object} param  请求参数
 * @param {Boolean} isMsg 是否提示错误消息
 */
this.$postSync( url, param, isMsg)

/**
 * get请求方法
 * @param {String} url 接口
 * @param {Object} param  请求参数
 * @param {Boolean} isMsg 是否提示错误消息
 */
this.$getSync( url, param, isMsg)


// 用法, 方法前加async, 接口请求前面加await, res为接口返回参数
async loadList () {
    let res1 = await this.$postSync(api)
    let res2 = await this.$postSync(api)
}

# 3、isCode 按钮权限

/**
 * 判断资源code是否存在
 * @param {String} code 资源code
 */
$isCode(code)

# 4、deleteInfo 删除信息

/**
 * 删除信息
 * @param {String} api 接口
 * @param {Object} param 接口入参
 * @param {function} callback 成功回调
 */
this.$deleteInfo(api, param, title, callback)

# 5、parseObj 解构对象给另一个对象

/**
 * 解构对象给另一个对象
 * @param {Oject} obj 赋值对象
 * @param {Oject} data 解构对象
 * @param {Array} arr 解构参数
 */
 this.$parseObj(obj, data, arr)

# 6、downloadFile 下载文件

/**
 * 下载文件
 * @param {String} api 接口
 * @param {Object} params 请求参数
 * @param {String} fileName 文件名
 */
this.$downloadFile(api, params, fileName) 

# 7、dayjs 日期格式化

/**
 * 日期格式化
 * @param {String} 要格式化的日期
 * @param {String} 格式化
 * @return {String} 格式化后的日期
 */
this.$dayjs(param).format('YYYY-MM-DD HH:mm:ss')

// 更多使用方法请参考
https://www.cnblogs.com/cjrfan/p/9154539.html

# 8、debounce 防抖函数

/**
 * 防抖函数
 * @param {function} fn 函数
 * @param {number} delay 延迟
 */
this.$debounce(fn) 

// 用法
loadList: window.Vue.prototype.$debounce(function () {
	this.$refs.table.loadList()
})

# 9、throttle 节流函数

/**
 * 节流函数
 * @param {function} fn 函数
 * @param {number} delay 延迟
 */
this.$throttle(fn)


//用法
loadList: window.Vue.prototype.$throttle(function () {
	this.$refs.table.loadList()
})

# 10、deepClone 深拷贝

/**
 * 深拷贝对象
 * @param {Object} obj 拷贝对象
 * @retrun Object
 */
this.$deepClone(obj)

# 11、openBlank 打开浏览器弹框页

/**
 * 打开浏览器弹框页
 * @param {String} url 地址或路由
 * @param {Number} width 弹框宽度
 * @param {Number} height 弹框高度
 */
this.$openBlank(url)

# 12、moneyFormat 金额格式化

/**
 * 金额格式化
 * 参数说明:
 * @param {number} number:要格式化的数字
 * @param {number} decimals:保留几位小数
 * @param {string} dec_point:小数点符号,默认为点 “.”
 * @param {string} thousands_sep:千分位符号,默认为逗号 “,”
 * */
this.$moneyFormat(number, decimals, dec_point, thousands_sep)

# 13、存储操作

将 localStorage、sessionStorage 的常规操作进行封装,方便使用

  • localStorage
this.$localCache.getItem('user')
this.$localCache.setItem('name','张三')
this.$localCache.removeItem('token')
this.$localCache.clear()
  • sessionStorage
this.$sessionCache.getItem('user')

其余用法同 localCache

# 14、微前端子应用路由跳转

/**
 * 微前端子应用路由跳转
 * @param {String} url 路由
 * @param {Object} mainRouter 主应用路由实例(例如this.$store.state.router)
 * @param {Object} params 路由传参参数,可为空
 */
this.$qiankunJump(url, this.$store.state.router)

# 15 模糊搜索

/**
 * 模糊搜索
 * @param {Array} list 搜索列表数据
 * @param {String} keyWord 搜索的关键字
 * @param {String} attribute 搜索 item 字段名
 * @returns {Array} 搜索过滤后数据
 */
this.$fuzzyQuery(list,keyWord,attribute)