commit:支持activiti

This commit is contained in:
Jerry
2021-10-20 17:43:53 +08:00
parent b772e75de6
commit 00cc13b87d
861 changed files with 219314 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
const defaultLineChartOption = {
grid: {
left: '3%',
right: '4%',
bottom: '20px',
containLabel: true
},
xAxis: {
axisLabel: {
interval: 0,
showMaxLabel: true
}
},
legend: {
top: '3%'
}
}
const defaultBarChartOption = {
grid: {
left: '3%',
right: '4%',
bottom: '20px',
containLabel: true
},
xAxis: {
axisLabel: {
interval: 0,
showMaxLabel: true
}
},
legend: {
top: '3%'
}
}
const defaultPieChartOption = {
grid: {
left: '3%',
right: '4%',
bottom: '20px',
containLabel: true
},
legend: {
top: '3%'
},
series: {
center: ['50%', '60%']
}
}
export {
defaultLineChartOption,
defaultBarChartOption,
defaultPieChartOption
}

View File

@@ -0,0 +1,442 @@
import JSEncrypt from 'jsencrypt';
// eslint-disable-next-line no-unused-vars
// import Cookies from 'js-cookie';
/**
* 列表数据转换树形数据
* @param {Array} data 要转换的列表
* @param {String} id 主键字段字段名
* @param {String} pid 父字段字段名
* @returns {Array} 转换后的树数据
*/
export function treeDataTranslate (data, id = 'id', pid = 'parentId') {
var res = []
var temp = {}
for (var i = 0; i < data.length; i++) {
temp[data[i][id]] = data[i]
}
for (var k = 0; k < data.length; k++) {
if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
if (!temp[data[k][pid]]['children']) {
temp[data[k][pid]]['children'] = []
}
if (!temp[data[k][pid]]['_level']) {
temp[data[k][pid]]['_level'] = 1
}
data[k]['_level'] = temp[data[k][pid]]._level + 1
data[k]['_parent'] = data[k][pid]
temp[data[k][pid]]['children'].push(data[k])
} else {
res.push(data[k])
}
}
return res
}
/**
* 获取字符串字节长度中文算2个字符
* @param {String} str 要获取长度的字符串
*/
export function getStringLength (str) {
return str.replace(/[\u4e00-\u9fa5\uff00-\uffff]/g, '**').length
}
/**
* 获取uuid
*/
export function getUUID () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
});
}
/**
* 大小驼峰变换函数
* @param name 要转换的字符串
* @param type 转换的类型0转换成小驼峰1转换成大驼峰
*/
export function nameTranslate (name, type) {
name = name.toLowerCase();
let nameArray = name.split('_');
nameArray.forEach((item, index) => {
if (index === 0) {
name = type === 1 ? item.slice(0, 1).toUpperCase() + item.slice(1) : item;
} else {
name = name + item.slice(0, 1).toUpperCase() + item.slice(1);
}
});
nameArray = name.split('-');
nameArray.forEach((item, index) => {
if (index === 0) {
name = type === 1 ? item.slice(0, 1).toUpperCase() + item.slice(1) : item;
} else {
name = name + item.slice(0, 1).toUpperCase() + item.slice(1);
}
});
return name;
}
/**
* 通过id从树中获取指定的节点
* @param {Object} node 根节点
* @param {String|Nubmer} id 键值
* @param {Array} list 保存查询路径
* @param {String} idKey 主键字段名
* @param {String} childKey 子节点字段名
*/
function findNode (node, id, list, idKey = 'id', childKey = 'children') {
if (Array.isArray(list)) list.push(node[idKey]);
if (node[idKey] === id) {
return node;
}
if (node[childKey] != null && Array.isArray(node[childKey])) {
for (let i = 0; i < node[childKey].length; i++) {
let tempNode = findNode(node[childKey][i], id, list, idKey, childKey);
if (tempNode) return tempNode;
}
}
if (Array.isArray(list)) list.pop();
}
/**
* 通过id返回从根节点到指定节点的路径
* @param {Array} treeRoot 树根节点数组
* @param {*} id 要查询的节点的id
* @param {*} idKey 主键字段名
* @param {*} childKey 子节点字段名
*/
export function findTreeNodePath (treeRoot, id, idKey = 'id', childKey = 'children') {
let tempList = [];
for (let i = 0; i < treeRoot.length; i++) {
if (findNode(treeRoot[i], id, tempList, idKey, childKey)) {
return tempList;
}
}
return [];
}
/**
* 通过id从树中查找节点
* @param {Array} treeRoot 根节点数组
* @param {*} id 要查找的节点的id
* @param {*} idKey 主键字段名
* @param {*} childKey 子节点字段名
*/
export function findTreeNode (treeRoot, id, idKey = 'id', childKey = 'children') {
for (let i = 0; i < treeRoot.length; i++) {
let tempNode = findNode(treeRoot[i], id, undefined, idKey, childKey);
if (tempNode) return tempNode;
}
}
/**
* 把Object转换成query字符串
* @param {Object} params 要转换的Object
*/
export function objectToQueryString (params) {
if (params == null) {
return null;
} else {
return Object.keys(params).map((key) => {
if (params[key] !== undefined) {
return `${key}=${params[key]}`;
} else {
return undefined;
}
}).filter(item => item != null).join('&');
}
}
/**
* 从数组中查找某一项
* @param {Array} list 要查找的数组
* @param {String} id 要查找的节点id
* @param {String} idKey 主键字段名如果为null则直接比较
* @param {Boolean} removeItem 是否从数组中移除查找到的节点
* @returns {Object} 找到返回节点没找到返回undefined
*/
export function findItemFromList (list, id, idKey, removeItem = false) {
if (Array.isArray(list) && list.length > 0 && id != null) {
for (let i = 0; i < list.length; i++) {
let item = list[i];
if (((idKey == null || idKey === '') && item === id) || (idKey != null && item[idKey] === id)) {
if (removeItem) list.splice(i, 1);
return item;
}
}
}
return null;
}
/**
* 将数据保存到sessionStorage
* @param {*} key sessionStorage的键值
* @param {*} value 要保存的数据
*/
export function setObjectToSessionStorage (key, value) {
if (key == null || key === '') return false;
if (value == null) {
window.sessionStorage.removeItem(key);
return true;
} else {
let jsonObj = {
data: value
}
window.sessionStorage.setItem(key, JSON.stringify(jsonObj));
return true;
}
}
/**
* 从sessionStorage里面获取数据
* @param {String} key 键值
* @param {*} defaultValue 默认值
*/
export function getObjectFromSessionStorage (key, defaultValue) {
let jsonObj = null;
try {
jsonObj = JSON.parse(window.sessionStorage.getItem(key));
jsonObj = (jsonObj || {}).data;
} catch (e) {
jsonObj = defaultValue;
};
return (jsonObj != null) ? jsonObj : defaultValue;
}
/**
* 判读字符串是否一个数字
* @param {String} str 要判断的字符串
*/
export function isNumber (str) {
let num = Number.parseFloat(str);
if (Number.isNaN(num)) return false;
return num.toString() === str;
}
/**
* 生成随机数
* @param {Integer} min 随机数最小值
* @param {Integer} max 随机数最大值
*/
export function random (min, max) {
let base = Math.random();
return min + base * (max - min);
}
/**
* 加密
* @param {*} value 要加密的字符串
*/
const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpC4QMnbTrQOFriJJCCFFWhlruBJThAEBfRk7pRx1jsAhyNVL3CqJb0tRvpnbCnJhrRAEPdgFHXv5A0RrvFp+5Cw7QoFH6O9rKB8+0H7+aVQeKITMUHf/XMXioymw6Iq4QfWd8RhdtM1KM6eGTy8aU7SO2s69Mc1LXefg/x3yw6wIDAQAB';
export function encrypt (value) {
if (value == null || value === '') return null;
let encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);
return encodeURIComponent(encrypt.encrypt(value));
}
export function getToken () {
return sessionStorage.getItem('token');
// return Cookies.get('token');
}
export function setToken (token) {
if (token == null || token === '') {
sessionStorage.removeItem('token');
// Cookies.remove('token');
} else {
sessionStorage.setItem('token', token);
// Cookies.set('token', token);
}
}
export function traversalTree (treeNode, callback, childrenKey = 'children') {
if (treeNode != null && Array.isArray(treeNode[childrenKey]) && treeNode[childrenKey].length > 0) {
treeNode[childrenKey].forEach(childNode => {
traversalTree(childNode, callback, childrenKey);
});
}
return typeof callback === 'function' ? callback(treeNode) : undefined;
}
export class TreeTableImpl {
constructor (dataList, options) {
this.options = {
idKey: options ? options.idKey : 'id',
nameKey: options ? options.nameKey : 'name',
parentIdKey: options ? options.parentIdKey : 'parentId',
isLefeCallback: options ? options.isLefeCallback : undefined,
checkStrictly: options ? options.checkStrictly : false
}
this.dataList = Array.isArray(dataList) ? dataList : [];
this.dataMap = new Map();
this.dataList.forEach(item => {
this.dataMap.set(item[this.options.idKey], item);
});
// 表格选中行
this.checkedRows = undefined;
this.onCheckedRowChange = this.onCheckedRowChange.bind(this);
}
/**
* 过滤表格数据
* @param {string} filterString 过滤条件字符串
* @param {boolean} onlyChecked 是否只显示选中节点
* @returns {array} 过滤后的表格数据列表
*/
getFilterTableData (filterString, onlyChecked = false) {
let { idKey, nameKey, parentIdKey, isLefeCallback } = this.options;
let tempMap = new Map();
let parentIdList = [];
this.dataList.forEach(item => {
if ((filterString == null || filterString === '' || item[nameKey].indexOf(filterString) !== -1) &&
(!onlyChecked || (this.checkedRows != null && this.checkedRows.get(item[idKey])))) {
if (isLefeCallback == null || !isLefeCallback(item)) {
parentIdList.push(item[idKey]);
}
// 将命中节点以及它的父节点都设置为命中
let tempItem = item;
do {
tempMap.set(tempItem[idKey], tempItem);
tempItem = this.dataMap.get(tempItem[parentIdKey]);
} while (tempItem != null)
}
});
return this.dataList.map(item => {
let disabled = true;
if (parentIdList.indexOf(item[parentIdKey]) !== -1 || tempMap.get(item[idKey]) != null) {
if (parentIdList.indexOf(item[parentIdKey]) !== -1 && (isLefeCallback == null || !isLefeCallback(item))) {
parentIdList.push(item[idKey]);
}
disabled = false;
}
return {
...item,
__disabled: disabled
}
});
}
/**
* 获取表格树数据,计算选中状态
* @param {array} dataList 表格列表数据
*/
getTableTreeData (dataList, checkedRows) {
let { idKey, parentIdKey, checkStrictly } = this.options;
let treeData = [];
function calcPermCodeTreeAttribute (treeNode, checkedRows) {
let checkedItem = checkedRows == null ? null : checkedRows.get(treeNode[idKey]);
treeNode.__checked = checkedItem != null;
// 是否所有子权限字都被选中
let allChildChecked = true;
// 是否任意子权限字被选中
let hasChildChecked = false;
// 如果存在子权限字
if (Array.isArray(treeNode.children) && treeNode.children.length > 0) {
treeNode.children.forEach(item => {
let isChecked = calcPermCodeTreeAttribute(item, checkedRows);
hasChildChecked = hasChildChecked || isChecked;
allChildChecked = allChildChecked && isChecked;
});
} else {
allChildChecked = false;
}
treeNode.__indeterminate = !checkStrictly && hasChildChecked && !allChildChecked;
treeNode.__checked = treeNode.__checked || (allChildChecked && !checkStrictly);
return treeNode.__checked || treeNode.__indeterminate;
}
if (Array.isArray(dataList)) {
treeData = treeDataTranslate(dataList.map(item => {
return {...item};
}), idKey, parentIdKey);
treeData.forEach(item => {
calcPermCodeTreeAttribute(item, checkedRows);
});
}
return treeData;
}
/**
* 树表格行选中状态改变
* @param {object} row 选中状态改变行数据
*/
onCheckedRowChange (row) {
if (this.checkedRows == null) {
this.checkedRows = new Map();
} else {
let temp = new Map();
this.checkedRows.forEach((item, key) => {
temp.set(key, item);
});
this.checkedRows = temp;
}
let { idKey } = this.options;
if (!row.__checked || row.__indeterminate) {
// 节点之前未被选中或者之前为半选状态,修改当前节点以及子节点为选中状态
this.checkedRows.set(row[idKey], row);
if (Array.isArray(row.children) && !this.options.checkStrictly) {
row.children.forEach(childNode => {
traversalTree(childNode, (node) => {
this.checkedRows.set(node[idKey], node);
});
});
}
} else {
// 节点之前为选中状态,修改节点以及子节点为未选中状态
this.checkedRows.delete(row[idKey]);
if (Array.isArray(row.children) && !this.options.checkStrictly) {
row.children.forEach(childNode => {
traversalTree(childNode, (node) => {
this.checkedRows.delete(node[idKey]);
});
});
}
}
}
/**
* 获取所有选中的权限字节点
* @param {array} treeData 树数据
* @param {boolean} includeHalfChecked 是否包含半选节点默认为false
* @returns {array} 选中节点列表
*/
getCheckedRows (treeData, includeHalfChecked = false) {
let checkedRows = [];
function traversalCallback (node) {
if (node == null) return;
if (node.__checked || (includeHalfChecked && node.__indeterminate)) {
checkedRows.push(node);
}
}
if (Array.isArray(treeData) && treeData.length > 0) {
treeData.forEach(permCode => {
traversalTree(permCode, traversalCallback, 'children');
});
}
return checkedRows;
}
/**
* 设置选中节点
* @param {array} checkedRows
*/
setCheckedRows (checkedRows) {
this.checkedRows = new Map();
if (Array.isArray(checkedRows)) {
checkedRows.forEach(item => {
let node = this.dataMap.get(item[this.options.idKey]);
if (node != null) {
this.checkedRows.set(node[this.options.idKey], node);
}
});
}
}
/**
* 根据id获取表格行
* @param {*} id
*/
getTableRow (id) {
return this.dataMap.get(id);
}
}

View File

@@ -0,0 +1,33 @@
const pattern = {
mobie: /^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/,
english: /^[a-zA-Z]+$/,
englishAndNumber: /^[a-zA-Z0-9]+$/
}
/**
* 邮箱
* @param str
*/
export function isEmail (str) {
return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(str)
}
/**
* 手机号码
* @param str
*/
export function isMobile (str) {
return pattern.mobie.test(str)
}
/**
* 电话号码
* @param str
*/
export function isPhone (str) {
return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(str)
}
export default {
pattern
}

View File

@@ -0,0 +1,322 @@
import { Message } from 'element-ui';
import { treeDataTranslate } from '@/utils';
const DEFAULT_PAGE_SIZE = 10;
export class DropdownWidget {
/**
* 下拉组件Select、Cascade、TreeSelect、Tree等
* @param {function () : Promise} loadDropdownData 下拉数据获取函数
* @param {Boolean} isTree 是否是树数据
* @param {String} idKey 键字段字段名
* @param {String} parentIdKey 父字段字段名
*/
constructor (loadDropdownData, isTree = false, idKey = 'id', parentIdKey = 'parentId') {
this.loading = false;
this.dirty = true;
this.dropdownList = [];
this.isTree = isTree;
this.idKey = idKey;
this.parentIdKey = parentIdKey;
this.loadDropdownData = loadDropdownData;
this.setDropdownList = this.setDropdownList.bind(this);
this.onVisibleChange = this.onVisibleChange.bind(this);
}
/**
* 重新获取下拉数据
*/
reloadDropdownData () {
return new Promise((resolve, reject) => {
if (!this.loading) {
if (typeof this.loadDropdownData === 'function') {
this.loading = true;
this.loadDropdownData().then(dataList => {
this.setDropdownList(dataList);
this.loading = false;
this.dirty = false;
resolve(this.dropdownList);
}).catch(e => {
this.setDropdownList([]);
this.loading = false;
reject(this.dropdownList);
});
} else {
reject(new Error('获取下拉数据失败'));
}
} else {
resolve(this.dropdownList);
}
});
}
/**
* 下拉框显示或隐藏时调用
* @param {Boolean} isShow 正在显示或者隐藏
*/
onVisibleChange (isShow) {
return new Promise((resolve, reject) => {
if (isShow && this.dirty && !this.loading) {
this.reloadDropdownData().then(res => {
resolve(res);
}).catch(e => {
reject(e);
});
} else {
resolve(this.dropdownList);
}
});
}
/**
* 设置下拉数据
* @param {Array} dataList 要显示的下拉数据
*/
setDropdownList (dataList) {
if (Array.isArray(dataList)) {
this.dropdownList = this.isTree ? treeDataTranslate(dataList, this.idKey, this.parentIdKey) : dataList;
}
}
}
export class TableWidget {
/**
* 表格组件
* @param {function (params: Object) : Promise} loadTableData 表数据获取函数
* @param {function () : Boolean} verifyTableParameter 表数据获取检验函数
* @param {Boolean} paged 是否支持分页
* @param {Boolean} rowSelection 是否支持行选择
* @param {String} orderFieldName 默认排序字段
* @param {Boolean} ascending 默认排序方式true为正序false为倒序
* @param {String} dateAggregateBy 默认排序字段的日期统计类型
*/
constructor (loadTableData, verifyTableParameter, paged, rowSelection, orderFieldName, ascending, dateAggregateBy) {
this.currentRow = null;
this.loading = false;
this.oldPage = 0;
this.currentPage = 1;
this.oldPageSize = DEFAULT_PAGE_SIZE;
this.pageSize = DEFAULT_PAGE_SIZE;
this.totalCount = 0;
this.dataList = [];
this.orderInfo = {
fieldName: orderFieldName,
asc: ascending,
dateAggregateBy: dateAggregateBy
};
this.paged = paged;
this.rowSelection = rowSelection;
this.searchVerify = verifyTableParameter || function () { return true; };
this.loadTableData = loadTableData || function () { return Promise.resolve(); };
this.onCurrentPageChange = this.onCurrentPageChange.bind(this);
this.onPageSizeChange = this.onPageSizeChange.bind(this);
this.onSortChange = this.onSortChange.bind(this);
this.getTableIndex = this.getTableIndex.bind(this);
this.currentRowChange = this.currentRowChange.bind(this);
}
/**
* 表格分页变化
* @param {Integer} newCurrentPage 变化后的显示页面
*/
onCurrentPageChange (newCurrentPage) {
this.loadTableDataImpl(newCurrentPage, this.pageSize).then(() => {
this.oldPage = this.currentPage = newCurrentPage;
}).catch(() => {
this.currentPage = this.oldPage;
});
}
/**
* 表格分页每页显示数量变化
* @param {Integer} newPageSize 变化后的每页显示数量
*/
onPageSizeChange (newPageSize) {
this.pageSize = newPageSize;
this.currentPage = 1
this.loadTableDataImpl(1, newPageSize).then(() => {
this.oldPage = this.currentPage;
this.oldPageSize = this.pageSize;
}).catch(e => {
this.currentPage = this.oldPage;
this.pageSize = this.oldPageSize;
});
}
/**
* 表格排序字段变化
* @param {String} prop 排序字段的字段名
* @param {String} order 正序还是倒序
*/
onSortChange ({ prop, order }) {
this.orderInfo.fieldName = prop;
this.orderInfo.asc = (order === 'ascending');
this.refreshTable();
}
/**
* 获取每一行的index信息
* @param {Integer} index 表格在本页位置
*/
getTableIndex (index) {
return this.paged ? ((this.currentPage - 1) * this.pageSize + (index + 1)) : (index + 1);
}
/**
* 当前选中行改变
* @param {Object} currentRow 当前选中行
* @param {Object} oldRow 老的选中行
*/
currentRowChange (currentRow, oldRow) {
this.currentRow = currentRow;
}
clearTable () {
this.currentRow = null;
this.oldPage = 0;
this.currentPage = 1;
this.totalCount = 0;
this.dataList = [];
}
/**
* 获取表格数据
* @param {Integer} pageNum 当前分页
* @param {Integer} pageSize 每页数量
* @param {Boolean} reload 是否重新获取数据
*/
loadTableDataImpl (pageNum, pageSize, reload = false) {
return new Promise((resolve, reject) => {
if (typeof this.loadTableData !== 'function') {
reject();
} else {
// 如果pageSize和pageNum没有变化并且不强制刷新
if (this.paged && !reload && this.oldPage === pageNum && this.oldPageSize === pageSize) {
resolve();
} else {
let params = {};
if (this.orderInfo.fieldName != null) params.orderParam = [this.orderInfo];
if (this.paged) {
params.pageParam = {
pageNum,
pageSize
}
}
this.loading = true;
this.loadTableData(params).then(tableData => {
this.dataList = tableData.dataList;
this.totalCount = tableData.totalCount;
this.loading = false;
resolve();
}).catch(e => {
this.loading = false;
reject(e);
});
}
}
});
}
/**
* 刷新表格数据
* @param {Boolean} research 是否按照新的查询条件重新查询调用verify函数
* @param {Integer} pageNum 当前页面
*/
refreshTable (research = false, pageNum = undefined, showMsg = false) {
let reload = false;
if (research) {
if (typeof this.searchVerify === 'function' && !this.searchVerify()) return;
reload = true;
}
if (Number.isInteger(pageNum) && pageNum !== this.currentPage) {
this.loadTableDataImpl(pageNum, this.pageSize, reload).then(res => {
this.oldPage = this.currentPage = pageNum;
if (research && showMsg) Message.success('查询成功');
}).catch(e => {
this.currentPage = this.oldPage;
});
} else {
this.loadTableDataImpl(this.currentPage, this.pageSize, true).catch(e => {});
}
}
}
export class UploadWidget {
/**
* 上传组件
* @param {Integer} maxCount 最大上传数量
*/
constructor (maxCount = 1) {
this.maxCount = maxCount;
this.fileList = [];
this.onFileChange = this.onFileChange.bind(this);
}
/**
* 上传文件列表改变
* @param {Object} file 改变的文件
* @param {Array} fileList 改变后的文件列表
*/
onFileChange (file, fileList) {
if (Array.isArray(fileList) && fileList.length > 0) {
if (this.maxCount === 1) {
this.fileList = [fileList[fileList.length - 1]];
} else {
this.fileList = fileList;
}
} else {
this.fileList = undefined;
}
return this.fileList;
}
}
export class ChartWidget {
/**
* 图表组件
* @param {function (params) : Promise} loadTableData chart数据获取函数
* @param {function () : Boolean} verifyTableParameter 数据参数检验函数
* @param {Array} columns 数据列
*/
constructor (loadTableData, verifyTableParameter, columns) {
this.columns = columns;
this.loading = false;
this.dataEmpty = false;
this.chartData = undefined;
this.chartObject = undefined;
this.dimensionMaps = new Map();
this.chartSetting = undefined;
this.searchVerify = verifyTableParameter || function () { return true; };
this.loadTableData = loadTableData || function () { return Promise.resolve(); };
}
/**
* 获取图表数据
* @param {Boolean} reload 是否重新获取数据
*/
loadChartDataImpl (reload = false) {
return new Promise((resolve, reject) => {
if (typeof this.loadTableData !== 'function') {
reject();
} else {
if (!reload) {
resolve();
} else {
this.loading = true;
this.loadTableData().then(tableData => {
this.chartData = {
columns: this.columns,
rows: tableData.dataList
}
this.loading = false;
if (this.chartObject) this.chartObject.resize();
resolve();
}).catch(e => {
console.error(e);
this.loading = false;
reject(e);
});
}
}
});
}
/**
* 刷新图表数据
* @param {Boolean} research 是否按照新的查询条件重新查询调用verify函数
*/
refreshChart (research = false) {
if (research) {
if (typeof this.searchVerify === 'function' && !this.searchVerify()) return;
}
this.loadChartDataImpl(true).catch(e => {});
}
}