Commit f8a1640f by xinla

--no commit message

1 parent 3f1c5a41
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
* 通用js方法封装处理,挂载到 Vue.prototype * 通用js方法封装处理,挂载到 Vue.prototype
*/ */
const baseURL = window.lwConfig.BASE_API const baseURL = window.lwConfig.BASE_API
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import axios from 'axios' import axios from 'axios'
// 日期格式化 // 日期格式化
export function parseTime(time, pattern) { export function parseTime(time, pattern) {
if (arguments.length === 0 || !time) { if (arguments.length === 0 || !time) {
return null return null
} }
...@@ -47,17 +47,17 @@ ...@@ -47,17 +47,17 @@
return value || 0 return value || 0
}) })
return time_str return time_str
} }
// 表单重置 // 表单重置
export function resetForm(refName) { export function resetForm(refName) {
if (this.$refs[refName]) { if (this.$refs[refName]) {
this.$refs[refName].resetFields() this.$refs[refName].resetFields()
} }
} }
// 添加日期范围 // 添加日期范围
export function addDateRange(params, dateRange) { export function addDateRange(params, dateRange) {
var search = params var search = params
search.beginTime = '' search.beginTime = ''
search.endTime = '' search.endTime = ''
...@@ -66,10 +66,10 @@ ...@@ -66,10 +66,10 @@
search.endTime = this.dateRange[1] search.endTime = this.dateRange[1]
} }
return search return search
} }
// 回显数据字典 // 回显数据字典
export function selectDictLabel(datas, value) { export function selectDictLabel(datas, value) {
var actions = [] var actions = []
Object.keys(datas).some((key) => { Object.keys(datas).some((key) => {
if (datas[key].dictValue == '' + value) { if (datas[key].dictValue == '' + value) {
...@@ -78,10 +78,10 @@ ...@@ -78,10 +78,10 @@
} }
}) })
return actions.join('') return actions.join('')
} }
// 回显数据字典(字符串数组) // 回显数据字典(字符串数组)
export function selectDictLabels(datas, value, separator) { export function selectDictLabels(datas, value, separator) {
var actions = [] var actions = []
var currentSeparator = undefined === separator ? ',' : separator var currentSeparator = undefined === separator ? ',' : separator
var temp = value.split(currentSeparator) var temp = value.split(currentSeparator)
...@@ -93,10 +93,10 @@ ...@@ -93,10 +93,10 @@
}) })
}) })
return actions.join('').substring(0, actions.join('').length - 1) return actions.join('').substring(0, actions.join('').length - 1)
} }
// 通用下载方法 系统内部 // 通用下载方法 系统内部
export function download(fileName) { export function download(fileName) {
axios({ axios({
method: 'GET', method: 'GET',
url: baseURL + '/common/download?fileName=' + encodeURI(fileName) + '&delete=' + true, url: baseURL + '/common/download?fileName=' + encodeURI(fileName) + '&delete=' + true,
...@@ -117,10 +117,10 @@ ...@@ -117,10 +117,10 @@
dom.parentNode.removeChild(dom) dom.parentNode.removeChild(dom)
window.URL.revokeObjectURL(url) window.URL.revokeObjectURL(url)
}) })
} }
// 通用下载方法 网络文件路径 // 通用下载方法 网络文件路径
export function downloadNet(url, fileName) { export function downloadNet(url, fileName) {
axios({ axios({
method: 'GET', method: 'GET',
url: baseURL + '/common/download/url?url=' + url, url: baseURL + '/common/download/url?url=' + url,
...@@ -141,10 +141,10 @@ ...@@ -141,10 +141,10 @@
dom.parentNode.removeChild(dom) dom.parentNode.removeChild(dom)
window.URL.revokeObjectURL(url) window.URL.revokeObjectURL(url)
}) })
} }
// 字符串格式化(%s ) // 字符串格式化(%s )
export function sprintf(str) { export function sprintf(str) {
var args = arguments, var args = arguments,
flag = true, flag = true,
i = 1 i = 1
...@@ -157,24 +157,24 @@ ...@@ -157,24 +157,24 @@
return arg return arg
}) })
return flag ? str : '' return flag ? str : ''
} }
// 转换字符串,undefined,null等转化为"" // 转换字符串,undefined,null等转化为""
export function praseStrEmpty(str) { export function praseStrEmpty(str) {
if (!str || str == 'undefined' || str == 'null') { if (!str || str == 'undefined' || str == 'null') {
return '' return ''
} }
return str return str
} }
/** /**
* 数组构造树型结构数据 * 数组构造树型结构数据
* @param {Array} data 数据源 * @param {Array} data 数据源
* @param {*} id id字段 默认 'id' * @param {*} id id字段 默认 'id'
* @param {*} parentId 父节点字段 默认 'parentId' * @param {*} parentId 父节点字段 默认 'parentId'
* @param {*} children 孩子节点字段 默认 'children' * @param {*} children 孩子节点字段 默认 'children'
*/ */
export function handleTree(data, id, parentId, children) { export function handleTree(data, id, parentId, children) {
id = id || 'id' id = id || 'id'
parentId = parentId || 'parentId' parentId = parentId || 'parentId'
children = children || 'children' children = children || 'children'
...@@ -200,19 +200,21 @@ ...@@ -200,19 +200,21 @@
} }
}) })
return result return result
} }
/** /**
* 树转数组 * 树转数组
* @param {*} tree * @param {*} tree
* @param {*} children 孩子节点字段 默认 'children' * @param {*} children 孩子节点字段 默认 'children'
* @param {Function} callback 回调函数 * @param {Function} callback 回调函数
* @returns {Array} * @returns {Array}
*/ */
export function treeToArray(tree = [], children = 'children', callback) { export function treeToArray(tree = [], children = 'children', callback) {
let result = [] let result = []
let level = 0
function dg(obj) { function dg(obj) {
callback && callback(obj, result) callback && callback(obj, result, level)
++level
if (obj[children]) { if (obj[children]) {
result.push(...obj[children]) result.push(...obj[children])
obj[children].forEach((e) => { obj[children].forEach((e) => {
...@@ -220,6 +222,7 @@ ...@@ -220,6 +222,7 @@
}) })
// delete obj.children // delete obj.children
} }
--level
} }
if (Array.isArray(tree)) { if (Array.isArray(tree)) {
result.push(...tree) result.push(...tree)
...@@ -229,13 +232,13 @@ ...@@ -229,13 +232,13 @@
dg(tree) dg(tree)
} }
return result return result
} }
/** /**
* dataURL转化为File对象 * dataURL转化为File对象
* @param {*} dataURL 本地数据 base64 * @param {*} dataURL 本地数据 base64
*/ */
export function dataURLtoFile(dataURL) { export function dataURLtoFile(dataURL) {
const arr = dataURL.split(',') const arr = dataURL.split(',')
const mime = arr[0].match(/:(.*?);/)[1] const mime = arr[0].match(/:(.*?);/)[1]
const bstr = atob(arr[1]) const bstr = atob(arr[1])
...@@ -246,10 +249,10 @@ ...@@ -246,10 +249,10 @@
n -= 1 // to make eslint happy n -= 1 // to make eslint happy
} }
return new File([u8arr], '', { type: mime }) return new File([u8arr], '', { type: mime })
} }
// FormData 格式转化 // FormData 格式转化
export function toFormData(val) { export function toFormData(val) {
let formData = new FormData() let formData = new FormData()
for (let i in val) { for (let i in val) {
isArray(val[i], i) isArray(val[i], i)
...@@ -281,5 +284,4 @@ ...@@ -281,5 +284,4 @@
} }
} }
return formData return formData
}
\ No newline at end of file \ No newline at end of file
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!