use public date format

This commit is contained in:
Fine 2022-08-21 12:55:35 +08:00
parent 9c2be1a64f
commit 4ed22ffa23
12 changed files with 70 additions and 48 deletions

View File

@ -14,6 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import dayjs from "dayjs";
import getLocalTime from "@/utils/localtime";
export default function dateFormatStep( export default function dateFormatStep(
date: Date, date: Date,
step: string, step: string,
@ -99,3 +101,9 @@ export const dateFormatTime = (date: Date, step: string): string => {
} }
return ""; return "";
}; };
export const dateFormat = (
date: number,
utc: string,
pattern = "YYYY-MM-DD HH:mm:ss"
) => dayjs(getLocalTime(utc, new Date(date))).format(pattern);

View File

@ -27,7 +27,9 @@ limitations under the License. -->
['message', 'stack'].includes(item.label) ? 'max-item' : '', ['message', 'stack'].includes(item.label) ? 'max-item' : '',
]" ]"
> >
<span v-if="item.label === 'time'">{{ dateFormat(data.time) }}</span> <span v-if="item.label === 'time'">{{
dateFormat(data.time, appStore.utc)
}}</span>
<span v-else-if="item.label === 'errorUrl'">{{ data.pagePath }}</span> <span v-else-if="item.label === 'errorUrl'">{{ data.pagePath }}</span>
<el-tooltip v-else :content="data[item.label] || '-'"> <el-tooltip v-else :content="data[item.label] || '-'">
<span> <span>
@ -39,20 +41,19 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import dayjs from "dayjs";
import { BrowserLogConstants } from "./data"; import { BrowserLogConstants } from "./data";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
/*global defineProps, defineEmits, NodeListOf */ /*global defineProps, defineEmits, NodeListOf */
const props = defineProps({ const props = defineProps({
data: { type: Object as any, default: () => ({}) }, data: { type: Object as any, default: () => ({}) },
}); });
const appStore = useAppStoreWithOut();
const columns = BrowserLogConstants; const columns = BrowserLogConstants;
const emit = defineEmits(["select"]); const emit = defineEmits(["select"]);
const logItem = ref<any>(null); const logItem = ref<any>(null);
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern);
function showSelectSpan() { function showSelectSpan() {
const items: NodeListOf<any> = document.querySelectorAll(".log-item"); const items: NodeListOf<any> = document.querySelectorAll(".log-item");

View File

@ -24,7 +24,7 @@ limitations under the License. -->
v-if="['timestamp', 'time'].includes(item.label)" v-if="['timestamp', 'time'].includes(item.label)"
class="g-sm-8 mb-10" class="g-sm-8 mb-10"
> >
{{ dateFormat(currentLog[item.label]) }} {{ dateFormat(currentLog[item.label], appStore.utc) }}
</span> </span>
<textarea <textarea
class="content mb-10" class="content mb-10"
@ -43,8 +43,9 @@ limitations under the License. -->
import { computed } from "vue"; import { computed } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import dayjs from "dayjs";
import { Option } from "@/types/app"; import { Option } from "@/types/app";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -52,6 +53,7 @@ const props = defineProps({
columns: { type: Array as PropType<Option[]>, default: () => [] }, columns: { type: Array as PropType<Option[]>, default: () => [] },
}); });
const { t } = useI18n(); const { t } = useI18n();
const appStore = useAppStoreWithOut();
const logTags = computed(() => { const logTags = computed(() => {
if (!props.currentLog.tags) { if (!props.currentLog.tags) {
return []; return [];
@ -60,8 +62,6 @@ const logTags = computed(() => {
return `${d.key} = ${d.value}`; return `${d.key} = ${d.value}`;
}); });
}); });
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.content { .content {

View File

@ -22,7 +22,7 @@ limitations under the License. -->
@click="selectLog(item.label, data[item.label])" @click="selectLog(item.label, data[item.label])"
> >
<span v-if="item.label === 'timestamp'"> <span v-if="item.label === 'timestamp'">
{{ dateFormat(data.timestamp) }} {{ dateFormat(data.timestamp, appStore.utc) }}
</span> </span>
<span v-else-if="item.label === 'tags'"> <span v-else-if="item.label === 'tags'">
{{ tags }} {{ tags }}
@ -39,11 +39,12 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, inject } from "vue"; import { computed, inject } from "vue";
import dayjs from "dayjs";
import { ServiceLogConstants } from "./data"; import { ServiceLogConstants } from "./data";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
/*global defineProps, defineEmits, Recordable */ /*global defineProps, defineEmits, Recordable */
const props = defineProps({ const props = defineProps({
@ -51,6 +52,7 @@ const props = defineProps({
noLink: { type: Boolean, default: true }, noLink: { type: Boolean, default: true },
}); });
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const appStore = useAppStoreWithOut();
const options: Recordable<LayoutConfig> = inject("options") || {}; const options: Recordable<LayoutConfig> = inject("options") || {};
const emit = defineEmits(["select"]); const emit = defineEmits(["select"]);
const columns = ServiceLogConstants; const columns = ServiceLogConstants;
@ -64,8 +66,6 @@ const tags = computed(() => {
) )
); );
}); });
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern);
function selectLog(label: string, value: string) { function selectLog(label: string, value: string) {
if (label === "traceId") { if (label === "traceId") {

View File

@ -461,14 +461,14 @@ function visTimeline() {
task.value = properties.data; task.value = properties.data;
}); });
const itemsAlwaysDraggable = const itemsAlwaysDraggable =
fixedTriggerDuration < 1800 fixedTriggerDuration > 1800
? { ? {
item: true, item: true,
range: true, range: true,
} }
: undefined; : undefined;
const editable = const editable =
fixedTriggerDuration < 1800 fixedTriggerDuration > 1800
? { ? {
updateTime: true, updateTime: true,
} }

View File

@ -70,10 +70,15 @@ limitations under the License. -->
</a> </a>
</div> </div>
<div class="grey ell sm"> <div class="grey ell sm">
<span class="mr-10 sm">{{ dateFormat(i.taskStartTime) }}</span> <span class="mr-10 sm">
{{ dateFormat(i.taskStartTime, appStore.utc) }}
</span>
<span class="mr-10 sm"> <span class="mr-10 sm">
{{ {{
dateFormat(i.taskStartTime + i.fixedTriggerDuration * 1000) dateFormat(
i.taskStartTime + i.fixedTriggerDuration * 1000,
appStore.utc
)
}} }}
</span> </span>
</div> </div>
@ -94,14 +99,13 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import dayjs from "dayjs";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useNetworkProfilingStore } from "@/store/modules/network-profiling"; import { useNetworkProfilingStore } from "@/store/modules/network-profiling";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
import { EBPFTaskList } from "@/types/ebpf"; import { EBPFTaskList } from "@/types/ebpf";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import TaskDetails from "../../components/TaskDetails.vue"; import TaskDetails from "../../components/TaskDetails.vue";
import dateFormatStep from "@/utils/dateFormat"; import dateFormatStep, { dateFormat } from "@/utils/dateFormat";
import getLocalTime from "@/utils/localtime"; import getLocalTime from "@/utils/localtime";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
@ -109,8 +113,6 @@ const { t } = useI18n();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const networkProfilingStore = useNetworkProfilingStore(); const networkProfilingStore = useNetworkProfilingStore();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern);
const viewDetail = ref<boolean>(false); const viewDetail = ref<boolean>(false);
const enableTasks = ref<boolean>(false); const enableTasks = ref<boolean>(false);

View File

@ -43,7 +43,7 @@ limitations under the License. -->
</div> </div>
<div class="grey ell sm"> <div class="grey ell sm">
<span class="tag mr-10 sm"> {{ i.duration }} ms </span> <span class="tag mr-10 sm"> {{ i.duration }} ms </span>
{{ dateFormat(parseInt(i.start)) }} {{ dateFormat(parseInt(i.start), appStore.utc) }}
</div> </div>
</td> </td>
</tr> </tr>
@ -53,16 +53,16 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import dayjs from "dayjs";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useProfileStore } from "@/store/modules/profile"; import { useProfileStore } from "@/store/modules/profile";
import { Trace } from "@/types/trace"; import { Trace } from "@/types/trace";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
const { t } = useI18n(); const { t } = useI18n();
const profileStore = useProfileStore(); const profileStore = useProfileStore();
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") => const appStore = useAppStoreWithOut();
dayjs(date).format(pattern);
const selectedKey = ref<string>(""); const selectedKey = ref<string>("");
async function selectTrace(item: Trace) { async function selectTrace(item: Trace) {

View File

@ -40,9 +40,16 @@ limitations under the License. -->
</a> </a>
</div> </div>
<div class="grey ell sm"> <div class="grey ell sm">
<span class="mr-10 sm">{{ dateFormat(i.startTime) }}</span> <span class="mr-10 sm">{{
dateFormat(i.startTime, appStore.utc)
}}</span>
<span class="mr-10 sm"> <span class="mr-10 sm">
{{ dateFormat(i.startTime + i.duration * 60 * 1000) }} {{
dateFormat(
i.startTime + i.duration * 60 * 1000,
appStore.utc
)
}}
</span> </span>
</div> </div>
</td> </td>
@ -71,7 +78,7 @@ limitations under the License. -->
<div class="mb-10 clear item"> <div class="mb-10 clear item">
<span class="g-sm-4 grey">{{ t("monitorTime") }}:</span> <span class="g-sm-4 grey">{{ t("monitorTime") }}:</span>
<span class="g-sm-8 wba"> <span class="g-sm-8 wba">
{{ dateFormat(selectedTask.startTime) }} {{ dateFormat(selectedTask.startTime, appStore.utc) }}
</span> </span>
</div> </div>
<div class="mb-10 clear item"> <div class="mb-10 clear item">
@ -113,7 +120,7 @@ limitations under the License. -->
<span class="mr-10 grey">{{ t("operationType") }}:</span> <span class="mr-10 grey">{{ t("operationType") }}:</span>
<span class="mr-20">{{ d.operationType }}</span> <span class="mr-20">{{ d.operationType }}</span>
<span class="mr-10 grey">{{ t("time") }}:</span> <span class="mr-10 grey">{{ t("time") }}:</span>
<span>{{ dateFormat(d.operationTime) }}</span> <span>{{ dateFormat(d.operationTime, appStore.utc) }}</span>
</div> </div>
</div> </div>
</div> </div>
@ -122,18 +129,18 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import dayjs from "dayjs";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
import { useProfileStore } from "@/store/modules/profile"; import { useProfileStore } from "@/store/modules/profile";
import { TaskLog, TaskListItem } from "@/types/profile"; import { TaskLog, TaskListItem } from "@/types/profile";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
const { t } = useI18n(); const { t } = useI18n();
const profileStore = useProfileStore(); const profileStore = useProfileStore();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") => const appStore = useAppStoreWithOut();
dayjs(date).format(pattern);
const viewDetail = ref<boolean>(false); const viewDetail = ref<boolean>(false);
const service = ref<string>(""); const service = ref<string>("");
const selectedTask = ref<TaskListItem | Record<string, never>>({}); const selectedTask = ref<TaskListItem | Record<string, never>>({});

View File

@ -57,7 +57,9 @@ limitations under the License. -->
<div> <div>
<div class="tag mr-5">{{ t("start") }}</div> <div class="tag mr-5">{{ t("start") }}</div>
<span class="mr-15 sm"> <span class="mr-15 sm">
{{ dateFormat(parseInt(traceStore.currentTrace.start)) }} {{
dateFormat(parseInt(traceStore.currentTrace.start), appStore.utc)
}}
</span> </span>
<div class="tag mr-5">{{ t("duration") }}</div> <div class="tag mr-5">{{ t("duration") }}</div>
<span class="mr-15 sm" <span class="mr-15 sm"
@ -120,7 +122,6 @@ limitations under the License. -->
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import dayjs from "dayjs";
import { ref, defineComponent, inject } from "vue"; import { ref, defineComponent, inject } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useTraceStore } from "@/store/modules/trace"; import { useTraceStore } from "@/store/modules/trace";
@ -130,6 +131,8 @@ import graphs from "./components/index";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
export default defineComponent({ export default defineComponent({
name: "TraceDetail", name: "TraceDetail",
@ -137,6 +140,7 @@ export default defineComponent({
...graphs, ...graphs,
}, },
setup() { setup() {
const appStore = useAppStoreWithOut();
/*global Recordable */ /*global Recordable */
const options: Recordable<LayoutConfig> = inject("options") || {}; const options: Recordable<LayoutConfig> = inject("options") || {};
const { t } = useI18n(); const { t } = useI18n();
@ -144,8 +148,6 @@ export default defineComponent({
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const traceId = ref<string>(""); const traceId = ref<string>("");
const displayMode = ref<string>("List"); const displayMode = ref<string>("List");
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern);
function handleClick() { function handleClick() {
copy(traceId.value || traceStore.currentTrace.traceIds[0].value); copy(traceId.value || traceStore.currentTrace.traceIds[0].value);
@ -180,6 +182,7 @@ export default defineComponent({
handleClick, handleClick,
t, t,
searchTraceLogs, searchTraceLogs,
appStore,
loading, loading,
traceId, traceId,
}; };

View File

@ -59,7 +59,7 @@ limitations under the License. -->
</div> </div>
<div class="grey ell sm"> <div class="grey ell sm">
<span class="tag mr-10 sm">{{ i.duration }} ms</span <span class="tag mr-10 sm">{{ i.duration }} ms</span
>{{ dateFormat(parseInt(i.start, 10)) }} >{{ dateFormat(parseInt(i.start, 10), appStore.utc) }}
</div> </div>
</td> </td>
</tr> </tr>
@ -70,7 +70,6 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import dayjs from "dayjs";
import { ref, computed } from "vue"; import { ref, computed } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useTraceStore } from "@/store/modules/trace"; import { useTraceStore } from "@/store/modules/trace";
@ -78,6 +77,8 @@ import { ElMessage } from "element-plus";
import { QueryOrders } from "../../data"; import { QueryOrders } from "../../data";
import { Option } from "@/types/app"; import { Option } from "@/types/app";
import { Trace } from "@/types/trace"; import { Trace } from "@/types/trace";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
const { t } = useI18n(); const { t } = useI18n();
const traceStore = useTraceStore(); const traceStore = useTraceStore();
@ -89,8 +90,7 @@ const total = computed(() =>
? pageSize.value * traceStore.conditions.paging.pageNum + 1 ? pageSize.value * traceStore.conditions.paging.pageNum + 1
: pageSize.value * traceStore.conditions.paging.pageNum : pageSize.value * traceStore.conditions.paging.pageNum
); );
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") => const appStore = useAppStoreWithOut();
dayjs(date).format(pattern);
function searchTrace() { function searchTrace() {
loading.value = true; loading.value = true;

View File

@ -62,7 +62,7 @@ limitations under the License. -->
<div v-for="(i, index) in currentSpan.logs" :key="index"> <div v-for="(i, index) in currentSpan.logs" :key="index">
<div class="mb-10 sm"> <div class="mb-10 sm">
<span class="mr-10">{{ t("time") }}:</span <span class="mr-10">{{ t("time") }}:</span
><span class="grey">{{ dateFormat(i.time) }}</span> ><span class="grey">{{ dateFormat(i.time, appStore.utc) }}</span>
</div> </div>
<div class="mb-15 clear" v-for="(_i, _index) in i.data" :key="_index"> <div class="mb-15 clear" v-for="(_i, _index) in i.data" :key="_index">
<div class="mb-10"> <div class="mb-10">
@ -86,10 +86,11 @@ limitations under the License. -->
import { inject } from "vue"; import { inject } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import type { PropType } from "vue"; import type { PropType } from "vue";
import dayjs from "dayjs";
import copy from "@/utils/copy"; import copy from "@/utils/copy";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
/*global defineProps, Recordable */ /*global defineProps, Recordable */
const options: Recordable<LayoutConfig> = inject("options") || {}; const options: Recordable<LayoutConfig> = inject("options") || {};
@ -97,8 +98,7 @@ const props = defineProps({
currentSpan: { type: Object as PropType<any>, default: () => ({}) }, currentSpan: { type: Object as PropType<any>, default: () => ({}) },
}); });
const { t } = useI18n(); const { t } = useI18n();
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") => const appStore = useAppStoreWithOut();
dayjs(date).format(pattern);
async function getTaceLogs() { async function getTaceLogs() {
const { associationWidget } = getDashboard(); const { associationWidget } = getDashboard();
associationWidget( associationWidget(

View File

@ -77,7 +77,7 @@ limitations under the License. -->
</el-tooltip> </el-tooltip>
</div> </div>
<div class="start-time"> <div class="start-time">
{{ dateFormat(data.startTime) }} {{ dateFormat(data.startTime, appStore.utc) }}
</div> </div>
<div class="exec-ms"> <div class="exec-ms">
{{ {{
@ -138,11 +138,12 @@ limitations under the License. -->
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import dayjs from "dayjs";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { ref, computed, defineComponent } from "vue"; import { ref, computed, defineComponent } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import SpanDetail from "../D3Graph/SpanDetail.vue"; import SpanDetail from "../D3Graph/SpanDetail.vue";
import { dateFormat } from "@/utils/dateFormat";
import { useAppStoreWithOut } from "@/store/modules/app";
const props = { const props = {
data: { type: Object as PropType<any>, default: () => ({}) }, data: { type: Object as PropType<any>, default: () => ({}) },
@ -156,11 +157,10 @@ export default defineComponent({
emits: ["select"], emits: ["select"],
components: { SpanDetail }, components: { SpanDetail },
setup(props, { emit }) { setup(props, { emit }) {
const appStore = useAppStoreWithOut();
const displayChildren = ref<boolean>(true); const displayChildren = ref<boolean>(true);
const showDetail = ref<boolean>(false); const showDetail = ref<boolean>(false);
const { t } = useI18n(); const { t } = useI18n();
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern);
const selfTime = computed(() => (props.data.dur ? props.data.dur : 0)); const selfTime = computed(() => (props.data.dur ? props.data.dur : 0));
const execTime = computed(() => const execTime = computed(() =>
props.data.endTime - props.data.startTime props.data.endTime - props.data.startTime
@ -239,6 +239,7 @@ export default defineComponent({
selectedItem, selectedItem,
viewSpan, viewSpan,
t, t,
appStore,
}; };
}, },
}); });