/* global window */import classnames from 'classnames'import lodash from 'lodash'import config from './config'import request from './request'import { color } from './theme'// 连字符转驼峰String.prototype.hyphenToHump = function () {return this.replace(/-(\w)/g, (...args) => {return args[1].toUpperCase()})}// 驼峰转连字符String.prototype.humpToHyphen = function () {return this.replace(/([A-Z])/g, '-1ドル').toLowerCase()}// 日期格式化Date.prototype.format = function (format) {const o = {'M+': this.getMonth() + 1,'d+': this.getDate(),'h+': this.getHours(),'H+': this.getHours(),'m+': this.getMinutes(),'s+': this.getSeconds(),'q+': Math.floor((this.getMonth() + 3) / 3),S: this.getMilliseconds(),}if (/(y+)/.test(format)) {format = format.replace(RegExp.1ドル, `${this.getFullYear()}`.substr(4 - RegExp.1ドル.length))}for (let k in o) {if (new RegExp(`(${k})`).test(format)) {format = format.replace(RegExp.1ドル, RegExp.1ドル.length === 1 ? o[k] : (`00${o[k]}`).substr(`${o[k]}`.length))}}return format}/*** @param {String}* @return {String}*/const queryURL = (name) => {let reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`, 'i')let r = window.location.search.substr(1).match(reg)if (r != null) return decodeURI(r[2])return null}/*** 数组内查询* @param {array} array* @param {String} id* @param {String} keyAlias* @return {Array}*/const queryArray = (array, key, keyAlias = 'key') => {if (!(array instanceof Array)) {return null}const item = array.filter(_ => _[keyAlias] === key)if (item.length) {return item[0]}return null}/*** 数组格式转树状结构* @param {array} array* @param {String} id* @param {String} pid* @param {String} children* @return {Array}*/const arrayToTree = (array, id = 'id', pid = 'pid', children = 'children') => {let data = lodash.cloneDeep(array)let result = []let hash = {}data.forEach((item, index) => {hash[data[index][id]] = data[index]})data.forEach((item) => {let hashVP = hash[item[pid]]if (hashVP) {!hashVP[children] && (hashVP[children] = [])hashVP[children].push(item)} else {result.push(item)}})return result}const treeToArray=(tree)=>{let array=[]tree.map((item) => {if (item.roleModuleTrees.length>0) {item.children=item.roleModuleTreesitem.roleModuleTrees.map((childItem)=>{if(childItem.roleModuleTrees.length>0){childItem.children=childItem.roleModuleTreeschildItem.roleModuleTrees.map((childChildItem)=>{childChildItem.id=childChildItem.moduleIdchildChildItem.name=childChildItem.moduleNamechildChildItem.route=childChildItem.urlchildChildItem.bpid=childItem.idchildChildItem.mpid=childItem.idarray.push(item)})}childItem.id=childItem.moduleIdchildItem.name=item.moduleNamechildItem.route=item.urlchildItem.bpid=item.idchildItem.mpid=item.idarray.push(item)})}item.id=item.moduleIditem.name=item.moduleNamearray.push(item)})return array;}module.exports = {config,request,color,classnames,queryURL,queryArray,treeToArray,arrayToTree,}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。