Commit 103ee4cc by linjinhong

podus添加时间转换

parent 473240f9
......@@ -32,6 +32,7 @@ declare module 'vue' {
ElImage: typeof import('element-plus/es')['ElImage']
ElInput: typeof import('element-plus/es')['ElInput']
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
ElLink: typeof import('element-plus/es')['ElLink']
ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElOption: typeof import('element-plus/es')['ElOption']
......
......@@ -16,6 +16,7 @@
"dayjs": "^1.11.13",
"element-plus": "^2.6.0",
"lodash-es": "^4.17.21",
"luxon": "^3.7.1",
"pinia": "^2.1.7",
"splitpanes": "^3.1.5",
"vue": "^3.4.19",
......@@ -26,6 +27,7 @@
"xlsx": "^0.18.5"
},
"devDependencies": {
"@types/luxon": "^3.7.1",
"@types/splitpanes": "^2.2.6",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
......@@ -1989,6 +1991,13 @@
"@types/lodash": "*"
}
},
"node_modules/@types/luxon": {
"version": "3.7.1",
"resolved": "https://registry.npmmirror.com/@types/luxon/-/luxon-3.7.1.tgz",
"integrity": "sha512-H3iskjFIAn5SlJU7OuxUmTEpebK6TKB8rxZShDslBMZJ5u9S//KM1sbdAisiSrqwLQncVjnpi2OK2J51h+4lsg==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/semver": {
"version": "7.7.0",
"resolved": "https://registry.npmmirror.com/@types/semver/-/semver-7.7.0.tgz",
......@@ -4882,6 +4891,15 @@
"yallist": "^3.0.2"
}
},
"node_modules/luxon": {
"version": "3.7.1",
"resolved": "https://registry.npmmirror.com/luxon/-/luxon-3.7.1.tgz",
"integrity": "sha512-RkRWjA926cTvz5rAb1BqyWkKbbjzCGchDUIKMCUvNi17j6f6j8uHGDV82Aqcqtzd+icoYpELmG3ksgGiFNNcNg==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/magic-string": {
"version": "0.30.17",
"resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.17.tgz",
......
......@@ -18,6 +18,7 @@
"dayjs": "^1.11.13",
"element-plus": "^2.6.0",
"lodash-es": "^4.17.21",
"luxon": "^3.7.1",
"pinia": "^2.1.7",
"splitpanes": "^3.1.5",
"vue": "^3.4.19",
......@@ -28,6 +29,7 @@
"xlsx": "^0.18.5"
},
"devDependencies": {
"@types/luxon": "^3.7.1",
"@types/splitpanes": "^2.2.6",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
......
<template>
<div class="log-list">
<div
v-for="l in logList"
:key="l.id"
class="log-item flex"
>
<div v-for="l in logList" :key="l.id" class="log-item flex">
<div class="log-item-icon">
<Icon name="a-2labadianji3x" />
</div>
<div class="log-item-time">
<span>{{ l.createTime }}</span>
<span>{{ l.local && `${l.local}:` }}{{ l.createTime }}</span>
</div>
<div v-if="l.employeeName" class="log-item-name">
<span>{{ l.employeeName }}</span>
......@@ -45,7 +41,7 @@ defineProps({
}
.log-item-time {
width: 140px;
// width: 220px;
}
.log-item-name {
......
......@@ -200,6 +200,7 @@ export interface LogListData {
employeeName?: string
description?: string
createTime?: string
local?: string
}
export interface QaData {
......
......@@ -144,6 +144,7 @@ export interface LogListData {
description: string
deleteContent: string
createTime: string
local?: string
}
export interface ProductionClient {
code?: string
......
import { get } from 'lodash-es'
import { ElMessage } from 'element-plus'
import { DateTime } from 'luxon'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function val<T>(data: T, key: string | ((data: T) => any)) {
if (typeof key === 'function') return key(data)
......@@ -20,3 +21,22 @@ export function copyText(text: string) {
document.body.removeChild(oInput)
ElMessage.success('复制成功')
}
/**
* 将本地时间转换为北京时间(自动检测时区)
* @param {string} localTime - 本地时间字符串,格式 YYYY-MM-DD HH:mm:ss
* @returns {string} 北京时间,格式 YYYY-MM-DD HH:mm:ss
*/
export function convertToChinaTime(
timeString: string,
currentZone: string = 'local',
targetZone: string = 'Asia/Shanghai',
) {
// 将输入的时间字符串解析为本地时间,假设输入时间是本地时间
const inputTime = DateTime.fromFormat(timeString, 'yyyy-MM-dd HH:mm:ss', {
zone: currentZone,
})
const chinaTime = inputTime.setZone(targetZone)
return chinaTime.toFormat('yyyy-MM-dd HH:mm:ss')
}
......@@ -36,6 +36,7 @@ import { showConfirm } from '@/utils/ui'
import { isArray, isString } from '@/utils/validate'
import ResultInfo from '../podUs/components/ResultInfo.vue'
import { filePath } from '@/api/axios'
import { convertToChinaTime } from '@/utils/index'
import { useValue } from '@/utils/hooks/useValue'
......@@ -341,6 +342,19 @@ const pickerOptions = {
return [start, end]
},
},
{
text: '转换中国时间',
value: () => {
console.log(3469, timeRange.value)
if (timeRange.value?.length) {
const end = timeRange.value[1] ?? ''
const start = timeRange.value[0] ?? ''
return [convertToChinaTime(start), convertToChinaTime(end)]
} else {
return getDateRange(0)
}
},
},
],
}
......@@ -420,7 +434,7 @@ const submitExportForm = async () => {
} catch (e) {
exportVisible.value = false
exportLoading.value = false
}
}
}
const handleSizeChange = (pageSize: number) => {
pagination.value.pageSize = pageSize
......@@ -514,7 +528,13 @@ const operationLog = async () => {
if (currentRowId.value) {
const res = await getOperationLogApi(currentRowId.value as number)
if (res.code !== 200) return
logList.value = res.data
logList.value = res.data.map((el) => {
return {
...el,
local: 'BeiJing',
}
})
tempChinaLogs.value = [...logList.value]
}
} catch (e) {
console.error(e)
......@@ -620,6 +640,17 @@ const getOrderByIdApi = async (type: string) => {
}
}
const tempChinaLogs = ref<LogListData[]>([])
function changeChinaTime(zone: string) {
logList.value = tempChinaLogs.value.map((el) => {
return {
...el,
createTime: convertToChinaTime(el.createTime, 'Asia/Shanghai', zone),
local: zone.split('/')[1] === 'Shanghai' ? 'BeiJing' : zone.split('/')[1],
}
})
}
const resultConfirm = () => {
search()
loadTabData()
......@@ -1000,6 +1031,29 @@ onMounted(() => {
</TableView>
</el-tab-pane>
<el-tab-pane label="操作日志" @tab-click="operationLog">
<div>
<el-button
type="primary"
size="small"
@click="changeChinaTime('Asia/Shanghai')"
>转换为中国时间</el-button
>
<el-button
type="primary"
size="small"
style="margin-left: 10px"
@click="changeChinaTime('America/New_York')"
>转换为新泽西时间</el-button
>
<el-button
type="primary"
size="small"
style="margin-left: 10px"
@click="changeChinaTime('America/Los_Angeles')"
>转换为洛杉矶时间</el-button
>
</div>
<LogList
v-loading="logLoading"
:log-list="logList"
......
......@@ -1892,6 +1892,32 @@
width="1000px"
:close-on-click-modal="false"
>
<template #header="{ titleId, titleClass }">
<div style="display: flex" class="my-header">
<div :id="titleId" :class="titleClass">操作日志</div>
<!-- <el-button
type="primary"
size="small"
style="margin-left: 10px"
@click="changeChinaTime"
>转换为中国时间</el-button
> -->
<el-button
type="primary"
size="small"
style="margin-left: 10px"
@click="changeChinaTime('America/New_York')"
>转换为新泽西时间</el-button
>
<el-button
type="primary"
size="small"
style="margin-left: 10px"
@click="changeChinaTime('America/Los_Angeles')"
>转换为洛杉矶时间</el-button
>
</div>
</template>
<LogList :log-list="logList" />
</el-dialog>
<FastProduction
......@@ -2172,6 +2198,7 @@
<script setup lang="ts">
import { getUserMarkList } from '@/api/common'
// import { AnyObject } from '@/types/api/warehouse'
import { convertToChinaTime } from '@/utils/index'
import {
InfoFilled,
ArrowDown,
......@@ -2462,6 +2489,19 @@ const pickerOptions = {
return [start, end]
},
},
{
text: '转换中国时间',
value: () => {
console.log(3469, timeRange.value)
if (timeRange.value?.length) {
const end = timeRange.value[1] ?? ''
const start = timeRange.value[0] ?? ''
return [convertToChinaTime(start), convertToChinaTime(end)]
} else {
return getDateRange(0)
}
},
},
],
}
const filteredImages = (imageAry: string | null) => {
......@@ -3724,7 +3764,14 @@ const operationLog = async (id: number, e: MouseEvent | null) => {
try {
const res = await getOperationLogApi(id)
if (res.code !== 200) return
logList.value = res.data
logList.value = res.data.map((el) => {
return {
...el,
local: 'BeiJing',
}
})
tempChinaLogs.value = [...logList.value]
logVisible.value = true
} catch (e) {
console.error(e)
......@@ -4755,6 +4802,17 @@ const statusPush = async () => {
}
}
const tempChinaLogs = ref<LogListData[]>([])
function changeChinaTime(zone: string) {
logList.value = tempChinaLogs.value.map((el) => {
return {
...el,
createTime: convertToChinaTime(el.createTime, 'Asia/Shanghai', zone),
local: zone.split('/')[1],
}
})
}
useRouter().beforeEach((to, from, next) => {
handleBeforeRouteLeave(to, from, next)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment