Skip to content

Commit b79a187

Browse files
YunaiVgitee-org
authored andcommitted
!78 项目全局使用formatDate方法移除parseTime方法
Merge pull request !78 from puhui999/dev
2 parents 0d6ecfb + 0501983 commit b79a187

File tree

17 files changed

+60
-134
lines changed

17 files changed

+60
-134
lines changed

build/vite/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import progress from 'vite-plugin-progress'
66
import EslintPlugin from 'vite-plugin-eslint'
77
import PurgeIcons from 'vite-plugin-purge-icons'
88
import { ViteEjsPlugin } from 'vite-plugin-ejs'
9+
// @ts-ignore
910
import ElementPlus from 'unplugin-element-plus/vite'
1011
import AutoImport from 'unplugin-auto-import/vite'
1112
import Components from 'unplugin-vue-components/vite'
1213
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
1314
import viteCompression from 'vite-plugin-compression'
15+
import topLevelAwait from 'vite-plugin-top-level-await'
1416
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
1517
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
1618
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
@@ -95,6 +97,12 @@ export function createVitePlugins() {
9597
ext: '.gz', // 生成的压缩包后缀
9698
deleteOriginFile: false //压缩后是否删除源文件
9799
}),
98-
ViteEjsPlugin()
100+
ViteEjsPlugin(),
101+
topLevelAwait({
102+
// The export name of top-level await promise for each chunk module
103+
promiseExportName: '__tla',
104+
// The function to generate import names of top-level await promise in each chunk module
105+
promiseImportName: (i) => `__tla_${i}`
106+
})
99107
]
100108
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"vite-plugin-progress": "^0.0.6",
123123
"vite-plugin-purge-icons": "^0.9.2",
124124
"vite-plugin-svg-icons": "^2.0.1",
125+
"vite-plugin-top-level-await": "^1.3.0",
125126
"vite-plugin-vue-setup-extend": "^0.4.0",
126127
"vite-plugin-windicss": "^1.8.10",
127128
"vue-tsc": "^1.2.0",

src/components/bpmnProcessDesigner/package/designer/ProcessViewer.vue

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ const elementHover = (element) => {
280280
if (element.value.type === 'bpmn:StartEvent' && processInstance.value) {
281281
html = `<p>发起人:${processInstance.value.startUser.nickname}</p>
282282
<p>部门:${processInstance.value.startUser.deptName}</p>
283-
<p>创建时间:${parseTime(processInstance.value.createTime)}`
283+
<p>创建时间:${formatDate(processInstance.value.createTime)}`
284284
} else if (element.value.type === 'bpmn:UserTask') {
285285
// debugger
286286
let task = taskList.value.find((m) => m.id === activity.taskId) // 找到活动对应的 taskId
@@ -297,26 +297,26 @@ const elementHover = (element) => {
297297
html = `<p>审批人:${task.assigneeUser.nickname}</p>
298298
<p>部门:${task.assigneeUser.deptName}</p>
299299
<p>结果:${dataResult}</p>
300-
<p>创建时间:${parseTime(task.createTime)}</p>`
300+
<p>创建时间:${formatDate(task.createTime)}</p>`
301301
// html = `<p>审批人:${task.assigneeUser.nickname}</p>
302302
// <p>部门:${task.assigneeUser.deptName}</p>
303303
// <p>结果:${getIntDictOptions(
304304
// DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT,
305305
// task.result
306306
// )}</p>
307-
// <p>创建时间:${parseTime(task.createTime)}</p>`
307+
// <p>创建时间:${formatDate(task.createTime)}</p>`
308308
if (task.endTime) {
309-
html += `<p>结束时间:${parseTime(task.endTime)}</p>`
309+
html += `<p>结束时间:${formatDate(task.endTime)}</p>`
310310
}
311311
if (task.reason) {
312312
html += `<p>审批建议:${task.reason}</p>`
313313
}
314314
} else if (element.value.type === 'bpmn:ServiceTask' && processInstance.value) {
315315
if (activity.startTime > 0) {
316-
html = `<p>创建时间:${parseTime(activity.startTime)}</p>`
316+
html = `<p>创建时间:${formatDate(activity.startTime)}</p>`
317317
}
318318
if (activity.endTime > 0) {
319-
html += `<p>结束时间:${parseTime(activity.endTime)}</p>`
319+
html += `<p>结束时间:${formatDate(activity.endTime)}</p>`
320320
}
321321
console.log(html)
322322
} else if (element.value.type === 'bpmn:EndEvent' && processInstance.value) {
@@ -333,7 +333,7 @@ const elementHover = (element) => {
333333
// processInstance.value.result
334334
// )}</p>`
335335
if (processInstance.value.endTime) {
336-
html += `<p>结束时间:${parseTime(processInstance.value.endTime)}</p>`
336+
html += `<p>结束时间:${formatDate(processInstance.value.endTime)}</p>`
337337
}
338338
}
339339
console.log(html, 'html111111111111111')
@@ -348,50 +348,6 @@ const elementOut = (element) => {
348348
toRaw(overlays.value).remove({ element })
349349
elementOverlayIds.value[element.id] = null
350350
}
351-
const parseTime = (time) => {
352-
if (!time) {
353-
return null
354-
}
355-
const format = '{y}-{m}-{d} {h}:{i}:{s}'
356-
let date
357-
if (typeof time === 'object') {
358-
date = time
359-
} else {
360-
if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
361-
time = parseInt(time)
362-
} else if (typeof time === 'string') {
363-
time = time
364-
.replace(new RegExp(/-/gm), '/')
365-
.replace('T', ' ')
366-
.replace(new RegExp(/\.[\d]{3}/gm), '')
367-
}
368-
if (typeof time === 'number' && time.toString().length === 10) {
369-
time = time * 1000
370-
}
371-
date = new Date(time)
372-
}
373-
const formatObj = {
374-
y: date.getFullYear(),
375-
m: date.getMonth() + 1,
376-
d: date.getDate(),
377-
h: date.getHours(),
378-
i: date.getMinutes(),
379-
s: date.getSeconds(),
380-
a: date.getDay()
381-
}
382-
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
383-
let value = formatObj[key]
384-
// Note: getDay() returns 0 on Sunday
385-
if (key === 'a') {
386-
return ['', '', '', '', '', '', ''][value]
387-
}
388-
if (result.length > 0 && value < 10) {
389-
value = '0' + value
390-
}
391-
return value || 0
392-
})
393-
return time_str
394-
}
395351
396352
onMounted(() => {
397353
xml.value = props.value

src/config/axios/service.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,19 @@ const handleAuthorized = () => {
219219
if (!isRelogin.show) {
220220
isRelogin.show = true
221221
ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), {
222+
showCancelButton: false,
223+
closeOnClickModal: false,
224+
showClose: false,
222225
confirmButtonText: t('login.relogin'),
223-
cancelButtonText: t('common.cancel'),
224226
type: 'warning'
227+
}).then(() => {
228+
const { wsCache } = useCache()
229+
resetRouter() // 重置静态路由表
230+
wsCache.clear()
231+
removeToken()
232+
isRelogin.show = false
233+
window.location.href = '/'
225234
})
226-
.then(() => {
227-
const { wsCache } = useCache()
228-
resetRouter() // 重置静态路由表
229-
wsCache.clear()
230-
removeToken()
231-
isRelogin.show = false
232-
window.location.href = '/'
233-
})
234-
.catch(() => {
235-
isRelogin.show = false
236-
})
237235
}
238236
return Promise.reject(t('sys.api.timeoutMessage'))
239237
}

src/layout/components/Message/src/Message.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { parseTime } from '@/utils/formatTime'
2+
import { formatDate } from '@/utils/formatTime'
33
import * as NotifyMessageApi from '@/api/system/notify/message'
44
55
const { push } = useRouter()
@@ -57,7 +57,7 @@ onMounted(() => {
5757
{{ item.templateNickname }}:{{ item.templateContent }}
5858
</span>
5959
<span class="message-date">
60-
{{ parseTime(item.createTime) }}
60+
{{ formatDate(item.createTime) }}
6161
</span>
6262
</div>
6363
</div>

src/plugins/vxeTable/renderer/preview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ VXETable.renderer.add('XPreview', {
2525
)
2626
} else {
2727
return (
28+
// @ts-ignore
2829
<ElLink href={row[column.field]} target="_blank">
2930
{row[column.field]}
3031
</ElLink>

src/store/modules/dict.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineStore } from 'pinia'
22
import { store } from '../index'
3+
// @ts-ignore
34
import { DictDataVO } from '@/api/system/dict/types'
45
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
56
const { wsCache } = useCache('sessionStorage')

src/types/auto-components.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare module '@vue/runtime-core' {
2424
Echart: typeof import('./../components/Echart/src/Echart.vue')['default']
2525
Editor: typeof import('./../components/Editor/src/Editor.vue')['default']
2626
ElAutoResizer: typeof import('element-plus/es')['ElAutoResizer']
27+
ElAvatar: typeof import('element-plus/es')['ElAvatar']
2728
ElBadge: typeof import('element-plus/es')['ElBadge']
2829
ElButton: typeof import('element-plus/es')['ElButton']
2930
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
@@ -68,6 +69,7 @@ declare module '@vue/runtime-core' {
6869
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
6970
ElSelect: typeof import('element-plus/es')['ElSelect']
7071
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
72+
ElSpace: typeof import('element-plus/es')['ElSpace']
7173
ElSwitch: typeof import('element-plus/es')['ElSwitch']
7274
ElTable: typeof import('element-plus/es')['ElTable']
7375
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
@@ -78,7 +80,6 @@ declare module '@vue/runtime-core' {
7880
ElTimeline: typeof import('element-plus/es')['ElTimeline']
7981
ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem']
8082
ElTooltip: typeof import('element-plus/es')['ElTooltip']
81-
ElTransfer: typeof import('element-plus/es')['ElTransfer']
8283
ElTree: typeof import('element-plus/es')['ElTree']
8384
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
8485
ElUpload: typeof import('element-plus/es')['ElUpload']

src/utils/formatTime.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,6 @@ export function formatDate(date: Date, format?: string): string {
2323
return dayjs(date).format(format)
2424
}
2525

26-
// TODO 芋艿:稍后去掉
27-
// 日期格式化
28-
export function parseTime(time: any, pattern?: string) {
29-
if (arguments.length === 0 || !time) {
30-
return null
31-
}
32-
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
33-
let date
34-
if (typeof time === 'object') {
35-
date = time
36-
} else {
37-
if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
38-
time = parseInt(time)
39-
} else if (typeof time === 'string') {
40-
time = time
41-
.replace(new RegExp(/-/gm), '/')
42-
.replace('T', ' ')
43-
.replace(new RegExp(/\.\d{3}/gm), '')
44-
}
45-
if (typeof time === 'number' && time.toString().length === 10) {
46-
time = time * 1000
47-
}
48-
date = new Date(time)
49-
}
50-
const formatObj = {
51-
y: date.getFullYear(),
52-
m: date.getMonth() + 1,
53-
d: date.getDate(),
54-
h: date.getHours(),
55-
i: date.getMinutes(),
56-
s: date.getSeconds(),
57-
a: date.getDay()
58-
}
59-
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
60-
let value = formatObj[key]
61-
// Note: getDay() returns 0 on Sunday
62-
if (key === 'a') {
63-
return ['日', '一', '二', '三', '四', '五', '六'][value]
64-
}
65-
if (result.length > 0 && value < 10) {
66-
value = '0' + value
67-
}
68-
return value || 0
69-
})
70-
return time_str
71-
}
72-
7326
/**
7427
* 获取当前日期是第几周
7528
* @param dateTime 当前传入的日期值
@@ -87,8 +40,7 @@ export function getWeek(dateTime: Date): number {
8740
if (dayOfWeek != 0) spendDay = 7 - dayOfWeek + 1
8841
firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay)
8942
const d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000)
90-
const result = Math.ceil(d / 7)
91-
return result
43+
return Math.ceil(d / 7)
9244
}
9345

9446
/**

src/utils/tree.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export const handleTree = (data: any[], id?: string, parentId?: string, children
265265
}
266266
return tree
267267
}
268+
268269
/**
269270
* 构造树型结构数据
270271
* @param {*} data 数据源
@@ -273,6 +274,7 @@ export const handleTree = (data: any[], id?: string, parentId?: string, children
273274
* @param {*} children 孩子节点字段 默认 'children'
274275
* @param {*} rootId 根Id 默认 0
275276
*/
277+
// @ts-ignore
276278
export const handleTree2 = (data, id, parentId, children, rootId) => {
277279
id = id || 'id'
278280
parentId = parentId || 'parentId'

0 commit comments

Comments
 (0)