[修改]此工具类应使用参数dateRange而非bind在model上的dateRange
正在显示
1 个修改的文件
包含
148 行增加
和
148 行删除
| 1 | -/** | ||
| 2 | - * 通用js方法封装处理 | ||
| 3 | - * Copyright (c) 2019 ruoyi | ||
| 4 | - */ | ||
| 5 | - | ||
| 6 | -const baseURL = process.env.VUE_APP_BASE_API | ||
| 7 | - | ||
| 8 | -// 日期格式化 | ||
| 9 | -export function parseTime(time, pattern) { | ||
| 10 | - if (arguments.length === 0 || !time) { | ||
| 11 | - return null | ||
| 12 | - } | ||
| 13 | - const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' | ||
| 14 | - let date | ||
| 15 | - if (typeof time === 'object') { | ||
| 16 | - date = time | ||
| 17 | - } else { | ||
| 18 | - if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { | ||
| 19 | - time = parseInt(time) | ||
| 20 | - } else if (typeof time === 'string') { | ||
| 21 | - time = time.replace(new RegExp(/-/gm), '/'); | ||
| 22 | - } | ||
| 23 | - if ((typeof time === 'number') && (time.toString().length === 10)) { | ||
| 24 | - time = time * 1000 | ||
| 25 | - } | ||
| 26 | - date = new Date(time) | ||
| 27 | - } | ||
| 28 | - const formatObj = { | ||
| 29 | - y: date.getFullYear(), | ||
| 30 | - m: date.getMonth() + 1, | ||
| 31 | - d: date.getDate(), | ||
| 32 | - h: date.getHours(), | ||
| 33 | - i: date.getMinutes(), | ||
| 34 | - s: date.getSeconds(), | ||
| 35 | - a: date.getDay() | ||
| 36 | - } | ||
| 37 | - const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { | ||
| 38 | - let value = formatObj[key] | ||
| 39 | - // Note: getDay() returns 0 on Sunday | ||
| 40 | - if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] } | ||
| 41 | - if (result.length > 0 && value < 10) { | ||
| 42 | - value = '0' + value | ||
| 43 | - } | ||
| 44 | - return value || 0 | ||
| 45 | - }) | ||
| 46 | - return time_str | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | -// 表单重置 | ||
| 50 | -export function resetForm(refName) { | ||
| 51 | - if (this.$refs[refName]) { | ||
| 52 | - this.$refs[refName].resetFields(); | ||
| 53 | - } | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -// 添加日期范围 | ||
| 57 | -export function addDateRange(params, dateRange) { | ||
| 58 | - var search = params; | ||
| 59 | - search.beginTime = ""; | ||
| 60 | - search.endTime = ""; | ||
| 61 | - if (null != dateRange && '' != dateRange) { | ||
| 62 | - search.beginTime = this.dateRange[0]; | ||
| 63 | - search.endTime = this.dateRange[1]; | ||
| 64 | - } | ||
| 65 | - return search; | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -// 回显数据字典 | ||
| 69 | -export function selectDictLabel(datas, value) { | ||
| 70 | - var actions = []; | ||
| 71 | - Object.keys(datas).some((key) => { | ||
| 72 | - if (datas[key].dictValue == ('' + value)) { | ||
| 73 | - actions.push(datas[key].dictLabel); | ||
| 74 | - return true; | ||
| 75 | - } | ||
| 76 | - }) | ||
| 77 | - return actions.join(''); | ||
| 78 | -} | ||
| 79 | - | ||
| 80 | -// 回显数据字典(字符串数组) | ||
| 81 | -export function selectDictLabels(datas, value, separator) { | ||
| 82 | - var actions = []; | ||
| 83 | - var currentSeparator = undefined === separator ? "," : separator; | ||
| 84 | - var temp = value.split(currentSeparator); | ||
| 85 | - Object.keys(value.split(currentSeparator)).some((val) => { | ||
| 86 | - Object.keys(datas).some((key) => { | ||
| 87 | - if (datas[key].dictValue == ('' + temp[val])) { | ||
| 88 | - actions.push(datas[key].dictLabel + currentSeparator); | ||
| 89 | - } | ||
| 90 | - }) | ||
| 91 | - }) | ||
| 92 | - return actions.join('').substring(0, actions.join('').length - 1); | ||
| 93 | -} | ||
| 94 | - | ||
| 95 | -// 通用下载方法 | ||
| 96 | -export function download(fileName) { | ||
| 97 | - window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true; | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -// 字符串格式化(%s ) | ||
| 101 | -export function sprintf(str) { | ||
| 102 | - var args = arguments, flag = true, i = 1; | ||
| 103 | - str = str.replace(/%s/g, function () { | ||
| 104 | - var arg = args[i++]; | ||
| 105 | - if (typeof arg === 'undefined') { | ||
| 106 | - flag = false; | ||
| 107 | - return ''; | ||
| 108 | - } | ||
| 109 | - return arg; | ||
| 110 | - }); | ||
| 111 | - return flag ? str : ''; | ||
| 112 | -} | ||
| 113 | - | ||
| 114 | -// 转换字符串,undefined,null等转化为"" | ||
| 115 | -export function praseStrEmpty(str) { | ||
| 116 | - if (!str || str == "undefined" || str == "null") { | ||
| 117 | - return ""; | ||
| 118 | - } | ||
| 119 | - return str; | ||
| 120 | -} | ||
| 121 | - | ||
| 122 | -/** | ||
| 123 | - * 构造树型结构数据 | ||
| 124 | - * @param {*} data 数据源 | ||
| 125 | - * @param {*} id id字段 默认 'id' | ||
| 126 | - * @param {*} parentId 父节点字段 默认 'parentId' | ||
| 127 | - * @param {*} children 孩子节点字段 默认 'children' | ||
| 128 | - * @param {*} rootId 根Id 默认 0 | ||
| 129 | - */ | ||
| 130 | -export function handleTree(data, id, parentId, children, rootId) { | ||
| 131 | - id = id || 'id' | ||
| 132 | - parentId = parentId || 'parentId' | ||
| 133 | - children = children || 'children' | ||
| 134 | - rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0 | ||
| 135 | - //对源数据深度克隆 | ||
| 136 | - const cloneData = JSON.parse(JSON.stringify(data)) | ||
| 137 | - //循环所有项 | ||
| 138 | - const treeData = cloneData.filter(father => { | ||
| 139 | - let branchArr = cloneData.filter(child => { | ||
| 140 | - //返回每一项的子级数组 | ||
| 141 | - return father[id] === child[parentId] | ||
| 142 | - }); | ||
| 143 | - branchArr.length > 0 ? father.children = branchArr : ''; | ||
| 144 | - //返回第一层 | ||
| 145 | - return father[parentId] === rootId; | ||
| 146 | - }); | ||
| 147 | - return treeData != '' ? treeData : data; | ||
| 148 | -} | 1 | +/** |
| 2 | + * 通用js方法封装处理 | ||
| 3 | + * Copyright (c) 2019 ruoyi | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +const baseURL = process.env.VUE_APP_BASE_API | ||
| 7 | + | ||
| 8 | +// 日期格式化 | ||
| 9 | +export function parseTime(time, pattern) { | ||
| 10 | + if (arguments.length === 0 || !time) { | ||
| 11 | + return null | ||
| 12 | + } | ||
| 13 | + const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' | ||
| 14 | + let date | ||
| 15 | + if (typeof time === 'object') { | ||
| 16 | + date = time | ||
| 17 | + } else { | ||
| 18 | + if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { | ||
| 19 | + time = parseInt(time) | ||
| 20 | + } else if (typeof time === 'string') { | ||
| 21 | + time = time.replace(new RegExp(/-/gm), '/'); | ||
| 22 | + } | ||
| 23 | + if ((typeof time === 'number') && (time.toString().length === 10)) { | ||
| 24 | + time = time * 1000 | ||
| 25 | + } | ||
| 26 | + date = new Date(time) | ||
| 27 | + } | ||
| 28 | + const formatObj = { | ||
| 29 | + y: date.getFullYear(), | ||
| 30 | + m: date.getMonth() + 1, | ||
| 31 | + d: date.getDate(), | ||
| 32 | + h: date.getHours(), | ||
| 33 | + i: date.getMinutes(), | ||
| 34 | + s: date.getSeconds(), | ||
| 35 | + a: date.getDay() | ||
| 36 | + } | ||
| 37 | + const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { | ||
| 38 | + let value = formatObj[key] | ||
| 39 | + // Note: getDay() returns 0 on Sunday | ||
| 40 | + if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] } | ||
| 41 | + if (result.length > 0 && value < 10) { | ||
| 42 | + value = '0' + value | ||
| 43 | + } | ||
| 44 | + return value || 0 | ||
| 45 | + }) | ||
| 46 | + return time_str | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +// 表单重置 | ||
| 50 | +export function resetForm(refName) { | ||
| 51 | + if (this.$refs[refName]) { | ||
| 52 | + this.$refs[refName].resetFields(); | ||
| 53 | + } | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// 添加日期范围 | ||
| 57 | +export function addDateRange(params, dateRange) { | ||
| 58 | + var search = params; | ||
| 59 | + search.beginTime = ""; | ||
| 60 | + search.endTime = ""; | ||
| 61 | + if (null != dateRange && '' != dateRange) { | ||
| 62 | + search.beginTime = dateRange[0]; | ||
| 63 | + search.endTime = dateRange[1]; | ||
| 64 | + } | ||
| 65 | + return search; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +// 回显数据字典 | ||
| 69 | +export function selectDictLabel(datas, value) { | ||
| 70 | + var actions = []; | ||
| 71 | + Object.keys(datas).some((key) => { | ||
| 72 | + if (datas[key].dictValue == ('' + value)) { | ||
| 73 | + actions.push(datas[key].dictLabel); | ||
| 74 | + return true; | ||
| 75 | + } | ||
| 76 | + }) | ||
| 77 | + return actions.join(''); | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +// 回显数据字典(字符串数组) | ||
| 81 | +export function selectDictLabels(datas, value, separator) { | ||
| 82 | + var actions = []; | ||
| 83 | + var currentSeparator = undefined === separator ? "," : separator; | ||
| 84 | + var temp = value.split(currentSeparator); | ||
| 85 | + Object.keys(value.split(currentSeparator)).some((val) => { | ||
| 86 | + Object.keys(datas).some((key) => { | ||
| 87 | + if (datas[key].dictValue == ('' + temp[val])) { | ||
| 88 | + actions.push(datas[key].dictLabel + currentSeparator); | ||
| 89 | + } | ||
| 90 | + }) | ||
| 91 | + }) | ||
| 92 | + return actions.join('').substring(0, actions.join('').length - 1); | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +// 通用下载方法 | ||
| 96 | +export function download(fileName) { | ||
| 97 | + window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true; | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +// 字符串格式化(%s ) | ||
| 101 | +export function sprintf(str) { | ||
| 102 | + var args = arguments, flag = true, i = 1; | ||
| 103 | + str = str.replace(/%s/g, function () { | ||
| 104 | + var arg = args[i++]; | ||
| 105 | + if (typeof arg === 'undefined') { | ||
| 106 | + flag = false; | ||
| 107 | + return ''; | ||
| 108 | + } | ||
| 109 | + return arg; | ||
| 110 | + }); | ||
| 111 | + return flag ? str : ''; | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +// 转换字符串,undefined,null等转化为"" | ||
| 115 | +export function praseStrEmpty(str) { | ||
| 116 | + if (!str || str == "undefined" || str == "null") { | ||
| 117 | + return ""; | ||
| 118 | + } | ||
| 119 | + return str; | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +/** | ||
| 123 | + * 构造树型结构数据 | ||
| 124 | + * @param {*} data 数据源 | ||
| 125 | + * @param {*} id id字段 默认 'id' | ||
| 126 | + * @param {*} parentId 父节点字段 默认 'parentId' | ||
| 127 | + * @param {*} children 孩子节点字段 默认 'children' | ||
| 128 | + * @param {*} rootId 根Id 默认 0 | ||
| 129 | + */ | ||
| 130 | +export function handleTree(data, id, parentId, children, rootId) { | ||
| 131 | + id = id || 'id' | ||
| 132 | + parentId = parentId || 'parentId' | ||
| 133 | + children = children || 'children' | ||
| 134 | + rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0 | ||
| 135 | + //对源数据深度克隆 | ||
| 136 | + const cloneData = JSON.parse(JSON.stringify(data)) | ||
| 137 | + //循环所有项 | ||
| 138 | + const treeData = cloneData.filter(father => { | ||
| 139 | + let branchArr = cloneData.filter(child => { | ||
| 140 | + //返回每一项的子级数组 | ||
| 141 | + return father[id] === child[parentId] | ||
| 142 | + }); | ||
| 143 | + branchArr.length > 0 ? father.children = branchArr : ''; | ||
| 144 | + //返回第一层 | ||
| 145 | + return father[parentId] === rootId; | ||
| 146 | + }); | ||
| 147 | + return treeData != '' ? treeData : data; | ||
| 148 | +} |
-
请 注册 或 登录 后发表评论