Commit 319dfc2de3db01f11ccdda006e8555a5f06a6e1b
1 parent
3ba458b1
修改函数命名防止冲突
Showing
13 changed files
with
51 additions
and
39 deletions
ruoyi-ui/src/main.js
| ... | ... | @@ -18,13 +18,13 @@ import './assets/icons' // icon |
| 18 | 18 | import './permission' // permission control |
| 19 | 19 | import { getDicts } from "@/api/system/dict/data"; |
| 20 | 20 | import { getConfigKey } from "@/api/system/config"; |
| 21 | -import { dateFormat, resetForm, addDateRange, selectDictLabel } from "@/utils/ruoyi"; | |
| 21 | +import { parseTime, resetForm, addDateRange, selectDictLabel } from "@/utils/ruoyi"; | |
| 22 | 22 | import Pagination from "@/components/Pagination"; |
| 23 | 23 | |
| 24 | 24 | // 全局方法挂载 |
| 25 | 25 | Vue.prototype.getDicts = getDicts |
| 26 | 26 | Vue.prototype.getConfigKey = getConfigKey |
| 27 | -Vue.prototype.dateFormat = dateFormat | |
| 27 | +Vue.prototype.parseTime = parseTime | |
| 28 | 28 | Vue.prototype.resetForm = resetForm |
| 29 | 29 | Vue.prototype.addDateRange = addDateRange |
| 30 | 30 | Vue.prototype.selectDictLabel = selectDictLabel | ... | ... |
ruoyi-ui/src/utils/ruoyi.js
| ... | ... | @@ -4,12 +4,42 @@ |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | // 日期格式化 |
| 7 | -export function dateFormat(date, pattern) { | |
| 8 | - var d = new Date(date).Format("yyyy-MM-dd hh:mm:ss"); | |
| 9 | - if (pattern) { | |
| 10 | - d = new Date(date).Format(pattern); | |
| 11 | - } | |
| 12 | - return d.toLocaleString(); | |
| 7 | +export function parseTime(time, pattern) { | |
| 8 | + if (arguments.length === 0) { | |
| 9 | + return null | |
| 10 | + } | |
| 11 | + const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' | |
| 12 | + let date | |
| 13 | + if (typeof time === 'object') { | |
| 14 | + date = time | |
| 15 | + } else { | |
| 16 | + if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { | |
| 17 | + time = parseInt(time) | |
| 18 | + } | |
| 19 | + if ((typeof time === 'number') && (time.toString().length === 10)) { | |
| 20 | + time = time * 1000 | |
| 21 | + } | |
| 22 | + date = new Date(time) | |
| 23 | + } | |
| 24 | + const formatObj = { | |
| 25 | + y: date.getFullYear(), | |
| 26 | + m: date.getMonth() + 1, | |
| 27 | + d: date.getDate(), | |
| 28 | + h: date.getHours(), | |
| 29 | + i: date.getMinutes(), | |
| 30 | + s: date.getSeconds(), | |
| 31 | + a: date.getDay() | |
| 32 | + } | |
| 33 | + const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { | |
| 34 | + let value = formatObj[key] | |
| 35 | + // Note: getDay() returns 0 on Sunday | |
| 36 | + if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } | |
| 37 | + if (result.length > 0 && value < 10) { | |
| 38 | + value = '0' + value | |
| 39 | + } | |
| 40 | + return value || 0 | |
| 41 | + }) | |
| 42 | + return time_str | |
| 13 | 43 | } |
| 14 | 44 | |
| 15 | 45 | // 表单重置 |
| ... | ... | @@ -55,22 +85,4 @@ export function sprintf(str) { |
| 55 | 85 | return arg; |
| 56 | 86 | }); |
| 57 | 87 | return flag ? str : ''; |
| 58 | -} | |
| 59 | - | |
| 60 | -Date.prototype.Format = function (fmt) { | |
| 61 | - var o = { | |
| 62 | - "M+": this.getMonth() + 1, // 月份 | |
| 63 | - "d+": this.getDate(), // 日 | |
| 64 | - "h+": this.getHours(), // 小时 | |
| 65 | - "m+": this.getMinutes(), // 分 | |
| 66 | - "s+": this.getSeconds(), // 秒 | |
| 67 | - "q+": Math.floor((this.getMonth() + 3) / 3), // 季度 | |
| 68 | - "S": this.getMilliseconds() // 毫秒 | |
| 69 | - }; | |
| 70 | - if (/(y+)/.test(fmt)) | |
| 71 | - fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); | |
| 72 | - for (var k in o) | |
| 73 | - if (new RegExp("(" + k + ")").test(fmt)) | |
| 74 | - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); | |
| 75 | - return fmt; | |
| 76 | -} | |
| 77 | 88 | \ No newline at end of file |
| 89 | +} | |
| 78 | 90 | \ No newline at end of file | ... | ... |
ruoyi-ui/src/views/monitor/logininfor/index.vue
| ... | ... | @@ -65,7 +65,7 @@ |
| 65 | 65 | <el-table-column label="操作信息" align="center" prop="msg" /> |
| 66 | 66 | <el-table-column label="登录日期" align="center" prop="loginTime" width="180"> |
| 67 | 67 | <template slot-scope="scope"> |
| 68 | - <span>{{ dateFormat(scope.row.loginTime) }}</span> | |
| 68 | + <span>{{ parseTime(scope.row.loginTime) }}</span> | |
| 69 | 69 | </template> |
| 70 | 70 | </el-table-column> |
| 71 | 71 | </el-table> | ... | ... |
ruoyi-ui/src/views/monitor/operlog/index.vue
| ... | ... | @@ -81,7 +81,7 @@ |
| 81 | 81 | <el-table-column label="操作状态" align="center" prop="status" :formatter="statusFormat" /> |
| 82 | 82 | <el-table-column label="操作日期" align="center" prop="operTime" width="180"> |
| 83 | 83 | <template slot-scope="scope"> |
| 84 | - <span>{{ dateFormat(scope.row.operTime) }}</span> | |
| 84 | + <span>{{ parseTime(scope.row.operTime) }}</span> | |
| 85 | 85 | </template> |
| 86 | 86 | </el-table-column> |
| 87 | 87 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| ... | ... | @@ -135,7 +135,7 @@ |
| 135 | 135 | </el-form-item> |
| 136 | 136 | </el-col> |
| 137 | 137 | <el-col :span="12"> |
| 138 | - <el-form-item label="操作时间:">{{ dateFormat(form.operTime) }}</el-form-item> | |
| 138 | + <el-form-item label="操作时间:">{{ parseTime(form.operTime) }}</el-form-item> | |
| 139 | 139 | </el-col> |
| 140 | 140 | <el-col :span="24"> |
| 141 | 141 | <el-form-item label="异常信息:" v-if="form.status === 1">{{ form.errorMsg }}</el-form-item> | ... | ... |
ruoyi-ui/src/views/system/config/index.vue
| ... | ... | @@ -58,7 +58,7 @@ |
| 58 | 58 | <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> |
| 59 | 59 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 60 | 60 | <template slot-scope="scope"> |
| 61 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 61 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 62 | 62 | </template> |
| 63 | 63 | </el-table-column> |
| 64 | 64 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/dept/index.vue
| ... | ... | @@ -51,7 +51,7 @@ |
| 51 | 51 | <el-table-column prop="status" label="状态" :formatter="statusFormat" width="100"></el-table-column> |
| 52 | 52 | <el-table-column label="创建时间" align="center" prop="createTime" width="200"> |
| 53 | 53 | <template slot-scope="scope"> |
| 54 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 54 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 55 | 55 | </template> |
| 56 | 56 | </el-table-column> |
| 57 | 57 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/dict/data.vue
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> |
| 46 | 46 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 47 | 47 | <template slot-scope="scope"> |
| 48 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 48 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 49 | 49 | </template> |
| 50 | 50 | </el-table-column> |
| 51 | 51 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/dict/index.vue
| ... | ... | @@ -69,7 +69,7 @@ |
| 69 | 69 | <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> |
| 70 | 70 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 71 | 71 | <template slot-scope="scope"> |
| 72 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 72 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 73 | 73 | </template> |
| 74 | 74 | </el-table-column> |
| 75 | 75 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/menu/index.vue
| ... | ... | @@ -44,7 +44,7 @@ |
| 44 | 44 | <el-table-column prop="visible" label=" 可见" :formatter="visibleFormat" width="80px"></el-table-column> |
| 45 | 45 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 46 | 46 | <template slot-scope="scope"> |
| 47 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 47 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 48 | 48 | </template> |
| 49 | 49 | </el-table-column> |
| 50 | 50 | <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/notice/index.vue
| ... | ... | @@ -60,7 +60,7 @@ |
| 60 | 60 | <el-table-column label="创建者" align="center" prop="createBy" width="100" /> |
| 61 | 61 | <el-table-column label="创建时间" align="center" prop="createTime" width="100"> |
| 62 | 62 | <template slot-scope="scope"> |
| 63 | - <span>{{ dateFormat(scope.row.createTime, 'yyyy-MM-dd') }}</span> | |
| 63 | + <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span> | |
| 64 | 64 | </template> |
| 65 | 65 | </el-table-column> |
| 66 | 66 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/post/index.vue
| ... | ... | @@ -43,7 +43,7 @@ |
| 43 | 43 | <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" /> |
| 44 | 44 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 45 | 45 | <template slot-scope="scope"> |
| 46 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 46 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 47 | 47 | </template> |
| 48 | 48 | </el-table-column> |
| 49 | 49 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/role/index.vue
| ... | ... | @@ -78,7 +78,7 @@ |
| 78 | 78 | </el-table-column> |
| 79 | 79 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 80 | 80 | <template slot-scope="scope"> |
| 81 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 81 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 82 | 82 | </template> |
| 83 | 83 | </el-table-column> |
| 84 | 84 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ... | ... |
ruoyi-ui/src/views/system/user/index.vue
| ... | ... | @@ -100,7 +100,7 @@ |
| 100 | 100 | </el-table-column> |
| 101 | 101 | <el-table-column label="创建时间" align="center" prop="createTime" width="160"> |
| 102 | 102 | <template slot-scope="scope"> |
| 103 | - <span>{{ dateFormat(scope.row.createTime) }}</span> | |
| 103 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 104 | 104 | </template> |
| 105 | 105 | </el-table-column> |
| 106 | 106 | <el-table-column | ... | ... |