eslint
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
import { mergeRecursive } from "@/utils/ruoyi";
|
||||
import DictMeta from './DictMeta'
|
||||
import DictData from './DictData'
|
||||
import Vue from 'vue';
|
||||
import { mergeRecursive } from '@/utils/ruoyi';
|
||||
import DictMeta from './DictMeta';
|
||||
import DictData from './DictData';
|
||||
|
||||
const DEFAULT_DICT_OPTIONS = {
|
||||
types: [],
|
||||
}
|
||||
types: []
|
||||
};
|
||||
|
||||
/**
|
||||
* @classdesc 字典
|
||||
@@ -15,31 +15,31 @@ const DEFAULT_DICT_OPTIONS = {
|
||||
*/
|
||||
export default class Dict {
|
||||
constructor() {
|
||||
this.owner = null
|
||||
this.label = {}
|
||||
this.type = {}
|
||||
this.owner = null;
|
||||
this.label = {};
|
||||
this.type = {};
|
||||
}
|
||||
|
||||
init(options) {
|
||||
if (options instanceof Array) {
|
||||
options = { types: options }
|
||||
options = { types: options };
|
||||
}
|
||||
const opts = mergeRecursive(DEFAULT_DICT_OPTIONS, options)
|
||||
const opts = mergeRecursive(DEFAULT_DICT_OPTIONS, options);
|
||||
if (opts.types === undefined) {
|
||||
throw new Error('need dict types')
|
||||
throw new Error('need dict types');
|
||||
}
|
||||
const ps = []
|
||||
this._dictMetas = opts.types.map(t => DictMeta.parse(t))
|
||||
this._dictMetas.forEach(dictMeta => {
|
||||
const type = dictMeta.type
|
||||
Vue.set(this.label, type, {})
|
||||
Vue.set(this.type, type, [])
|
||||
const ps = [];
|
||||
this._dictMetas = opts.types.map((t) => DictMeta.parse(t));
|
||||
this._dictMetas.forEach((dictMeta) => {
|
||||
const type = dictMeta.type;
|
||||
Vue.set(this.label, type, {});
|
||||
Vue.set(this.type, type, []);
|
||||
if (dictMeta.lazy) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
ps.push(loadDict(this, dictMeta))
|
||||
})
|
||||
return Promise.all(ps)
|
||||
ps.push(loadDict(this, dictMeta));
|
||||
});
|
||||
return Promise.all(ps);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,11 +47,11 @@ export default class Dict {
|
||||
* @param {String} type 字典类型
|
||||
*/
|
||||
reloadDict(type) {
|
||||
const dictMeta = this._dictMetas.find(e => e.type === type)
|
||||
const dictMeta = this._dictMetas.find((e) => e.type === type);
|
||||
if (dictMeta === undefined) {
|
||||
return Promise.reject(`the dict meta of ${type} was not found`)
|
||||
return Promise.reject(`the dict meta of ${type} was not found`);
|
||||
}
|
||||
return loadDict(this, dictMeta)
|
||||
return loadDict(this, dictMeta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,21 +62,20 @@ export default class Dict {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function loadDict(dict, dictMeta) {
|
||||
return dictMeta.request(dictMeta)
|
||||
.then(response => {
|
||||
const type = dictMeta.type
|
||||
let dicts = dictMeta.responseConverter(response, dictMeta)
|
||||
if (!(dicts instanceof Array)) {
|
||||
console.error('the return of responseConverter must be Array.<DictData>')
|
||||
dicts = []
|
||||
} else if (dicts.filter(d => d instanceof DictData).length !== dicts.length) {
|
||||
console.error('the type of elements in dicts must be DictData')
|
||||
dicts = []
|
||||
}
|
||||
dict.type[type].splice(0, Number.MAX_SAFE_INTEGER, ...dicts)
|
||||
dicts.forEach(d => {
|
||||
Vue.set(dict.label[type], d.value, d.label)
|
||||
})
|
||||
return dicts
|
||||
})
|
||||
return dictMeta.request(dictMeta).then((response) => {
|
||||
const type = dictMeta.type;
|
||||
let dicts = dictMeta.responseConverter(response, dictMeta);
|
||||
if (!(dicts instanceof Array)) {
|
||||
console.error('the return of responseConverter must be Array.<DictData>');
|
||||
dicts = [];
|
||||
} else if (dicts.filter((d) => d instanceof DictData).length !== dicts.length) {
|
||||
console.error('the type of elements in dicts must be DictData');
|
||||
dicts = [];
|
||||
}
|
||||
dict.type[type].splice(0, Number.MAX_SAFE_INTEGER, ...dicts);
|
||||
dicts.forEach((d) => {
|
||||
Vue.set(dict.label[type], d.value, d.label);
|
||||
});
|
||||
return dicts;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import DictOptions from './DictOptions'
|
||||
import DictData from './DictData'
|
||||
import DictOptions from './DictOptions';
|
||||
import DictData from './DictData';
|
||||
|
||||
export default function(dict, dictMeta) {
|
||||
const label = determineDictField(dict, dictMeta.labelField, ...DictOptions.DEFAULT_LABEL_FIELDS)
|
||||
const value = determineDictField(dict, dictMeta.valueField, ...DictOptions.DEFAULT_VALUE_FIELDS)
|
||||
return new DictData(dict[label], dict[value], dict)
|
||||
export default function (dict, dictMeta) {
|
||||
const label = determineDictField(dict, dictMeta.labelField, ...DictOptions.DEFAULT_LABEL_FIELDS);
|
||||
const value = determineDictField(dict, dictMeta.valueField, ...DictOptions.DEFAULT_VALUE_FIELDS);
|
||||
return new DictData(dict[label], dict[value], dict);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -13,5 +13,5 @@ export default function(dict, dictMeta) {
|
||||
* @param {...String} fields
|
||||
*/
|
||||
function determineDictField(dict, ...fields) {
|
||||
return fields.find(f => Object.prototype.hasOwnProperty.call(dict, f))
|
||||
return fields.find((f) => Object.prototype.hasOwnProperty.call(dict, f));
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
export default class DictData {
|
||||
constructor(label, value, raw) {
|
||||
this.label = label
|
||||
this.value = value
|
||||
this.raw = raw
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.raw = raw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mergeRecursive } from "@/utils/ruoyi";
|
||||
import DictOptions from './DictOptions'
|
||||
import { mergeRecursive } from '@/utils/ruoyi';
|
||||
import DictOptions from './DictOptions';
|
||||
|
||||
/**
|
||||
* @classdesc 字典元数据
|
||||
@@ -10,29 +10,28 @@ import DictOptions from './DictOptions'
|
||||
*/
|
||||
export default class DictMeta {
|
||||
constructor(options) {
|
||||
this.type = options.type
|
||||
this.request = options.request
|
||||
this.responseConverter = options.responseConverter
|
||||
this.labelField = options.labelField
|
||||
this.valueField = options.valueField
|
||||
this.lazy = options.lazy === true
|
||||
this.type = options.type;
|
||||
this.request = options.request;
|
||||
this.responseConverter = options.responseConverter;
|
||||
this.labelField = options.labelField;
|
||||
this.valueField = options.valueField;
|
||||
this.lazy = options.lazy === true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析字典元数据
|
||||
* @param {Object} options
|
||||
* @returns {DictMeta}
|
||||
*/
|
||||
DictMeta.parse= function(options) {
|
||||
let opts = null
|
||||
DictMeta.parse = function (options) {
|
||||
let opts = null;
|
||||
if (typeof options === 'string') {
|
||||
opts = DictOptions.metas[options] || {}
|
||||
opts.type = options
|
||||
opts = DictOptions.metas[options] || {};
|
||||
opts.type = options;
|
||||
} else if (typeof options === 'object') {
|
||||
opts = options
|
||||
opts = options;
|
||||
}
|
||||
opts = mergeRecursive(DictOptions.metas['*'], opts)
|
||||
return new DictMeta(opts)
|
||||
}
|
||||
opts = mergeRecursive(DictOptions.metas['*'], opts);
|
||||
return new DictMeta(opts);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mergeRecursive } from "@/utils/ruoyi";
|
||||
import dictConverter from './DictConverter'
|
||||
import { mergeRecursive } from '@/utils/ruoyi';
|
||||
import dictConverter from './DictConverter';
|
||||
|
||||
export const options = {
|
||||
metas: {
|
||||
@@ -8,16 +8,16 @@ export const options = {
|
||||
* 字典请求,方法签名为function(dictMeta: DictMeta): Promise
|
||||
*/
|
||||
request: (dictMeta) => {
|
||||
console.log(`load dict ${dictMeta.type}`)
|
||||
return Promise.resolve([])
|
||||
console.log(`load dict ${dictMeta.type}`);
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
/**
|
||||
* 字典响应数据转换器,方法签名为function(response: Object, dictMeta: DictMeta): DictData
|
||||
*/
|
||||
responseConverter,
|
||||
labelField: 'label',
|
||||
valueField: 'value',
|
||||
},
|
||||
valueField: 'value'
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 默认标签字段
|
||||
@@ -26,8 +26,8 @@ export const options = {
|
||||
/**
|
||||
* 默认值字段
|
||||
*/
|
||||
DEFAULT_VALUE_FIELDS: ['value', 'id', 'uid', 'key'],
|
||||
}
|
||||
DEFAULT_VALUE_FIELDS: ['value', 'id', 'uid', 'key']
|
||||
};
|
||||
|
||||
/**
|
||||
* 映射字典
|
||||
@@ -36,16 +36,16 @@ export const options = {
|
||||
* @returns {DictData}
|
||||
*/
|
||||
function responseConverter(response, dictMeta) {
|
||||
const dicts = response.content instanceof Array ? response.content : response
|
||||
const dicts = response.content instanceof Array ? response.content : response;
|
||||
if (dicts === undefined) {
|
||||
console.warn(`no dict data of "${dictMeta.type}" found in the response`)
|
||||
return []
|
||||
console.warn(`no dict data of "${dictMeta.type}" found in the response`);
|
||||
return [];
|
||||
}
|
||||
return dicts.map(d => dictConverter(d, dictMeta))
|
||||
return dicts.map((d) => dictConverter(d, dictMeta));
|
||||
}
|
||||
|
||||
export function mergeOptions(src) {
|
||||
mergeRecursive(options, src)
|
||||
mergeRecursive(options, src);
|
||||
}
|
||||
|
||||
export default options
|
||||
export default options;
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import Dict from './Dict'
|
||||
import { mergeOptions } from './DictOptions'
|
||||
import Dict from './Dict';
|
||||
import { mergeOptions } from './DictOptions';
|
||||
|
||||
export default function(Vue, options) {
|
||||
mergeOptions(options)
|
||||
export default function (Vue, options) {
|
||||
mergeOptions(options);
|
||||
Vue.mixin({
|
||||
data() {
|
||||
if (this.$options === undefined || this.$options.dicts === undefined || this.$options.dicts === null) {
|
||||
return {}
|
||||
return {};
|
||||
}
|
||||
const dict = new Dict()
|
||||
dict.owner = this
|
||||
const dict = new Dict();
|
||||
dict.owner = this;
|
||||
return {
|
||||
dict
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
if (!(this.dict instanceof Dict)) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
options.onCreated && options.onCreated(this.dict)
|
||||
options.onCreated && options.onCreated(this.dict);
|
||||
this.dict.init(this.$options.dicts).then(() => {
|
||||
options.onReady && options.onReady(this.dict)
|
||||
options.onReady && options.onReady(this.dict);
|
||||
this.$nextTick(() => {
|
||||
this.$emit('dictReady', this.dict)
|
||||
this.$emit('dictReady', this.dict);
|
||||
if (this.$options.methods && this.$options.methods.onDictReady instanceof Function) {
|
||||
this.$options.methods.onDictReady.call(this, this.dict)
|
||||
this.$options.methods.onDictReady.call(this, this.dict);
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default {
|
||||
'401': '认证失败,无法访问系统资源',
|
||||
'403': '当前操作没有权限',
|
||||
'404': '访问资源不存在',
|
||||
'default': '系统未知错误,请反馈给管理员'
|
||||
}
|
||||
401: '认证失败,无法访问系统资源',
|
||||
403: '当前操作没有权限',
|
||||
404: '访问资源不存在',
|
||||
default: '系统未知错误,请反馈给管理员'
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { parseTime } from './ruoyi';
|
||||
* 表格时间格式化
|
||||
*/
|
||||
export function formatDate(cellValue) {
|
||||
if (cellValue == null || cellValue == '') return '';
|
||||
if (cellValue == null || cellValue === '') return '';
|
||||
var date = new Date(cellValue);
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
||||
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min';
|
||||
|
||||
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||
|
||||
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
|
||||
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
||||
const publicKey =
|
||||
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' + 'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==';
|
||||
|
||||
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
||||
const privateKey =
|
||||
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
||||
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
|
||||
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
|
||||
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
|
||||
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
|
||||
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
|
||||
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
|
||||
'UP8iWi1Qw0Y='
|
||||
'UP8iWi1Qw0Y=';
|
||||
|
||||
// 加密
|
||||
export function encrypt(txt) {
|
||||
const encryptor = new JSEncrypt()
|
||||
encryptor.setPublicKey(publicKey) // 设置公钥
|
||||
return encryptor.encrypt(txt) // 对数据进行加密
|
||||
const encryptor = new JSEncrypt();
|
||||
encryptor.setPublicKey(publicKey); // 设置公钥
|
||||
return encryptor.encrypt(txt); // 对数据进行加密
|
||||
}
|
||||
|
||||
// 解密
|
||||
export function decrypt(txt) {
|
||||
const encryptor = new JSEncrypt()
|
||||
encryptor.setPrivateKey(privateKey) // 设置私钥
|
||||
return encryptor.decrypt(txt) // 对数据进行解密
|
||||
const encryptor = new JSEncrypt();
|
||||
encryptor.setPrivateKey(privateKey); // 设置私钥
|
||||
return encryptor.decrypt(txt); // 对数据进行解密
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { successCode } from '@/global/global';
|
||||
|
||||
let downloadLoadingInstance;
|
||||
// 是否显示重新登录
|
||||
export let isRelogin = { show: false };
|
||||
export const isRelogin = { show: false };
|
||||
|
||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
|
||||
// 创建axios实例
|
||||
|
||||
@@ -78,7 +78,7 @@ export function selectDictLabel(datas, value) {
|
||||
}
|
||||
var actions = [];
|
||||
Object.keys(datas).some((key) => {
|
||||
if (datas[key].value == '' + value) {
|
||||
if (datas[key].value === '' + value) {
|
||||
actions.push(datas[key].label);
|
||||
return true;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ export function selectDictLabels(datas, value, separator) {
|
||||
Object.keys(value.split(currentSeparator)).some((val) => {
|
||||
var match = false;
|
||||
Object.keys(datas).some((key) => {
|
||||
if (datas[key].value == '' + temp[val]) {
|
||||
if (datas[key].value === '' + temp[val]) {
|
||||
actions.push(datas[key].label + currentSeparator);
|
||||
match = true;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ export function sprintf(str) {
|
||||
|
||||
// 转换字符串,undefined,null等转化为""
|
||||
export function parseStrEmpty(str) {
|
||||
if (!str || str == 'undefined' || str == 'null') {
|
||||
if (!str || str === 'undefined' || str === 'null') {
|
||||
return '';
|
||||
}
|
||||
return str;
|
||||
@@ -140,7 +140,7 @@ export function parseStrEmpty(str) {
|
||||
export function mergeRecursive(source, target) {
|
||||
for (var p in target) {
|
||||
try {
|
||||
if (target[p].constructor == Object) {
|
||||
if (target[p].constructor === Object) {
|
||||
source[p] = mergeRecursive(source[p], target[p]);
|
||||
} else {
|
||||
source[p] = target[p];
|
||||
@@ -241,15 +241,14 @@ export async function blobValidate(data) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function isNullOrEmpty(val) {
|
||||
if (val === null || val === undefined) {
|
||||
return true
|
||||
return true;
|
||||
} else if (val === {} || Object.keys(val).length === 0) {
|
||||
return true
|
||||
return true;
|
||||
} else if (val.length === 0) {
|
||||
return true
|
||||
return true;
|
||||
} else {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,36 @@
|
||||
Math.easeInOutQuad = function(t, b, c, d) {
|
||||
t /= d / 2
|
||||
Math.easeInOutQuad = function (t, b, c, d) {
|
||||
t /= d / 2;
|
||||
if (t < 1) {
|
||||
return c / 2 * t * t + b
|
||||
return (c / 2) * t * t + b;
|
||||
}
|
||||
t--
|
||||
return -c / 2 * (t * (t - 2) - 1) + b
|
||||
}
|
||||
t--;
|
||||
return (-c / 2) * (t * (t - 2) - 1) + b;
|
||||
};
|
||||
|
||||
// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
|
||||
var requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60) }
|
||||
})()
|
||||
var requestAnimFrame = (function () {
|
||||
return (
|
||||
window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
function (callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
}
|
||||
);
|
||||
})();
|
||||
|
||||
/**
|
||||
* Because it's so fucking difficult to detect the scrolling element, just move them all
|
||||
* @param {number} amount
|
||||
*/
|
||||
function move(amount) {
|
||||
document.documentElement.scrollTop = amount
|
||||
document.body.parentNode.scrollTop = amount
|
||||
document.body.scrollTop = amount
|
||||
document.documentElement.scrollTop = amount;
|
||||
document.body.parentNode.scrollTop = amount;
|
||||
document.body.scrollTop = amount;
|
||||
}
|
||||
|
||||
function position() {
|
||||
return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop
|
||||
return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,27 +39,27 @@ function position() {
|
||||
* @param {Function} callback
|
||||
*/
|
||||
export function scrollTo(to, duration, callback) {
|
||||
const start = position()
|
||||
const change = to - start
|
||||
const increment = 20
|
||||
let currentTime = 0
|
||||
duration = (typeof (duration) === 'undefined') ? 500 : duration
|
||||
var animateScroll = function() {
|
||||
const start = position();
|
||||
const change = to - start;
|
||||
const increment = 20;
|
||||
let currentTime = 0;
|
||||
duration = typeof duration === 'undefined' ? 500 : duration;
|
||||
var animateScroll = function () {
|
||||
// increment the time
|
||||
currentTime += increment
|
||||
currentTime += increment;
|
||||
// find the value with the quadratic in-out easing function
|
||||
var val = Math.easeInOutQuad(currentTime, start, change, duration)
|
||||
var val = Math.easeInOutQuad(currentTime, start, change, duration);
|
||||
// move the document.body
|
||||
move(val)
|
||||
move(val);
|
||||
// do the animation unless its over
|
||||
if (currentTime < duration) {
|
||||
requestAnimFrame(animateScroll)
|
||||
requestAnimFrame(animateScroll);
|
||||
} else {
|
||||
if (callback && typeof (callback) === 'function') {
|
||||
if (callback && typeof callback === 'function') {
|
||||
// the animation is done so lets callback
|
||||
callback()
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
animateScroll()
|
||||
};
|
||||
animateScroll();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
/**
|
||||
* @Author: Lei Ding
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
|
||||
import Vue from 'vue';
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user