提交 5947eb9e authored 作者: 刘守彩's avatar 刘守彩

feat: utils update

上级 17e54a2d
......@@ -204,7 +204,7 @@ export default {
}
}
// 获取达到条件的日期是星期X
const thisWeek = this.formatDate(
const thisWeek = this.$formatDate(
new Date(YY + '-' + MM + '-' + thisDD + ' 00:00:00'),
'week'
);
......@@ -231,7 +231,7 @@ export default {
} else if (this.dayRule == 'weekDay') {
// 如果指定了是星期几
// 获取当前日期是属于星期几
const thisWeek = this.formatDate(
const thisWeek = this.$formatDate(
new Date(YY + '-' + MM + '-' + DD + ' 00:00:00'),
'week'
);
......@@ -251,7 +251,7 @@ export default {
} else if (this.dayRule == 'assWeek') {
// 如果指定了是第几周的星期几
// 获取每月1号是属于星期几
const thisWeek = this.formatDate(
const thisWeek = this.$formatDate(
new Date(YY + '-' + MM + '-' + DD + ' 00:00:00'),
'week'
);
......@@ -281,7 +281,7 @@ export default {
}
}
// 获取月末最后一天是星期几
const thisWeek = this.formatDate(
const thisWeek = this.$formatDate(
new Date(YY + '-' + MM + '-' + thisDD + ' 00:00:00'),
'week'
);
......@@ -576,7 +576,7 @@ export default {
}
},
// 格式化日期格式如:2017-9-19 18:04:33
formatDate(value, type) {
$formatDate(value, type) {
// 计算日期相关值
const time = typeof value === 'number' ? new Date(value) : value;
const Y = time.getFullYear();
......@@ -609,7 +609,7 @@ export default {
// 检查日期是否存在
checkDate(value) {
const time = new Date(value);
const format = this.formatDate(time);
const format = this.$formatDate(time);
return value === format;
}
}
......
......@@ -4,21 +4,25 @@ import { download } from '@/utils/request';
import { getDicts } from '@/api/system/dict/data';
import { getConfigKey } from '@/api/system/config';
import {
parseTime,
resetForm,
addDateRange,
selectDictLabel,
selectDictLabels,
handleTree
} from '@/utils/ruoyi';
import { formatDate, debounce, throttle, cloneDeep } from '@/utils/index';
// 全局方法挂载
Vue.prototype.getDicts = getDicts;
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;
Vue.prototype.$getDicts = getDicts;
Vue.prototype.$getConfigKey = getConfigKey;
Vue.prototype.$resetForm = resetForm;
Vue.prototype.$addDateRange = addDateRange;
Vue.prototype.$selectDictLabel = selectDictLabel;
Vue.prototype.$selectDictLabels = selectDictLabels;
Vue.prototype.$download = download;
Vue.prototype.$handleTree = handleTree;
Vue.prototype.$formatDate = formatDate;
Vue.prototype.$debounce = debounce;
Vue.prototype.$throttle = throttle;
Vue.prototype.$cloneDeep = cloneDeep;
/**
* 通用js方法封装处理
* Copyright (c) 2019 ruoyi
*/
// 日期格式化
export function parseTime(time, pattern) {
if (arguments.length === 0 || !time) {
return null;
}
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}';
let date;
if (typeof time === 'object') {
date = time;
} else {
if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
time = parseInt(time);
} else if (typeof time === 'string') {
time = time
.replace(new RegExp(/-/gm), '/')
.replace('T', ' ')
.replace(new RegExp(/\.[\d]{3}/gm), '');
}
if (typeof time === 'number' && time.toString().length === 10) {
time = time * 1000;
}
date = new Date(time);
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
};
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key];
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value];
}
if (result.length > 0 && value < 10) {
value = '0' + value;
}
return value || 0;
});
return time_str;
}
// 表单重置
export function resetForm(refName) {
if (this.$refs[refName]) {
......
......@@ -345,7 +345,7 @@
</el-col>
<el-col :span="12">
<el-form-item label="下次执行时间:">{{
parseTime(form.nextValidTime)
$formatDate(form.nextValidTime)
}}</el-form-item>
</el-col>
<el-col :span="24">
......@@ -463,7 +463,7 @@ export default {
},
// 任务组名字典翻译
jobGroupFormat(row, column) {
return this.selectDictLabel(this.dict.type.sys_job_group, row.jobGroup);
return this.$selectDictLabel(this.dict.type.sys_job_group, row.jobGroup);
},
// 取消按钮
cancel() {
......@@ -482,7 +482,7 @@ export default {
concurrent: 1,
status: '0'
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -491,7 +491,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
// 多选框选中数据
......@@ -616,7 +616,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'monitor/job/export',
{
...this.queryParams
......
......@@ -168,7 +168,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -298,7 +298,7 @@ export default {
/** 查询调度日志列表 */
getList() {
this.loading = true;
listJobLog(this.addDateRange(this.queryParams, this.dateRange)).then(
listJobLog(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.jobLogList = response.rows;
this.total = response.total;
......@@ -319,7 +319,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
// 多选框选中数据
......@@ -361,7 +361,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'/monitor/jobLog/export',
{
...this.queryParams
......
......@@ -174,7 +174,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.loginTime) }}</span>
<span>{{ $formatDate(scope.row.loginTime) }}</span>
</template>
</el-table-column>
</ty-table>
......@@ -232,7 +232,7 @@ export default {
getList() {
this.loading = true;
this.$_syncQueryUrl(this.queryParams);
list(this.addDateRange(this.queryParams, this.dateRange)).then(
list(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.list = response.rows;
this.total = response.total;
......@@ -248,7 +248,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.queryParams.pageNum = 1;
this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order);
},
......@@ -307,7 +307,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'monitor/logininfor/export',
{
...this.queryParams
......
......@@ -74,7 +74,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.loginTime) }}</span>
<span>{{ $formatDate(scope.row.loginTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -145,7 +145,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
/** 强退按钮操作 */
......
......@@ -189,7 +189,7 @@
:sort-orders="['descending', 'ascending']"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.operTime) }}</span>
<span>{{ $formatDate(scope.row.operTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -270,7 +270,7 @@
</el-col>
<el-col :span="8">
<el-form-item label="操作时间:">{{
parseTime(form.operTime)
$formatDate(form.operTime)
}}</el-form-item>
</el-col>
<el-col :span="24">
......@@ -334,7 +334,7 @@ export default {
/** 查询登录日志 */
getList() {
this.loading = true;
list(this.addDateRange(this.queryParams, this.dateRange)).then(
list(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.list = response.rows;
this.total = response.total;
......@@ -344,7 +344,7 @@ export default {
},
// 操作日志类型字典翻译
typeFormat(row, column) {
return this.selectDictLabel(
return this.$selectDictLabel(
this.dict.type.sys_oper_type,
row.businessType
);
......@@ -357,7 +357,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.queryParams.pageNum = 1;
this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order);
},
......@@ -406,7 +406,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'monitor/operlog/export',
{
...this.queryParams
......
......@@ -167,7 +167,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -298,7 +298,7 @@ export default {
/** 查询参数列表 */
getList() {
this.loading = true;
listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(
listConfig(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.configList = response.rows;
this.total = response.total;
......@@ -321,7 +321,7 @@ export default {
configType: 'Y',
remark: undefined
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -331,7 +331,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
/** 新增按钮操作 */
......@@ -392,7 +392,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'system/config/export',
{
...this.queryParams
......
......@@ -88,7 +88,7 @@
width="200"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -283,7 +283,7 @@ export default {
getList() {
this.loading = true;
listDept(this.queryParams).then((response) => {
this.deptList = this.handleTree(response.data, 'deptId');
this.deptList = this.$handleTree(response.data, 'deptId');
this.loading = false;
});
},
......@@ -315,7 +315,7 @@ export default {
email: undefined,
status: '0'
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -323,7 +323,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
/** 新增按钮操作 */
......@@ -335,7 +335,7 @@ export default {
this.open = true;
this.title = '添加部门';
listDept().then((response) => {
this.deptOptions = this.handleTree(response.data, 'deptId');
this.deptOptions = this.$handleTree(response.data, 'deptId');
});
},
/** 展开/折叠操作 */
......@@ -354,7 +354,7 @@ export default {
this.open = true;
this.title = '修改部门';
listDeptExcludeChild(row.deptId).then((response) => {
this.deptOptions = this.handleTree(response.data, 'deptId');
this.deptOptions = this.$handleTree(response.data, 'deptId');
if (this.deptOptions.length == 0) {
const noResultsOptions = {
deptId: this.form.parentId,
......
......@@ -150,7 +150,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -380,7 +380,7 @@ export default {
status: '0',
remark: undefined
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -394,7 +394,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.queryParams.dictType = this.defaultDictType;
this.handleQuery();
},
......@@ -466,7 +466,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'system/dict/data/export',
{
...this.queryParams
......
......@@ -170,7 +170,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -294,7 +294,7 @@ export default {
/** 查询字典类型列表 */
getList() {
this.loading = true;
listType(this.addDateRange(this.queryParams, this.dateRange)).then(
listType(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.typeList = response.rows;
this.total = response.total;
......@@ -316,7 +316,7 @@ export default {
status: '0',
remark: undefined
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -326,7 +326,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
/** 新增按钮操作 */
......@@ -387,7 +387,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'system/dict/type/export',
{
...this.queryParams
......
......@@ -103,7 +103,7 @@
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -424,7 +424,7 @@ export default {
getList() {
this.loading = true;
listMenu(this.queryParams).then((response) => {
this.menuList = this.handleTree(response.data, 'menuId');
this.menuList = this.$handleTree(response.data, 'menuId');
this.loading = false;
});
},
......@@ -444,7 +444,7 @@ export default {
listMenu().then((response) => {
this.menuOptions = [];
const menu = { menuId: 0, menuName: '主类目', children: [] };
menu.children = this.handleTree(response.data, 'menuId');
menu.children = this.$handleTree(response.data, 'menuId');
this.menuOptions.push(menu);
});
},
......@@ -467,7 +467,7 @@ export default {
visible: '0',
status: '0'
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -475,7 +475,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
/** 新增按钮操作 */
......
......@@ -139,7 +139,7 @@
width="100"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -312,7 +312,7 @@ export default {
noticeContent: undefined,
status: '0'
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -321,7 +321,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
// 多选框选中数据
......
......@@ -123,7 +123,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -275,7 +275,7 @@ export default {
status: '0',
remark: undefined
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -284,7 +284,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
// 多选框选中数据
......@@ -345,7 +345,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'system/post/export',
{
...this.queryParams
......
......@@ -108,7 +108,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -204,7 +204,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
// 多选框选中数据
......
......@@ -149,7 +149,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -441,7 +441,7 @@ export default {
/** 查询角色列表 */
getList() {
this.loading = true;
listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
listRole(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.roleList = response.rows;
this.total = response.total;
......@@ -533,7 +533,7 @@ export default {
deptCheckStrictly: true,
remark: undefined
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -543,7 +543,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
// 多选框选中数据
......@@ -698,7 +698,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'system/role/export',
{
...this.queryParams
......
......@@ -75,7 +75,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
</el-table>
......@@ -152,7 +152,7 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.handleQuery();
},
/** 选择授权用户操作 */
......
......@@ -41,7 +41,7 @@
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
</el-table>
......
......@@ -225,7 +225,7 @@
width="160"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ $formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
......@@ -615,7 +615,7 @@ export default {
created() {
this.getList();
this.getDeptTree();
this.getConfigKey('sys.user.initPassword').then((response) => {
this.$getConfigKey('sys.user.initPassword').then((response) => {
this.initPassword = response.msg;
});
},
......@@ -623,7 +623,7 @@ export default {
/** 查询用户列表 */
getList() {
this.loading = true;
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
listUser(this.$addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.userList = response.rows;
this.total = response.total;
......@@ -683,7 +683,7 @@ export default {
postIds: [],
roleIds: []
};
this.resetForm('form');
this.$resetForm('form');
},
/** 搜索按钮操作 */
handleQuery() {
......@@ -693,7 +693,7 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm('queryForm');
this.$resetForm('queryForm');
this.queryParams.deptId = undefined;
this.$refs.tree.setCurrentKey(null);
this.handleQuery();
......@@ -800,7 +800,7 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.download(
this.$download(
'system/user/export',
{
...this.queryParams
......@@ -815,7 +815,7 @@ export default {
},
/** 下载模板操作 */
importTemplate() {
this.download(
this.$download(
'system/user/importTemplate',
{},
`user_template_${new Date().getTime()}.xlsx`
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论