vue版本上线
This commit is contained in:
113
jshERP-web/src/utils/JEditableTableUtil.js
Normal file
113
jshERP-web/src/utils/JEditableTableUtil.js
Normal file
@@ -0,0 +1,113 @@
|
||||
const FormTypes = {
|
||||
normal: 'normal',
|
||||
input: 'input',
|
||||
inputNumber: 'inputNumber',
|
||||
checkbox: 'checkbox',
|
||||
select: 'select',
|
||||
date: 'date',
|
||||
datetime: 'datetime',
|
||||
upload: 'upload',
|
||||
file: 'file',
|
||||
image: 'image',
|
||||
popup:'popup',
|
||||
popupJsh:'popupJsh',
|
||||
list_multi:"list_multi",
|
||||
sel_search:"sel_search",
|
||||
radio:'radio',
|
||||
checkbox_meta:"checkbox_meta",
|
||||
input_pop:'input_pop',
|
||||
slot: 'slot',
|
||||
hidden: 'hidden'
|
||||
}
|
||||
const VALIDATE_NO_PASSED = Symbol()
|
||||
export { FormTypes, VALIDATE_NO_PASSED }
|
||||
|
||||
/**
|
||||
* 获取指定的 $refs 对象
|
||||
* 有时候可能会遇到组件未挂载到页面中的情况,导致无法获取 $refs 中的某个对象
|
||||
* 这个方法可以等待挂载完成之后再返回 $refs 的对象,避免报错
|
||||
* @author sunjianlei
|
||||
**/
|
||||
export function getRefPromise(vm, name) {
|
||||
return new Promise((resolve) => {
|
||||
(function next() {
|
||||
let ref = vm.$refs[name]
|
||||
if (ref) {
|
||||
resolve(ref)
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
next()
|
||||
}, 10)
|
||||
}
|
||||
})()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 一次性验证主表单和所有的次表单
|
||||
* @param form 主表单 form 对象
|
||||
* @param cases 接收一个数组,每项都是一个JEditableTable实例
|
||||
* @returns {Promise<any>}
|
||||
* @author sunjianlei
|
||||
*/
|
||||
export function validateFormAndTables(form, cases) {
|
||||
|
||||
if (!(form && typeof form.validateFields === 'function')) {
|
||||
throw `form 参数需要的是一个form对象,而传入的却是${typeof form}`
|
||||
}
|
||||
|
||||
let options = {}
|
||||
return new Promise((resolve, reject) => {
|
||||
// 验证主表表单
|
||||
form.validateFields((err, values) => {
|
||||
err ? reject({ error: VALIDATE_NO_PASSED }) : resolve(values)
|
||||
})
|
||||
}).then(values => {
|
||||
Object.assign(options, { formValue: values })
|
||||
// 验证所有子表的表单
|
||||
return validateTables(cases)
|
||||
}).then(all => {
|
||||
Object.assign(options, { tablesValue: all })
|
||||
return Promise.resolve(options)
|
||||
}).catch(error => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证并获取一个或多个表格的所有值
|
||||
* @param cases 接收一个数组,每项都是一个JEditableTable实例
|
||||
* @param deleteTempId 是否删除临时ID,如果设为true,行编辑就不返回新增行的ID,ID需要后台生成
|
||||
* @author sunjianlei
|
||||
*/
|
||||
export function validateTables(cases, deleteTempId) {
|
||||
if (!(cases instanceof Array)) {
|
||||
throw `'validateTables'函数的'cases'参数需要的是一个数组,而传入的却是${typeof cases}`
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
let tables = []
|
||||
let index = 0;
|
||||
if(!cases || cases.length==0){
|
||||
resolve()
|
||||
}
|
||||
(function next() {
|
||||
let vm = cases[index]
|
||||
vm.getAll(true, deleteTempId).then(all => {
|
||||
tables[index] = all
|
||||
// 判断校验是否全部完成,完成返回成功,否则继续进行下一步校验
|
||||
if (++index === cases.length) {
|
||||
resolve(tables)
|
||||
} else (
|
||||
next()
|
||||
)
|
||||
}, error => {
|
||||
// 出现未验证通过的表单,不再进行下一步校验,直接返回失败并跳转到该表格
|
||||
if (error === VALIDATE_NO_PASSED) {
|
||||
reject({ error: VALIDATE_NO_PASSED, index })
|
||||
}
|
||||
reject(error)
|
||||
})
|
||||
})()
|
||||
})
|
||||
}
|
||||
107
jshERP-web/src/utils/LunarFullCalendarUtil.js
Normal file
107
jshERP-web/src/utils/LunarFullCalendarUtil.js
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* LunarFullCalendar 公共 js
|
||||
*
|
||||
* @version 1.0.0
|
||||
* @author sunjianlei
|
||||
*
|
||||
* */
|
||||
|
||||
import { getRefPromise } from '@/utils/JEditableTableUtil'
|
||||
|
||||
/* 日历的视图类型 */
|
||||
const calendarViewType = {
|
||||
month: 'month', // 月视图
|
||||
basicWeek: 'basicWeek', // 基础周视图
|
||||
basicDay: 'basicDay',// 基础天视图
|
||||
agendaWeek: 'agendaWeek', // 议程周视图
|
||||
agendaDay: 'agendaDay', // 议程天视图
|
||||
}
|
||||
|
||||
/* 定义默认视图 */
|
||||
const defaultView = calendarViewType.month
|
||||
|
||||
/* 定义日历默认配置 */
|
||||
const defaultSettings = {
|
||||
locale: 'zh-cn',
|
||||
// 按钮文字
|
||||
buttonText: {
|
||||
today: '今天',
|
||||
month: '月',
|
||||
week: '周',
|
||||
day: '日'
|
||||
},
|
||||
// 头部排列方式
|
||||
header: {
|
||||
left: 'prev,next, today',
|
||||
center: 'title',
|
||||
right: 'hide, custom, month,agendaWeek,agendaDay'
|
||||
},
|
||||
//点击今天日列表图
|
||||
eventLimitClick: 'day',
|
||||
// 隐藏超出的事件
|
||||
eventLimit: true,
|
||||
// 设置每周开始日期为周日
|
||||
firstDay: 0,
|
||||
// 默认显示视图
|
||||
defaultView,
|
||||
timeFormat: 'H:mm',
|
||||
axisFormat: 'H:mm',
|
||||
// agenda视图下是否显示all-day
|
||||
allDaySlot: true,
|
||||
// agenda视图下all-day的显示文本
|
||||
allDayText: '全天',
|
||||
// 时区默认本地的
|
||||
timezone: 'local',
|
||||
// 周视图和日视同的左侧时间显示
|
||||
slotLabelFormat: 'HH:mm',
|
||||
// 设置第二天阈值
|
||||
nextDayThreshold: '00:00:00',
|
||||
}
|
||||
|
||||
/** 提供了一些增强方法 */
|
||||
const CalendarMixins = {
|
||||
data() {
|
||||
return {
|
||||
calenderCurrentViewType: defaultView
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
getCalendarConfigEventHandler() {
|
||||
return {
|
||||
// 处理 view changed 事件
|
||||
viewRender: (view, element) => {
|
||||
let { type } = view
|
||||
|
||||
let lastViewType = this.calenderCurrentViewType
|
||||
this.calenderCurrentViewType = type
|
||||
|
||||
if (typeof this.handleViewRender === 'function') {
|
||||
this.handleViewRender(type, view, element)
|
||||
}
|
||||
|
||||
if (lastViewType !== this.calenderCurrentViewType && typeof this.handleViewChanged === 'function') {
|
||||
this.handleViewChanged(type, view, element)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
/** 获取 LunarFullCalendar 实例,ref = baseCalendar */
|
||||
getCalendar(fn) {
|
||||
return getRefPromise(this, 'baseCalendar').then(fn)
|
||||
},
|
||||
|
||||
calendarEmit(name, data) {
|
||||
this.getCalendar(ref => ref.$emit(name, data))
|
||||
},
|
||||
|
||||
/** 强制重新加载所有的事件(日程)*/
|
||||
calendarReloadEvents() {
|
||||
this.calendarEmit('reload-events')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { defaultSettings, calendarViewType, CalendarMixins }
|
||||
19
jshERP-web/src/utils/auth.js
Normal file
19
jshERP-web/src/utils/auth.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 弃用
|
||||
*/
|
||||
import { setStore, getStore, clearStore } from "@/utils/storage"
|
||||
|
||||
export const TokenKey = 'Access-Token'
|
||||
|
||||
export function getToken() {
|
||||
return getStore(TokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
// key, token, timeout = 86400s
|
||||
return setStore(TokenKey, token, 86400)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return clearStore(TokenKey)
|
||||
}
|
||||
243
jshERP-web/src/utils/authFilter.js
Normal file
243
jshERP-web/src/utils/authFilter.js
Normal file
@@ -0,0 +1,243 @@
|
||||
import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
|
||||
|
||||
export function disabledAuthFilter(code,formData) {
|
||||
if(nodeDisabledAuth(code,formData)){
|
||||
return true;
|
||||
}else{
|
||||
return globalDisabledAuth(code);
|
||||
}
|
||||
}
|
||||
|
||||
function nodeDisabledAuth(code,formData){
|
||||
console.log("页面权限禁用--NODE--开始");
|
||||
let permissionList = [];
|
||||
try {
|
||||
console.log("页面权限禁用--NODE--开始",formData);
|
||||
if (formData) {
|
||||
let bpmList = formData.permissionList;
|
||||
permissionList = bpmList.filter(item=>item.type=='2')
|
||||
// for (let bpm of bpmList) {
|
||||
// if(bpm.type == '2') {
|
||||
// permissionList.push(bpm);
|
||||
// }
|
||||
// }
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
//console.log("页面权限异常----", e);
|
||||
}
|
||||
if (permissionList.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log("流程节点页面权限禁用--NODE--开始");
|
||||
let permissions = [];
|
||||
for (let item of permissionList) {
|
||||
if(item.type == '2') {
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
//console.log("页面权限----"+code);
|
||||
if (!permissions.includes(code)) {
|
||||
return false;
|
||||
}else{
|
||||
for (let item2 of permissionList) {
|
||||
if(code === item2.action){
|
||||
console.log("流程节点页面权限禁用--NODE--生效");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function globalDisabledAuth(code){
|
||||
console.log("全局页面禁用权限--Global--开始");
|
||||
|
||||
let permissionList = [];
|
||||
let allPermissionList = [];
|
||||
|
||||
//let authList = Vue.ls.get(USER_AUTH);
|
||||
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
for (let auth of authList) {
|
||||
if(auth.type == '2') {
|
||||
permissionList.push(auth);
|
||||
}
|
||||
}
|
||||
//console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
for (let gauth of allAuthList) {
|
||||
if(gauth.type == '2') {
|
||||
allPermissionList.push(gauth);
|
||||
}
|
||||
}
|
||||
//设置全局配置是否有命中
|
||||
let gFlag = false;//禁用命中
|
||||
let invalidFlag = false;//无效命中
|
||||
if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
|
||||
for (let itemG of allPermissionList) {
|
||||
if(code === itemG.action){
|
||||
if(itemG.status == '0'){
|
||||
invalidFlag = true;
|
||||
break;
|
||||
}else{
|
||||
gFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(invalidFlag){
|
||||
return false;
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
return gFlag;
|
||||
}
|
||||
let permissions = [];
|
||||
for (let item of permissionList) {
|
||||
if(item.type == '2') {
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
//console.log("页面禁用权限----"+code);
|
||||
if (!permissions.includes(code)) {
|
||||
return gFlag;
|
||||
}else{
|
||||
for (let item2 of permissionList) {
|
||||
if(code === item2.action){
|
||||
console.log("全局页面权限解除禁用--Global--生效");
|
||||
gFlag = false;
|
||||
}
|
||||
}
|
||||
return gFlag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function colAuthFilter(columns,pre) {
|
||||
let authList = getNoAuthCols(pre);
|
||||
const cols = columns.filter(item => {
|
||||
if (hasColoum(item,authList)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return cols
|
||||
}
|
||||
|
||||
/**
|
||||
* 【子表行编辑】实现两个功能:
|
||||
* 1、隐藏JEditableTable无权限的字段
|
||||
* 2、禁用JEditableTable无权限的字段
|
||||
* @param columns
|
||||
* @param pre
|
||||
* @returns {*}
|
||||
*/
|
||||
export function colAuthFilterJEditableTable(columns,pre) {
|
||||
let authList = getAllShowAndDisabledAuthCols(pre);
|
||||
const cols = columns.filter(item => {
|
||||
let oneAuth = authList.find(auth => {
|
||||
return auth.action === pre + item.key;
|
||||
});
|
||||
if(!oneAuth){
|
||||
return true
|
||||
}
|
||||
|
||||
//代码严谨处理,防止一个授权标识,配置多次
|
||||
if(oneAuth instanceof Array){
|
||||
oneAuth = oneAuth[0]
|
||||
}
|
||||
|
||||
//禁用逻辑
|
||||
if (oneAuth.type == '2' && !oneAuth.isAuth) {
|
||||
item["disabled"] = true
|
||||
return true
|
||||
}
|
||||
//隐藏逻辑逻辑
|
||||
if (oneAuth.type == '1' && !oneAuth.isAuth) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
return cols
|
||||
}
|
||||
|
||||
|
||||
function hasColoum(item,authList){
|
||||
if (authList.includes(item.dataIndex)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
//权限无效时不做控制,有效时控制,只能控制 显示不显示
|
||||
//根据授权码前缀获取未授权的列信息
|
||||
function getNoAuthCols(pre){
|
||||
let permissionList = [];
|
||||
let allPermissionList = [];
|
||||
|
||||
//let authList = Vue.ls.get(USER_AUTH);
|
||||
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
for (let auth of authList) {
|
||||
//显示策略,有效状态
|
||||
if(auth.type == '1'&&startWith(auth.action,pre)) {
|
||||
permissionList.push(substrPre(auth.action,pre));
|
||||
}
|
||||
}
|
||||
//console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
for (let gauth of allAuthList) {
|
||||
//显示策略,有效状态
|
||||
if(gauth.type == '1'&&gauth.status == '1'&&startWith(gauth.action,pre)) {
|
||||
allPermissionList.push(substrPre(gauth.action,pre));
|
||||
}
|
||||
}
|
||||
const cols = allPermissionList.filter(item => {
|
||||
if (permissionList.includes(item)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
return cols;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 额外增加方法【用于行编辑组件】
|
||||
* date: 2020-04-05
|
||||
* author: scott
|
||||
* @param pre
|
||||
* @returns {*[]}
|
||||
*/
|
||||
function getAllShowAndDisabledAuthCols(pre){
|
||||
//用户拥有的权限
|
||||
let userAuthList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
//全部权限配置
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
|
||||
let newAllAuthList = allAuthList.map(function (item, index) {
|
||||
let hasAuthArray = userAuthList.filter(u => u.action===item.action );
|
||||
if (hasAuthArray && hasAuthArray.length>0) {
|
||||
item["isAuth"] = true
|
||||
}
|
||||
return item;
|
||||
})
|
||||
|
||||
return newAllAuthList;
|
||||
}
|
||||
|
||||
function startWith(str,pre) {
|
||||
if (pre == null || pre == "" || str==null|| str==""|| str.length == 0 || pre.length > str.length)
|
||||
return false;
|
||||
if (str.substr(0, pre.length) == pre)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function substrPre(str,pre) {
|
||||
return str.substr(pre.length);
|
||||
}
|
||||
37
jshERP-web/src/utils/axios.js
Normal file
37
jshERP-web/src/utils/axios.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const VueAxios = {
|
||||
vm: {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
install(Vue, router = {}, instance) {
|
||||
if (this.installed) {
|
||||
return;
|
||||
}
|
||||
this.installed = true;
|
||||
|
||||
if (!instance) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('You have to install axios');
|
||||
return;
|
||||
}
|
||||
|
||||
Vue.axios = instance;
|
||||
|
||||
Object.defineProperties(Vue.prototype, {
|
||||
axios: {
|
||||
get: function get() {
|
||||
return instance;
|
||||
}
|
||||
},
|
||||
$http: {
|
||||
get: function get() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
VueAxios,
|
||||
// eslint-disable-next-line no-undef
|
||||
//instance as axios
|
||||
}
|
||||
52
jshERP-web/src/utils/commonUploadFile.js
Normal file
52
jshERP-web/src/utils/commonUploadFile.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import { getFileAccessHttpUrl } from '@/api/manage'
|
||||
const getFileName=(path)=>{
|
||||
if(path.lastIndexOf("\\")>=0){
|
||||
let reg=new RegExp("\\\\","g");
|
||||
path = path.replace(reg,"/");
|
||||
}
|
||||
return path.substring(path.lastIndexOf("/")+1);
|
||||
}
|
||||
|
||||
const uidGenerator=()=>{
|
||||
return '-'+parseInt(Math.random()*10000+1,10);
|
||||
}
|
||||
|
||||
const getFilePaths=(uploadFiles)=>{
|
||||
let arr = [];
|
||||
if(!uploadFiles){
|
||||
return ""
|
||||
}
|
||||
for(let a=0;a<uploadFiles.length;a++){
|
||||
arr.push(uploadFiles[a].response.message)
|
||||
}
|
||||
if(arr && arr.length>0){
|
||||
return arr.join(",")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
const getUploadFileList=(paths)=>{
|
||||
if(!paths){
|
||||
return [];
|
||||
}
|
||||
let fileList = [];
|
||||
let arr = paths.split(",")
|
||||
for(let a=0;a<arr.length;a++){
|
||||
if(!arr[a]){
|
||||
continue
|
||||
}else{
|
||||
fileList.push({
|
||||
uid:uidGenerator(),
|
||||
name:getFileName(arr[a]),
|
||||
status: 'done',
|
||||
url: getFileAccessHttpUrl(arr[a]),
|
||||
response:{
|
||||
status:"history",
|
||||
message:arr[a]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
export {getFilePaths,getUploadFileList}
|
||||
22
jshERP-web/src/utils/desform/CustomExpression.js
Normal file
22
jshERP-web/src/utils/desform/CustomExpression.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
*
|
||||
* 这里填写用户自定义的表达式
|
||||
* 可用在Online表单的默认值表达式中使用
|
||||
* 需要外部使用的变量或方法一定要 export,否则无法识别
|
||||
* 示例:
|
||||
* export const name = '张三'; // const 是常量
|
||||
* export let age = 17; // 看情况 export const 还是 let ,两者都可正常使用
|
||||
* export function content(arg) { // export 方法,可传参数,使用时要加括号,值一定要return回去,可以返回Promise
|
||||
* return 'content' + arg;
|
||||
* }
|
||||
* export const address = (arg) => content(arg) + ' | 北京市'; // export 箭头函数也可以
|
||||
*
|
||||
*/
|
||||
|
||||
/** 字段默认值官方示例:获取地址 */
|
||||
export function demoFieldDefVal_getAddress(arg) {
|
||||
if (!arg) {
|
||||
arg = '朝阳区'
|
||||
}
|
||||
return `北京市 ${arg}`
|
||||
}
|
||||
23
jshERP-web/src/utils/device.js
Normal file
23
jshERP-web/src/utils/device.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import enquireJs from 'enquire.js'
|
||||
|
||||
const enquireScreen = function (call) {
|
||||
// tablet
|
||||
const handler = {
|
||||
match: function () {
|
||||
call && call(0)
|
||||
},
|
||||
unmatch: function () {
|
||||
call && call(-1)
|
||||
}
|
||||
}
|
||||
// mobile
|
||||
const handler2 = {
|
||||
match: () => {
|
||||
call && call(1)
|
||||
}
|
||||
}
|
||||
enquireJs.register('screen and (max-width: 1087.99px)', handler)
|
||||
enquireJs.register('screen and (max-width: 767.99px)', handler2)
|
||||
}
|
||||
|
||||
export default enquireScreen
|
||||
6003
jshERP-web/src/utils/encryption/aesEncrypt.js
Normal file
6003
jshERP-web/src/utils/encryption/aesEncrypt.js
Normal file
File diff suppressed because it is too large
Load Diff
30
jshERP-web/src/utils/filter.js
Normal file
30
jshERP-web/src/utils/filter.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import Vue from "vue";
|
||||
import * as dayjs from "dayjs";
|
||||
|
||||
Vue.filter('NumberFormat', function (value) {
|
||||
if (!value) {
|
||||
return '0'
|
||||
}
|
||||
let intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') //将整数部分逢三一断
|
||||
return intPartFormat
|
||||
})
|
||||
|
||||
Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(dataStr).format(pattern)
|
||||
})
|
||||
|
||||
Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(dataStr).format(pattern)
|
||||
})
|
||||
|
||||
/** 字符串超长截取省略号显示 */
|
||||
Vue.filter('ellipsis', function (value, vlength = 25) {
|
||||
if(!value){
|
||||
return "";
|
||||
}
|
||||
console.log('vlength: '+ vlength);
|
||||
if (value.length > vlength) {
|
||||
return value.slice(0, vlength) + '...'
|
||||
}
|
||||
return value
|
||||
})
|
||||
120
jshERP-web/src/utils/hasPermission.js
Normal file
120
jshERP-web/src/utils/hasPermission.js
Normal file
@@ -0,0 +1,120 @@
|
||||
import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
|
||||
|
||||
const hasPermission = {
|
||||
install (Vue, options) {
|
||||
console.log(options);
|
||||
Vue.directive('has', {
|
||||
inserted: (el, binding, vnode)=>{
|
||||
console.log("页面权限控制----");
|
||||
//console.time()
|
||||
//节点权限处理,如果命中则不进行全局权限处理
|
||||
if(!filterNodePermission(el, binding, vnode)){
|
||||
filterGlobalPermission(el, binding, vnode);
|
||||
}
|
||||
//console.timeEnd() //计时结束并输出时长
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 流程节点权限控制
|
||||
*/
|
||||
export function filterNodePermission(el, binding, vnode) {
|
||||
let permissionList = [];
|
||||
try {
|
||||
let obj = vnode.context.$props.formData;
|
||||
if (obj) {
|
||||
let bpmList = obj.permissionList;
|
||||
for (let bpm of bpmList) {
|
||||
if(bpm.type != '2') {
|
||||
permissionList.push(bpm);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
//console.log("页面权限异常----", e);
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
//el.parentNode.removeChild(el)
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log("流程节点页面权限--NODE--");
|
||||
let permissions = [];
|
||||
for (let item of permissionList) {
|
||||
if(item.type != '2') {
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
//console.log("页面权限----"+permissions);
|
||||
//console.log("页面权限----"+binding.value);
|
||||
if (!permissions.includes(binding.value)) {
|
||||
//el.parentNode.removeChild(el)
|
||||
return false;
|
||||
}else{
|
||||
for (let item2 of permissionList) {
|
||||
if(binding.value === item2.action){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局权限控制
|
||||
*/
|
||||
export function filterGlobalPermission(el, binding, vnode) {
|
||||
console.log("全局页面权限--Global--");
|
||||
|
||||
let permissionList = [];
|
||||
let allPermissionList = [];
|
||||
|
||||
//let authList = Vue.ls.get(USER_AUTH);
|
||||
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
for (let auth of authList) {
|
||||
if(auth.type != '2') {
|
||||
permissionList.push(auth);
|
||||
}
|
||||
}
|
||||
//console.log("页面权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
for (let gauth of allAuthList) {
|
||||
if(gauth.type != '2') {
|
||||
allPermissionList.push(gauth);
|
||||
}
|
||||
}
|
||||
//设置全局配置是否有命中
|
||||
let invalidFlag = false;//无效命中
|
||||
if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
|
||||
for (let itemG of allPermissionList) {
|
||||
if(binding.value === itemG.action){
|
||||
if(itemG.status == '0'){
|
||||
invalidFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(invalidFlag){
|
||||
return;
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
el.parentNode.removeChild(el);
|
||||
return;
|
||||
}
|
||||
let permissions = [];
|
||||
for (let item of permissionList) {
|
||||
if(item.type != '2'){
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
if (!permissions.includes(binding.value)) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
export default hasPermission;
|
||||
40
jshERP-web/src/utils/mixin.js
Normal file
40
jshERP-web/src/utils/mixin.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// import Vue from 'vue'
|
||||
import { mapState } from "vuex";
|
||||
|
||||
// const mixinsComputed = Vue.config.optionMergeStrategies.computed
|
||||
// const mixinsMethods = Vue.config.optionMergeStrategies.methods
|
||||
|
||||
const mixin = {
|
||||
computed: {
|
||||
...mapState({
|
||||
layoutMode: state => state.app.layout,
|
||||
navTheme: state => state.app.theme,
|
||||
primaryColor: state => state.app.color,
|
||||
colorWeak: state => state.app.weak,
|
||||
multipage: state => state.app.multipage,//多页签设置
|
||||
fixedHeader: state => state.app.fixedHeader,
|
||||
fixSiderbar: state => state.app.fixSiderbar,
|
||||
contentWidth: state => state.app.contentWidth,
|
||||
autoHideHeader: state => state.app.autoHideHeader,
|
||||
sidebarOpened: state => state.app.sidebar.opened
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const mixinDevice = {
|
||||
computed: {
|
||||
...mapState({
|
||||
device: state => state.app.device,
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
isMobile () {
|
||||
return this.device === 'mobile'
|
||||
},
|
||||
isDesktop () {
|
||||
return this.device === 'desktop'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { mixin, mixinDevice }
|
||||
8
jshERP-web/src/utils/permissions.js
Normal file
8
jshERP-web/src/utils/permissions.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export function actionToObject(json) {
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
} catch (e) {
|
||||
console.log('err', e.message)
|
||||
}
|
||||
return []
|
||||
}
|
||||
115
jshERP-web/src/utils/props-util.js
Normal file
115
jshERP-web/src/utils/props-util.js
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 该文件截取自 "ant-design-vue/es/_util/props-util.js" 文件,并对其做出特殊修改
|
||||
*/
|
||||
function classNames() {
|
||||
let classes = []
|
||||
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
let arg = arguments[i]
|
||||
if (!arg) continue
|
||||
|
||||
let argType = typeof arg
|
||||
|
||||
if (argType === 'string' || argType === 'number') {
|
||||
classes.push(arg)
|
||||
} else if (Array.isArray(arg) && arg.length) {
|
||||
let inner = classNames.apply(null, arg)
|
||||
if (inner) {
|
||||
classes.push(inner)
|
||||
}
|
||||
} else if (argType === 'object') {
|
||||
for (let key in arg) {
|
||||
if (arg.hasOwnProperty(key) && arg[key]) {
|
||||
classes.push(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return classes.join(' ')
|
||||
}
|
||||
|
||||
const camelizeRE = /-(\w)/g
|
||||
|
||||
function camelize(str) {
|
||||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
|
||||
}
|
||||
|
||||
|
||||
function objectCamelize(obj) {
|
||||
let res = {}
|
||||
Object.keys(obj).forEach(k => (res[camelize(k)] = obj[k]))
|
||||
return res
|
||||
}
|
||||
|
||||
function parseStyleText(cssText = '', camel) {
|
||||
const res = {}
|
||||
const listDelimiter = /;(?![^(]*\))/g
|
||||
const propertyDelimiter = /:(.+)/
|
||||
cssText.split(listDelimiter).forEach(function (item) {
|
||||
if (item) {
|
||||
const tmp = item.split(propertyDelimiter)
|
||||
if (tmp.length > 1) {
|
||||
const k = camel ? camelize(tmp[0].trim()) : tmp[0].trim()
|
||||
res[k] = tmp[1].trim()
|
||||
}
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
export function getClass(ele) {
|
||||
let data = {}
|
||||
if (ele.data) {
|
||||
data = ele.data
|
||||
} else if (ele.$vnode && ele.$vnode.data) {
|
||||
data = ele.$vnode.data
|
||||
}
|
||||
const tempCls = data.class || {}
|
||||
const staticClass = data.staticClass
|
||||
let cls = {}
|
||||
staticClass &&
|
||||
staticClass.split(' ').forEach(c => {
|
||||
cls[c.trim()] = true
|
||||
})
|
||||
if (typeof tempCls === 'string') {
|
||||
tempCls.split(' ').forEach(c => {
|
||||
cls[c.trim()] = true
|
||||
})
|
||||
} else if (Array.isArray(tempCls)) {
|
||||
classNames(tempCls)
|
||||
.split(' ')
|
||||
.forEach(c => {
|
||||
cls[c.trim()] = true
|
||||
})
|
||||
} else {
|
||||
cls = { ...cls, ...tempCls }
|
||||
}
|
||||
return cls
|
||||
}
|
||||
|
||||
export function getStyle(ele, camel) {
|
||||
|
||||
getClass(ele)
|
||||
|
||||
let data = {}
|
||||
if (ele.data) {
|
||||
data = ele.data
|
||||
} else if (ele.$vnode && ele.$vnode.data) {
|
||||
data = ele.$vnode.data
|
||||
}
|
||||
|
||||
// update-begin-author:sunjianlei date:20200303 for: style 和 staticStyle 可以共存
|
||||
let style = data.style || {}
|
||||
let staticStyle = data.staticStyle
|
||||
staticStyle = staticStyle ? objectCamelize(data.staticStyle) : {}
|
||||
// update-end-author:sunjianlei date:20200303 for: style 和 staticStyle 可以共存
|
||||
|
||||
if (typeof style === 'string') {
|
||||
style = parseStyleText(style, camel)
|
||||
} else if (camel && style) {
|
||||
// 驼峰化
|
||||
style = objectCamelize(style)
|
||||
}
|
||||
return { ...staticStyle, ...style }
|
||||
}
|
||||
|
||||
116
jshERP-web/src/utils/request.js
Normal file
116
jshERP-web/src/utils/request.js
Normal file
@@ -0,0 +1,116 @@
|
||||
import Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
import store from '@/store'
|
||||
import { VueAxios } from './axios'
|
||||
import {Modal, notification} from 'ant-design-vue'
|
||||
import { ACCESS_TOKEN } from "@/store/mutation-types"
|
||||
|
||||
/**
|
||||
* 【指定 axios的 baseURL】
|
||||
* 如果手工指定 baseURL: '/jshERP-boot'
|
||||
* 则映射后端域名,通过 vue.config.js
|
||||
* @type {*|string}
|
||||
*/
|
||||
let apiBaseUrl = window._CONFIG['domianURL'] || "/jshERP-boot";
|
||||
console.log("apiBaseUrl= ",apiBaseUrl)
|
||||
// 创建 axios 实例
|
||||
const service = axios.create({
|
||||
baseURL: apiBaseUrl, // api base_url
|
||||
timeout: 9000 // 请求超时时间
|
||||
})
|
||||
|
||||
const err = (error) => {
|
||||
if (error.response) {
|
||||
let data = error.response.data
|
||||
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||
console.log("------异常响应------",token)
|
||||
console.log("------异常响应------",error.response.status)
|
||||
switch (error.response.status) {
|
||||
case 403:
|
||||
notification.error({ message: '系统提示', description: '拒绝访问',duration: 4})
|
||||
break
|
||||
case 500:
|
||||
//notification.error({ message: '系统提示', description:'Token失效,请重新登录!',duration: 4})
|
||||
if(token && data.message=="Token失效,请重新登录"){
|
||||
// update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||
// store.dispatch('Logout').then(() => {
|
||||
// window.location.reload()
|
||||
// })
|
||||
Modal.error({
|
||||
title: '登录已过期',
|
||||
content: '很抱歉,登录已过期,请重新登录',
|
||||
okText: '重新登录',
|
||||
mask: false,
|
||||
onOk: () => {
|
||||
store.dispatch('Logout').then(() => {
|
||||
Vue.ls.remove(ACCESS_TOKEN)
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
})
|
||||
// update-end- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||
}
|
||||
break
|
||||
case 404:
|
||||
notification.error({ message: '系统提示', description:'很抱歉,资源未找到!',duration: 4})
|
||||
break
|
||||
case 504:
|
||||
notification.error({ message: '系统提示', description: '网络超时'})
|
||||
break
|
||||
case 401:
|
||||
notification.error({ message: '系统提示', description:'未授权,请重新登录',duration: 4})
|
||||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
break
|
||||
default:
|
||||
notification.error({
|
||||
message: '系统提示',
|
||||
description: data.message,
|
||||
duration: 4
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
return Promise.reject(error)
|
||||
};
|
||||
|
||||
// request interceptor
|
||||
service.interceptors.request.use(config => {
|
||||
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||
if (token) {
|
||||
config.headers[ 'X-Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
||||
}
|
||||
if(config.method=='get'){
|
||||
if(config.url.indexOf("systemConfig/getDictItems")<0){
|
||||
config.params = {
|
||||
_t: Date.parse(new Date())/1000,
|
||||
...config.params
|
||||
}
|
||||
}
|
||||
}
|
||||
return config
|
||||
},(error) => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// response interceptor
|
||||
service.interceptors.response.use((response) => {
|
||||
return response.data
|
||||
}, err)
|
||||
|
||||
const installer = {
|
||||
vm: {},
|
||||
install (Vue, router = {}) {
|
||||
Vue.use(VueAxios, router, service)
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
installer as VueAxios,
|
||||
service as axios
|
||||
}
|
||||
78
jshERP-web/src/utils/storage.js
Normal file
78
jshERP-web/src/utils/storage.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Set storage
|
||||
*
|
||||
* @param name
|
||||
* @param content
|
||||
* @param maxAge
|
||||
*/
|
||||
export const setStore = (name, content, maxAge = null) => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof content !== 'string') {
|
||||
content = JSON.stringify(content)
|
||||
}
|
||||
|
||||
let storage = global.window.localStorage
|
||||
|
||||
storage.setItem(name, content)
|
||||
if (maxAge && !isNaN(parseInt(maxAge))) {
|
||||
let timeout = parseInt(new Date().getTime() / 1000)
|
||||
storage.setItem(`${name}_expire`, timeout + maxAge)
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get storage
|
||||
*
|
||||
* @param name
|
||||
* @returns {*}
|
||||
*/
|
||||
export const getStore = name => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
let content = window.localStorage.getItem(name)
|
||||
let _expire = window.localStorage.getItem(`${name}_expire`)
|
||||
|
||||
if (_expire) {
|
||||
let now = parseInt(new Date().getTime() / 1000)
|
||||
if (now > _expire) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(content)
|
||||
} catch (e) {
|
||||
return content
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear storage
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
export const clearStore = name => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.removeItem(name)
|
||||
window.localStorage.removeItem(`${name}_expire`)
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear all storage
|
||||
*/
|
||||
export const clearAll = () => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.clear()
|
||||
}
|
||||
|
||||
539
jshERP-web/src/utils/util.js
Normal file
539
jshERP-web/src/utils/util.js
Normal file
@@ -0,0 +1,539 @@
|
||||
import * as api from '@/api/api'
|
||||
import { isURL } from '@/utils/validate'
|
||||
import Vue from 'vue'
|
||||
|
||||
export function timeFix() {
|
||||
const time = new Date()
|
||||
const hour = time.getHours()
|
||||
return hour < 9 ? '早上好' : (hour <= 11 ? '上午好' : (hour <= 13 ? '中午好' : (hour < 20 ? '下午好' : '晚上好')))
|
||||
}
|
||||
|
||||
export function welcome() {
|
||||
const arr = ['休息一会儿吧', '准备吃什么呢?', '要不要打一把 DOTA', '我猜你可能累了']
|
||||
let index = Math.floor((Math.random()*arr.length))
|
||||
return arr[index]
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发 window.resize
|
||||
*/
|
||||
export function triggerWindowResizeEvent() {
|
||||
let event = document.createEvent('HTMLEvents')
|
||||
event.initEvent('resize', true, true)
|
||||
event.eventType = 'message'
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤对象中为空的属性
|
||||
* @param obj
|
||||
* @returns {*}
|
||||
*/
|
||||
export function filterObj(obj) {
|
||||
if (!(typeof obj == 'object')) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ( let key in obj) {
|
||||
if (obj.hasOwnProperty(key)
|
||||
&& (obj[key] == null || obj[key] == undefined || obj[key] === '')) {
|
||||
delete obj[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间格式化
|
||||
* @param value
|
||||
* @param fmt
|
||||
* @returns {*}
|
||||
*/
|
||||
export function formatDate(value, fmt) {
|
||||
let regPos = /^\d+(\.\d+)?$/;
|
||||
if(regPos.test(value)){
|
||||
//如果是数字
|
||||
let getDate = new Date(value);
|
||||
let o = {
|
||||
'M+': getDate.getMonth() + 1,
|
||||
'd+': getDate.getDate(),
|
||||
'h+': getDate.getHours(),
|
||||
'm+': getDate.getMinutes(),
|
||||
's+': getDate.getSeconds(),
|
||||
'q+': Math.floor((getDate.getMonth() + 3) / 3),
|
||||
'S': getDate.getMilliseconds()
|
||||
};
|
||||
if (/(y+)/.test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
|
||||
}
|
||||
for (let k in o) {
|
||||
if (new RegExp('(' + k + ')').test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
|
||||
}
|
||||
}
|
||||
return fmt;
|
||||
}else{
|
||||
//TODO
|
||||
value = value.trim();
|
||||
return value.substr(0,fmt.length);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成首页路由
|
||||
export function generateIndexRouter(data) {
|
||||
let indexRouter = generateChildRouters(data)
|
||||
// let indexRouter = [{
|
||||
// path: '/',
|
||||
// name: 'dashboard',
|
||||
// //component: () => import('@/components/layouts/BasicLayout'),
|
||||
// component: resolve => require(['@/components/layouts/TabLayout'], resolve),
|
||||
// meta: {
|
||||
// title: '首页',
|
||||
// icon: 'icon-present'
|
||||
// },
|
||||
// redirect: '/dashboard/analysis',
|
||||
// children: [
|
||||
// ...generateChildRouters(data)
|
||||
// ]
|
||||
// },
|
||||
// {
|
||||
// "path": "*", "redirect": "/404", "hidden": true
|
||||
// }]
|
||||
return indexRouter;
|
||||
}
|
||||
|
||||
// 生成嵌套路由(子路由)
|
||||
|
||||
function generateChildRouters (data) {
|
||||
const routers = [];
|
||||
for (let item of data) {
|
||||
let componentPath = "";
|
||||
item.route = "1";
|
||||
if(item.component.indexOf("layouts")>=0){
|
||||
componentPath = () => import('@/components'+item.component);
|
||||
} else {
|
||||
componentPath = () => import('@/views'+item.component);
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
let URL = (item.url|| '').replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)) // URL支持{{ window.xxx }}占位符变量
|
||||
if (isURL(URL)) {
|
||||
item.url = URL;
|
||||
}
|
||||
let menu = {
|
||||
path: item.url,
|
||||
name: item.text,
|
||||
component: componentPath,
|
||||
meta: {
|
||||
title: item.text,
|
||||
icon: item.icon,
|
||||
url: item.url,
|
||||
// permissionList:"",
|
||||
// keepAlive:"",
|
||||
}
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
menu.children = [...generateChildRouters( item.children)];
|
||||
}
|
||||
//--update-begin----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------
|
||||
//判断是否生成路由
|
||||
if(item.route && item.route === '0'){
|
||||
//console.log(' 不生成路由 item.route: '+item.route);
|
||||
//console.log(' 不生成路由 item.path: '+item.path);
|
||||
}else{
|
||||
routers.push(menu);
|
||||
}
|
||||
//--update-end----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------
|
||||
}
|
||||
return routers
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度克隆对象、数组
|
||||
* @param obj 被克隆的对象
|
||||
* @return 克隆后的对象
|
||||
*/
|
||||
export function cloneObject(obj) {
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成数字
|
||||
*
|
||||
* 示例:生成长度为 12 的随机数:randomNumber(12)
|
||||
* 示例:生成 3~23 之间的随机数:randomNumber(3, 23)
|
||||
*
|
||||
* @param1 最小值 | 长度
|
||||
* @param2 最大值
|
||||
* @return int 生成后的数字
|
||||
*/
|
||||
export function randomNumber() {
|
||||
// 生成 最小值 到 最大值 区间的随机数
|
||||
const random = (min, max) => {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||
}
|
||||
if (arguments.length === 1) {
|
||||
let [length] = arguments
|
||||
// 生成指定长度的随机数字,首位一定不是 0
|
||||
let nums = [...Array(length).keys()].map((i) => (i > 0 ? random(0, 9) : random(1, 9)))
|
||||
return parseInt(nums.join(''))
|
||||
} else if (arguments.length >= 2) {
|
||||
let [min, max] = arguments
|
||||
return random(min, max)
|
||||
} else {
|
||||
return Number.NaN
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成字符串
|
||||
* @param length 字符串的长度
|
||||
* @param chats 可选字符串区间(只会生成传入的字符串中的字符)
|
||||
* @return string 生成的字符串
|
||||
*/
|
||||
export function randomString(length, chats) {
|
||||
if (!length) length = 1
|
||||
if (!chats) chats = '0123456789qwertyuioplkjhgfdsazxcvbnm'
|
||||
let str = ''
|
||||
for (let i = 0; i < length; i++) {
|
||||
let num = randomNumber(0, chats.length - 1)
|
||||
str += chats[num]
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成uuid
|
||||
* @return string 生成的uuid
|
||||
*/
|
||||
export function randomUUID() {
|
||||
let chats = '0123456789abcdef'
|
||||
return randomString(32, chats)
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线转驼峰
|
||||
* @param string
|
||||
* @returns {*}
|
||||
*/
|
||||
export function underLine2CamelCase(string){
|
||||
return string.replace( /_([a-z])/g, function( all, letter ) {
|
||||
return letter.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否显示办理按钮
|
||||
* @param bpmStatus
|
||||
* @returns {*}
|
||||
*/
|
||||
export function showDealBtn(bpmStatus){
|
||||
if(bpmStatus!="1"&&bpmStatus!="3"&&bpmStatus!="4"){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增强CSS,可以在页面上输出全局css
|
||||
* @param css 要增强的css
|
||||
* @param id style标签的id,可以用来清除旧样式
|
||||
*/
|
||||
export function cssExpand(css, id) {
|
||||
let style = document.createElement('style')
|
||||
style.type = "text/css"
|
||||
style.innerHTML = `@charset "UTF-8"; ${css}`
|
||||
// 清除旧样式
|
||||
if (id) {
|
||||
let $style = document.getElementById(id)
|
||||
if ($style != null) $style.outerHTML = ''
|
||||
style.id = id
|
||||
}
|
||||
// 应用新样式
|
||||
document.head.appendChild(style)
|
||||
}
|
||||
|
||||
|
||||
/** 用于js增强事件,运行JS代码,可以传参 */
|
||||
// options 所需参数:
|
||||
// 参数名 类型 说明
|
||||
// vm VueComponent vue实例
|
||||
// event Object event对象
|
||||
// jsCode String 待执行的js代码
|
||||
// errorMessage String 执行出错后的提示(控制台)
|
||||
export function jsExpand(options = {}) {
|
||||
|
||||
// 绑定到window上的keyName
|
||||
let windowKeyName = 'J_CLICK_EVENT_OPTIONS'
|
||||
if (typeof window[windowKeyName] != 'object') {
|
||||
window[windowKeyName] = {}
|
||||
}
|
||||
|
||||
// 随机生成JS增强的执行id,防止冲突
|
||||
let id = randomString(16, 'qwertyuioplkjhgfdsazxcvbnm'.toUpperCase())
|
||||
// 封装按钮点击事件
|
||||
let code = `
|
||||
(function (o_${id}) {
|
||||
try {
|
||||
(function (globalEvent, vm) {
|
||||
${options.jsCode}
|
||||
})(o_${id}.event, o_${id}.vm)
|
||||
} catch (e) {
|
||||
o_${id}.error(e)
|
||||
}
|
||||
o_${id}.done()
|
||||
})(window['${windowKeyName}']['EVENT_${id}'])
|
||||
`
|
||||
// 创建script标签
|
||||
const script = document.createElement('script')
|
||||
// 将需要传递的参数挂载到window对象上
|
||||
window[windowKeyName]['EVENT_' + id] = {
|
||||
vm: options.vm,
|
||||
event: options.event,
|
||||
// 当执行完成时,无论如何都会调用的回调事件
|
||||
done() {
|
||||
// 执行完后删除新增的 script 标签不会撤销执行结果(已产生的结果不会被撤销)
|
||||
script.outerHTML = ''
|
||||
delete window[windowKeyName]['EVENT_' + id]
|
||||
},
|
||||
// 当js运行出错的时候调用的事件
|
||||
error(e) {
|
||||
console.group(`${options.errorMessage || '用户自定义JS增强代码运行出错'}(${new Date()})`)
|
||||
console.error(e)
|
||||
console.groupEnd()
|
||||
}
|
||||
}
|
||||
// 将事件挂载到document中
|
||||
script.innerHTML = code
|
||||
document.body.appendChild(script)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重复值验证工具方法
|
||||
*
|
||||
* 使用示例:
|
||||
* { validator: (rule, value, callback) => validateDuplicateValue('sys_fill_rule', 'rule_code', value, this.model.id, callback) }
|
||||
*
|
||||
* @param tableName 被验证的表名
|
||||
* @param fieldName 被验证的字段名
|
||||
* @param fieldVal 被验证的值
|
||||
* @param dataId 数据ID,可空
|
||||
* @param callback
|
||||
*/
|
||||
export function validateDuplicateValue(tableName, fieldName, fieldVal, dataId, callback) {
|
||||
if (fieldVal) {
|
||||
let params = { tableName, fieldName, fieldVal, dataId }
|
||||
api.duplicateCheck(params).then(res => {
|
||||
res['success'] ? callback() : callback(res['message'])
|
||||
}).catch(err => {
|
||||
callback(err.message || err)
|
||||
})
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编码校验规则code,校验传入的值是否合法
|
||||
*
|
||||
* 使用示例:
|
||||
* { validator: (rule, value, callback) => validateCheckRule('common', value, callback) }
|
||||
*
|
||||
* @param ruleCode 编码校验规则 code
|
||||
* @param value 被验证的值
|
||||
* @param callback
|
||||
*/
|
||||
export function validateCheckRule(ruleCode, value, callback) {
|
||||
if (ruleCode && value) {
|
||||
value = encodeURIComponent(value)
|
||||
api.checkRuleByCode({ ruleCode, value }).then(res => {
|
||||
res['success'] ? callback() : callback(res['message'])
|
||||
}).catch(err => {
|
||||
callback(err.message || err)
|
||||
})
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果值不存在就 push 进数组,反之不处理
|
||||
* @param array 要操作的数据
|
||||
* @param value 要添加的值
|
||||
* @param key 可空,如果比较的是对象,可能存在地址不一样但值实际上是一样的情况,可以传此字段判断对象中唯一的字段,例如 id。不传则直接比较实际值
|
||||
* @returns {boolean} 成功 push 返回 true,不处理返回 false
|
||||
*/
|
||||
export function pushIfNotExist(array, value, key) {
|
||||
for (let item of array) {
|
||||
if (key && (item[key] === value[key])) {
|
||||
return false
|
||||
} else if (item === value) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
array.push(value)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 可用于判断是否成功
|
||||
* @type {symbol}
|
||||
*/
|
||||
export const succeedSymbol = Symbol()
|
||||
/**
|
||||
* 可用于判断是否失败
|
||||
* @type {symbol}
|
||||
*/
|
||||
export const failedSymbol = Symbol()
|
||||
|
||||
/**
|
||||
* 使 promise 无论如何都会 resolve,除非传入的参数不是一个Promise对象或返回Promise对象的方法
|
||||
* 一般用在 Promise.all 中
|
||||
*
|
||||
* @param promise 可传Promise对象或返回Promise对象的方法
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export function alwaysResolve(promise) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let p = promise
|
||||
if (typeof promise === 'function') {
|
||||
p = promise()
|
||||
}
|
||||
if (p instanceof Promise) {
|
||||
p.then(data => {
|
||||
resolve({ type: succeedSymbol, data })
|
||||
}).catch(error => {
|
||||
resolve({ type: failedSymbol, error })
|
||||
})
|
||||
} else {
|
||||
reject('alwaysResolve: 传入的参数不是一个Promise对象或返回Promise对象的方法')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单实现防抖方法
|
||||
*
|
||||
* 防抖(debounce)函数在第一次触发给定的函数时,不立即执行函数,而是给出一个期限值(delay),比如100ms。
|
||||
* 如果100ms内再次执行函数,就重新开始计时,直到计时结束后再真正执行函数。
|
||||
* 这样做的好处是如果短时间内大量触发同一事件,只会执行一次函数。
|
||||
*
|
||||
* @param fn 要防抖的函数
|
||||
* @param delay 防抖的毫秒数
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function simpleDebounce(fn, delay = 100) {
|
||||
let timer = null
|
||||
return function () {
|
||||
let args = arguments
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(null, args)
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 不用正则的方式替换所有值
|
||||
* @param text 被替换的字符串
|
||||
* @param checker 替换前的内容
|
||||
* @param replacer 替换后的内容
|
||||
* @returns {String} 替换后的字符串
|
||||
*/
|
||||
export function replaceAll(text, checker, replacer) {
|
||||
let lastText = text
|
||||
text = text.replace(checker, replacer)
|
||||
if (lastText !== text) {
|
||||
return replaceAll(text, checker, replacer)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换商品扩展字段的格式
|
||||
* @param thisRows
|
||||
* @param checker
|
||||
* @param replacer
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getMpListShort(thisRows, checker, replacer) {
|
||||
let mPropertyListShort = ''
|
||||
let nativeNameStr = ''
|
||||
for (let i = 0; i < thisRows.length; i++) {
|
||||
if (thisRows[i].enabled) {
|
||||
nativeNameStr += thisRows[i].nativeName + ",";
|
||||
}
|
||||
}
|
||||
if (nativeNameStr) {
|
||||
mPropertyListShort = nativeNameStr.substring(0, nativeNameStr.length - 1);
|
||||
}
|
||||
return mPropertyListShort
|
||||
}
|
||||
|
||||
/**
|
||||
* js获取当前月份, 格式“yyyy-MM”
|
||||
*/
|
||||
export function getNowFormatMonth() {
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var month = date.getMonth() + 1;
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
var currentdate = date.getFullYear() + seperator1 + month;
|
||||
return currentdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* js获取当前日期, 格式“yyyy-MM-dd”
|
||||
*/
|
||||
export function getFormatDate() {
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() + 1;
|
||||
var strDate = date.getDate();
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (strDate >= 0 && strDate <= 9) {
|
||||
strDate = "0" + strDate;
|
||||
}
|
||||
var currentdate = year + seperator1 + month + seperator1 + strDate;
|
||||
return currentdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* js获取当前时间, 格式“yyyy-MM-dd HH:MM:SS”
|
||||
*/
|
||||
export function getNowFormatDateTime() {
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var seperator2 = ":";
|
||||
var month = date.getMonth() + 1;
|
||||
var strDate = date.getDate();
|
||||
var strHours = date.getHours();
|
||||
var strMinutes = date.getMinutes();
|
||||
var strSeconds = date.getSeconds();
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (strDate >= 0 && strDate <= 9) {
|
||||
strDate = "0" + strDate;
|
||||
}
|
||||
if (strHours >= 0 && strHours <= 9) {
|
||||
strHours = "0" + strHours;
|
||||
}
|
||||
if (strMinutes >= 0 && strMinutes <= 9) {
|
||||
strMinutes = "0" + strMinutes;
|
||||
}
|
||||
if (strSeconds >= 0 && strSeconds <= 9) {
|
||||
strSeconds = "0" + strSeconds;
|
||||
}
|
||||
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
|
||||
+ " " + strHours + seperator2 + strMinutes
|
||||
+ seperator2 + strSeconds;
|
||||
return currentdate;
|
||||
}
|
||||
31
jshERP-web/src/utils/validate.js
Normal file
31
jshERP-web/src/utils/validate.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 邮箱
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isEmail (s) {
|
||||
return /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isMobile (s) {
|
||||
return /^1[0-9]{10}$/.test(s)
|
||||
}
|
||||
|
||||
/**
|
||||
* 电话号码
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isPhone (s) {
|
||||
return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
|
||||
}
|
||||
|
||||
/**
|
||||
* URL地址
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isURL (s) {
|
||||
return /^http[s]?:\/\/.*/.test(s)
|
||||
}
|
||||
5
jshERP-web/src/utils/vueBus.js
Normal file
5
jshERP-web/src/utils/vueBus.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import Bus from 'vue';
|
||||
let install = function (Vue) {
|
||||
Vue.prototype.$bus = new Bus()
|
||||
}
|
||||
export default { install };
|
||||
Reference in New Issue
Block a user