chore: initialize qiming workspace repository
This commit is contained in:
114
qiming-mobile/uni_modules/uni-ai-x/components/msg-tool-bar.uvue
Normal file
114
qiming-mobile/uni_modules/uni-ai-x/components/msg-tool-bar.uvue
Normal file
@@ -0,0 +1,114 @@
|
||||
<template>
|
||||
<view class="tool-bar-container">
|
||||
<text class="iconfont icon-Copy btn" @tap="copy"></text>
|
||||
<text class="time">{{createTime}}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="uts" setup>
|
||||
import { MsgItem } from '@/uni_modules/uni-ai-x/sdk';
|
||||
import { formatTimeAgo } from '@/utils/common';
|
||||
import { useI18n } from '@/utils/i18n';
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
// 使用 ref 来存储时间,自动更新时间
|
||||
const createTime = ref<string>('')
|
||||
|
||||
const props = defineProps<{
|
||||
msg: MsgItem
|
||||
}>()
|
||||
|
||||
const msg = computed<MsgItem>(() => props.msg as MsgItem)
|
||||
|
||||
// 更新时间的函数
|
||||
const updateTime = () => {
|
||||
createTime.value = formatTimeAgo(msg.value.create_time)
|
||||
}
|
||||
|
||||
// 定时器ID
|
||||
let timerId: number | null = null
|
||||
|
||||
// 启动定时器,每分钟更新一次
|
||||
const startTimer = () => {
|
||||
// 立即更新一次
|
||||
updateTime()
|
||||
// 每分钟更新一次(60000毫秒)
|
||||
timerId = setInterval(() => {
|
||||
updateTime()
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
// 停止定时器
|
||||
const stopTimer = () => {
|
||||
if (timerId !== null) {
|
||||
clearInterval(timerId)
|
||||
timerId = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
startTimer()
|
||||
})
|
||||
|
||||
// 组件卸载时清理定时器
|
||||
onUnmounted(() => {
|
||||
stopTimer()
|
||||
})
|
||||
|
||||
const copy = () => {
|
||||
// 兼容性处理
|
||||
const text = msg.value.text || msg.value.body
|
||||
if (typeof text != 'string') {
|
||||
uni.showToast({
|
||||
title: t('Mobile.ThirdParty.UniAiX.invalidMessageContent'),
|
||||
icon: 'none',
|
||||
})
|
||||
return
|
||||
}
|
||||
uni.setClipboardData({
|
||||
data: text as string,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: t('Mobile.Common.copySuccess'),
|
||||
icon: 'success',
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({
|
||||
title: t('Mobile.Common.copyFailed'),
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.tool-bar-container {
|
||||
width: 100%;
|
||||
padding: 8rpx 0 16rpx 0;
|
||||
margin-top: 16rpx;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.btn {
|
||||
font-size: 36rpx;
|
||||
margin-right: 32rpx;
|
||||
// #ifdef WEB
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
filter: brightness(0.8);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
.time {
|
||||
margin-left: auto;
|
||||
font-size: 28rpx;
|
||||
color: rgba(0, 0, 0, 0.45);
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user