| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
- <view>
- <cu-custom bgImage="/static/bg.png" :isBack="true">
- <template v-slot:content>
- <text class="text-black">消息转发</text>
- </template>
- </cu-custom>
- <scroll-view scroll-x style="margin: 30upx 20upx;white-space: nowrap;">
- <user-avatar style="width: 168upx" @tap="sendHandle(chat.id,chat.type)" v-for="(chat, index) in chatStore.chats" :key="index" :chat="chat"/>
- </scroll-view>
- <index-bar :index-map="map">
- <view v-for="(item,key) in map.keys()" :key="key">
- <view :class="'indexItem-' + item" :id="'indexes-' + item" :data-index="item">
- <view class="padding">{{ item }}</view>
- <view class="cu-list menu-avatar no-padding">
- <view class="cu-item" v-for="(item) in map.get(item)" :key="item.id"
- :data-target="'move-box-' + item.id" @tap="sendHandle(item.id,item.type)">
- <image class="cu-avatar radius lg" :src="item.avatar"></image>
- <view class="content">
- <view class="text-grey">{{ item.name }}</view>
- <view class="text-gray text-sm">
- {{ item.name }}
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </index-bar>
- </view>
- </template>
- <script setup lang="ts">
- import {ref} from "vue";
- import FriendApi from "@/api/FriendApi";
- import Tools from "@/utils/Tools";
- import CuCustom from '@/colorui/components/cu-custom.vue'
- import UserAvatar from '@/components/UserAvatar.vue'
- import {useChatStore} from "@/store/chatStore";
- import {useUserStore} from "@/store/userStore";
- import type Message from "@/mode/Message";
- import ChatType from "@/utils/ChatType";
- import type ChatSimple from "@/mode/ChatSimple";
- import type User from "@/mode/User";
- import GroupApi from "@/api/GroupApi";
- import type Group from "@/mode/Group";
- import IndexBar from '@/components/IndexBar.vue'
- import {useWsStore} from "@/store/WsStore";
- import MessageUtils from "@/utils/MessageUtils";
- import {useMessageStore} from "@/store/messageStore";
- import {storeToRefs} from "pinia";
- import {onLoad} from "@dcloudio/uni-app";
- import MessageType from "@/utils/MessageType";
- import Auth from "@/api/Auth";
- const fontValue=ref(Auth.getfontSize());
- const chatStore = useChatStore();
- const userStore = useUserStore();
- const messageStore = useMessageStore();
- const currentUser = userStore.getUser();
- const map = ref(new Map());
- const hidden = ref(true);
- const multiple = ref(false);
- const wsStore = useWsStore();
- const {checkList} = storeToRefs(useMessageStore())
- //可以转发的对象
- const items = ref<ChatSimple[]>([]);
- onLoad((opt) => {
- console.log(opt)
- console.log(opt?.multiple)
- console.log(typeof opt?.multiple)
- if (opt?.multiple === 'true') {
- multiple.value = true;
- }
- });
- const loadData = () => {
- FriendApi.friends().then((res) => {
- items.value = res.data.map((item: User) => {
- return {id: item.id, name: item.name, avatar: item.avatar, type: ChatType.FRIEND,}
- })
- return GroupApi.list()
- }).then((res) => {
- items.value.push(...res.data.map((item: Group) => {
- return {id: item.id, name: item.name, avatar: item.avatar, type: ChatType.GROUP,}
- }))
- map.value = Tools.listToMap(items.value);
- });
- };
- const sendHandle = (id: string, type: string) => {
- if (currentUser) {
- if (!multiple.value) {
- checkList.value.forEach((message: Message) => {
- let msg: Message = {
- messageType: message.messageType,
- chatId: id,
- fromId: currentUser.id,
- content: message.content,
- type: type,
- extend: message.extend
- };
- wsStore.sendMessage(msg);
- })
- messageStore.setCheckList([])
- messageStore.setShowMultipleCheck(false)
- MessageUtils.message('已经转发')
- uni.navigateBack()
- }else {
- const message0 = checkList.value[0]
- const fromId = message0?.fromId
- const toId = message0?.chatId
- let showName = '群聊'
- if(message0.type === ChatType.FRIEND && fromId && toId){
- showName = userStore.getMapUser(fromId)?.name + '和' + userStore.getMapUser(toId)?.name
- }
- //按照id排序checkList.value
- checkList.value.sort((a, b) => a!.id - b!.id)
- const message: Message = {
- messageType: MessageType.forward,
- content: `${showName}的聊天记录`,
- chatId: id,
- fromId: currentUser.id,
- type: type,
- mine: false,
- timestamp: new Date().getTime(),
- extend: {
- messageList: checkList.value
- }
- }
- wsStore.sendMessage(message)
- messageStore.setCheckList([])
- messageStore.setShowMultipleCheck(false)
- MessageUtils.message('已经转发')
- uni.navigateBack()
- }
- }
- };
- loadData();
- </script>
- <style scoped></style>
|