flat: 图片优化

This commit is contained in:
史典卓
2025-03-28 18:19:05 +08:00
parent 68e78d9624
commit b8ee5e7c17
43 changed files with 151 additions and 38 deletions

View File

@@ -433,6 +433,12 @@ function parseQueryParams(url = window.location.href) {
return params; return params;
} }
function formatFileSize(bytes) {
if (bytes < 1024) return bytes + ' B'
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB'
else if (bytes < 1024 * 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(2) + ' MB'
else return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB'
}
export const $api = { export const $api = {
msg, msg,
prePage, prePage,
@@ -442,7 +448,8 @@ export const $api = {
streamRequest, streamRequest,
chatRequest, chatRequest,
insertSortData, insertSortData,
uploadFile uploadFile,
formatFileSize
} }
export default { export default {

View File

@@ -122,9 +122,18 @@
<!-- btn --> <!-- btn -->
<CollapseTransition :show="showfile"> <CollapseTransition :show="showfile">
<view class="area-file"> <view class="area-file">
<image class="file-img" @click="uploadCamera" src="/static/icon/carmreupload.png"></image> <view class="file-card" @click="uploadCamera">
<image class="file-img" @click="getUploadFile" src="/static/icon/fileupload.png"></image> <image class="card-img" src="/static/icon/file1.png"></image>
<image class="file-img" @click="uploadCamera('album')" src="/static/icon/imgupload.png"></image> <text>拍照上传</text>
</view>
<view class="file-card" @click="uploadCamera('album')">
<image class="card-img" src="/static/icon/file2.png"></image>
<text>相册上传</text>
</view>
<view class="file-card" @click="getUploadFile">
<image class="card-img" src="/static/icon/file3.png"></image>
<text>文件上传</text>
</view>
</view> </view>
</CollapseTransition> </CollapseTransition>
@@ -132,20 +141,26 @@
<view class="area-uploadfiles" v-if="filesList.length"> <view class="area-uploadfiles" v-if="filesList.length">
<scroll-view class="uploadfiles-scroll" scroll-x="true"> <scroll-view class="uploadfiles-scroll" scroll-x="true">
<view class="uploadfiles-list"> <view class="uploadfiles-list">
<view class="file-uploadsend" v-for="(file, index) in filesList" :key="index"> <view
class="file-uploadsend"
:class="{ 'file-border': isImage(file.type) }"
v-for="(file, index) in filesList"
:key="index"
>
<image <image
class="file-icon" class="file-iconImg"
@click="jumpUrl(file)" @click="jumpUrl(file)"
v-if="isImage(file.type)" v-if="isImage(file.type)"
src="/static/icon/image.png" :src="file.url"
></image> ></image>
<image <view class="file-doc" @click="jumpUrl(file)" v-else>
class="file-icon" <view style="width: 100%">
@click="jumpUrl(file)" <view class="filename-text">{{ file.name }}</view>
v-if="isFile(file.type)" <view class="filename-size">{{ file.size }}</view>
src="/static/icon/doc.png" </view>
></image> <FileIcon :type="file.type"></FileIcon>
<text class="filename-text">{{ file.name }}</text> <!-- <image class="file-icon" @click="jumpUrl(file)" :src=""></image> -->
</view>
<view class="file-del" catchtouchmove="true" @click="delfile(file)"> <view class="file-del" catchtouchmove="true" @click="delfile(file)">
<uni-icons type="closeempty" color="#4B4B4B" size="10"></uni-icons> <uni-icons type="closeempty" color="#4B4B4B" size="10"></uni-icons>
</view> </view>
@@ -169,6 +184,7 @@ const { messages, isTyping, textInput, chatSessionID } = storeToRefs(useChatGrou
import CollapseTransition from '@/components/CollapseTransition/CollapseTransition.vue'; import CollapseTransition from '@/components/CollapseTransition/CollapseTransition.vue';
import FadeView from '@/components/FadeView/FadeView.vue'; import FadeView from '@/components/FadeView/FadeView.vue';
import AudioWave from './AudioWave.vue'; import AudioWave from './AudioWave.vue';
import FileIcon from './fileIcon.vue';
import { useAudioRecorder } from '@/hook/useRealtimeRecorder.js'; import { useAudioRecorder } from '@/hook/useRealtimeRecorder.js';
const { isRecording, recognizedText, startRecording, stopRecording, cancelRecording } = useAudioRecorder( const { isRecording, recognizedText, startRecording, stopRecording, cancelRecording } = useAudioRecorder(
@@ -245,14 +261,16 @@ const sendMessageGuess = (item) => {
const delfile = (file) => { const delfile = (file) => {
uni.showModal({ uni.showModal({
content: '确认删除文件?', content: '确认删除文件?',
success() { success(res) {
filesList.value = filesList.value.filter((item) => item.url !== file.url); if (res.confirm) {
if (!filesList.value.length) { filesList.value = filesList.value.filter((item) => item.url !== file.url);
if (textInput.value === state.uploadFileTips) { if (!filesList.value.length) {
textInput.value = ''; if (textInput.value === state.uploadFileTips) {
textInput.value = '';
}
} }
$api.msg('附件删除成功');
} }
$api.msg('附件删除成功');
}, },
}); });
}; };
@@ -289,12 +307,16 @@ function getGuess() {
}); });
} }
function isImage(fileNmae) { function isImage(type) {
return new RegExp('image').test(fileNmae); return new RegExp('image').test(type);
} }
function isFile(fileNmae) { function isFile(type) {
return new RegExp('custom-doc').test(fileNmae); const allowedTypes = config.allowedFileTypes || [];
if (!allowedTypes.includes(type)) {
return false;
}
return true;
} }
function jumpUrl(file) { function jumpUrl(file) {
@@ -347,6 +369,7 @@ function getUploadFile(type = 'camera') {
const tempFilePaths = res.tempFilePaths; const tempFilePaths = res.tempFilePaths;
const file = res.tempFiles[0]; const file = res.tempFiles[0];
const allowedTypes = config.allowedFileTypes || []; const allowedTypes = config.allowedFileTypes || [];
const size = $api.formatFileSize(file.size);
if (!allowedTypes.includes(file.type)) { if (!allowedTypes.includes(file.type)) {
return $api.msg('仅支持 txt md html word pdf ppt csv excel 格式类型'); return $api.msg('仅支持 txt md html word pdf ppt csv excel 格式类型');
} }
@@ -355,8 +378,9 @@ function getUploadFile(type = 'camera') {
resData = JSON.parse(resData); resData = JSON.parse(resData);
filesList.value.push({ filesList.value.push({
url: resData.msg, url: resData.msg,
type: 'custom-doc', type: file.type,
name: file.name, name: file.name,
size: size,
}); });
textInput.value = state.uploadFileTips; textInput.value = state.uploadFileTips;
}); });
@@ -605,7 +629,7 @@ image-margin-top = 40rpx
padding: 20rpx; padding: 20rpx;
} }
.input-area { .input-area {
padding: 32rpx; padding: 32rpx 28rpx 24rpx 28rpx;
position: relative; position: relative;
background: #FFFFFF; background: #FFFFFF;
box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(11,44,112,0.06); box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(11,44,112,0.06);
@@ -697,13 +721,28 @@ image-margin-top = 40rpx
width: 100% width: 100%
grid-template-columns: repeat(3, 1fr) grid-template-columns: repeat(3, 1fr)
grid-gap: 20rpx grid-gap: 20rpx
padding: 20rpx 0 0 0; padding: 32rpx 0 0 0;
.file-img .file-card
height: 179rpx display: flex
width: 100% flex-direction: column
align-items: center
padding: 24rpx 0
background: #F5F5F5;
border-radius: 20rpx 20rpx 20rpx 20rpx;
text
font-size: 24rpx
font-weight: 500
color: #000000
padding-top: 8rpx
.card-img
height: 56rpx
width: 56rpx
.file-card:active
background: #e8e8e8
.area-uploadfiles .area-uploadfiles
position: absolute position: absolute
top: -100rpx top: -180rpx
width: calc(100% - 40rpx) width: calc(100% - 40rpx)
background: #FFFFFF background: #FFFFFF
left: 0 left: 0
@@ -715,18 +754,21 @@ image-margin-top = 40rpx
height: 100% height: 100%
display: flex display: flex
flex-wrap: nowrap flex-wrap: nowrap
.file-uploadsend .file-doc
display: flex display: flex
flex-wrap: nowrap flex-direction: column
justify-content: center align-items: flex-start
align-items: center justify-content: space-between
padding: 16rpx 20rpx 18rpx 20rpx
height: calc(100% - 40rpx)
.file-uploadsend
margin: 10rpx 18rpx 0 10rpx; margin: 10rpx 18rpx 0 10rpx;
height: 100% height: 100%
border-radius: 30rpx border-radius: 30rpx
font-size: 24rpx font-size: 24rpx
position: relative position: relative
width: 218rpx; width: 360rpx;
height: 80rpx; height: 160rpx;
border-radius: 12rpx 12rpx 12rpx 12rpx; border-radius: 12rpx 12rpx 12rpx 12rpx;
border: 2rpx solid #E2E2E2; border: 2rpx solid #E2E2E2;
.file-del .file-del
@@ -751,13 +793,27 @@ image-margin-top = 40rpx
text-overflow: ellipsis text-overflow: ellipsis
white-space: nowrap white-space: nowrap
color: #333333 color: #333333
font-size: 24rpx
flex: 1 flex: 1
font-weight: 500 font-weight: 500
max-width: 100% max-width: 100%
.filename-size
overflow: hidden
text-overflow: ellipsis
white-space: nowrap
color: #7B7B7B;
flex: 1
max-width: 100%
.file-icon .file-icon
height: 40rpx height: 40rpx
width: 40rpx width: 40rpx
margin: 0 18rpx 0 18rpx .file-iconImg
height: 100%
width: 100%
border-radius: 15rpx
.file-border
width: 160rpx;
border: 0
@keyframes ai-circle { @keyframes ai-circle {
0% { 0% {

View File

@@ -0,0 +1,50 @@
<template>
<image v-if="type === 'application/pdf'" :src="pdfIcon" class="file-icon" />
<image
v-else-if="
type === 'application/msword' ||
type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
"
:src="docIcon"
class="file-icon"
/>
<image
v-else-if="
type === 'application/vnd.ms-powerpoint' ||
type === 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
"
:src="pptIcon"
class="file-icon"
/>
<image v-else-if="type === 'text/markdown'" :src="mdIcon" class="file-icon" />
<image v-else-if="type === 'text/plain'" :src="txtIcon" class="file-icon" />
<image v-else-if="type === 'text/html'" :src="htmlIcon" class="file-icon" />
<image
v-else-if="
type === 'application/vnd.ms-excel' ||
type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
"
:src="excelIcon"
class="file-icon"
/>
<image v-else :src="otherIcon" class="file-icon" />
</template>
<script setup>
import pdfIcon from '@/static/file/pdf.png';
import docIcon from '@/static/file/doc.png';
import pptIcon from '@/static/file/ppt.png';
import mdIcon from '@/static/file/md.png';
import txtIcon from '@/static/file/txt.png';
import htmlIcon from '@/static/file/html.png';
import excelIcon from '@/static/file/excel.png';
import otherIcon from '@/static/file/other.png';
const props = defineProps({
type: String,
});
const type = props.type;
</script>
<style></style>

BIN
static/.DS_Store vendored

Binary file not shown.

BIN
static/file/csv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B

BIN
static/file/doc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
static/file/excel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
static/file/html.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

BIN
static/file/md.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

BIN
static/file/other.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

BIN
static/file/pdf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

BIN
static/file/ppt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

BIN
static/file/txt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
static/icon/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 700 B

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 B

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 469 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 B

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 B

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 691 B

BIN
static/icon/file1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

BIN
static/icon/file2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

BIN
static/icon/file3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 791 B

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 807 B

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 1008 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 847 B

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 474 B

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 419 B

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 984 B

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.